Package ariba.util.core

Examples of ariba.util.core.FastStringBuffer


        return classForName;
    }

    public static String getString (Reader reader)
    {
        FastStringBuffer stringBuffer = new FastStringBuffer();
        char charBuf[] = new char[CharBufSize];
        int actualReadCount = 0;
        try {
            while ((actualReadCount = reader.read(charBuf, 0, CharBufSize)) != -1) {
                stringBuffer.appendCharRange(charBuf, 0, actualReadCount);
            }
        }
        catch (IOException exception) {
            throw new AWGenericException("Error while converting stream to string. ", exception);
        }
        return stringBuffer.toString();
    }
View Full Code Here


        int occurrences = StringUtil.occurs(originalString, markerString);
        if (occurrences == 0) {
            return(originalString);
        }
        int newLength = originalStringLength + (occurrences * replaceStringLength);
        FastStringBuffer buf = new FastStringBuffer(newLength);

        int oldoffset = 0;
        int offset = originalString.indexOf(markerString, 0);
        while (offset != -1) {
            buf.appendStringRange(originalString, oldoffset, offset);
            buf.append(replaceString);
            offset += markerStringLength;
            oldoffset = offset;
            offset = originalString.indexOf(markerString, offset);
        }
        buf.appendStringRange(originalString, oldoffset, originalStringLength);

        return buf.toString();
    }
View Full Code Here

            }
            else {
                if (buf == null) {
                    /* we already know that we need extra chars,
                    so create the buffer with len greater than orginal chars*/
                    buf = new FastStringBuffer((statusText.length() + 10));
                }
                buf.appendStringRange(statusText, preIndex, i);
                buf.append(escape);
                preIndex = (i+1);
            }
View Full Code Here

        return buf;
    }

    public static String XMLEncode (String statusText)
    {
        FastStringBuffer buf = XMLEncode(statusText, null);
        if (buf == null) {
            return statusText;
        }
        return buf.toString();
    }
