Search in sources :

Example 21 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project j2objc by google.

the class OutputProperties method getQNameProperties.

/**
   * Searches for the list of qname properties with the specified key in
   * the property list.
   * If the key is not found in this property list, the default property list,
   * and its defaults, recursively, are then checked. The method returns
   * <code>null</code> if the property is not found.
   *
   * @param   key   the property key.
   * @param props the list of properties to search in.
   * @return  the value in this property list as a vector of QNames, or false
   * if null or not "yes".
   */
public static Vector getQNameProperties(String key, Properties props) {
    String s = props.getProperty(key);
    if (null != s) {
        Vector v = new Vector();
        int l = s.length();
        boolean inCurly = false;
        FastStringBuffer buf = new FastStringBuffer();
        // which theoretically shouldn't happen if they contain legal URLs.
        for (int i = 0; i < l; i++) {
            char c = s.charAt(i);
            if (Character.isWhitespace(c)) {
                if (!inCurly) {
                    if (buf.length() > 0) {
                        QName qname = QName.getQNameFromString(buf.toString());
                        v.addElement(qname);
                        buf.reset();
                    }
                    continue;
                }
            } else if ('{' == c)
                inCurly = true;
            else if ('}' == c)
                inCurly = false;
            buf.append(c);
        }
        if (buf.length() > 0) {
            QName qname = QName.getQNameFromString(buf.toString());
            v.addElement(qname);
            buf.reset();
        }
        return v;
    } else
        return null;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer) QName(org.apache.xml.utils.QName) Vector(java.util.Vector)

Example 22 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project j2objc by google.

the class OutputProperties method setQNameProperties.

/**
   * Set an output property with a QName list value.  The QNames will be turned
   * into strings with the namespace in curly brackets.
   *
   * @param key the key to be placed into the property list.
   * @param v non-null list of QNames corresponding to <tt>key</tt>.
   * @see javax.xml.transform.OutputKeys
   */
public void setQNameProperties(String key, Vector v) {
    int s = v.size();
    // Just an initial guess at reasonable tuning parameters
    FastStringBuffer fsb = new FastStringBuffer(9, 9);
    for (int i = 0; i < s; i++) {
        QName qname = (QName) v.elementAt(i);
        fsb.append(qname.toNamespacedString());
        // Don't append space after last value
        if (i < s - 1)
            fsb.append(' ');
    }
    m_properties.put(key, fsb.toString());
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer) QName(org.apache.xml.utils.QName)

Example 23 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project j2objc by google.

the class ElemNumber method formatNumberList.

/**
   * Format a vector of numbers into a formatted string.
   * 
   * @param transformer non-null reference to the the current transform-time state.
   * @param list Array of one or more long integer numbers.
   * @param contextNode The node that "." expresses.
   * @return String that represents list according to
   * %conversion-atts; attributes.
   * TODO: Optimize formatNumberList so that it caches the last count and
   * reuses that info for the next count.
   *
   * @throws TransformerException
   */
