Search in sources :

Example 1 with CharArrayWrapper

use of org.apache.xml.utils.res.CharArrayWrapper in project robovm by robovm.

the class ElemNumber method getFormattedNumber.

// end formatNumberList method
/*
  * Get Formatted number
  */
/**
   * Format the given number and store it in the given buffer 
   *
   *
   * @param transformer non-null reference to the the current transform-time state.
   * @param contextNode The node that "." expresses.
   * @param numberType Type to format to
   * @param numberWidth Maximum length of formatted number
   * @param listElement Number to format
   * @param formattedNumber Buffer to store formatted number
   *
   * @throws javax.xml.transform.TransformerException
   */
private void getFormattedNumber(TransformerImpl transformer, int contextNode, char numberType, int numberWidth, long listElement, FastStringBuffer formattedNumber) throws javax.xml.transform.TransformerException {
    String letterVal = (m_lettervalue_avt != null) ? m_lettervalue_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
    /**
     * Wrapper of Chars for converting integers into alpha counts.
     */
    CharArrayWrapper alphaCountTable = null;
    XResourceBundle thisBundle = null;
    switch(numberType) {
        case 'A':
            if (null == m_alphaCountTable) {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode));
                m_alphaCountTable = (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET);
            }
            int2alphaCount(listElement, m_alphaCountTable, formattedNumber);
            break;
        case 'a':
            if (null == m_alphaCountTable) {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode));
                m_alphaCountTable = (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET);
            }
            FastStringBuffer stringBuf = StringBufferPool.get();
            try {
                int2alphaCount(listElement, m_alphaCountTable, stringBuf);
                formattedNumber.append(stringBuf.toString().toLowerCase(getLocale(transformer, contextNode)));
            } finally {
                StringBufferPool.free(stringBuf);
            }
            break;
        case 'I':
            formattedNumber.append(long2roman(listElement, true));
            break;
        case 'i':
            formattedNumber.append(long2roman(listElement, true).toLowerCase(getLocale(transformer, contextNode)));
            break;
        case 0x3042:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "HA"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x3044:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "HI"));
                if ((letterVal != null) && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x30A2:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "A"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x30A4:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "I"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x4E00:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("zh", "CN"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL)) {
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                } else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x58F9:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("zh", "TW"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x0E51:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("th", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x05D0:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("he", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x10D0:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ka", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x03B1:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("el", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x0430:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("cy", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    //if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        default:
            // "1"
            DecimalFormat formatter = getNumberFormatter(transformer, contextNode);
            String padString = formatter == null ? String.valueOf(0) : formatter.format(0);
            String numString = formatter == null ? String.valueOf(listElement) : formatter.format(listElement);
            int nPadding = numberWidth - numString.length();
            for (int k = 0; k < nPadding; k++) {
                formattedNumber.append(padString);
            }
            formattedNumber.append(numString);
    }
}
Also used : Locale(java.util.Locale) FastStringBuffer(org.apache.xml.utils.FastStringBuffer) CharArrayWrapper(org.apache.xml.utils.res.CharArrayWrapper) DecimalFormat(java.text.DecimalFormat) XResourceBundle(org.apache.xml.utils.res.XResourceBundle)

Example 2 with CharArrayWrapper

use of org.apache.xml.utils.res.CharArrayWrapper in project robovm by robovm.

the class ElemNumber method tradAlphaCount.

/**
   * Convert a long integer into traditional alphabetic counting, in other words
   * count using the traditional numbering.
   * 
   * @param val Value to convert -- must be greater than zero.
   * @param thisBundle Resource bundle to use
   * 
   * @return String representing alpha count of number.
   * @see XSLProcessor#DecimalToRoman
   *
   * Note that the radix of the conversion is inferred from the size
   * of the table.
   */
protected String tradAlphaCount(long val, XResourceBundle thisBundle) {
    // if this number is larger than the largest number we can represent, error!
    if (val > Long.MAX_VALUE) {
        this.error(XSLTErrorResources.ER_NUMBER_TOO_BIG);
        return XSLTErrorResources.ERROR_STRING;
    }
    char[] table = null;
    // index in table of the last character that we stored
    // start off with anything other than zero to make correction work
    int lookupIndex = 1;
    // Create a buffer to hold the result
    // TODO:  size of the table can be detereined by computing
    // logs of the radix.  For now, we fake it.
    char[] buf = new char[100];
    //some languages go left to right(ie. english), right to left (ie. Hebrew),
    //top to bottom (ie.Japanese), etc... Handle them differently
    //String orientation = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.LANG_ORIENTATION);
    // next character to set in the buffer
    int charPos;
    //start at 0
    charPos = 0;
    // array of number groups: ie.1000, 100, 10, 1
    IntArrayWrapper groups = (IntArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_NUMBERGROUPS);
    // array of tables of hundreds, tens, digits...
    StringArrayWrapper tables = (StringArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_NUM_TABLES));
    //some languages have additive alphabetical notation,
    //some multiplicative-additive, etc... Handle them differently.
    String numbering = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.LANG_NUMBERING);
    // do multiplicative part first
    if (numbering.equals(org.apache.xml.utils.res.XResourceBundle.LANG_MULT_ADD)) {
        String mult_order = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.MULT_ORDER);
        LongArrayWrapper multiplier = (LongArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_MULTIPLIER));
        CharArrayWrapper zeroChar = (CharArrayWrapper) thisBundle.getObject("zero");
        int i = 0;
        // skip to correct multiplier
        while (i < multiplier.getLength() && val < multiplier.getLong(i)) {
            i++;
        }
        do {
            if (i >= multiplier.getLength())
                //number is smaller than multipliers
                break;
            // 0X100 is replaced by the zero character, we don't need one for 0X10
            if (val < multiplier.getLong(i)) {
                if (zeroChar.getLength() == 0) {
                    i++;
                } else {
                    if (buf[charPos - 1] != zeroChar.getChar(0))
                        buf[charPos++] = zeroChar.getChar(0);
                    i++;
                }
            } else if (val >= multiplier.getLong(i)) {
                long mult = val / multiplier.getLong(i);
                // save this.
                val = val % multiplier.getLong(i);
                int k = 0;
                while (k < groups.getLength()) {
                    // initialize for each table
                    lookupIndex = 1;
                    if (// look for right table
                    mult / groups.getInt(k) <= 0)
                        k++;
                    else {
                        // get the table
                        CharArrayWrapper THEletters = (CharArrayWrapper) thisBundle.getObject(tables.getString(k));
                        table = new char[THEletters.getLength() + 1];
                        int j;
                        for (j = 0; j < THEletters.getLength(); j++) {
                            table[j + 1] = THEletters.getChar(j);
                        }
                        // don't need this                                                                         
                        table[0] = THEletters.getChar(j - 1);
                        // index in "table" of the next char to emit
                        lookupIndex = (int) mult / groups.getInt(k);
                        //this should not happen
                        if (lookupIndex == 0 && mult == 0)
                            break;
                        char multiplierChar = ((CharArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_MULTIPLIER_CHAR))).getChar(i);
                        // put out the next character of output   
                        if (lookupIndex < table.length) {
                            if (mult_order.equals(org.apache.xml.utils.res.XResourceBundle.MULT_PRECEDES)) {
                                buf[charPos++] = multiplierChar;
                                buf[charPos++] = table[lookupIndex];
                            } else {
                                // don't put out 1 (ie 1X10 is just 10)
                                if (lookupIndex == 1 && i == multiplier.getLength() - 1) {
                                } else
                                    buf[charPos++] = table[lookupIndex];
                                buf[charPos++] = multiplierChar;
                            }
                            // all done!
                            break;
                        } else
                            return XSLTErrorResources.ERROR_STRING;
                    }
                //end else
                }
                // end while        
                i++;
            }
        // end else if
        } while (// end do while
        i < multiplier.getLength());
    }
    // Now do additive part...
    int count = 0;
    String tableName;
    // do this for each table of hundreds, tens, digits...
    while (count < groups.getLength()) {
        if (// look for correct table
        val / groups.getInt(count) <= 0)
            count++;
        else {
            CharArrayWrapper theletters = (CharArrayWrapper) thisBundle.getObject(tables.getString(count));
            table = new char[theletters.getLength() + 1];
            int j;
            // need to start filling the table up at index 1
            for (j = 0; j < theletters.getLength(); j++) {
                table[j + 1] = theletters.getChar(j);
            }
            // don't need this
            table[0] = theletters.getChar(j - 1);
            // index in "table" of the next char to emit
            lookupIndex = (int) val / groups.getInt(count);
            // shift input by one "column"
            val = val % groups.getInt(count);
            // this should not happen
            if (lookupIndex == 0 && val == 0)
                break;
            if (lookupIndex < table.length) {
                // put out the next character of output       
                // left to right or top to bottom                                       
                buf[charPos++] = table[lookupIndex];
            } else
                return XSLTErrorResources.ERROR_STRING;
            count++;
        }
    }
    // String s = new String(buf, 0, charPos);
    return new String(buf, 0, charPos);
}
Also used : CharArrayWrapper(org.apache.xml.utils.res.CharArrayWrapper) StringArrayWrapper(org.apache.xml.utils.res.StringArrayWrapper) IntArrayWrapper(org.apache.xml.utils.res.IntArrayWrapper) LongArrayWrapper(org.apache.xml.utils.res.LongArrayWrapper)

