saximpl.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,896 行 · 第 1/4 页
JAVA
1,896 行
} int eType = getIdForNamespace(s); return ((Integer)_nsIndex.get(new Integer(eType))).intValue(); } /** * Returns the namespace type of a specific node */ public int getNamespaceType(final int node) { return super.getNamespaceType(node); } /** * Sets up a translet-to-dom type mapping table */ private int[] setupMapping(String[] names, String[] uris, int[] types, int nNames) { // Padding with number of names, because they // may need to be added, i.e for RTFs. See copy03 final int[] result = new int[m_expandedNameTable.getSize()]; for (int i = 0; i < nNames; i++) { //int type = getGeneralizedType(namesArray[i]); int type = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], false); result[type] = type; } return result; } /** * Returns the internal type associated with an expanded QName */ public int getGeneralizedType(final String name) { return getGeneralizedType(name, true); } /** * Returns the internal type associated with an expanded QName */ public int getGeneralizedType(final String name, boolean searchOnly) { String lName, ns = null; int index = -1; int code; // Is there a prefix? if ((index = name.lastIndexOf(":"))> -1) { ns = name.substring(0, index); } // Local part of name is after colon. lastIndexOf returns -1 if // there is no colon, so lNameStartIdx will be zero in that case. int lNameStartIdx = index+1; // Distinguish attribute and element names. Attribute has @ before // local part of name. if (name.charAt(lNameStartIdx) == '@') { code = DTM.ATTRIBUTE_NODE; lNameStartIdx++; } else { code = DTM.ELEMENT_NODE; } // Extract local name lName = (lNameStartIdx == 0) ? name : name.substring(lNameStartIdx); return m_expandedNameTable.getExpandedTypeID(ns, lName, code, searchOnly); } /** * Get mapping from DOM element/attribute types to external types */ public short[] getMapping(String[] names, String[] uris, int[] types) { // Delegate the work to getMapping2 if the document is not fully built. // Some of the processing has to be different in this case. if (_namesSize < 0) { return getMapping2(names, uris, types); } int i; final int namesLength = names.length; final int exLength = m_expandedNameTable.getSize(); final short[] result = new short[exLength]; // primitive types map to themselves for (i = 0; i < DTM.NTYPES; i++) { result[i] = (short)i; } for (i = NTYPES; i < exLength; i++) { result[i] = m_expandedNameTable.getType(i); } // actual mapping of caller requested names for (i = 0; i < namesLength; i++) { int genType = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], true); if (genType >= 0 && genType < exLength) { result[genType] = (short)(i + DTM.NTYPES); } } return result; } /** * Get mapping from external element/attribute types to DOM types */ public int[] getReverseMapping(String[] names, String[] uris, int[] types) { int i; final int[] result = new int[names.length + DTM.NTYPES]; // primitive types map to themselves for (i = 0; i < DTM.NTYPES; i++) { result[i] = i; } // caller's types map into appropriate dom types for (i = 0; i < names.length; i++) { int type = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], true); result[i+DTM.NTYPES] = type; } return(result); } /** * Get mapping from DOM element/attribute types to external types. * This method is used when the document is not fully built. */ private short[] getMapping2(String[] names, String[] uris, int[] types) { int i; final int namesLength = names.length; final int exLength = m_expandedNameTable.getSize(); int[] generalizedTypes = null; if (namesLength > 0) { generalizedTypes = new int[namesLength]; } int resultLength = exLength; for (i = 0; i < namesLength; i++) { // When the document is not fully built, the searchOnly // flag should be set to false. That means we should add // the type if it is not already in the expanded name table. //generalizedTypes[i] = getGeneralizedType(names[i], false); generalizedTypes[i] = m_expandedNameTable.getExpandedTypeID(uris[i], names[i], types[i], false); if (_namesSize < 0 && generalizedTypes[i] >= resultLength) { resultLength = generalizedTypes[i] + 1; } } final short[] result = new short[resultLength]; // primitive types map to themselves for (i = 0; i < DTM.NTYPES; i++) { result[i] = (short)i; } for (i = NTYPES; i < exLength; i++) { result[i] = m_expandedNameTable.getType(i); } // actual mapping of caller requested names for (i = 0; i < namesLength; i++) { int genType = generalizedTypes[i]; if (genType >= 0 && genType < resultLength) { result[genType] = (short)(i + DTM.NTYPES); } } return(result); } /** * Get mapping from DOM namespace types to external namespace types */ public short[] getNamespaceMapping(String[] namespaces) { int i; final int nsLength = namespaces.length; final int mappingLength = _uriCount; final short[] result = new short[mappingLength]; // Initialize all entries to -1 for (i=0; i<mappingLength; i++) { result[i] = (short)(-1); } for (i=0; i<nsLength; i++) { int eType = getIdForNamespace(namespaces[i]); Integer type = (Integer)_nsIndex.get(new Integer(eType)); if (type != null) { result[type.intValue()] = (short)i; } } return(result); } /** * Get mapping from external namespace types to DOM namespace types */ public short[] getReverseNamespaceMapping(String[] namespaces) { int i; final int length = namespaces.length; final short[] result = new short[length]; for (i = 0; i < length; i++) { int eType = getIdForNamespace(namespaces[i]); Integer type = (Integer)_nsIndex.get(new Integer(eType)); result[i] = (type == null) ? -1 : type.shortValue(); } return result; } /** * Construct a SAXImpl object using the default block size. */ public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, boolean buildIdIndex) { this(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing, DEFAULT_BLOCKSIZE, buildIdIndex, false); } /** * Construct a SAXImpl object using the given block size. */ public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean buildIdIndex, boolean newNameTable) { super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing, blocksize, false, buildIdIndex, newNameTable); _dtmManager = mgr; _size = blocksize; // Use a smaller size for the space stack if the blocksize is small _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64]; /* From DOMBuilder */ _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE; // If the input source is DOMSource, set the _document field and // create the node2Ids table. if (source instanceof DOMSource) { _hasDOMSource = true; DOMSource domsrc = (DOMSource)source; Node node = domsrc.getNode(); if (node instanceof Document) { _document = (Document)node; } else { _document = node.getOwnerDocument(); } _node2Ids = new Hashtable(); } } /** * Migrate a DTM built with an old DTMManager to a new DTMManager. * After the migration, the new DTMManager will treat the DTM as * one that is built by itself. * This is used to support DTM sharing between multiple transformations. * @param manager the DTMManager */ public void migrateTo(DTMManager manager) { super.migrateTo(manager); if (manager instanceof XSLTCDTMManager) { _dtmManager = (XSLTCDTMManager)manager; } } /** * Return the node identity for a given id String * * @param idString The id String * @return The identity of the node whose id is the given String. */ public int getElementById(String idString) { Node node = _document.getElementById(idString); if (node != null) { Integer id = (Integer)_node2Ids.get(node); return (id != null) ? id.intValue() : DTM.NULL; } else { return DTM.NULL; } } /** * Return true if the input source is DOMSource. */ public boolean hasDOMSource() { return _hasDOMSource; } /*---------------------------------------------------------------------------*/ /* DOMBuilder methods begin */ /*---------------------------------------------------------------------------*/ /** * Call this when an xml:space attribute is encountered to * define the whitespace strip/preserve settings. */ private void xmlSpaceDefine(String val, final int node) { final boolean setting = val.equals(PRESERVE_STRING); if (setting != _preserve) { _xmlSpaceStack[_idx++] = node; _preserve = setting; } } /** * Call this from endElement() to revert strip/preserve setting * to whatever it was before the corresponding startElement(). */ private void xmlSpaceRevert(final int node) { if (node == _xmlSpaceStack[_idx - 1]) { _idx--; _preserve = !_preserve; } } /** * Find out whether or not to strip whitespace nodes. * * * @return whether or not to strip whitespace nodes. */ protected boolean getShouldStripWhitespace() { return _preserve ? false : super.getShouldStripWhitespace(); } /** * Creates a text-node and checks if it is a whitespace node. */ private void handleTextEscaping() { if (_disableEscaping && _textNodeToProcess != DTM.NULL && _type(_textNodeToProcess) == DTM.TEXT_NODE) { if (_dontEscape == null) { _dontEscape = new BitArray(_size); } // Resize the _dontEscape BitArray if necessary. if (_textNodeToProcess >= _dontEscape.size()) { _dontEscape.resize(_dontEscape.size() * 2); } _dontEscape.setBit(_textNodeToProcess); _disableEscaping = false; } _textNodeToProcess = DTM.NULL; } /****************************************************************/ /* SAX Interface Starts Here */ /****************************************************************/ /** * SAX2: Receive notification of character data. */ public void characters(char[] ch, int start, int length) throws SAXException { super.characters(ch, start, length); _disableEscaping = !_escaping; _textNodeToProcess = getNumberOfNodes(); } /** * SAX2: Receive notification of the beginning of a document. */ public void startDocument() throws SAXException { super.startDocument(); _nsIndex.put(new Integer(0), new Integer(_uriCount++)); definePrefixAndUri(XML_PREFIX, XML_URI); } /** * SAX2: Receive notification of the end of a document. */ public void endDocument() throws SAXException { super.endDocument(); handleTextEscaping(); _namesSize = m_expandedNameTable.getSize(); } /** * Specialized interface used by DOM2SAX. This one has an extra Node * parameter to build the Node -> id map. */ public void startElement(String uri, String localName, String qname, Attributes attributes, Node node) throws SAXException { this.startElement(uri, localName, qname, attributes); if (m_buildIdIndex) { _node2Ids.put(node, new Integer(m_parents.peek())); } } /** * SAX2: Receive notification of the beginning of an element. */ public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException { super.startElement(uri, localName, qname, attributes); handleTextEscaping(); if (m_wsfilter != null) { // Look for any xml:space attributes // Depending on the implementation of attributes, this // might be faster than looping through all attributes. ILENE final int index = attributes.getIndex(XMLSPACE_STRING); if (index >= 0) { xmlSpaceDefine(attributes.getValue(index), m_parents.peek()); } } } /** * SAX2: Receive notification of the end of an element. */ public void endElement(String namespaceURI, String localName, String qname) throws SAXException { super.endElement(namespaceURI, localName, qname); handleTextEscaping(); // Revert to strip/preserve-space setting from before this element if (m_wsfilter != null) { xmlSpaceRevert(m_previous); } } /** * SAX2: Receive notification of a processing instruction. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?