String formatNumberList(TransformerImpl transformer, long[] list, int contextNode) throws TransformerException {
    String numStr;
    FastStringBuffer formattedNumber = StringBufferPool.get();
    try {
        int nNumbers = list.length, numberWidth = 1;
        char numberType = '1';
        String formatToken, lastSepString = null, formatTokenString = null;
        // If a seperator hasn't been specified, then use "."  
        // as a default separator. 
        // For instance: [2][1][5] with a format value of "1 "
        // should format to "2.1.5 " (I think).
        // Otherwise, use the seperator specified in the format string.
        // For instance: [2][1][5] with a format value of "01-001. "
        // should format to "02-001-005 ".
        String lastSep = ".";
        // true if first token  
        boolean isFirstToken = true;
        String formatValue = (null != m_format_avt) ? m_format_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
        if (null == formatValue)
            formatValue = "1";
        NumberFormatStringTokenizer formatTokenizer = new NumberFormatStringTokenizer(formatValue);
        // Loop through all the numbers in the list.
        for (int i = 0; i < nNumbers; i++) {
            // Loop to the next digit, letter, or separator.
            if (formatTokenizer.hasMoreTokens()) {
                formatToken = formatTokenizer.nextToken();
                // it is a number format directive.
                if (Character.isLetterOrDigit(formatToken.charAt(formatToken.length() - 1))) {
                    numberWidth = formatToken.length();
                    numberType = formatToken.charAt(numberWidth - 1);
                } else // then append the formatToken.
                if (formatTokenizer.isLetterOrDigitAhead()) {
                    formatTokenString = formatToken;
                    // should format to "2--1--5. " (I guess).
                    while (formatTokenizer.nextIsSep()) {
                        formatToken = formatTokenizer.nextToken();
                        formatTokenString += formatToken;
                    }
                    // should format to "2-1-5 ".
                    if (!isFirstToken)
                        lastSep = formatTokenString;
                    // Since we know the next is a number or digit, we get it now.
                    formatToken = formatTokenizer.nextToken();
                    numberWidth = formatToken.length();
                    numberType = formatToken.charAt(numberWidth - 1);
                } else // only separators left
                {
                    // Set up the string for the trailing characters after 
                    // the last number is formatted (i.e. after the loop).
                    lastSepString = formatToken;
                    // And append any remaining characters to the lastSepString.
                    while (formatTokenizer.hasMoreTokens()) {
                        formatToken = formatTokenizer.nextToken();
                        lastSepString += formatToken;
                    }
                }
            // else
            }
            // should format to "(2-1-5.) " (I guess).
            if (null != formatTokenString && isFirstToken) {
                formattedNumber.append(formatTokenString);
            } else if (null != lastSep && !isFirstToken)
                formattedNumber.append(lastSep);
            getFormattedNumber(transformer, contextNode, numberType, numberWidth, list[i], formattedNumber);
            // After the first pass, this should be false
            isFirstToken = false;
        }
        // Skip past all remaining letters or digits
        while (formatTokenizer.isLetterOrDigitAhead()) {
            formatTokenizer.nextToken();
        }
        if (lastSepString != null)
            formattedNumber.append(lastSepString);
        while (formatTokenizer.hasMoreTokens()) {
            formatToken = formatTokenizer.nextToken();
            formattedNumber.append(formatToken);
        }
        numStr = formattedNumber.toString();
    } finally {
        StringBufferPool.free(formattedNumber);
    }
    return numStr;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 24 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class ElemNumber method formatNumberList.

/**
   * Format a vector of numbers into a formatted string.
   * 
   * @param transformer non-null reference to the the current transform-time state.
   * @param list Array of one or more long integer numbers.
   * @param contextNode The node that "." expresses.
   * @return String that represents list according to
   * %conversion-atts; attributes.
   * TODO: Optimize formatNumberList so that it caches the last count and
   * reuses that info for the next count.
   *
   * @throws TransformerException
   */
String formatNumberList(TransformerImpl transformer, long[] list, int contextNode) throws TransformerException {
    String numStr;
    FastStringBuffer formattedNumber = StringBufferPool.get();
    try {
        int nNumbers = list.length, numberWidth = 1;
        char numberType = '1';
        String formatToken, lastSepString = null, formatTokenString = null;
        // If a seperator hasn't been specified, then use "."  
        // as a default separator. 
        // For instance: [2][1][5] with a format value of "1 "
        // should format to "2.1.5 " (I think).
        // Otherwise, use the seperator specified in the format string.
        // For instance: [2][1][5] with a format value of "01-001. "
        // should format to "02-001-005 ".
        String lastSep = ".";
        // true if first token  
        boolean isFirstToken = true;
        String formatValue = (null != m_format_avt) ? m_format_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
        if (null == formatValue)
            formatValue = "1";
        NumberFormatStringTokenizer formatTokenizer = new NumberFormatStringTokenizer(formatValue);
        // Loop through all the numbers in the list.
        for (int i = 0; i < nNumbers; i++) {
            // Loop to the next digit, letter, or separator.
            if (formatTokenizer.hasMoreTokens()) {
                formatToken = formatTokenizer.nextToken();
                // it is a number format directive.
                if (Character.isLetterOrDigit(formatToken.charAt(formatToken.length() - 1))) {
                    numberWidth = formatToken.length();
                    numberType = formatToken.charAt(numberWidth - 1);
                } else // then append the formatToken.
                if (formatTokenizer.isLetterOrDigitAhead()) {
                    formatTokenString = formatToken;
                    // should format to "2--1--5. " (I guess).
                    while (formatTokenizer.nextIsSep()) {
                        formatToken = formatTokenizer.nextToken();
                        formatTokenString += formatToken;
                    }
                    // should format to "2-1-5 ".
                    if (!isFirstToken)
                        lastSep = formatTokenString;
                    // Since we know the next is a number or digit, we get it now.
                    formatToken = formatTokenizer.nextToken();
                    numberWidth = formatToken.length();
                    numberType = formatToken.charAt(numberWidth - 1);
                } else // only separators left
                {
                    // Set up the string for the trailing characters after 
                    // the last number is formatted (i.e. after the loop).
                    lastSepString = formatToken;
                    // And append any remaining characters to the lastSepString.
                    while (formatTokenizer.hasMoreTokens()) {
                        formatToken = formatTokenizer.nextToken();
                        lastSepString += formatToken;
                    }
                }
            // else
            }
            // should format to "(2-1-5.) " (I guess).
            if (null != formatTokenString && isFirstToken) {
                formattedNumber.append(formatTokenString);
            } else if (null != lastSep && !isFirstToken)
                formattedNumber.append(lastSep);
            getFormattedNumber(transformer, contextNode, numberType, numberWidth, list[i], formattedNumber);
            // After the first pass, this should be false
            isFirstToken = false;
        }
        // Skip past all remaining letters or digits
        while (formatTokenizer.isLetterOrDigitAhead()) {
            formatTokenizer.nextToken();
        }
        if (lastSepString != null)
            formattedNumber.append(lastSepString);
        while (formatTokenizer.hasMoreTokens()) {
            formatToken = formatTokenizer.nextToken();
            formattedNumber.append(formatToken);
        }
        numStr = formattedNumber.toString();
    } finally {
        StringBufferPool.free(formattedNumber);
    }
    return numStr;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer)

Example 25 with FastStringBuffer

use of org.apache.xml.utils.FastStringBuffer in project robovm by robovm.

the class OutputProperties method getQNameProperties.

/**
   * Searches for the list of qname properties with the specified key in
   * the property list.
   * If the key is not found in this property list, the default property list,
   * and its defaults, recursively, are then checked. The method returns
   * <code>null</code> if the property is not found.
   *
   * @param   key   the property key.
   * @param props the list of properties to search in.
   * @return  the value in this property list as a vector of QNames, or false
   * if null or not "yes".
   */
public static Vector getQNameProperties(String key, Properties props) {
    String s = props.getProperty(key);
    if (null != s) {
        Vector v = new Vector();
        int l = s.length();
        boolean inCurly = false;
        FastStringBuffer buf = new FastStringBuffer();
        // which theoretically shouldn't happen if they contain legal URLs.
        for (int i = 0; i < l; i++) {
            char c = s.charAt(i);
            if (Character.isWhitespace(c)) {
                if (!inCurly) {
                    if (buf.length() > 0) {
                        QName qname = QName.getQNameFromString(buf.toString());
                        v.addElement(qname);
                        buf.reset();
                    }
                    continue;
                }
            } else if ('{' == c)
                inCurly = true;
            else if ('}' == c)
                inCurly = false;
            buf.append(c);
        }
        if (buf.length() > 0) {
            QName qname = QName.getQNameFromString(buf.toString());
            v.addElement(qname);
            buf.reset();
        }
        return v;
    } else
        return null;
}
Also used : FastStringBuffer(org.apache.xml.utils.FastStringBuffer) QName(org.apache.xml.utils.QName) Vector(java.util.Vector)

Aggregations

FastStringBuffer (org.apache.xml.utils.FastStringBuffer)35 Node (org.w3c.dom.Node)9 XMLString (org.apache.xml.utils.XMLString)8 QName (org.apache.xml.utils.QName)4 DecimalFormat (java.text.DecimalFormat)2 Locale (java.util.Locale)2 Vector (java.util.Vector)2 XMLStringFactory (org.apache.xml.utils.XMLStringFactory)2 CharArrayWrapper (org.apache.xml.utils.res.CharArrayWrapper)2 XResourceBundle (org.apache.xml.utils.res.XResourceBundle)2