code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
protected boolean nextNode() { if (null == m_incrementalSAXSource) return false; if (m_endDocumentOccured) { clearCoRoutine(); return false; } Object gotMore = m_incrementalSAXSource.deliverMoreNodes(true); // gotMore may be a Boolean (TRUE if still parsing, FALSE if // EOF) or an exception if IncrementalSAXSource malfunctioned // (code error rather than user error). // // %REVIEW% Currently the ErrorHandlers sketched herein are // no-ops, so I'm going to initially leave this also as a // no-op. if (!(gotMore instanceof Boolean)) { if(gotMore instanceof RuntimeException) { throw (RuntimeException)gotMore; } else if(gotMore instanceof Exception) { throw new WrappedRuntimeException((Exception)gotMore); } // for now... clearCoRoutine(); return false; // %TBD% } if (gotMore != Boolean.TRUE) { // EOF reached without satisfying the request clearCoRoutine(); // Drop connection, stop trying // %TBD% deregister as its listener? } return true; }
This method should try and build one or more nodes in the table. @return The true if a next node is found or false if there are no more nodes.
SAX2DTM::nextNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
private final boolean isTextType(int type) { return (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type); }
Bottleneck determination of text type. @param type oneof DTM.XXX_NODE. @return true if this is a text or cdata section.
SAX2DTM::isTextType
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
protected void addNewDTMID(int nodeIndex) { try { if(m_mgr==null) throw new ClassCastException(); // Handle as Extended Addressing DTMManagerDefault mgrD=(DTMManagerDefault)m_mgr; int id=mgrD.getFirstFreeDTMID(); mgrD.addDTM(this,id,nodeIndex); m_dtmIdent.addElement(id<<DTMManager.IDENT_DTM_NODE_BITS); } catch(ClassCastException e) { // %REVIEW% Wrong error message, but I've been told we're trying // not to add messages right not for I18N reasons. // %REVIEW% Should this be a Fatal Error? error(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DTMIDS_AVAIL, null));//"No more DTM IDs are available"; } }
Get a new DTM ID beginning at the specified node index. @param nodeIndex The node identity at which the new DTM ID will begin addressing.
SAX2DTM::addNewDTMID
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
protected void setSourceLocation() { m_sourceSystemId.addElement(m_locator.getSystemId()); m_sourceLine.addElement(m_locator.getLineNumber()); m_sourceColumn.addElement(m_locator.getColumnNumber()); //%REVIEW% %BUG% Prevent this from arising in the first place // by not allowing the enabling conditions to change after we start // building the document. if (m_sourceSystemId.size() != m_size) { String msg = "CODING ERROR in Source Location: " + m_size + " != " + m_sourceSystemId.size(); System.err.println(msg); throw new RuntimeException(msg); } }
Store the source location of the current node. This method must be called as every node is added to the DTM or for no node.
SAX2DTM::setSourceLocation
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public String getPrefix(String qname, String uri) { String prefix; int uriIndex = -1; if (null != uri && uri.length() > 0) { do { uriIndex = m_prefixMappings.indexOf(uri, ++uriIndex); } while ( (uriIndex & 0x01) == 0); if (uriIndex >= 0) { prefix = (String) m_prefixMappings.elementAt(uriIndex - 1); } else if (null != qname) { int indexOfNSSep = qname.indexOf(':'); if (qname.equals("xmlns")) prefix = ""; else if (qname.startsWith("xmlns:")) prefix = qname.substring(indexOfNSSep + 1); else prefix = (indexOfNSSep > 0) ? qname.substring(0, indexOfNSSep) : null; } else { prefix = null; } } else if (null != qname) { int indexOfNSSep = qname.indexOf(':'); if (indexOfNSSep > 0) { if (qname.startsWith("xmlns:")) prefix = qname.substring(indexOfNSSep + 1); else prefix = qname.substring(0, indexOfNSSep); } else { if (qname.equals("xmlns")) prefix = ""; else prefix = null; } } else { prefix = null; } return prefix; }
Get a prefix either from the qname or from the uri mapping, or just make one up! @param qname The qualified name, which may be null. @param uri The namespace URI, which may be null. @return The prefix if there is one, or null.
SAX2DTM::getPrefix
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public String getNamespaceURI(String prefix) { String uri = ""; int prefixIndex = m_contextIndexes.peek() - 1 ; if(null == prefix) prefix = ""; do { prefixIndex = m_prefixMappings.indexOf(prefix, ++prefixIndex); } while ( (prefixIndex >= 0) && (prefixIndex & 0x01) == 0x01); if (prefixIndex > -1) { uri = (String) m_prefixMappings.elementAt(prefixIndex + 1); } return uri; }
Get a prefix either from the qname or from the uri mapping, or just make one up! @return The prefix if there is one, or null.
SAX2DTM::getNamespaceURI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void setIDAttribute(String id, int elem) { m_idAttributes.put(id, new Integer(elem)); }
Set an ID string to node association in the ID table. @param id The ID string. @param elem The associated element handle.
SAX2DTM::setIDAttribute
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public InputSource resolveEntity(String publicId, String systemId) throws SAXException { return null; }
Resolve an external entity. <p>Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.</p> @param publicId The public identifer, or null if none is available. @param systemId The system identifier provided in the XML document. @return The new input source, or null to require the default behaviour. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.EntityResolver#resolveEntity @throws SAXException
SAX2DTM::resolveEntity
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void notationDecl(String name, String publicId, String systemId) throws SAXException { // no op }
Receive notification of a notation declaration. <p>By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.</p> @param name The notation name. @param publicId The notation public identifier, or null if not available. @param systemId The notation system identifier. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.DTDHandler#notationDecl @throws SAXException
SAX2DTM::notationDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void unparsedEntityDecl( String name, String publicId, String systemId, String notationName) throws SAXException { if (null == m_entities) { m_entities = new Vector(); } try { systemId = SystemIDResolver.getAbsoluteURI(systemId, getDocumentBaseURI()); } catch (Exception e) { throw new org.xml.sax.SAXException(e); } // private static final int ENTITY_FIELD_PUBLICID = 0; m_entities.addElement(publicId); // private static final int ENTITY_FIELD_SYSTEMID = 1; m_entities.addElement(systemId); // private static final int ENTITY_FIELD_NOTATIONNAME = 2; m_entities.addElement(notationName); // private static final int ENTITY_FIELD_NAME = 3; m_entities.addElement(name); }
Receive notification of an unparsed entity declaration. <p>By default, do nothing. Application writers may override this method in a subclass to keep track of the unparsed entities declared in a document.</p> @param name The entity name. @param publicId The entity public identifier, or null if not available. @param systemId The entity system identifier. @param notationName The name of the associated notation. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.DTDHandler#unparsedEntityDecl @throws SAXException
SAX2DTM::unparsedEntityDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void startPrefixMapping(String prefix, String uri) throws SAXException { if (DEBUG) System.out.println("startPrefixMapping: prefix: " + prefix + ", uri: " + uri); if(null == prefix) prefix = ""; m_prefixMappings.addElement(prefix); // JDK 1.1.x compat -sc m_prefixMappings.addElement(uri); // JDK 1.1.x compat -sc }
Receive notification of the start of a Namespace mapping. <p>By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).</p> @param prefix The Namespace prefix being declared. @param uri The Namespace URI mapped to the prefix. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#startPrefixMapping
SAX2DTM::startPrefixMapping
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void endPrefixMapping(String prefix) throws SAXException { if (DEBUG) System.out.println("endPrefixMapping: prefix: " + prefix); if(null == prefix) prefix = ""; int index = m_contextIndexes.peek() - 1; do { index = m_prefixMappings.indexOf(prefix, ++index); } while ( (index >= 0) && ((index & 0x01) == 0x01) ); if (index > -1) { m_prefixMappings.setElementAt("%@$#^@#", index); m_prefixMappings.setElementAt("%@$#^@#", index + 1); } // no op }
Receive notification of the end of a Namespace mapping. <p>By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.</p> @param prefix The Namespace prefix being declared. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#endPrefixMapping
SAX2DTM::endPrefixMapping
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
protected boolean declAlreadyDeclared(String prefix) { int startDecls = m_contextIndexes.peek(); java.util.Vector prefixMappings = m_prefixMappings; int nDecls = prefixMappings.size(); for (int i = startDecls; i < nDecls; i += 2) { String prefixDecl = (String) prefixMappings.elementAt(i); if (prefixDecl == null) continue; if (prefixDecl.equals(prefix)) return true; } return false; }
Check if a declaration has already been made for a given prefix. @param prefix non-null prefix string. @return true if the declaration has already been declared in the current context.
SAX2DTM::declAlreadyDeclared
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void startElement( String uri, String localName, String qName, Attributes attributes) throws SAXException { if (DEBUG) { System.out.println("startElement: uri: " + uri + ", localname: " + localName + ", qname: "+qName+", atts: " + attributes); boolean DEBUG_ATTRS=true; if(DEBUG_ATTRS & attributes!=null) { int n = attributes.getLength(); if(n==0) System.out.println("\tempty attribute list"); else for (int i = 0; i < n; i++) System.out.println("\t attr: uri: " + attributes.getURI(i) + ", localname: " + attributes.getLocalName(i) + ", qname: " + attributes.getQName(i) + ", type: " + attributes.getType(i) + ", value: " + attributes.getValue(i) ); } } charactersFlush(); int exName = m_expandedNameTable.getExpandedTypeID(uri, localName, DTM.ELEMENT_NODE); String prefix = getPrefix(qName, uri); int prefixIndex = (null != prefix) ? m_valuesOrPrefixes.stringToIndex(qName) : 0; int elemNode = addNode(DTM.ELEMENT_NODE, exName, m_parents.peek(), m_previous, prefixIndex, true); if(m_indexing) indexNode(exName, elemNode); m_parents.push(elemNode); int startDecls = m_contextIndexes.peek(); int nDecls = m_prefixMappings.size(); int prev = DTM.NULL; if(!m_pastFirstElement) { // SPECIAL CASE: Implied declaration at root element prefix="xml"; String declURL = "http://www.w3.org/XML/1998/namespace"; exName = m_expandedNameTable.getExpandedTypeID(null, prefix, DTM.NAMESPACE_NODE); int val = m_valuesOrPrefixes.stringToIndex(declURL); prev = addNode(DTM.NAMESPACE_NODE, exName, elemNode, prev, val, false); m_pastFirstElement=true; } for (int i = startDecls; i < nDecls; i += 2) { prefix = (String) m_prefixMappings.elementAt(i); if (prefix == null) continue; String declURL = (String) m_prefixMappings.elementAt(i + 1); exName = m_expandedNameTable.getExpandedTypeID(null, prefix, DTM.NAMESPACE_NODE); int val = m_valuesOrPrefixes.stringToIndex(declURL); prev = addNode(DTM.NAMESPACE_NODE, exName, elemNode, prev, val, false); } int n = attributes.getLength(); for (int i = 0; i < n; i++) { String attrUri = attributes.getURI(i); String attrQName = attributes.getQName(i); String valString = attributes.getValue(i); prefix = getPrefix(attrQName, attrUri); int nodeType; String attrLocalName = attributes.getLocalName(i); if ((null != attrQName) && (attrQName.equals("xmlns") || attrQName.startsWith("xmlns:"))) { if (declAlreadyDeclared(prefix)) continue; // go to the next attribute. nodeType = DTM.NAMESPACE_NODE; } else { nodeType = DTM.ATTRIBUTE_NODE; if (attributes.getType(i).equalsIgnoreCase("ID")) setIDAttribute(valString, elemNode); } // Bit of a hack... if somehow valString is null, stringToIndex will // return -1, which will make things very unhappy. if(null == valString) valString = ""; int val = m_valuesOrPrefixes.stringToIndex(valString); //String attrLocalName = attributes.getLocalName(i); if (null != prefix) { prefixIndex = m_valuesOrPrefixes.stringToIndex(attrQName); int dataIndex = m_data.size(); m_data.addElement(prefixIndex); m_data.addElement(val); val = -dataIndex; } exName = m_expandedNameTable.getExpandedTypeID(attrUri, attrLocalName, nodeType); prev = addNode(nodeType, exName, elemNode, prev, val, false); } if (DTM.NULL != prev) m_nextsib.setElementAt(DTM.NULL,prev); if (null != m_wsfilter) { short wsv = m_wsfilter.getShouldStripSpace(makeNodeHandle(elemNode), this); boolean shouldStrip = (DTMWSFilter.INHERIT == wsv) ? getShouldStripWhitespace() : (DTMWSFilter.STRIP == wsv); pushShouldStripWhitespace(shouldStrip); } m_previous = DTM.NULL; m_contextIndexes.push(m_prefixMappings.size()); // for the children. }
Receive notification of the start of an element. <p>By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).</p> @param uri The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed. @param localName The local name (without prefix), or the empty string if Namespace processing is not being performed. @param qName The qualified name (with prefix), or the empty string if qualified names are not available. @param attributes The specified or defaulted attributes. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#startElement
SAX2DTM::startElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void characters(char ch[], int start, int length) throws SAXException { if (m_textPendingStart == -1) // First one in this block { m_textPendingStart = m_chars.size(); m_coalescedTextType = m_textType; } // Type logic: If all adjacent text is CDATASections, the // concatentated text is treated as a single CDATASection (see // initialization above). If any were ordinary Text, the whole // thing is treated as Text. This may be worth %REVIEW%ing. else if (m_textType == DTM.TEXT_NODE) { m_coalescedTextType = DTM.TEXT_NODE; } m_chars.append(ch, start, length); }
Receive notification of character data inside an element. <p>By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).</p> @param ch The characters. @param start The start position in the character array. @param length The number of characters to use from the character array. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#characters
SAX2DTM::characters
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { // %OPT% We can probably take advantage of the fact that we know this // is whitespace. characters(ch, start, length); }
Receive notification of ignorable whitespace in element content. <p>By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).</p> @param ch The whitespace characters. @param start The start position in the character array. @param length The number of characters to use from the character array. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#ignorableWhitespace
SAX2DTM::ignorableWhitespace
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void processingInstruction(String target, String data) throws SAXException { if (DEBUG) System.out.println("processingInstruction: target: " + target +", data: "+data); charactersFlush(); int exName = m_expandedNameTable.getExpandedTypeID(null, target, DTM.PROCESSING_INSTRUCTION_NODE); int dataIndex = m_valuesOrPrefixes.stringToIndex(data); m_previous = addNode(DTM.PROCESSING_INSTRUCTION_NODE, exName, m_parents.peek(), m_previous, dataIndex, false); }
Receive notification of a processing instruction. <p>By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.</p> @param target The processing instruction target. @param data The processing instruction data, or null if none is supplied. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#processingInstruction
SAX2DTM::processingInstruction
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void skippedEntity(String name) throws SAXException { // %REVIEW% What should be done here? // no op }
Receive notification of a skipped entity. <p>By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.</p> @param name The name of the skipped entity. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#processingInstruction
SAX2DTM::skippedEntity
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void warning(SAXParseException e) throws SAXException { // %REVIEW% Is there anyway to get the JAXP error listener here? System.err.println(e.getMessage()); }
Receive notification of a parser warning. <p>The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each warning, such as inserting the message in a log file or printing it to the console.</p> @param e The warning information encoded as an exception. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ErrorHandler#warning @see org.xml.sax.SAXParseException
SAX2DTM::warning
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void error(SAXParseException e) throws SAXException { throw e; }
Receive notification of a recoverable parser error. <p>The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each error, such as inserting the message in a log file or printing it to the console.</p> @param e The warning information encoded as an exception. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ErrorHandler#warning @see org.xml.sax.SAXParseException
SAX2DTM::error
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public void fatalError(SAXParseException e) throws SAXException { throw e; }
Report a fatal XML parsing error. <p>The default implementation throws a SAXParseException. Application writers may override this method in a subclass if they need to take specific actions for each fatal error (such as collecting all of the errors into a single report): in any case, the application must stop all regular processing when this method is invoked, since the document is no longer reliable, and the parser may no longer report parsing events.</p> @param e The error information encoded as an exception. @throws SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ErrorHandler#fatalError @see org.xml.sax.SAXParseException
SAX2DTM::fatalError
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public SourceLocator getSourceLocatorFor(int node) { if (m_useSourceLocationProperty) { node = makeNodeIdentity(node); return new NodeLocator(null, m_sourceSystemId.elementAt(node), m_sourceLine.elementAt(node), m_sourceColumn.elementAt(node)); } else if(m_locator!=null) { return new NodeLocator(null,m_locator.getSystemId(),-1,-1); } else if(m_systemId!=null) { return new NodeLocator(null,m_systemId,-1,-1); } return null; }
Retrieve the SourceLocator associated with a specific node. This is only meaningful if the XalanProperties.SOURCE_LOCATION flag was set True using setProperty; if it was never set, or was set false, we will return null. (We _could_ return a locator with the document's base URI and bogus line/column information. Trying that; see the else clause.) *
SAX2DTM::getSourceLocatorFor
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Apache-2.0
public ObjectVector(ObjectVector v) { m_map = new Object[v.m_mapSize]; m_mapSize = v.m_mapSize; m_firstFree = v.m_firstFree; m_blocksize = v.m_blocksize; System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree); }
Copy constructor for ObjectVector @param v Existing ObjectVector to copy
ObjectVector::ObjectVector
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void addElement(Object value) { if ((m_firstFree + 1) >= m_mapSize) { m_mapSize += m_blocksize; Object newMap[] = new Object[m_mapSize]; System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); m_map = newMap; } m_map[m_firstFree] = value; m_firstFree++; }
Append an object onto the vector. @param value Object to add to the list
ObjectVector::addElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void addElements(Object value, int numberOfElements) { if ((m_firstFree + numberOfElements) >= m_mapSize) { m_mapSize += (m_blocksize+numberOfElements); Object newMap[] = new Object[m_mapSize]; System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); m_map = newMap; } for (int i = 0; i < numberOfElements; i++) { m_map[m_firstFree] = value; m_firstFree++; } }
Append several Object values onto the vector. @param value Object to add to the list
ObjectVector::addElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void addElements(int numberOfElements) { if ((m_firstFree + numberOfElements) >= m_mapSize) { m_mapSize += (m_blocksize+numberOfElements); Object newMap[] = new Object[m_mapSize]; System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); m_map = newMap; } m_firstFree += numberOfElements; }
Append several slots onto the vector, but do not set the values. @param numberOfElements number of slots to append
ObjectVector::addElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void insertElementAt(Object value, int at) { if ((m_firstFree + 1) >= m_mapSize) { m_mapSize += m_blocksize; Object newMap[] = new Object[m_mapSize]; System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); m_map = newMap; } if (at <= (m_firstFree - 1)) { System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at); } m_map[at] = value; m_firstFree++; }
Inserts the specified object in this vector at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously. @param value Object to insert @param at Index of where to insert
ObjectVector::insertElementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void removeAllElements() { for (int i = 0; i < m_firstFree; i++) { m_map[i] = null; } m_firstFree = 0; }
Remove all elements objects from the list.
ObjectVector::removeAllElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final boolean removeElement(Object s) { for (int i = 0; i < m_firstFree; i++) { if (m_map[i] == s) { if ((i + 1) < m_firstFree) System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i); else m_map[i] = null; m_firstFree--; return true; } } return false; }
Removes the first occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously. @param s Object to remove from array @return True if the object was removed, false if it was not found
ObjectVector::removeElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void removeElementAt(int i) { if (i > m_firstFree) System.arraycopy(m_map, i + 1, m_map, i, m_firstFree); else m_map[i] = null; m_firstFree--; }
Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously. @param i index of where to remove an object
ObjectVector::removeElementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final boolean contains(Object s) { for (int i = 0; i < m_firstFree; i++) { if (m_map[i] == s) return true; } return false; }
Tell if the table contains the given Object. @param s object to look for @return true if the object is in the list
ObjectVector::contains
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public final void setToSize(int size) { Object newMap[] = new Object[size]; System.arraycopy(m_map, 0, newMap, 0, m_firstFree); m_mapSize = size; m_map = newMap; }
Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method. @param elem Object to look for @return the index of the first occurrence of the object argument in this vector at position index or later in the vector; returns -1 if the object is not found. public final int lastIndexOf(Object elem) { for (int i = (m_firstFree - 1); i >= 0; i--) { if (m_map[i] == elem) return i; } return java.lang.Integer.MIN_VALUE; } /* Reset the array to the supplied size. @param size
ObjectVector::setToSize
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public Object clone() throws CloneNotSupportedException { return new ObjectVector(this); }
Returns clone of current ObjectVector @return clone of current ObjectVector
ObjectVector::clone
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/ObjectVector.java
Apache-2.0
public DefaultErrorHandler(PrintWriter pw) { m_pw = pw; }
Constructor DefaultErrorHandler
DefaultErrorHandler::DefaultErrorHandler
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public PrintWriter getErrorWriter() { // Defer creating the java.io.PrintWriter until an error needs to be // reported. if (m_pw == null) { m_pw = new PrintWriter(System.err, true); } return m_pw; }
Retrieve <code>java.io.PrintWriter</code> to which errors are being directed. @return The <code>PrintWriter</code> installed via the constructor or the default <code>PrintWriter</code>
DefaultErrorHandler::getErrorWriter
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void warning(SAXParseException exception) throws SAXException { PrintWriter pw = getErrorWriter(); printLocation(pw, exception); pw.println("Parser warning: " + exception.getMessage()); }
Receive notification of a warning. <p>SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML 1.0 recommendation. The default behaviour is to take no action.</p> <p>The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.</p> @param exception The warning information encapsulated in a SAX parse exception. @throws SAXException Any SAX exception, possibly wrapping another exception.
DefaultErrorHandler::warning
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void error(SAXParseException exception) throws SAXException { //printLocation(exception); // getErrorWriter().println(exception.getMessage()); throw exception; }
Receive notification of a recoverable error. <p>This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.</p> <p>The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML 1.0 recommendation does not require it to do so.</p> @param exception The error information encapsulated in a SAX parse exception. @throws SAXException Any SAX exception, possibly wrapping another exception.
DefaultErrorHandler::error
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void fatalError(SAXParseException exception) throws SAXException { // printLocation(exception); // getErrorWriter().println(exception.getMessage()); throw exception; }
Receive notification of a non-recoverable error. <p>This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.</p> <p>The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting addition error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.</p> @param exception The error information encapsulated in a SAX parse exception. @throws SAXException Any SAX exception, possibly wrapping another exception.
DefaultErrorHandler::fatalError
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void warning(TransformerException exception) throws TransformerException { PrintWriter pw = getErrorWriter(); printLocation(pw, exception); pw.println(exception.getMessage()); }
Receive notification of a warning. <p>SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML 1.0 recommendation. The default behaviour is to take no action.</p> <p>The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.</p> @param exception The warning information encapsulated in a SAX parse exception. @throws javax.xml.transform.TransformerException Any SAX exception, possibly wrapping another exception. @see javax.xml.transform.TransformerException
DefaultErrorHandler::warning
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void error(TransformerException exception) throws TransformerException { // If the m_throwExceptionOnError flag is true, rethrow the exception. // Otherwise report the error to System.err. if (m_throwExceptionOnError) throw exception; else { PrintWriter pw = getErrorWriter(); printLocation(pw, exception); pw.println(exception.getMessage()); } }
Receive notification of a recoverable error. <p>This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.</p> <p>The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML 1.0 recommendation does not require it to do so.</p> @param exception The error information encapsulated in a SAX parse exception. @throws javax.xml.transform.TransformerException Any SAX exception, possibly wrapping another exception. @see javax.xml.transform.TransformerException
DefaultErrorHandler::error
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public void fatalError(TransformerException exception) throws TransformerException { // If the m_throwExceptionOnError flag is true, rethrow the exception. // Otherwise report the error to System.err. if (m_throwExceptionOnError) throw exception; else { PrintWriter pw = getErrorWriter(); printLocation(pw, exception); pw.println(exception.getMessage()); } }
Receive notification of a non-recoverable error. <p>This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.</p> <p>The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting addition error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.</p> @param exception The error information encapsulated in a SAX parse exception. @throws javax.xml.transform.TransformerException Any SAX exception, possibly wrapping another exception. @see javax.xml.transform.TransformerException
DefaultErrorHandler::fatalError
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DefaultErrorHandler.java
Apache-2.0
public StylesheetPIHandler(String baseID, String media, String title, String charset) { m_baseID = baseID; m_media = media; m_title = title; m_charset = charset; }
Construct a StylesheetPIHandler instance that will search for xml-stylesheet PIs based on the given criteria. @param baseID The base ID of the XML document, needed to resolve relative IDs. @param media The desired media criteria. @param title The desired title criteria. @param charset The desired character set criteria.
StylesheetPIHandler::StylesheetPIHandler
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
Apache-2.0
public Source getAssociatedStylesheet() { int sz = m_stylesheets.size(); if (sz > 0) { Source source = (Source) m_stylesheets.elementAt(sz-1); return source; } else return null; }
Return the last stylesheet found that match the constraints. @return Source object that references the last stylesheet reference that matches the constraints.
StylesheetPIHandler::getAssociatedStylesheet
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
Apache-2.0
public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { if (target.equals("xml-stylesheet")) { String href = null; // CDATA #REQUIRED String type = null; // CDATA #REQUIRED String title = null; // CDATA #IMPLIED String media = null; // CDATA #IMPLIED String charset = null; // CDATA #IMPLIED boolean alternate = false; // (yes|no) "no" StringTokenizer tokenizer = new StringTokenizer(data, " \t=\n", true); boolean lookedAhead = false; Source source = null; String token = ""; while (tokenizer.hasMoreTokens()) { if (!lookedAhead) token = tokenizer.nextToken(); else lookedAhead = false; if (tokenizer.hasMoreTokens() && (token.equals(" ") || token.equals("\t") || token.equals("="))) continue; String name = token; if (name.equals("type")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); type = token.substring(1, token.length() - 1); } else if (name.equals("href")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); href = token; if (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); // If the href value has parameters to be passed to a // servlet(something like "foobar?id=12..."), // we want to make sure we get them added to // the href value. Without this check, we would move on // to try to process another attribute and that would be // wrong. // We need to set lookedAhead here to flag that we // already have the next token. while ( token.equals("=") && tokenizer.hasMoreTokens()) { href = href + token + tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); lookedAhead = true; } else { break; } } } href = href.substring(1, href.length() - 1); try { // Add code to use a URIResolver. Patch from Dmitri Ilyin. if (m_uriResolver != null) { source = m_uriResolver.resolve(href, m_baseID); } else { href = SystemIDResolver.getAbsoluteURI(href, m_baseID); source = new SAXSource(new InputSource(href)); } } catch(TransformerException te) { throw new org.xml.sax.SAXException(te); } } else if (name.equals("title")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); title = token.substring(1, token.length() - 1); } else if (name.equals("media")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); media = token.substring(1, token.length() - 1); } else if (name.equals("charset")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); charset = token.substring(1, token.length() - 1); } else if (name.equals("alternate")) { token = tokenizer.nextToken(); while (tokenizer.hasMoreTokens() && (token.equals(" " ) || token.equals("\t") || token.equals("="))) token = tokenizer.nextToken(); alternate = token.substring(1, token.length() - 1).equals("yes"); } } if ((null != type) && (type.equals("text/xsl") || type.equals("text/xml") || type.equals("application/xml+xslt")) && (null != href)) { if (null != m_media) { if (null != media) { if (!media.equals(m_media)) return; } else return; } if (null != m_charset) { if (null != charset) { if (!charset.equals(m_charset)) return; } else return; } if (null != m_title) { if (null != title) { if (!title.equals(m_title)) return; } else return; } m_stylesheets.addElement(source); } } }
Handle the xml-stylesheet processing instruction. @param target The processing instruction target. @param data The processing instruction data, or null if none is supplied. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see org.xml.sax.ContentHandler#processingInstruction @see <a href="http://www.w3.org/TR/xml-stylesheet/">Associating Style Sheets with XML documents, Version 1.0</a>
StylesheetPIHandler::processingInstruction
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
Apache-2.0
public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException { throw new StopParseException(); }
The spec notes that "The xml-stylesheet processing instruction is allowed only in the prolog of an XML document.", so, at least for right now, I'm going to go ahead an throw a TransformerException in order to stop the parse. @param namespaceURI The Namespace URI, or an empty string. @param localName The local name (without prefix), or empty string if not namespace processing. @param qName The qualified name (with prefix). @param atts The specified or defaulted attributes. @throws StopParseException since there can be no valid xml-stylesheet processing instructions past the first element.
StylesheetPIHandler::startElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
Apache-2.0
public void setBaseId(String baseId) { m_baseID = baseId; }
Added additional getter and setter methods for the Base Id to fix bugzilla bug 24187
StylesheetPIHandler::setBaseId
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StylesheetPIHandler.java
Apache-2.0
public synchronized static FastStringBuffer get() { return (FastStringBuffer) m_stringBufPool.getInstance(); }
Get the first free instance of a string buffer, or create one if there are no free instances. @return A string buffer ready for use.
StringBufferPool::get
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StringBufferPool.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StringBufferPool.java
Apache-2.0
public synchronized static void free(FastStringBuffer sb) { // Since this isn't synchronized, setLength must be // done before the instance is freed. // Fix attributed to Peter Speck <[email protected]>. sb.setLength(0); m_stringBufPool.freeInstance(sb); }
Return a string buffer back to the pool. @param sb Must be a non-null reference to a string buffer.
StringBufferPool::free
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StringBufferPool.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/StringBufferPool.java
Apache-2.0
public NodeVector(int blocksize) { m_blocksize = blocksize; m_mapSize = 0; }
Construct a NodeVector, using the given block size. @param blocksize Size of blocks to allocate
NodeVector::NodeVector
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
Apache-2.0
public void insertInOrder(int value) { for (int i = 0; i < m_firstFree; i++) { if (value < m_map[i]) { insertElementAt(value, i); return; } } addElement(value); }
Insert a node in order in the list. @param value Node to insert
NodeVector::insertInOrder
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
Apache-2.0
public void RemoveAllNoClear() { if (null == m_map) return; m_firstFree = 0; }
Set the length to zero, but don't clear the array.
NodeVector::RemoveAllNoClear
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
Apache-2.0
public void sort(int a[], int lo0, int hi0) throws Exception { int lo = lo0; int hi = hi0; // pause(lo, hi); if (lo >= hi) { return; } else if (lo == hi - 1) { /* * sort a two element list by swapping if necessary */ if (a[lo] > a[hi]) { int T = a[lo]; a[lo] = a[hi]; a[hi] = T; } return; } /* * Pick a pivot and move it out of the way */ int pivot = a[(lo + hi) / 2]; a[(lo + hi) / 2] = a[hi]; a[hi] = pivot; while (lo < hi) { /* * Search forward from a[lo] until an element is found that * is greater than the pivot or lo >= hi */ while (a[lo] <= pivot && lo < hi) { lo++; } /* * Search backward from a[hi] until element is found that * is less than the pivot, or lo >= hi */ while (pivot <= a[hi] && lo < hi) { hi--; } /* * Swap elements a[lo] and a[hi] */ if (lo < hi) { int T = a[lo]; a[lo] = a[hi]; a[hi] = T; // pause(); } // if (stopRequested) { // return; // } } /* * Put the median in the "center" of the list */ a[hi0] = a[hi]; a[hi] = pivot; /* * Recursive calls, elements a[lo0] to a[lo-1] are less than or * equal to pivot, elements a[hi+1] to a[hi0] are greater than * pivot. */ sort(a, lo0, lo - 1); sort(a, hi + 1, hi0); }
Sort an array using a quicksort algorithm. @param a The array to be sorted. @param lo0 The low index. @param hi0 The high index. @throws Exception
NodeVector::sort
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
Apache-2.0
public void sort() throws Exception { sort(m_map, 0, m_firstFree - 1); }
Sort an array using a quicksort algorithm. @throws Exception
NodeVector::sort
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NodeVector.java
Apache-2.0
public static Document createDocument(boolean isSecureProcessing) { try { // Use an implementation of the JAVA API for XML Parsing 1.0 to // create a DOM Document node to contain the result. DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setNamespaceAware(true); // BEGIN android-removed // If set, DocumentBuilderFactoryImpl.newDocumentBuilder() fails // because we haven't implemented validation // dfactory.setValidating(true); // BEGIN android-removed // BEGIN android-removed // We haven't implemented secure processing // if (isSecureProcessing) // { // try // { // dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // } // catch (ParserConfigurationException pce) {} // } // END android-removed DocumentBuilder docBuilder = dfactory.newDocumentBuilder(); Document outNode = docBuilder.newDocument(); return outNode; } catch (ParserConfigurationException pce) { throw new RuntimeException( XMLMessages.createXMLMessage( XMLErrorResources.ER_CREATEDOCUMENT_NOT_SUPPORTED, null)); //"createDocument() not supported in XPathContext!"); // return null; } }
DOM Level 1 did not have a standard mechanism for creating a new Document object. This function provides a DOM-implementation-independent abstraction for that for that concept. It's typically used when outputting a new DOM as the result of an operation. <p> TODO: This isn't directly compatable with DOM Level 2. The Level 2 createDocument call also creates the root element, and thus requires that you know what that element will be before creating the Document. We should think about whether we want to change this code, and the callers, so we can use the DOM's own method. (It's also possible that DOM Level 3 may relax this sequence, but you may give up some intelligence in the DOM by doing so; the intent was that knowing the document type and root element might let the DOM automatically switch to a specialized subclass for particular kinds of documents.) @param isSecureProcessing state of the secure processing feature. @return The newly created DOM Document object, with no children, or null if we can't find a DOM implementation that permits creating new empty Documents.
DOMHelper::createDocument
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static Document createDocument() { return createDocument(false); }
DOM Level 1 did not have a standard mechanism for creating a new Document object. This function provides a DOM-implementation-independent abstraction for that for that concept. It's typically used when outputting a new DOM as the result of an operation. @return The newly created DOM Document object, with no children, or null if we can't find a DOM implementation that permits creating new empty Documents.
DOMHelper::createDocument
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public boolean shouldStripSourceNode(Node textNode) throws javax.xml.transform.TransformerException { // return (null == m_envSupport) ? false : m_envSupport.shouldStripSourceNode(textNode); return false; }
Tells, through the combination of the default-space attribute on xsl:stylesheet, xsl:strip-space, xsl:preserve-space, and the xml:space attribute, whether or not extra whitespace should be stripped from the node. Literal elements from template elements should <em>not</em> be tested with this function. @param textNode A text node from the source tree. @return true if the text node should be stripped of extra whitespace. @throws javax.xml.transform.TransformerException @xsl.usage advanced
DOMHelper::shouldStripSourceNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getUniqueID(Node node) { return "N" + Integer.toHexString(node.hashCode()).toUpperCase(); }
Supports the XPath function GenerateID by returning a unique identifier string for any given DOM Node. <p> Warning: The base implementation uses the Node object's hashCode(), which is NOT guaranteed to be unique. If that method hasn't been overridden in this DOM ipmlementation, most Java implementions will derive it from the object's address and should be OK... but if your DOM uses a different definition of hashCode (eg hashing the contents of the subtree), or if your DOM may have multiple objects that represent a single Node in the data structure (eg via proxying), you may need to find another way to assign a unique identifier. <p> Also, be aware that if nodes are destroyed and recreated, there is an open issue regarding whether an ID may be reused. Currently we're assuming that the input document is stable for the duration of the XPath/XSLT operation, so this shouldn't arise in this context. <p> (DOM Level 3 is investigating providing a unique node "key", but that won't help Level 1 and Level 2 implementations.) @param node whose identifier you want to obtain @return a string which should be different for every Node object.
DOMHelper::getUniqueID
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static boolean isNodeAfter(Node node1, Node node2) { if (node1 == node2 || isNodeTheSame(node1, node2)) return true; // Default return value, if there is no defined ordering boolean isNodeAfter = true; Node parent1 = getParentOfNode(node1); Node parent2 = getParentOfNode(node2); // Optimize for most common case if (parent1 == parent2 || isNodeTheSame(parent1, parent2)) // then we know they are siblings { if (null != parent1) isNodeAfter = isNodeAfterSibling(parent1, node1, node2); else { // If both parents are null, ordering is not defined. // We're returning a value in lieu of throwing an exception. // Not a case we expect to arise in XPath, but beware if you // try to reuse this method. // We can just fall through in this case, which allows us // to hit the debugging code at the end of the function. //return isNodeAfter; } } else { // General strategy: Figure out the lengths of the two // ancestor chains, reconcile the lengths, and look for // the lowest common ancestor. If that ancestor is one of // the nodes being compared, it comes before the other. // Otherwise perform a sibling compare. // // NOTE: If no common ancestor is found, ordering is undefined // and we return the default value of isNodeAfter. // Count parents in each ancestor chain int nParents1 = 2, nParents2 = 2; // include node & parent obtained above while (parent1 != null) { nParents1++; parent1 = getParentOfNode(parent1); } while (parent2 != null) { nParents2++; parent2 = getParentOfNode(parent2); } // Initially assume scan for common ancestor starts with // the input nodes. Node startNode1 = node1, startNode2 = node2; // If one ancestor chain is longer, adjust its start point // so we're comparing at the same depths if (nParents1 < nParents2) { // Adjust startNode2 to depth of startNode1 int adjust = nParents2 - nParents1; for (int i = 0; i < adjust; i++) { startNode2 = getParentOfNode(startNode2); } } else if (nParents1 > nParents2) { // adjust startNode1 to depth of startNode2 int adjust = nParents1 - nParents2; for (int i = 0; i < adjust; i++) { startNode1 = getParentOfNode(startNode1); } } Node prevChild1 = null, prevChild2 = null; // so we can "back up" // Loop up the ancestor chain looking for common parent while (null != startNode1) { if (startNode1 == startNode2 || isNodeTheSame(startNode1, startNode2)) // common parent? { if (null == prevChild1) // first time in loop? { // Edge condition: one is the ancestor of the other. isNodeAfter = (nParents1 < nParents2) ? true : false; break; // from while loop } else { // Compare ancestors below lowest-common as siblings isNodeAfter = isNodeAfterSibling(startNode1, prevChild1, prevChild2); break; // from while loop } } // end if(startNode1 == startNode2) // Move up one level and try again prevChild1 = startNode1; startNode1 = getParentOfNode(startNode1); prevChild2 = startNode2; startNode2 = getParentOfNode(startNode2); } // end while(parents exist to examine) } // end big else (not immediate siblings) // WARNING: The following diagnostic won't report the early // "same node" case. Fix if/when needed. /* -- please do not remove... very useful for diagnostics -- System.out.println("node1 = "+node1.getNodeName()+"("+node1.getNodeType()+")"+ ", node2 = "+node2.getNodeName() +"("+node2.getNodeType()+")"+ ", isNodeAfter = "+isNodeAfter); */ return isNodeAfter; } // end isNodeAfter(Node node1, Node node2)
Figure out whether node2 should be considered as being later in the document than node1, in Document Order as defined by the XPath model. This may not agree with the ordering defined by other XML applications. <p> There are some cases where ordering isn't defined, and neither are the results of this function -- though we'll generally return true. TODO: Make sure this does the right thing with attribute nodes!!! @param node1 DOM Node to perform position comparison on. @param node2 DOM Node to perform position comparison on . @return false if node2 comes before node1, otherwise return true. You can think of this as <code>(node1.documentOrderPosition &lt;= node2.documentOrderPosition)</code>.
DOMHelper::isNodeAfter
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static boolean isNodeTheSame(Node node1, Node node2) { if (node1 instanceof DTMNodeProxy && node2 instanceof DTMNodeProxy) return ((DTMNodeProxy)node1).equals((DTMNodeProxy)node2); else return (node1 == node2); }
Use DTMNodeProxy to determine whether two nodes are the same. @param node1 The first DOM node to compare. @param node2 The second DOM node to compare. @return true if the two nodes are the same.
DOMHelper::isNodeTheSame
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
private static boolean isNodeAfterSibling(Node parent, Node child1, Node child2) { boolean isNodeAfterSibling = false; short child1type = child1.getNodeType(); short child2type = child2.getNodeType(); if ((Node.ATTRIBUTE_NODE != child1type) && (Node.ATTRIBUTE_NODE == child2type)) { // always sort attributes before non-attributes. isNodeAfterSibling = false; } else if ((Node.ATTRIBUTE_NODE == child1type) && (Node.ATTRIBUTE_NODE != child2type)) { // always sort attributes before non-attributes. isNodeAfterSibling = true; } else if (Node.ATTRIBUTE_NODE == child1type) { NamedNodeMap children = parent.getAttributes(); int nNodes = children.getLength(); boolean found1 = false, found2 = false; // Count from the start until we find one or the other. for (int i = 0; i < nNodes; i++) { Node child = children.item(i); if (child1 == child || isNodeTheSame(child1, child)) { if (found2) { isNodeAfterSibling = false; break; } found1 = true; } else if (child2 == child || isNodeTheSame(child2, child)) { if (found1) { isNodeAfterSibling = true; break; } found2 = true; } } } else { // TODO: Check performance of alternate solution: // There are two choices here: Count from the start of // the document until we find one or the other, or count // from one until we find or fail to find the other. // Either can wind up scanning all the siblings in the worst // case, which on a wide document can be a lot of work but // is more typically is a short list. // Scanning from the start involves two tests per iteration, // but it isn't clear that scanning from the middle doesn't // yield more iterations on average. // We should run some testcases. Node child = parent.getFirstChild(); boolean found1 = false, found2 = false; while (null != child) { // Node child = children.item(i); if (child1 == child || isNodeTheSame(child1, child)) { if (found2) { isNodeAfterSibling = false; break; } found1 = true; } else if (child2 == child || isNodeTheSame(child2, child)) { if (found1) { isNodeAfterSibling = true; break; } found2 = true; } child = child.getNextSibling(); } } return isNodeAfterSibling; } // end isNodeAfterSibling(Node parent, Node child1, Node child2)
Figure out if child2 is after child1 in document order. <p> Warning: Some aspects of "document order" are not well defined. For example, the order of attributes is considered meaningless in XML, and the order reported by our model will be consistant for a given invocation but may not match that of either the source file or the serialized output. @param parent Must be the parent of both child1 and child2. @param child1 Must be the child of parent and not equal to child2. @param child2 Must be the child of parent and not equal to child1. @return true if child 2 is after child1 in document order.
DOMHelper::isNodeAfterSibling
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public short getLevel(Node n) { short level = 1; while (null != (n = getParentOfNode(n))) { level++; } return level; }
Get the depth level of this node in the tree (equals 1 for a parentless node). @param n Node to be examined. @return the number of ancestors, plus one @xsl.usage internal
DOMHelper::getLevel
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getNamespaceForPrefix(String prefix, Element namespaceContext) { int type; Node parent = namespaceContext; String namespace = null; if (prefix.equals("xml")) { namespace = QName.S_XMLNAMESPACEURI; // Hardcoded, per Namespace spec } else if(prefix.equals("xmlns")) { // Hardcoded in the DOM spec, expected to be adopted by // Namespace spec. NOTE: Namespace declarations _must_ use // the xmlns: prefix; other prefixes declared as belonging // to this namespace will not be recognized and should // probably be rejected by parsers as erroneous declarations. namespace = "http://www.w3.org/2000/xmlns/"; } else { // Attribute name for this prefix's declaration String declname=(prefix=="") ? "xmlns" : "xmlns:"+prefix; // Scan until we run out of Elements or have resolved the namespace while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == Node.ELEMENT_NODE) || (type == Node.ENTITY_REFERENCE_NODE))) { if (type == Node.ELEMENT_NODE) { // Look for the appropriate Namespace Declaration attribute, // either "xmlns:prefix" or (if prefix is "") "xmlns". // TODO: This does not handle "implicit declarations" // which may be created when the DOM is edited. DOM Level // 3 will define how those should be interpreted. But // this issue won't arise in freshly-parsed DOMs. // NOTE: declname is set earlier, outside the loop. Attr attr=((Element)parent).getAttributeNode(declname); if(attr!=null) { namespace = attr.getNodeValue(); break; } } parent = getParentOfNode(parent); } } return namespace; }
Given an XML Namespace prefix and a context in which the prefix is to be evaluated, return the Namespace Name this prefix was bound to. Note that DOM Level 3 is expected to provide a version of this which deals with the DOM's "early binding" behavior. Default handling: @param prefix String containing namespace prefix to be resolved, without the ':' which separates it from the localname when used in a Node Name. The empty sting signifies the default namespace at this point in the document. @param namespaceContext Element which provides context for resolution. (We could extend this to work for other nodes by first seeking their nearest Element ancestor.) @return a String containing the Namespace URI which this prefix represents in the specified context.
DOMHelper::getNamespaceForPrefix
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getNamespaceOfNode(Node n) { String namespaceOfPrefix; boolean hasProcessedNS; NSInfo nsInfo; short ntype = n.getNodeType(); if (Node.ATTRIBUTE_NODE != ntype) { Object nsObj = m_NSInfos.get(n); // return value nsInfo = (nsObj == null) ? null : (NSInfo) nsObj; hasProcessedNS = (nsInfo == null) ? false : nsInfo.m_hasProcessedNS; } else { hasProcessedNS = false; nsInfo = null; } if (hasProcessedNS) { namespaceOfPrefix = nsInfo.m_namespace; } else { namespaceOfPrefix = null; String nodeName = n.getNodeName(); int indexOfNSSep = nodeName.indexOf(':'); String prefix; if (Node.ATTRIBUTE_NODE == ntype) { if (indexOfNSSep > 0) { prefix = nodeName.substring(0, indexOfNSSep); } else { // Attributes don't use the default namespace, so if // there isn't a prefix, we're done. return namespaceOfPrefix; } } else { prefix = (indexOfNSSep >= 0) ? nodeName.substring(0, indexOfNSSep) : ""; } boolean ancestorsHaveXMLNS = false; boolean nHasXMLNS = false; if (prefix.equals("xml")) { namespaceOfPrefix = QName.S_XMLNAMESPACEURI; } else { int parentType; Node parent = n; while ((null != parent) && (null == namespaceOfPrefix)) { if ((null != nsInfo) && (nsInfo.m_ancestorHasXMLNSAttrs == NSInfo.ANCESTORNOXMLNS)) { break; } parentType = parent.getNodeType(); if ((null == nsInfo) || nsInfo.m_hasXMLNSAttrs) { boolean elementHasXMLNS = false; if (parentType == Node.ELEMENT_NODE) { NamedNodeMap nnm = parent.getAttributes(); for (int i = 0; i < nnm.getLength(); i++) { Node attr = nnm.item(i); String aname = attr.getNodeName(); if (aname.charAt(0) == 'x') { boolean isPrefix = aname.startsWith("xmlns:"); if (aname.equals("xmlns") || isPrefix) { if (n == parent) nHasXMLNS = true; elementHasXMLNS = true; ancestorsHaveXMLNS = true; String p = isPrefix ? aname.substring(6) : ""; if (p.equals(prefix)) { namespaceOfPrefix = attr.getNodeValue(); break; } } } } } if ((Node.ATTRIBUTE_NODE != parentType) && (null == nsInfo) && (n != parent)) { nsInfo = elementHasXMLNS ? m_NSInfoUnProcWithXMLNS : m_NSInfoUnProcWithoutXMLNS; m_NSInfos.put(parent, nsInfo); } } if (Node.ATTRIBUTE_NODE == parentType) { parent = getParentOfNode(parent); } else { m_candidateNoAncestorXMLNS.addElement(parent); m_candidateNoAncestorXMLNS.addElement(nsInfo); parent = parent.getParentNode(); } if (null != parent) { Object nsObj = m_NSInfos.get(parent); // return value nsInfo = (nsObj == null) ? null : (NSInfo) nsObj; } } int nCandidates = m_candidateNoAncestorXMLNS.size(); if (nCandidates > 0) { if ((false == ancestorsHaveXMLNS) && (null == parent)) { for (int i = 0; i < nCandidates; i += 2) { Object candidateInfo = m_candidateNoAncestorXMLNS.elementAt(i + 1); if (candidateInfo == m_NSInfoUnProcWithoutXMLNS) { m_NSInfos.put(m_candidateNoAncestorXMLNS.elementAt(i), m_NSInfoUnProcNoAncestorXMLNS); } else if (candidateInfo == m_NSInfoNullWithoutXMLNS) { m_NSInfos.put(m_candidateNoAncestorXMLNS.elementAt(i), m_NSInfoNullNoAncestorXMLNS); } } } m_candidateNoAncestorXMLNS.removeAllElements(); } } if (Node.ATTRIBUTE_NODE != ntype) { if (null == namespaceOfPrefix) { if (ancestorsHaveXMLNS) { if (nHasXMLNS) m_NSInfos.put(n, m_NSInfoNullWithXMLNS); else m_NSInfos.put(n, m_NSInfoNullWithoutXMLNS); } else { m_NSInfos.put(n, m_NSInfoNullNoAncestorXMLNS); } } else { m_NSInfos.put(n, new NSInfo(namespaceOfPrefix, nHasXMLNS)); } } } return namespaceOfPrefix; }
Returns the namespace of the given node. Differs from simply getting the node's prefix and using getNamespaceForPrefix in that it attempts to cache some of the data in NSINFO objects, to avoid repeated lookup. TODO: Should we consider moving that logic into getNamespaceForPrefix? @param n Node to be examined. @return String containing the Namespace Name (uri) for this node. Note that this is undefined for any nodes other than Elements and Attributes.
DOMHelper::getNamespaceOfNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getLocalNameOfNode(Node n) { String qname = n.getNodeName(); int index = qname.indexOf(':'); return (index < 0) ? qname : qname.substring(index + 1); }
Returns the local name of the given node. If the node's name begins with a namespace prefix, this is the part after the colon; otherwise it's the full node name. @param n the node to be examined. @return String containing the Local Name
DOMHelper::getLocalNameOfNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getExpandedElementName(Element elem) { String namespace = getNamespaceOfNode(elem); return (null != namespace) ? namespace + ":" + getLocalNameOfNode(elem) : getLocalNameOfNode(elem); }
Returns the element name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. This is not a standard representation of a node name, but it allows convenient single-string comparison of the "universal" names of two nodes. @param elem Element to be examined. @return String in the form "namespaceURI:localname" if the node belongs to a namespace, or simply "localname" if it doesn't. @see #getExpandedAttributeName
DOMHelper::getExpandedElementName
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getExpandedAttributeName(Attr attr) { String namespace = getNamespaceOfNode(attr); return (null != namespace) ? namespace + ":" + getLocalNameOfNode(attr) : getLocalNameOfNode(attr); }
Returns the attribute name with the namespace prefix (if any) replaced by the Namespace URI it was bound to. This is not a standard representation of a node name, but it allows convenient single-string comparison of the "universal" names of two nodes. @param attr Attr to be examined @return String in the form "namespaceURI:localname" if the node belongs to a namespace, or simply "localname" if it doesn't. @see #getExpandedElementName
DOMHelper::getExpandedAttributeName
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public boolean isIgnorableWhitespace(Text node) { boolean isIgnorable = false; // return value // TODO: I can probably do something to figure out if this // space is ignorable from just the information in // the DOM tree. // -- You need to be able to distinguish whitespace // that is #PCDATA from whitespace that isn't. That requires // DTD support, which won't be standardized until DOM Level 3. return isIgnorable; }
Tell if the node is ignorable whitespace. Note that this can be determined only in the context of a DTD or other Schema, and that DOM Level 2 has nostandardized DOM API which can return that information. @deprecated @param node Node to be examined @return CURRENTLY HARDCODED TO FALSE, but should return true if and only if the node is of type Text, contains only whitespace, and does not appear as part of the #PCDATA content of an element. (Note that determining this last may require allowing for Entity References.)
DOMHelper::isIgnorableWhitespace
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public Node getRoot(Node node) { Node root = null; while (node != null) { root = node; node = getParentOfNode(node); } return root; }
Get the first unparented node in the ancestor chain. @deprecated @param node Starting node, to specify which chain to chase @return the topmost ancestor.
DOMHelper::getRoot
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public Node getRootNode(Node n) { int nt = n.getNodeType(); return ( (Node.DOCUMENT_NODE == nt) || (Node.DOCUMENT_FRAGMENT_NODE == nt) ) ? n : n.getOwnerDocument(); }
Get the root node of the document tree, regardless of whether or not the node passed in is a document node. <p> TODO: This doesn't handle DocumentFragments or "orphaned" subtrees -- it's currently returning ownerDocument even when the tree is not actually part of the main Document tree. We should either rewrite the description to say that it finds the Document node, or change the code to walk up the ancestor chain. @param n Node to be examined @return the Document node. Note that this is not the correct answer if n was (or was a child of) a DocumentFragment or an orphaned node, as can arise if the DOM has been edited rather than being generated by a parser.
DOMHelper::getRootNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public boolean isNamespaceNode(Node n) { if (Node.ATTRIBUTE_NODE == n.getNodeType()) { String attrName = n.getNodeName(); return (attrName.startsWith("xmlns:") || attrName.equals("xmlns")); } return false; }
Test whether the given node is a namespace decl node. In DOM Level 2 this can be done in a namespace-aware manner, but in Level 1 DOMs it has to be done by testing the node name. @param n Node to be examined. @return boolean -- true iff the node is an Attr whose name is "xmlns" or has the "xmlns:" prefix.
DOMHelper::isNamespaceNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static Node getParentOfNode(Node node) throws RuntimeException { Node parent; short nodeType = node.getNodeType(); if (Node.ATTRIBUTE_NODE == nodeType) { Document doc = node.getOwnerDocument(); /* TBD: if(null == doc) { throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CHILD_HAS_NO_OWNER_DOCUMENT, null));//"Attribute child does not have an owner document!"); } */ // Given how expensive the tree walk may be, we should first ask // whether this DOM can answer the question for us. The additional // test does slow down Level 1 DOMs slightly. DOMHelper2, which // is currently specialized for Xerces, assumes it can use the // Level 2 solution. We might want to have an intermediate stage, // which would assume DOM Level 2 but not assume Xerces. // // (Shouldn't have to check whether impl is null in a compliant DOM, // but let's be paranoid for a moment...) DOMImplementation impl=doc.getImplementation(); if(impl!=null && impl.hasFeature("Core","2.0")) { parent=((Attr)node).getOwnerElement(); return parent; } // DOM Level 1 solution, as fallback. Hugely expensive. Element rootElem = doc.getDocumentElement(); if (null == rootElem) { throw new RuntimeException( XMLMessages.createXMLMessage( XMLErrorResources.ER_CHILD_HAS_NO_OWNER_DOCUMENT_ELEMENT, null)); //"Attribute child does not have an owner document element!"); } parent = locateAttrParent(rootElem, node); } else { parent = node.getParentNode(); // if((Node.DOCUMENT_NODE != nodeType) && (null == parent)) // { // throw new RuntimeException("Child does not have parent!"); // } } return parent; }
Obtain the XPath-model parent of a DOM node -- ownerElement for Attrs, parent for other nodes. <p> Background: The DOM believes that you must be your Parent's Child, and thus Attrs don't have parents. XPath said that Attrs do have their owning Element as their parent. This function bridges the difference, either by using the DOM Level 2 ownerElement function or by using a "silly and expensive function" in Level 1 DOMs. <p> (There's some discussion of future DOMs generalizing ownerElement into ownerNode and making it work on all types of nodes. This still wouldn't help the users of Level 1 or Level 2 DOMs) <p> @param node Node whose XPath parent we want to obtain @return the parent of the node, or the ownerElement if it's an Attr node, or null if the node is an orphan. @throws RuntimeException if the Document has no root element. This can't arise if the Document was created via the DOM Level 2 factory methods, but is possible if other mechanisms were used to obtain it
DOMHelper::getParentOfNode
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public Element getElementByID(String id, Document doc) { return null; }
Given an ID, return the element. This can work only if the document is interpreted in the context of a DTD or Schema, since otherwise we don't know which attributes are or aren't IDs. <p> Note that DOM Level 1 had no ability to retrieve this information. DOM Level 2 introduced it but does not promise that it will be supported in all DOMs; those which can't support it will always return null. <p> TODO: getElementByID is currently unimplemented. Support DOM Level 2? @param id The unique identifier to be searched for. @param doc The document to search within. @return CURRENTLY HARDCODED TO NULL, but it should be: The node which has this unique identifier, or null if there is no such node or this DOM can't reliably recognize it.
DOMHelper::getElementByID
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public String getUnparsedEntityURI(String name, Document doc) { String url = ""; DocumentType doctype = doc.getDoctype(); if (null != doctype) { NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); if (null != notationName) // then it's unparsed { // The draft says: "The XSLT processor may use the public // identifier to generate a URI for the entity instead of the URI // specified in the system identifier. If the XSLT processor does // not use the public identifier to generate the URI, it must use // the system identifier; if the system identifier is a relative // URI, it must be resolved into an absolute URI using the URI of // the resource containing the entity declaration as the base // URI [RFC2396]." // So I'm falling a bit short here. url = entity.getSystemId(); if (null == url) { url = entity.getPublicId(); } else { // This should be resolved to an absolute URL, but that's hard // to do from here. } } } return url; }
The getUnparsedEntityURI function returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity. <p> XML processors may choose to use the System Identifier (if one is provided) to resolve the entity, rather than the URI in the Public Identifier. The details are dependent on the processor, and we would have to support some form of plug-in resolver to handle this properly. Currently, we simply return the System Identifier if present, and hope that it a usable URI or that our caller can map it to one. TODO: Resolve Public Identifiers... or consider changing function name. <p> If we find a relative URI reference, XML expects it to be resolved in terms of the base URI of the document. The DOM doesn't do that for us, and it isn't entirely clear whether that should be done here; currently that's pushed up to a higher levelof our application. (Note that DOM Level 1 didn't store the document's base URI.) TODO: Consider resolving Relative URIs. <p> (The DOM's statement that "An XML processor may choose to completely expand entities before the structure model is passed to the DOM" refers only to parsed entities, not unparsed, and hence doesn't affect this function.) @param name A string containing the Entity Name of the unparsed entity. @param doc Document node for the document to be searched. @return String containing the URI of the Unparsed Entity, or an empty string if no such entity exists.
DOMHelper::getUnparsedEntityURI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
private static Node locateAttrParent(Element elem, Node attr) { Node parent = null; // This should only be called for Level 1 DOMs, so we don't have to // worry about namespace issues. In later levels, it's possible // for a DOM to have two Attrs with the same NodeName but // different namespaces, and we'd need to get getAttributeNodeNS... // but later levels also have Attr.getOwnerElement. Attr check=elem.getAttributeNode(attr.getNodeName()); if(check==attr) parent = elem; if (null == parent) { for (Node node = elem.getFirstChild(); null != node; node = node.getNextSibling()) { if (Node.ELEMENT_NODE == node.getNodeType()) { parent = locateAttrParent((Element) node, attr); if (null != parent) break; } } } return parent; }
Support for getParentOfNode; walks a DOM tree until it finds the Element which owns the Attr. This is hugely expensive, and if at all possible you should use the DOM Level 2 Attr.ownerElement() method instead. <p> The DOM Level 1 developers expected that folks would keep track of the last Element they'd seen and could recover the info from that source. Obviously that doesn't work very well if the only information you've been presented with is the Attr. The DOM Level 2 getOwnerElement() method fixes that, but only for Level 2 and later DOMs. @param elem Element whose subtree is to be searched for this Attr @param attr Attr whose owner is to be located. @return the first Element whose attribute list includes the provided attr. In modern DOMs, this will also be the only such Element. (Early DOMs had some hope that Attrs might be sharable, but this idea has been abandoned.)
DOMHelper::locateAttrParent
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public void setDOMFactory(Document domFactory) { this.m_DOMFactory = domFactory; }
Store the factory object required to create DOM nodes in the result tree. In fact, that's just the result tree's Document node... @param domFactory The DOM Document Node within whose context the result tree will be built.
DOMHelper::setDOMFactory
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public Document getDOMFactory() { if (null == this.m_DOMFactory) { this.m_DOMFactory = createDocument(); } return this.m_DOMFactory; }
Retrieve the factory object required to create DOM nodes in the result tree. @return The result tree's DOM Document Node.
DOMHelper::getDOMFactory
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static String getNodeData(Node node) { FastStringBuffer buf = StringBufferPool.get(); String s; try { getNodeData(node, buf); s = (buf.length() > 0) ? buf.toString() : ""; } finally { StringBufferPool.free(buf); } return s; }
Get the textual contents of the node. See getNodeData(Node,FastStringBuffer) for discussion of how whitespace nodes are handled. @param node DOM Node to be examined @return String containing a concatenation of all the textual content within that node. @see #getNodeData(Node,FastStringBuffer)
DOMHelper::getNodeData
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public static void getNodeData(Node node, FastStringBuffer buf) { switch (node.getNodeType()) { case Node.DOCUMENT_FRAGMENT_NODE : case Node.DOCUMENT_NODE : case Node.ELEMENT_NODE : { for (Node child = node.getFirstChild(); null != child; child = child.getNextSibling()) { getNodeData(child, buf); } } break; case Node.TEXT_NODE : case Node.CDATA_SECTION_NODE : buf.append(node.getNodeValue()); break; case Node.ATTRIBUTE_NODE : buf.append(node.getNodeValue()); break; case Node.PROCESSING_INSTRUCTION_NODE : // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING); break; default : // ignore break; } }
Retrieve the text content of a DOM subtree, appending it into a user-supplied FastStringBuffer object. Note that attributes are not considered part of the content of an element. <p> There are open questions regarding whitespace stripping. Currently we make no special effort in that regard, since the standard DOM doesn't yet provide DTD-based information to distinguish whitespace-in-element-context from genuine #PCDATA. Note that we should probably also consider xml:space if/when we address this. DOM Level 3 may solve the problem for us. @param node Node whose subtree is to be walked, gathering the contents of all Text or CDATASection nodes. @param buf FastStringBuffer into which the contents of the text nodes are to be concatenated.
DOMHelper::getNodeData
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/DOMHelper.java
Apache-2.0
public void setFloatBuffer(float[] floatBuffer) { this.floatBuffer = floatBuffer; }
Set a new audio block. @param floatBuffer The audio block that is passed to the next processor.
AudioEvent::setFloatBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public float[] getFloatBuffer(){ return floatBuffer; }
The audio block in floats @return The float representation of the audio block.
AudioEvent::getFloatBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public double getRMS() { return calculateRMS(floatBuffer); }
Calculates and returns the root mean square of the signal. Please cache the result since it is calculated every time. @return The <a href="http://en.wikipedia.org/wiki/Root_mean_square">RMS</a> of the signal present in the current buffer.
AudioEvent::getRMS
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public double getdBSPL() { return soundPressureLevel(floatBuffer); }
Returns the dBSPL for a buffer. @return The dBSPL level for the buffer.
AudioEvent::getdBSPL
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public static double calculateRMS(float[] floatBuffer){ double rms = 0.0; for (int i = 0; i < floatBuffer.length; i++) { rms += floatBuffer[i] * floatBuffer[i]; } rms = rms / Double.valueOf(floatBuffer.length); rms = Math.sqrt(rms); return rms; }
Calculates and returns the root mean square of the signal. Please cache the result since it is calculated every time. @param floatBuffer The audio buffer to calculate the RMS for. @return The <a href="http://en.wikipedia.org/wiki/Root_mean_square">RMS</a> of the signal present in the current buffer.
AudioEvent::calculateRMS
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public void clearFloatBuffer() { Arrays.fill(floatBuffer, 0); }
Set all sample values to zero.
AudioEvent::clearFloatBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
private static double soundPressureLevel(final float[] buffer) { double rms = calculateRMS(buffer); return linearToDecibel(rms); }
Returns the dBSPL for a buffer. @param buffer The buffer with audio information. @return The dBSPL level for the buffer.
AudioEvent::soundPressureLevel
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
private static double linearToDecibel(final double value) { return 20.0 * Math.log10(value); }
Converts a linear to a dB value. @param value The value to convert. @return The converted value.
AudioEvent::linearToDecibel
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public boolean isSilence(double silenceThreshold) { return soundPressureLevel(floatBuffer) < silenceThreshold; }
Checks whether this block of audio is silent @param silenceThreshold the threshold in spl to use. @return True if SPL is below the threshold. False otherwise.
AudioEvent::isSilence
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public void setBytesProcessing(int bytesProcessing) { this.bytesProcessing = bytesProcessing; }
The number of bytes being processed. @param bytesProcessing Sets the number of bytes being processed.
AudioEvent::setBytesProcessing
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioEvent.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioEvent.java
Apache-2.0
public AudioDispatcher(final TarsosDSPAudioInputStream stream, final int audioBufferSize, final int bufferOverlap){ // The copy on write list allows concurrent modification of the list while // it is iterated. A nice feature to have when adding AudioProcessors while // the AudioDispatcher is running. audioProcessors = new CopyOnWriteArrayList<AudioProcessor>(); audioInputStream = stream; format = audioInputStream.getFormat(); setStepSizeAndOverlap(audioBufferSize, bufferOverlap); audioEvent = new AudioEvent(format); audioEvent.setFloatBuffer(audioFloatBuffer); audioEvent.setOverlap(bufferOverlap); converter = TarsosDSPAudioFloatConverter.getConverter(format); stopped = false; bytesToSkip = 0; zeroPadLastBuffer = true; }
Create a new dispatcher from a stream. @param stream The stream to read data from. @param audioBufferSize The size of the buffer defines how much samples are processed in one step. Common values are 1024,2048. @param bufferOverlap How much consecutive buffers overlap (in samples). Half of the AudioBufferSize is common (512, 1024) for an FFT.
AudioDispatcher::AudioDispatcher
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void skip(double seconds){ bytesToSkip = Math.round(seconds * format.getSampleRate()) * format.getFrameSize(); }
Skip a number of seconds before processing the stream. @param seconds The number of seconds to skip
AudioDispatcher::skip
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void setStepSizeAndOverlap(final int audioBufferSize, final int bufferOverlap){ audioFloatBuffer = new float[audioBufferSize]; floatOverlap = bufferOverlap; floatStepSize = audioFloatBuffer.length - floatOverlap; audioByteBuffer = new byte[audioFloatBuffer.length * format.getFrameSize()]; byteOverlap = floatOverlap * format.getFrameSize(); byteStepSize = floatStepSize * format.getFrameSize(); }
Set a new step size and overlap size. Both in number of samples. Watch out with this method: it should be called after a batch of samples is processed, not during. @param audioBufferSize The size of the buffer defines how much samples are processed in one step. Common values are 1024,2048. @param bufferOverlap How much consecutive buffers overlap (in samples). Half of the AudioBufferSize is common (512, 1024) for an FFT.
AudioDispatcher::setStepSizeAndOverlap
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void setZeroPadFirstBuffer(boolean zeroPadFirstBuffer){ this.zeroPadFirstBuffer = zeroPadFirstBuffer; }
if zero pad is true then the first buffer is only filled up to buffer size - hop size E.g. if the buffer is 2048 and the hop size is 48 then you get 2000x0 and 48 filled audio samples @param zeroPadFirstBuffer true if the buffer should be zeroPadFirstBuffer, false otherwise.
AudioDispatcher::setZeroPadFirstBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void setZeroPadLastBuffer(boolean zeroPadLastBuffer) { this.zeroPadLastBuffer = zeroPadLastBuffer; }
If zero pad last buffer is true then the last buffer is filled with zeros until the normal amount of elements are present in the buffer. Otherwise the buffer only contains the last elements and no zeros. By default it is set to true. @param zeroPadLastBuffer A boolean to control whether the last buffer is zero-padded.
AudioDispatcher::setZeroPadLastBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void addAudioProcessor(final AudioProcessor audioProcessor) { audioProcessors.add(audioProcessor); LOG.fine("Added an audioprocessor to the list of processors: " + audioProcessor.toString()); }
Adds an AudioProcessor to the chain of processors. @param audioProcessor The AudioProcessor to add.
AudioDispatcher::addAudioProcessor
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void removeAudioProcessor(final AudioProcessor audioProcessor) { audioProcessors.remove(audioProcessor); audioProcessor.processingFinished(); LOG.fine("Remove an audioprocessor to the list of processors: " + audioProcessor); }
Removes an AudioProcessor to the chain of processors and calls its <code>processingFinished</code> method. @param audioProcessor The AudioProcessor to remove.
AudioDispatcher::removeAudioProcessor
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void stop() { stopped = true; for (final AudioProcessor processor : audioProcessors) { processor.processingFinished(); } try { audioInputStream.close(); } catch (IOException e) { LOG.log(Level.SEVERE, "Closing audio stream error.", e); } }
Stops dispatching audio data.
AudioDispatcher::stop
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
private int readNextAudioBlock() throws IOException { assert floatOverlap < audioFloatBuffer.length; // Is this the first buffer? boolean isFirstBuffer = (bytesProcessed ==0 || bytesProcessed == bytesToSkip); final int offsetInBytes; final int offsetInSamples; final int bytesToRead; //Determine the amount of bytes to read from the stream if(isFirstBuffer && !zeroPadFirstBuffer){ //If this is the first buffer and we do not want to zero pad the //first buffer then read a full buffer bytesToRead = audioByteBuffer.length; // With an offset in bytes of zero; offsetInBytes = 0; offsetInSamples=0; }else{ //In all other cases read the amount of bytes defined by the step size bytesToRead = byteStepSize; offsetInBytes = byteOverlap; offsetInSamples = floatOverlap; } //Shift the audio information using array copy since it is probably faster than manually shifting it. // No need to do this on the first buffer if(!isFirstBuffer && audioFloatBuffer.length == floatOverlap + floatStepSize ){ System.arraycopy(audioFloatBuffer,floatStepSize, audioFloatBuffer,0 ,floatOverlap); /* for(int i = floatStepSize ; i < floatStepSize+floatOverlap ; i++){ audioFloatBuffer[i-floatStepSize] = audioFloatBuffer[i]; }*/ } // Total amount of bytes read int totalBytesRead = 0; // The amount of bytes read from the stream during one iteration. int bytesRead=0; // Is the end of the stream reached? boolean endOfStream = false; // Always try to read the 'bytesToRead' amount of bytes. // unless the stream is closed (stopped is true) or no bytes could be read during one iteration while(!stopped && !endOfStream && totalBytesRead<bytesToRead){ try{ bytesRead = audioInputStream.read(audioByteBuffer, offsetInBytes + totalBytesRead , bytesToRead - totalBytesRead); }catch(IndexOutOfBoundsException e){ // The pipe decoder generates an out of bounds if end // of stream is reached. Ugly hack... bytesRead = -1; } if(bytesRead == -1){ // The end of the stream is reached if the number of bytes read during this iteration equals -1 endOfStream = true; }else{ // Otherwise add the number of bytes read to the total totalBytesRead += bytesRead; } } if(endOfStream){ // Could not read a full buffer from the stream, there are two options: if(zeroPadLastBuffer){ //Make sure the last buffer has the same length as all other buffers and pad with zeros for(int i = offsetInBytes + totalBytesRead; i < audioByteBuffer.length; i++){ audioByteBuffer[i] = 0; } converter.toFloatArray(audioByteBuffer, offsetInBytes, audioFloatBuffer, offsetInSamples, floatStepSize); }else{ // Send a smaller buffer through the chain. byte[] audioByteBufferContent = audioByteBuffer; audioByteBuffer = new byte[offsetInBytes + totalBytesRead]; System.arraycopy(audioByteBufferContent, 0, audioByteBuffer, 0, audioByteBuffer.length); int totalSamplesRead = totalBytesRead/format.getFrameSize(); audioFloatBuffer = new float[offsetInSamples + totalBytesRead/format.getFrameSize()]; converter.toFloatArray(audioByteBuffer, offsetInBytes, audioFloatBuffer, offsetInSamples, totalSamplesRead); } }else if(bytesToRead == totalBytesRead) { // The expected amount of bytes have been read from the stream. if(isFirstBuffer && !zeroPadFirstBuffer){ converter.toFloatArray(audioByteBuffer, 0, audioFloatBuffer, 0, audioFloatBuffer.length); }else{ converter.toFloatArray(audioByteBuffer, offsetInBytes, audioFloatBuffer, offsetInSamples, floatStepSize); } } else if(!stopped) { // If the end of the stream has not been reached and the number of bytes read is not the // expected amount of bytes, then we are in an invalid state; throw new IOException(String.format("The end of the audio stream has not been reached and the number of bytes read (%d) is not equal " + "to the expected amount of bytes(%d).", totalBytesRead,bytesToRead)); } // Makes sure AudioEvent contains correct info. audioEvent.setFloatBuffer(audioFloatBuffer); audioEvent.setOverlap(offsetInSamples); return totalBytesRead; }
Reads the next audio block. It tries to read the number of bytes defined by the audio buffer size minus the overlap. If the expected number of bytes could not be read either the end of the stream is reached or something went wrong. The behavior for the first and last buffer is defined by their corresponding the zero pad settings. The method also handles the case if the first buffer is also the last. @return The number of bytes read. @throws IOException When something goes wrong while reading the stream. In particular, an IOException is thrown if the input stream has been closed.
AudioDispatcher::readNextAudioBlock
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public TarsosDSPAudioFormat getFormat(){ return format; }
The current format used to convert floats to bytes and back. @return The current format used to convert floats to bytes and back.
AudioDispatcher::getFormat
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public float secondsProcessed(){ return bytesProcessed / (format.getSampleSizeInBits() / 8) / format.getSampleRate() / format.getChannels() ; }
@return The currently processed number of seconds.
AudioDispatcher::secondsProcessed
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0
public void setAudioFloatBuffer(float[] audioBuffer){ audioFloatBuffer = audioBuffer; }
Set a new audio buffer @param audioBuffer The audio buffer to use.
AudioDispatcher::setAudioFloatBuffer
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/AudioDispatcher.java
Apache-2.0