View Full Code Here

    protected static void recordRequest (AWRequest request, OutputStream output)
      throws IOException
    {

        FastStringBuffer sb = new FastStringBuffer();
        sb.append(request.method());
        sb.append(" ");
        sb.append(request.uri());
        sb.append("?");
        sb.append(request.queryString());
        sb.append(" ");
        sb.append("HTTP/1.1");
        sb.append(Newline);

        output.write(sb.toString().getBytes(I18NUtil.EncodingUTF8));
        writeHeaders(request, output);
        output.write(Newline.getBytes(I18NUtil.EncodingUTF8));

        byte[] content = request.content();
        if (content != null) {
View Full Code Here

    private static byte[] semanticKeyTableBytes (AWResponse response)
    {
        byte[] semanticKeys = response._debugGetSemanticKeyMapping();
        if (semanticKeys == null) {
            Map semanticKeyToElementIdTable = getSemanticKeyToElementIdMappingIfAny(response);
            FastStringBuffer buffer = new FastStringBuffer();
            buffer.append(MappingSectionStartMark);
            buffer.append(Newline);
            Iterator keys = semanticKeyToElementIdTable.keySet().iterator();
            while (keys.hasNext()) {
                SemanticKey semanticKey = (SemanticKey)keys.next();
                Object elementId = semanticKeyToElementIdTable.get(semanticKey);
                buffer.append(AWRecordingManager.SemanticKeyMark);
                buffer.append(AWConstants.Colon.toString());
                buffer.append(semanticKey.uniqueKey());
                buffer.append(Equal);
                buffer.append(elementId.toString());
                buffer.append(Newline);
            }
            buffer.append(MappingSectionEndMark);
            try {
                semanticKeys = buffer.toString().getBytes(I18NUtil.EncodingUTF8);
            }
            catch (IOException ex) {
                throw new WrapperRuntimeException(ex);
            }
View Full Code Here

        return groovyClassForBody(packageName, className, scName, body);
    }

    public Class componentSubclass(String name, AWTemplate template)
    {
        final FastStringBuffer buf = new FastStringBuffer();

        // Get <groovy> tag content
        AWUtil.iterate(template, new AWUtil.ElementIterator() {
            public Object process(AWElement e) {
                if (e instanceof AWXGroovyTag) {
                    buf.append(((AWXGroovyTag)e).scriptString());
                }
                return null; // keep looking
            }
        });
        // Generate code for expression bindings
    /* Disable groovy expression in favor of util.expr expressions...
        buf.append("\n// Expression Binding generated accessors ---- \n ");
        AWUtil.iterate(template, new AWUtil.ElementIterator() {
            public Object process(AWElement e) {
               if (e instanceof AWBindable) {
                    AWBindable reference = ((AWBindable)e);
                    String prefix = reference.tagName(); // componentDefinition().componentName().replace('.','_');
                    processBindings(prefix, reference.allBindings(), buf);
                }
                return null; // keep looking
            }
        });
    */

        String string = buf.toString();
        return groovyClassForBody("ariba.ui.demoshell.demo",
                                  name.replace('.', '_').replace('-', '_'),
                                  "ariba.ui.demoshell.AWXHTMLComponent",
                                   string);
    }
View Full Code Here

    private static Pattern ClassDeclPattern = Pattern.compile("\\s*class\\s+(\\w+)\\s+extends\\s+([\\w\\.]+)\\s*");
    private static Pattern ImportDeclPattern = Pattern.compile("(\\s*import\\s+[\\w\\.]+\\*?[\\s\\;]*)+");

    protected Class groovyClassForBody (String packageName, String name, String parentClassName, String bodyString)
    {
        final FastStringBuffer buf = new FastStringBuffer();
        String className = uniqueName(name, _classesByName);
        String classString;

        // support for scripts where we don't wrap it -- i.e. where script sets own parent class, imports, etc
        // and can include multiple classes in single file.
        Matcher m = ClassDeclPattern.matcher(bodyString);
        if (m.find()) {
            String theirName = m.group(1);
            String theirSuper = m.group(2);
            classString = m.replaceFirst(Fmt.S("\n\nclass %s extends %s ", className, theirSuper));
        } else {
            String extraImports = "";
            m = ImportDeclPattern.matcher(bodyString);
            if (m.find() && m.start() < 2) {
                extraImports = m.group(0);
                bodyString = m.replaceFirst("");
            }

            classString = Fmt.S("package %s\n%s%s\nclass %s extends %s {\n %s \n}",
                    packageName,
                    "import ariba.ui.aribaweb.core.*;import ariba.ui.widgets.*;import ariba.ui.table.*;import ariba.ui.outline.*;import ariba.util.core.*;",
                    extraImports, className, parentClassName, bodyString);
        }

        // use groovy class loader to load class as necessary...
        GroovyClassLoader gcl = AWGroovyLoader.gcl();

        Log.aribaweb.debug("--- Generating class: %s", className);
        // classString += "\n\n class C2 { def test () { return \"Yeah!\" }; } \n";

        Class cls;
        try {
            cls = gcl.parseClass(classString, className+".groovy");
        } catch (Exception e) {
            FastStringBuffer lineBuf = new FastStringBuffer();
            String[] lines = classString.split("\n");
            for (int i=0; i < lines.length; i++) {
                lineBuf.append(Integer.toString(i+1));
                lineBuf.append(": ");
                lineBuf.append(lines[i]);
                lineBuf.append("\n");
            }
            throw new AWGenericException(Fmt.S("Exception parsing groovy for class %s: %s\n%s", className,
                    e.getMessage(), lineBuf.toString()));
        }
        _classesByName.put(className, cls);
        return cls;
    }
View Full Code Here

            throw new AWGenericException(
                "Invalid formValuesString -- contains escaped html: " +
                formValuesString);
        }
        Parameters parameters = new Parameters();
        FastStringBuffer buffer = new FastStringBuffer();
        StringTokenizer tokens = new StringTokenizer(formValuesString, "&");
        while (tokens.hasMoreTokens()) {
            String keyValuePair = tokens.nextToken();
            int pos = keyValuePair.indexOf('=');
            if (pos == -1) {
View Full Code Here

     * @aribaapi private
     */
    protected final void addCurrentRequestParams (AWRequestContext requestContext,
                                                  AWRedirect redirect)
    {
        FastStringBuffer url = new FastStringBuffer(redirect.url());

        Iterator keys = requestContext.formValues().keySet().iterator();
        while (keys.hasNext()) {
            String key = (String)keys.next();
            addQueryParam(url,key,requestContext.formValueForKey(key));
        }

        redirect.setUrl(url.toString());
    }
View Full Code Here

TOP

Related Classes of ariba.util.core.FastStringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.