📄 xmlwriternamespacebase.java
字号:
m_namespaceDepth = -1; } else { m_namespaceDepth = ((DeclarationInfo)m_namespaceStack.peek()).m_depth; } } /** * Get the current element nesting depth. Elements are only counted in the * depth returned when they're officially open - after the start tag has * been output and before the end tag has been output. * * @return number of nested elements at current point in output */ public final int getNestingDepth() { return m_nestingDepth; } /** * Get the number of namespaces currently defined. This is equivalent to the * index of the next extension namespace added. * * @return namespace count */ public final int getNamespaceCount() { int count = m_uris.length; if (m_extensionUris != null) { for (int i = 0; i < m_extensionUris.length; i++) { count += m_extensionUris[i].length; } } return count; } /** * Increment the current nesting depth. Subclasses need to call this method * whenever an element start tag is written. */ protected void incrementNesting() { m_nestingDepth++; } /** * Decrement the current nesting depth. Subclasses need to call this method * whenever an element end tag is written. */ protected void decrementNesting() { --m_nestingDepth; if (m_nestingDepth >= 0) { while (m_nestingDepth == m_namespaceDepth) { closeNamespaces(); } } } /** * Reset to initial state for reuse. Subclasses overriding this method need * to call this base class implementation during their processing. */ public void reset() { m_nestingDepth = 0; m_namespaceDepth = -1; m_namespaceStack.clear(); m_extensionUris = null; m_extensionPrefixes = null; } /** * Get namespace URIs for mapping. This gets the full ordered array of * namespaces known in the binding used for this marshalling, where the * index number of each namespace URI is the namespace index used to lookup * the prefix when marshalling a name in that namespace. The returned array * must not be modified. * * @return array of namespaces */ public final String[] getNamespaces() { return m_uris; } /** * Get URI for namespace. * * @param index namespace URI index number * @return namespace URI text, or <code>null</code> if the namespace index * is invalid */ public final String getNamespaceUri(int index) { if (index < m_uris.length) { return m_uris[index]; } else if (m_extensionUris != null) { index -= m_uris.length; for (int i = 0; i < m_extensionUris.length; i++) { int length = m_extensionUris[i].length; if (index < length) { return m_extensionUris[i][index]; } else { index -= length; } } } return null; } /** * Get current prefix defined for namespace. * * @param index namespace URI index number * @return current prefix text, or <code>null</code> if the namespace is not * currently mapped */ public final String getNamespacePrefix(int index) { if (index < m_prefixes.length) { return m_prefixes[index]; } else if (m_extensionUris != null) { index -= m_prefixes.length; for (int i = 0; i < m_extensionUris.length; i++) { int length = m_extensionUris[i].length; if (index < length) { return m_extensionPrefixes[i][index]; } else { index -= length; } } } return null; } /** * Get index of namespace mapped to prefix. This can be an expensive * operation with time proportional to the number of namespaces defined, so * it should be used with care. * * @param prefix text to match (non-<code>null</code>, use "" for default * prefix) * @return index namespace URI index number mapped to prefix */ public final int getPrefixIndex(String prefix) { if (m_extensionPrefixes != null) { for (int i = m_extensionPrefixes.length-1; i >= 0; i--) { String[] prefixes = m_extensionPrefixes[i]; for (int j = prefixes.length-1; j >= 0; j--) { if (prefix.equals(prefixes[j])) { int index = j + m_prefixes.length; for (int k = i-1; k >= 0; k--) { index += m_extensionPrefixes[k].length; } return index; } } } } for (int i = m_prefixes.length-1; i >= 0; i--) { if (prefix.equals(m_prefixes[i])) { return i; } } return -1; } /** * Grow array of array of strings. * * @param base array to be grown (<code>null</code> is treated as zero * length) * @param items array of strings to be added at end of base array * @return array with added array of items */ protected static String[][] growArray(String[][] base, String[] items) { if (base == null) { return new String[][] { items }; } else { int length = base.length; String[][] grow = new String[length+1][]; System.arraycopy(base, 0, grow, 0, length); grow[length] = items; return grow; } } /** * Shrink array of array of strings. * * @param base array to be shrunk * @return array with last set of items eliminated (<code>null</code> if * empty) */ protected static String[][] shrinkArray(String[][] base) { int length = base.length; if (length == 1) { return null; } else { String[][] shrink = new String[length-1][]; System.arraycopy(base, 0, shrink, 0, length-1); return shrink; } } /** * Append extension namespace URIs to those in mapping. * * @param uris namespace URIs to extend those in mapping */ public void pushExtensionNamespaces(String[] uris) { m_extensionUris = growArray(m_extensionUris, uris); m_extensionPrefixes = growArray(m_extensionPrefixes, new String[uris.length]); } /** * Remove extension namespace URIs. This removes the last set of * extension namespaces pushed using {@link #pushExtensionNamespaces}. */ public void popExtensionNamespaces() { m_extensionUris = shrinkArray(m_extensionUris); m_extensionPrefixes = shrinkArray(m_extensionPrefixes); } /** * Get extension namespace URIs added to those in mapping. This gets the * current set of extension definitions. The returned arrays must not be * modified. * * @return array of arrays of extension namespaces (<code>null</code> if * none) */ public final String[][] getExtensionNamespaces() { return m_extensionUris; } /** * Namespace declaration tracking information. This tracks all information * associated with an element that declares namespaces. */ private static class DeclarationInfo { /** Depth of element making declaration. */ public final int m_depth; /** Indexes of namespaces included in declarations. */ public final int[] m_deltas; /** Prior prefixes for namespaces. */ public final String[] m_priors; /** Simple constructor. */ public DeclarationInfo(int depth, int[] deltas, String[] priors) { m_depth = depth; m_deltas = deltas; m_priors = priors; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -