elemnumber.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,968 行 · 第 1/5 页
JAVA
1,968 行
} return formatter; } /** * Format a vector of numbers into a formatted string. * * @param xslNumberElement Element that takes %conversion-atts; attributes. * @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 = "."; boolean isFirstToken = true; // true if first token 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); // int sepCount = 0; // keep track of seperators // 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(); // If the first character of this token is a character or digit, then // it is a number format directive. if (Character.isLetterOrDigit( formatToken.charAt(formatToken.length() - 1))) { numberWidth = formatToken.length(); numberType = formatToken.charAt(numberWidth - 1); } // If there is a number format directive ahead, // then append the formatToken. else if (formatTokenizer.isLetterOrDigitAhead()) { formatTokenString = formatToken; // Append the formatToken string... // For instance [2][1][5] with a format value of "1--1. " // should format to "2--1--5. " (I guess). while (formatTokenizer.nextIsSep()) { formatToken = formatTokenizer.nextToken(); formatTokenString += formatToken; } // Record this separator, so it can be used as the // next separator, if the next is the last. // For instance: [2][1][5] with a format value of "1-1 " // 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 } // end if(formatTokenizer.hasMoreTokens()) // if this is the first token and there was a prefix // append the prefix else, append the separator // For instance, [2][1][5] with a format value of "(1-1.) " // 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); isFirstToken = false; // After the first pass, this should be false } // end for loop // Check to see if we finished up the format string... // 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; } // 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; switch (numberType) { case 'A' : if (m_alphaCountTable == null) { XResourceBundle thisBundle; thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle( org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode)); char[] alphabet; alphabet = (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET); m_alphaCountTable = alphabet; } int2alphaCount(listElement, m_alphaCountTable, formattedNumber); break; case 'a' : if (m_alphaCountTable == null) { XResourceBundle thisBundle; thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle( org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, getLocale(transformer, contextNode)); char[] alphabet; alphabet = (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET); m_alphaCountTable = 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 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET))); break; } case 0x3044 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET))); break; } case 0x30A2 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET))); break; } case 0x30A4 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET))); break; } case 0x4E00 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber); break; } case 0x58F9 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber); break; } case 0x0E51 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber); break; } case 0x05D0 : { XResourceBundle thisBundle; 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, (char[]) thisBundle.getObject(org.apache.xml.utils.res.XResourceBundle.LANG_ALPHABET), formattedNumber); break; } case 0x10D0 : { XResourceBundle thisBundle; thisBundle = (XResourceBundle) XResourceBundle.loadResourceBundle( org.apache.xml.utils.res.XResourceBundle.LANG_BUNDLE_NAME, new Locale("ka", ""));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?