Example 3 with CharArrayWrapper

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

the class ElemNumber method getFormattedNumber.

// end formatNumberList method
/*
  * Get Formatted number
  */
/**
 * Format the given number and store it in the given buffer
 *
 * @param transformer non-null reference to the the current transform-time state.
 * @param contextNode The node that "." expresses.
 * @param numberType Type to format to
 * @param numberWidth Maximum length of formatted number
 * @param listElement Number to format
 * @param formattedNumber Buffer to store formatted number
 *
 * @throws javax.xml.transform.TransformerException
 */
private void getFormattedNumber(TransformerImpl transformer, int contextNode, char numberType, int numberWidth, long listElement, FastStringBuffer formattedNumber) throws javax.xml.transform.TransformerException {
    String letterVal = (m_lettervalue_avt != null) ? m_lettervalue_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
    /**
     * Wrapper of Chars for converting integers into alpha counts.
     */
    CharArrayWrapper alphaCountTable = null;
    XResourceBundle thisBundle = null;
    switch(numberType) {
        case 'A':
            if (null == m_alphaCountTable) {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode));
                m_alphaCountTable = (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET);
            }
            int2alphaCount(listElement, m_alphaCountTable, formattedNumber);
            break;
        case 'a':
            if (null == m_alphaCountTable) {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode));
                m_alphaCountTable = (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET);
            }
            FastStringBuffer stringBuf = StringBufferPool.get();
            try {
                int2alphaCount(listElement, m_alphaCountTable, stringBuf);
                formattedNumber.append(stringBuf.toString().toLowerCase(getLocale(transformer, contextNode)));
            } finally {
                StringBufferPool.free(stringBuf);
            }
            break;
        case 'I':
            formattedNumber.append(long2roman(listElement, true));
            break;
        case 'i':
            formattedNumber.append(long2roman(listElement, true).toLowerCase(getLocale(transformer, contextNode)));
            break;
        case 0x3042:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "HA"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x3044:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "HI"));
                if ((letterVal != null) && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x30A2:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "A"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x30A4:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ja", "JP", "I"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    formattedNumber.append(int2singlealphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET)));
                break;
            }
        case 0x4E00:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("zh", "CN"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL)) {
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                } else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x58F9:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("zh", "TW"));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x0E51:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("th", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x05D0:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("he", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x10D0:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ka", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x03B1:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("el", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        case 0x0430:
            {
                thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle(org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("cy", ""));
                if (letterVal != null && letterVal.equals(Constants.ATTRVAL_TRADITIONAL))
                    formattedNumber.append(tradAlphaCount(listElement, thisBundle));
                else
                    // if (m_lettervalue_avt != null && m_lettervalue_avt.equals(Constants.ATTRVAL_ALPHABETIC))
                    int2alphaCount(listElement, (CharArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber);
                break;
            }
        default:
            // "1"
            DecimalFormat formatter = getNumberFormatter(transformer, contextNode);
            String padString = formatter == null ? String.valueOf(0) : formatter.format(0);
            String numString = formatter == null ? String.valueOf(listElement) : formatter.format(listElement);
            int nPadding = numberWidth - numString.length();
            for (int k = 0; k < nPadding; k++) {
                formattedNumber.append(padString);
            }
            formattedNumber.append(numString);
    }
}
Also used : Locale(java.util.Locale) FastStringBuffer(org.apache.xml.utils.FastStringBuffer) CharArrayWrapper(org.apache.xml.utils.res.CharArrayWrapper) DecimalFormat(java.text.DecimalFormat) XResourceBundle(org.apache.xml.utils.res.XResourceBundle)

Example 4 with CharArrayWrapper

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

the class ElemNumber method tradAlphaCount.

/**
 * Convert a long integer into traditional alphabetic counting, in other words
 * count using the traditional numbering.
 *
 * @param val Value to convert -- must be greater than zero.
 * @param thisBundle Resource bundle to use
 *
 * @return String representing alpha count of number.
 * @see XSLProcessor#DecimalToRoman
 *
 * Note that the radix of the conversion is inferred from the size
 * of the table.
 */
protected String tradAlphaCount(long val, XResourceBundle thisBundle) {
    // if this number is larger than the largest number we can represent, error!
    if (val > Long.MAX_VALUE) {
        this.error(XSLTErrorResources.ER_NUMBER_TOO_BIG);
        return XSLTErrorResources.ERROR_STRING;
    }
    char[] table = null;
    // index in table of the last character that we stored
    // start off with anything other than zero to make correction work
    int lookupIndex = 1;
    // Create a buffer to hold the result
    // TODO:  size of the table can be detereined by computing
    // logs of the radix.  For now, we fake it.
    char[] buf = new char[100];
    // some languages go left to right(ie. english), right to left (ie. Hebrew),
    // top to bottom (ie.Japanese), etc... Handle them differently
    // String orientation = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.LANG_ORIENTATION);
    // next character to set in the buffer
    int charPos;
    // start at 0
    charPos = 0;
    // array of number groups: ie.1000, 100, 10, 1
    IntArrayWrapper groups = (IntArrayWrapper) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_NUMBERGROUPS);
    // array of tables of hundreds, tens, digits...
    StringArrayWrapper tables = (StringArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_NUM_TABLES));
    // some languages have additive alphabetical notation,
    // some multiplicative-additive, etc... Handle them differently.
    String numbering = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.LANG_NUMBERING);
    // do multiplicative part first
    if (numbering.equals(org.apache.xml.utils.res.XResourceBundle.LANG_MULT_ADD)) {
        String mult_order = thisBundle.getString(org.apache.xml.utils.res.XResourceBundle.MULT_ORDER);
        LongArrayWrapper multiplier = (LongArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_MULTIPLIER));
        CharArrayWrapper zeroChar = (CharArrayWrapper) thisBundle.getObject("zero");
        int i = 0;
        // skip to correct multiplier
        while (i < multiplier.getLength() && val < multiplier.getLong(i)) {
            i++;
        }
        do {
            if (i >= multiplier.getLength())
                // number is smaller than multipliers
                break;
            // 0X100 is replaced by the zero character, we don't need one for 0X10
            if (val < multiplier.getLong(i)) {
                if (zeroChar.getLength() == 0) {
                    i++;
                } else {
                    if (buf[charPos - 1] != zeroChar.getChar(0))
                        buf[charPos++] = zeroChar.getChar(0);
                    i++;
                }
            } else if (val >= multiplier.getLong(i)) {
                long mult = val / multiplier.getLong(i);
                // save this.
                val = val % multiplier.getLong(i);
                int k = 0;
                while (k < groups.getLength()) {
                    // initialize for each table
                    lookupIndex = 1;
                    if (// look for right table
                    mult / groups.getInt(k) <= 0)
                        k++;
                    else {
                        // get the table
                        CharArrayWrapper THEletters = (CharArrayWrapper) thisBundle.getObject(tables.getString(k));
                        table = new char[THEletters.getLength() + 1];
                        int j;
                        for (j = 0; j < THEletters.getLength(); j++) {
                            table[j + 1] = THEletters.getChar(j);
                        }
                        // don't need this
                        table[0] = THEletters.getChar(j - 1);
                        // index in "table" of the next char to emit
                        lookupIndex = (int) mult / groups.getInt(k);
                        // this should not happen
                        if (lookupIndex == 0 && mult == 0)
                            break;
                        char multiplierChar = ((CharArrayWrapper) (thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_MULTIPLIER_CHAR))).getChar(i);
                        // put out the next character of output
                        if (lookupIndex < table.length) {
                            if (mult_order.equals(org.apache.xml.utils.res.XResourceBundle.MULT_PRECEDES)) {
                                buf[charPos++] = multiplierChar;
                                buf[charPos++] = table[lookupIndex];
                            } else {
                                // don't put out 1 (ie 1X10 is just 10)
                                if (lookupIndex == 1 && i == multiplier.getLength() - 1) {
                                } else
                                    buf[charPos++] = table[lookupIndex];
                                buf[charPos++] = multiplierChar;
                            }
                            // all done!
                            break;
                        } else
                            return XSLTErrorResources.ERROR_STRING;
                    }
                // end else
                }
                // end while
                i++;
            }
        // end else if
        } while (// end do while
        i < multiplier.getLength());
    }
    // Now do additive part...
    int count = 0;
    String tableName;
    // do this for each table of hundreds, tens, digits...
    while (count < groups.getLength()) {
        if (// look for correct table
        val / groups.getInt(count) <= 0)
            count++;
        else {
            CharArrayWrapper theletters = (CharArrayWrapper) thisBundle.getObject(tables.getString(count));
            table = new char[theletters.getLength() + 1];
            int j;
            // need to start filling the table up at index 1
            for (j = 0; j < theletters.getLength(); j++) {
                table[j + 1] = theletters.getChar(j);
            }
            // don't need this
            table[0] = theletters.getChar(j - 1);
            // index in "table" of the next char to emit
            lookupIndex = (int) val / groups.getInt(count);
            // shift input by one "column"
            val = val % groups.getInt(count);
            // this should not happen
            if (lookupIndex == 0 && val == 0)
                break;
            if (lookupIndex < table.length) {
                // put out the next character of output
                // left to right or top to bottom
                buf[charPos++] = table[lookupIndex];
            } else
                return XSLTErrorResources.ERROR_STRING;
            count++;
        }
    }
    // String s = new String(buf, 0, charPos);
    return new String(buf, 0, charPos);
}
Also used : CharArrayWrapper(org.apache.xml.utils.res.CharArrayWrapper) StringArrayWrapper(org.apache.xml.utils.res.StringArrayWrapper) IntArrayWrapper(org.apache.xml.utils.res.IntArrayWrapper) LongArrayWrapper(org.apache.xml.utils.res.LongArrayWrapper)

Aggregations

CharArrayWrapper (org.apache.xml.utils.res.CharArrayWrapper)4 DecimalFormat (java.text.DecimalFormat)2 Locale (java.util.Locale)2 FastStringBuffer (org.apache.xml.utils.FastStringBuffer)2 IntArrayWrapper (org.apache.xml.utils.res.IntArrayWrapper)2 LongArrayWrapper (org.apache.xml.utils.res.LongArrayWrapper)2 StringArrayWrapper (org.apache.xml.utils.res.StringArrayWrapper)2 XResourceBundle (org.apache.xml.utils.res.XResourceBundle)2