code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
844 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public SuballocatedIntVector() { this(2048); }
Default constructor. Note that the default block size is currently 2K, which may be overkill for small lists and undershootng for large ones.
SuballocatedIntVector::SuballocatedIntVector
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public SuballocatedIntVector(int blocksize, int numblocks) { //m_blocksize = blocksize; for(m_SHIFT=0;0!=(blocksize>>>=1);++m_SHIFT) ; m_blocksize=1<<m_SHIFT; m_MASK=m_blocksize-1; m_numblocks = numblocks; m_map0=new int[m_blocksize]; m_map = new int[numblocks][]; m_map[0]=m_map0; m_buildCache = m_map0; m_buildCacheStartIndex = 0; }
Construct a IntVector, using the given block size and number of blocks. For efficiency, we will round the requested size off to a power of two. @param blocksize Size of block to allocate @param numblocks Number of blocks to allocate *
SuballocatedIntVector::SuballocatedIntVector
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public SuballocatedIntVector(int blocksize) { this(blocksize, NUMBLOCKS_DEFAULT); }
Construct a IntVector, using the given block size and the default number of blocks (32). @param blocksize Size of block to allocate *
SuballocatedIntVector::SuballocatedIntVector
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public int size() { return m_firstFree; }
Get the length of the list. @return length of the list
SuballocatedIntVector::size
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public void setSize(int sz) { if(m_firstFree>sz) // Whups; had that backward! m_firstFree = sz; }
Set the length of the list. This will only work to truncate the list, and even then it has not been heavily tested and may not be trustworthy. @return length of the list
SuballocatedIntVector::setSize
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public void addElement(int value) { int indexRelativeToCache = m_firstFree - m_buildCacheStartIndex; // Is the new index an index into the cache row of m_map? if(indexRelativeToCache >= 0 && indexRelativeToCache < m_blocksize) { m_buildCache[indexRelativeToCache]=value; ++m_firstFree; } else { // Growing the outer array should be rare. We initialize to a // total of m_blocksize squared elements, which at the default // size is 4M integers... and we grow by at least that much each // time. However, attempts to microoptimize for this (assume // long enough and catch exceptions) yield no noticable // improvement. int index=m_firstFree>>>m_SHIFT; int offset=m_firstFree&m_MASK; if(index>=m_map.length) { int newsize=index+m_numblocks; int[][] newMap=new int[newsize][]; System.arraycopy(m_map, 0, newMap, 0, m_map.length); m_map=newMap; } int[] block=m_map[index]; if(null==block) block=m_map[index]=new int[m_blocksize]; block[offset]=value; // Cache the current row of m_map. Next m_blocksize-1 // values added will go to this row. m_buildCache = block; m_buildCacheStartIndex = m_firstFree-offset; ++m_firstFree; } }
Append a int onto the vector. @param value Int to add to the list
SuballocatedIntVector::addElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private void addElements(int value, int numberOfElements) { if(m_firstFree+numberOfElements<m_blocksize) for (int i = 0; i < numberOfElements; i++) { m_map0[m_firstFree++]=value; } else { int index=m_firstFree>>>m_SHIFT; int offset=m_firstFree&m_MASK; m_firstFree+=numberOfElements; while( numberOfElements>0) { if(index>=m_map.length) { int newsize=index+m_numblocks; int[][] newMap=new int[newsize][]; System.arraycopy(m_map, 0, newMap, 0, m_map.length); m_map=newMap; } int[] block=m_map[index]; if(null==block) block=m_map[index]=new int[m_blocksize]; int copied=(m_blocksize-offset < numberOfElements) ? m_blocksize-offset : numberOfElements; numberOfElements-=copied; while(copied-- > 0) block[offset++]=value; ++index;offset=0; } } }
Append several int values onto the vector. @param value Int to add to the list
SuballocatedIntVector::addElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private void addElements(int numberOfElements) { int newlen=m_firstFree+numberOfElements; if(newlen>m_blocksize) { int index=m_firstFree>>>m_SHIFT; int newindex=(m_firstFree+numberOfElements)>>>m_SHIFT; for(int i=index+1;i<=newindex;++i) m_map[i]=new int[m_blocksize]; } m_firstFree=newlen; }
Append several slots onto the vector, but do not set the values. Note: "Not Set" means the value is unspecified. @param numberOfElements Int to add to the list
SuballocatedIntVector::addElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private void insertElementAt(int value, int at) { if(at==m_firstFree) addElement(value); else if (at>m_firstFree) { int index=at>>>m_SHIFT; if(index>=m_map.length) { int newsize=index+m_numblocks; int[][] newMap=new int[newsize][]; System.arraycopy(m_map, 0, newMap, 0, m_map.length); m_map=newMap; } int[] block=m_map[index]; if(null==block) block=m_map[index]=new int[m_blocksize]; int offset=at&m_MASK; block[offset]=value; m_firstFree=offset+1; } else { int index=at>>>m_SHIFT; int maxindex=m_firstFree>>>m_SHIFT; // %REVIEW% (m_firstFree+1?) ++m_firstFree; int offset=at&m_MASK; int push; // ***** Easier to work down from top? while(index<=maxindex) { int copylen=m_blocksize-offset-1; int[] block=m_map[index]; if(null==block) { push=0; block=m_map[index]=new int[m_blocksize]; } else { push=block[m_blocksize-1]; System.arraycopy(block, offset , block, offset+1, copylen); } block[offset]=value; value=push; offset=0; ++index; } } }
Inserts the specified node 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. Insertion may be an EXPENSIVE operation! @param value Int to insert @param at Index of where to insert
SuballocatedIntVector::insertElementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public void removeAllElements() { m_firstFree = 0; m_buildCache = m_map0; m_buildCacheStartIndex = 0; }
Wipe it out. Currently defined as equivalent to setSize(0).
SuballocatedIntVector::removeAllElements
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private boolean removeElement(int s) { int at=indexOf(s,0); if(at<0) return false; removeElementAt(at); return true; }
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 Int to remove from array @return True if the int was removed, false if it was not found
SuballocatedIntVector::removeElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private void removeElementAt(int at) { // No point in removing elements that "don't exist"... if(at<m_firstFree) { int index=at>>>m_SHIFT; int maxindex=m_firstFree>>>m_SHIFT; int offset=at&m_MASK; while(index<=maxindex) { int copylen=m_blocksize-offset-1; int[] block=m_map[index]; if(null==block) block=m_map[index]=new int[m_blocksize]; else System.arraycopy(block, offset+1, block, offset, copylen); if(index<maxindex) { int[] next=m_map[index+1]; if(next!=null) block[m_blocksize-1]=(next!=null) ? next[0] : 0; } else block[m_blocksize-1]=0; offset=0; ++index; } } --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 and int
SuballocatedIntVector::removeElementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public void setElementAt(int value, int at) { if(at<m_blocksize) m_map0[at]=value; else { int index=at>>>m_SHIFT; int offset=at&m_MASK; if(index>=m_map.length) { int newsize=index+m_numblocks; int[][] newMap=new int[newsize][]; System.arraycopy(m_map, 0, newMap, 0, m_map.length); m_map=newMap; } int[] block=m_map[index]; if(null==block) block=m_map[index]=new int[m_blocksize]; block[offset]=value; } if(at>=m_firstFree) m_firstFree=at+1; }
Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded. The index must be a value greater than or equal to 0 and less than the current size of the vector. @param value object to set @param at Index of where to set the object
SuballocatedIntVector::setElementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public int elementAt(int i) { // This is actually a significant optimization! if(i<m_blocksize) return m_map0[i]; return m_map[i>>>m_SHIFT][i&m_MASK]; }
Get the nth element. This is often at the innermost loop of an application, so performance is critical. @param i index of value to get @return value at given index. If that value wasn't previously set, the result is undefined for performance reasons. It may throw an exception (see below), may return zero, or (if setSize has previously been used) may return stale data. @throws ArrayIndexOutOfBoundsException if the index was _clearly_ unreasonable (negative, or past the highest block). @throws NullPointerException if the index points to a block that could have existed (based on the highest index used) but has never had anything set into it. %REVIEW% Could add a catch to create the block in that case, or return 0. Try/Catch is _supposed_ to be nearly free when not thrown to. Do we believe that? Should we have a separate safeElementAt?
SuballocatedIntVector::elementAt
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private boolean contains(int s) { return (indexOf(s,0) >= 0); }
Tell if the table contains the given node. @param s object to look for @return true if the object is in the list
SuballocatedIntVector::contains
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public int indexOf(int elem, int index) { if(index>=m_firstFree) return -1; int bindex=index>>>m_SHIFT; int boffset=index&m_MASK; int maxindex=m_firstFree>>>m_SHIFT; int[] block; for(;bindex<maxindex;++bindex) { block=m_map[bindex]; if(block!=null) for(int offset=boffset;offset<m_blocksize;++offset) if(block[offset]==elem) return offset+bindex*m_blocksize; boffset=0; // after first } // Last block may need to stop before end int maxoffset=m_firstFree&m_MASK; block=m_map[maxindex]; for(int offset=boffset;offset<maxoffset;++offset) if(block[offset]==elem) return offset+maxindex*m_blocksize; return -1; }
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 @param index Index of where to begin search @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.
SuballocatedIntVector::indexOf
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public int indexOf(int elem) { return indexOf(elem,0); }
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.
SuballocatedIntVector::indexOf
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
private int lastIndexOf(int elem) { int boffset=m_firstFree&m_MASK; for(int index=m_firstFree>>>m_SHIFT; index>=0; --index) { int[] block=m_map[index]; if(block!=null) for(int offset=boffset; offset>=0; --offset) if(block[offset]==elem) return offset+index*m_blocksize; boffset=0; // after first } return -1; }
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.
SuballocatedIntVector::lastIndexOf
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public final int[] getMap0() { return m_map0; }
Return the internal m_map0 array @return the m_map0 array
SuballocatedIntVector::getMap0
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
Apache-2.0
public final int[][] getMap() { return m_map; }
Return the m_map double array @return the internal map of array of arrays
SuballocatedIntVector::getMap
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/SuballocatedIntVector.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 WrappedRuntimeException(Exception e) { super(e.getMessage()); m_exception = e; }
Construct a WrappedRuntimeException from a checked exception. @param e Primary checked exception
WrappedRuntimeException::WrappedRuntimeException
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
Apache-2.0
public WrappedRuntimeException(String msg, Exception e) { super(msg); m_exception = e; }
Constructor WrappedRuntimeException @param msg Exception information. @param e Primary checked exception
WrappedRuntimeException::WrappedRuntimeException
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
Apache-2.0
public Exception getException() { return m_exception; }
Get the checked exception that this runtime exception wraps. @return The primary checked exception
WrappedRuntimeException::getException
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/WrappedRuntimeException.java
Apache-2.0
public NameSpace(String prefix, String uri) { m_prefix = prefix; m_uri = uri; }
Construct a namespace for placement on the result tree namespace stack. @param prefix Prefix of this element @param uri URI of this element
NameSpace::NameSpace
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NameSpace.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/NameSpace.java
Apache-2.0
public MalformedURIException() { super(); }
Constructs a <code>MalformedURIException</code> with no specified detail message.
MalformedURIException::MalformedURIException
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public MalformedURIException(String p_msg) { super(p_msg); }
Constructs a <code>MalformedURIException</code> with the specified detail message. @param p_msg the detail message.
MalformedURIException::MalformedURIException
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(){}
Construct a new and uninitialized URI.
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(URI p_other) { initialize(p_other); }
Construct a new URI from another URI. All fields for this URI are set equal to the fields of the URI passed in. @param p_other the URI to copy (cannot be null)
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(String p_uriSpec) throws MalformedURIException { this((URI) null, p_uriSpec); }
Construct a new URI from a URI specification string. If the specification follows the "generic URI" syntax, (two slashes following the first colon), the specification will be parsed accordingly - setting the scheme, userinfo, host,port, path, query string and fragment fields as necessary. If the specification does not follow the "generic URI" syntax, the specification is parsed into a scheme and scheme-specific part (stored as the path) only. @param p_uriSpec the URI specification string (cannot be null or empty) @throws MalformedURIException if p_uriSpec violates any syntax rules
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(URI p_base, String p_uriSpec) throws MalformedURIException { initialize(p_base, p_uriSpec); }
Construct a new URI from a base URI and a URI specification string. The URI specification string may be a relative URI. @param p_base the base URI (cannot be null if p_uriSpec is null or empty) @param p_uriSpec the URI specification string (cannot be null or empty if p_base is null) @throws MalformedURIException if p_uriSpec violates any syntax rules
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(String p_scheme, String p_schemeSpecificPart) throws MalformedURIException { if (p_scheme == null || p_scheme.trim().length() == 0) { throw new MalformedURIException( "Cannot construct URI with null/empty scheme!"); } if (p_schemeSpecificPart == null || p_schemeSpecificPart.trim().length() == 0) { throw new MalformedURIException( "Cannot construct URI with null/empty scheme-specific part!"); } setScheme(p_scheme); setPath(p_schemeSpecificPart); }
Construct a new URI that does not follow the generic URI syntax. Only the scheme and scheme-specific part (stored as the path) are initialized. @param p_scheme the URI scheme (cannot be null or empty) @param p_schemeSpecificPart the scheme-specific part (cannot be null or empty) @throws MalformedURIException if p_scheme violates any syntax rules
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(String p_scheme, String p_host, String p_path, String p_queryString, String p_fragment) throws MalformedURIException { this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment); }
Construct a new URI that follows the generic URI syntax from its component parts. Each component is validated for syntax and some basic semantic checks are performed as well. See the individual setter methods for specifics. @param p_scheme the URI scheme (cannot be null or empty) @param p_host the hostname or IPv4 address for the URI @param p_path the URI path - if the path contains '?' or '#', then the query string and/or fragment will be set from the path; however, if the query and fragment are specified both in the path and as separate parameters, an exception is thrown @param p_queryString the URI query string (cannot be specified if path is null) @param p_fragment the URI fragment (cannot be specified if path is null) @throws MalformedURIException if any of the parameters violates syntax rules or semantic rules
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public URI(String p_scheme, String p_userinfo, String p_host, int p_port, String p_path, String p_queryString, String p_fragment) throws MalformedURIException { if (p_scheme == null || p_scheme.trim().length() == 0) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_REQUIRED, null)); //"Scheme is required!"); } if (p_host == null) { if (p_userinfo != null) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_USERINFO_IF_NO_HOST, null)); //"Userinfo may not be specified if host is not specified!"); } if (p_port != -1) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_PORT_IF_NO_HOST, null)); //"Port may not be specified if host is not specified!"); } } if (p_path != null) { if (p_path.indexOf('?') != -1 && p_queryString != null) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_QUERY_STRING_IN_PATH, null)); //"Query string cannot be specified in path and query string!"); } if (p_path.indexOf('#') != -1 && p_fragment != null) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_FRAGMENT_STRING_IN_PATH, null)); //"Fragment cannot be specified in both the path and fragment!"); } } setScheme(p_scheme); setHost(p_host); setPort(p_port); setUserinfo(p_userinfo); setPath(p_path); setQueryString(p_queryString); setFragment(p_fragment); }
Construct a new URI that follows the generic URI syntax from its component parts. Each component is validated for syntax and some basic semantic checks are performed as well. See the individual setter methods for specifics. @param p_scheme the URI scheme (cannot be null or empty) @param p_userinfo the URI userinfo (cannot be specified if host is null) @param p_host the hostname or IPv4 address for the URI @param p_port the URI port (may be -1 for "unspecified"; cannot be specified if host is null) @param p_path the URI path - if the path contains '?' or '#', then the query string and/or fragment will be set from the path; however, if the query and fragment are specified both in the path and as separate parameters, an exception is thrown @param p_queryString the URI query string (cannot be specified if path is null) @param p_fragment the URI fragment (cannot be specified if path is null) @throws MalformedURIException if any of the parameters violates syntax rules or semantic rules
MalformedURIException::URI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private void initialize(URI p_other) { m_scheme = p_other.getScheme(); m_userinfo = p_other.getUserinfo(); m_host = p_other.getHost(); m_port = p_other.getPort(); m_path = p_other.getPath(); m_queryString = p_other.getQueryString(); m_fragment = p_other.getFragment(); }
Initialize all fields of this URI from another URI. @param p_other the URI to copy (cannot be null)
MalformedURIException::initialize
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private void initialize(URI p_base, String p_uriSpec) throws MalformedURIException { if (p_base == null && (p_uriSpec == null || p_uriSpec.trim().length() == 0)) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_CANNOT_INIT_URI_EMPTY_PARMS, null)); //"Cannot initialize URI with empty parameters."); } // just make a copy of the base if spec is empty if (p_uriSpec == null || p_uriSpec.trim().length() == 0) { initialize(p_base); return; } String uriSpec = p_uriSpec.trim(); int uriSpecLen = uriSpec.length(); int index = 0; // check for scheme int colonIndex = uriSpec.indexOf(':'); if (colonIndex < 0) { if (p_base == null) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_SCHEME_IN_URI, new Object[]{uriSpec})); //"No scheme found in URI: "+uriSpec); } } else { initializeScheme(uriSpec); uriSpec = uriSpec.substring(colonIndex+1); // This is a fix for XALANJ-2059. if(m_scheme != null && p_base != null) { // a) If <uriSpec> starts with a slash (/), it means <uriSpec> is absolute // and p_base can be ignored. // For example, // uriSpec = file:/myDIR/myXSLFile.xsl // p_base = file:/myWork/ // // Here, uriSpec has absolute path after scheme file and : // Hence p_base can be ignored. // // b) Similarily, according to RFC 2396, uri is resolved for <uriSpec> relative to <p_base> // if scheme in <uriSpec> is same as scheme in <p_base>, else p_base can be ignored. // // c) if <p_base> is not hierarchical, it can be ignored. // if(uriSpec.startsWith("/") || !m_scheme.equals(p_base.m_scheme) || !p_base.getSchemeSpecificPart().startsWith("/")) { p_base = null; } } // Fix for XALANJ-2059 uriSpecLen = uriSpec.length(); } // two slashes means generic URI syntax, so we get the authority if (uriSpec.startsWith("//")) { index += 2; int startPos = index; // get authority - everything up to path, query or fragment char testChar = '\0'; while (index < uriSpecLen) { testChar = uriSpec.charAt(index); if (testChar == '/' || testChar == '?' || testChar == '#') { break; } index++; } // if we found authority, parse it out, otherwise we set the // host to empty string if (index > startPos) { initializeAuthority(uriSpec.substring(startPos, index)); } else { m_host = ""; } } initializePath(uriSpec.substring(index)); // Resolve relative URI to base URI - see RFC 2396 Section 5.2 // In some cases, it might make more sense to throw an exception // (when scheme is specified is the string spec and the base URI // is also specified, for example), but we're just following the // RFC specifications if (p_base != null) { // check to see if this is the current doc - RFC 2396 5.2 #2 // note that this is slightly different from the RFC spec in that // we don't include the check for query string being null // - this handles cases where the urispec is just a query // string or a fragment (e.g. "?y" or "#s") - // see <http://www.ics.uci.edu/~fielding/url/test1.html> which // identified this as a bug in the RFC if (m_path.length() == 0 && m_scheme == null && m_host == null) { m_scheme = p_base.getScheme(); m_userinfo = p_base.getUserinfo(); m_host = p_base.getHost(); m_port = p_base.getPort(); m_path = p_base.getPath(); if (m_queryString == null) { m_queryString = p_base.getQueryString(); } return; } // check for scheme - RFC 2396 5.2 #3 // if we found a scheme, it means absolute URI, so we're done if (m_scheme == null) { m_scheme = p_base.getScheme(); } // check for authority - RFC 2396 5.2 #4 // if we found a host, then we've got a network path, so we're done if (m_host == null) { m_userinfo = p_base.getUserinfo(); m_host = p_base.getHost(); m_port = p_base.getPort(); } else { return; } // check for absolute path - RFC 2396 5.2 #5 if (m_path.length() > 0 && m_path.startsWith("/")) { return; } // if we get to this point, we need to resolve relative path // RFC 2396 5.2 #6 String path = new String(); String basePath = p_base.getPath(); // 6a - get all but the last segment of the base URI path if (basePath != null) { int lastSlash = basePath.lastIndexOf('/'); if (lastSlash != -1) { path = basePath.substring(0, lastSlash + 1); } } // 6b - append the relative URI path path = path.concat(m_path); // 6c - remove all "./" where "." is a complete path segment index = -1; while ((index = path.indexOf("/./")) != -1) { path = path.substring(0, index + 1).concat(path.substring(index + 3)); } // 6d - remove "." if path ends with "." as a complete path segment if (path.endsWith("/.")) { path = path.substring(0, path.length() - 1); } // 6e - remove all "<segment>/../" where "<segment>" is a complete // path segment not equal to ".." index = -1; int segIndex = -1; String tempString = null; while ((index = path.indexOf("/../")) > 0) { tempString = path.substring(0, path.indexOf("/../")); segIndex = tempString.lastIndexOf('/'); if (segIndex != -1) { if (!tempString.substring(segIndex++).equals("..")) { path = path.substring(0, segIndex).concat(path.substring(index + 4)); } } } // 6f - remove ending "<segment>/.." where "<segment>" is a // complete path segment if (path.endsWith("/..")) { tempString = path.substring(0, path.length() - 3); segIndex = tempString.lastIndexOf('/'); if (segIndex != -1) { path = path.substring(0, segIndex + 1); } } m_path = path; } }
Initializes this URI from a base URI and a URI specification string. See RFC 2396 Section 4 and Appendix B for specifications on parsing the URI and Section 5 for specifications on resolving relative URIs and relative paths. @param p_base the base URI (may be null if p_uriSpec is an absolute URI) @param p_uriSpec the URI spec string which may be an absolute or relative URI (can only be null/empty if p_base is not null) @throws MalformedURIException if p_base is null and p_uriSpec is not an absolute URI or if p_uriSpec violates syntax rules
MalformedURIException::initialize
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private void initializeScheme(String p_uriSpec) throws MalformedURIException { int uriSpecLen = p_uriSpec.length(); int index = 0; String scheme = null; char testChar = '\0'; while (index < uriSpecLen) { testChar = p_uriSpec.charAt(index); if (testChar == ':' || testChar == '/' || testChar == '?' || testChar == '#') { break; } index++; } scheme = p_uriSpec.substring(0, index); if (scheme.length() == 0) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_SCHEME_INURI, null)); //"No scheme found in URI."); } else { setScheme(scheme); } }
Initialize the scheme for this URI from a URI string spec. @param p_uriSpec the URI specification (cannot be null) @throws MalformedURIException if URI does not have a conformant scheme
MalformedURIException::initializeScheme
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private void initializeAuthority(String p_uriSpec) throws MalformedURIException { int index = 0; int start = 0; int end = p_uriSpec.length(); char testChar = '\0'; String userinfo = null; // userinfo is everything up @ if (p_uriSpec.indexOf('@', start) != -1) { while (index < end) { testChar = p_uriSpec.charAt(index); if (testChar == '@') { break; } index++; } userinfo = p_uriSpec.substring(start, index); index++; } // host is everything up to ':' String host = null; start = index; while (index < end) { testChar = p_uriSpec.charAt(index); if (testChar == ':') { break; } index++; } host = p_uriSpec.substring(start, index); int port = -1; if (host.length() > 0) { // port if (testChar == ':') { index++; start = index; while (index < end) { index++; } String portStr = p_uriSpec.substring(start, index); if (portStr.length() > 0) { for (int i = 0; i < portStr.length(); i++) { if (!isDigit(portStr.charAt(i))) { throw new MalformedURIException( portStr + " is invalid. Port should only contain digits!"); } } try { port = Integer.parseInt(portStr); } catch (NumberFormatException nfe) { // can't happen } } } } setHost(host); setPort(port); setUserinfo(userinfo); }
Initialize the authority (userinfo, host and port) for this URI from a URI string spec. @param p_uriSpec the URI specification (cannot be null) @throws MalformedURIException if p_uriSpec violates syntax rules
MalformedURIException::initializeAuthority
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private void initializePath(String p_uriSpec) throws MalformedURIException { if (p_uriSpec == null) { throw new MalformedURIException( "Cannot initialize path from null string!"); } int index = 0; int start = 0; int end = p_uriSpec.length(); char testChar = '\0'; // path - everything up to query string or fragment while (index < end) { testChar = p_uriSpec.charAt(index); if (testChar == '?' || testChar == '#') { break; } // check for valid escape sequence if (testChar == '%') { if (index + 2 >= end ||!isHex(p_uriSpec.charAt(index + 1)) ||!isHex(p_uriSpec.charAt(index + 2))) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE, null)); //"Path contains invalid escape sequence!"); } } else if (!isReservedCharacter(testChar) &&!isUnreservedCharacter(testChar)) { if ('\\' != testChar) throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_INVALID_CHAR, new Object[]{String.valueOf(testChar)})); //"Path contains invalid character: " //+ testChar); } index++; } m_path = p_uriSpec.substring(start, index); // query - starts with ? and up to fragment or end if (testChar == '?') { index++; start = index; while (index < end) { testChar = p_uriSpec.charAt(index); if (testChar == '#') { break; } if (testChar == '%') { if (index + 2 >= end ||!isHex(p_uriSpec.charAt(index + 1)) ||!isHex(p_uriSpec.charAt(index + 2))) { throw new MalformedURIException( "Query string contains invalid escape sequence!"); } } else if (!isReservedCharacter(testChar) &&!isUnreservedCharacter(testChar)) { throw new MalformedURIException( "Query string contains invalid character:" + testChar); } index++; } m_queryString = p_uriSpec.substring(start, index); } // fragment - starts with # if (testChar == '#') { index++; start = index; while (index < end) { testChar = p_uriSpec.charAt(index); if (testChar == '%') { if (index + 2 >= end ||!isHex(p_uriSpec.charAt(index + 1)) ||!isHex(p_uriSpec.charAt(index + 2))) { throw new MalformedURIException( "Fragment contains invalid escape sequence!"); } } else if (!isReservedCharacter(testChar) &&!isUnreservedCharacter(testChar)) { throw new MalformedURIException( "Fragment contains invalid character:" + testChar); } index++; } m_fragment = p_uriSpec.substring(start, index); } }
Initialize the path for this URI from a URI string spec. @param p_uriSpec the URI specification (cannot be null) @throws MalformedURIException if p_uriSpec violates syntax rules
MalformedURIException::initializePath
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getScheme() { return m_scheme; }
Get the scheme for this URI. @return the scheme for this URI
MalformedURIException::getScheme
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getSchemeSpecificPart() { StringBuffer schemespec = new StringBuffer(); if (m_userinfo != null || m_host != null || m_port != -1) { schemespec.append("//"); } if (m_userinfo != null) { schemespec.append(m_userinfo); schemespec.append('@'); } if (m_host != null) { schemespec.append(m_host); } if (m_port != -1) { schemespec.append(':'); schemespec.append(m_port); } if (m_path != null) { schemespec.append((m_path)); } if (m_queryString != null) { schemespec.append('?'); schemespec.append(m_queryString); } if (m_fragment != null) { schemespec.append('#'); schemespec.append(m_fragment); } return schemespec.toString(); }
Get the scheme-specific part for this URI (everything following the scheme and the first colon). See RFC 2396 Section 5.2 for spec. @return the scheme-specific part for this URI
MalformedURIException::getSchemeSpecificPart
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getUserinfo() { return m_userinfo; }
Get the userinfo for this URI. @return the userinfo for this URI (null if not specified).
MalformedURIException::getUserinfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getHost() { return m_host; }
Get the host for this URI. @return the host for this URI (null if not specified).
MalformedURIException::getHost
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public int getPort() { return m_port; }
Get the port for this URI. @return the port for this URI (-1 if not specified).
MalformedURIException::getPort
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getPath(boolean p_includeQueryString, boolean p_includeFragment) { StringBuffer pathString = new StringBuffer(m_path); if (p_includeQueryString && m_queryString != null) { pathString.append('?'); pathString.append(m_queryString); } if (p_includeFragment && m_fragment != null) { pathString.append('#'); pathString.append(m_fragment); } return pathString.toString(); }
Get the path for this URI (optionally with the query string and fragment). @param p_includeQueryString if true (and query string is not null), then a "?" followed by the query string will be appended @param p_includeFragment if true (and fragment is not null), then a "#" followed by the fragment will be appended @return the path for this URI possibly including the query string and fragment
MalformedURIException::getPath
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getPath() { return m_path; }
Get the path for this URI. Note that the value returned is the path only and does not include the query string or fragment. @return the path for this URI.
MalformedURIException::getPath
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getQueryString() { return m_queryString; }
Get the query string for this URI. @return the query string for this URI. Null is returned if there was no "?" in the URI spec, empty string if there was a "?" but no query string following it.
MalformedURIException::getQueryString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String getFragment() { return m_fragment; }
Get the fragment for this URI. @return the fragment for this URI. Null is returned if there was no "#" in the URI spec, empty string if there was a "#" but no fragment following it.
MalformedURIException::getFragment
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setScheme(String p_scheme) throws MalformedURIException { if (p_scheme == null) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_FROM_NULL_STRING, null)); //"Cannot set scheme from null string!"); } if (!isConformantSchemeName(p_scheme)) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_SCHEME_NOT_CONFORMANT, null)); //"The scheme is not conformant."); } m_scheme = p_scheme.toLowerCase(); }
Set the scheme for this URI. The scheme is converted to lowercase before it is set. @param p_scheme the scheme for this URI (cannot be null) @throws MalformedURIException if p_scheme is not a conformant scheme name
MalformedURIException::setScheme
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setUserinfo(String p_userinfo) throws MalformedURIException { if (p_userinfo == null) { m_userinfo = null; } else { if (m_host == null) { throw new MalformedURIException( "Userinfo cannot be set when host is null!"); } // userinfo can contain alphanumerics, mark characters, escaped // and ';',':','&','=','+','$',',' int index = 0; int end = p_userinfo.length(); char testChar = '\0'; while (index < end) { testChar = p_userinfo.charAt(index); if (testChar == '%') { if (index + 2 >= end ||!isHex(p_userinfo.charAt(index + 1)) ||!isHex(p_userinfo.charAt(index + 2))) { throw new MalformedURIException( "Userinfo contains invalid escape sequence!"); } } else if (!isUnreservedCharacter(testChar) && USERINFO_CHARACTERS.indexOf(testChar) == -1) { throw new MalformedURIException( "Userinfo contains invalid character:" + testChar); } index++; } } m_userinfo = p_userinfo; }
Set the userinfo for this URI. If a non-null value is passed in and the host value is null, then an exception is thrown. @param p_userinfo the userinfo for this URI @throws MalformedURIException if p_userinfo contains invalid characters
MalformedURIException::setUserinfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setHost(String p_host) throws MalformedURIException { if (p_host == null || p_host.trim().length() == 0) { m_host = p_host; m_userinfo = null; m_port = -1; } else if (!isWellFormedAddress(p_host)) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_HOST_ADDRESS_NOT_WELLFORMED, null)); //"Host is not a well formed address!"); } m_host = p_host; }
Set the host for this URI. If null is passed in, the userinfo field is also set to null and the port is set to -1. @param p_host the host for this URI @throws MalformedURIException if p_host is not a valid IP address or DNS hostname.
MalformedURIException::setHost
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setPort(int p_port) throws MalformedURIException { if (p_port >= 0 && p_port <= 65535) { if (m_host == null) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_PORT_WHEN_HOST_NULL, null)); //"Port cannot be set when host is null!"); } } else if (p_port != -1) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_INVALID_PORT, null)); //"Invalid port number!"); } m_port = p_port; }
Set the port for this URI. -1 is used to indicate that the port is not specified, otherwise valid port numbers are between 0 and 65535. If a valid port number is passed in and the host field is null, an exception is thrown. @param p_port the port number for this URI @throws MalformedURIException if p_port is not -1 and not a valid port number
MalformedURIException::setPort
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setPath(String p_path) throws MalformedURIException { if (p_path == null) { m_path = null; m_queryString = null; m_fragment = null; } else { initializePath(p_path); } }
Set the path for this URI. If the supplied path is null, then the query string and fragment are set to null as well. If the supplied path includes a query string and/or fragment, these fields will be parsed and set as well. Note that, for URIs following the "generic URI" syntax, the path specified should start with a slash. For URIs that do not follow the generic URI syntax, this method sets the scheme-specific part. @param p_path the path for this URI (may be null) @throws MalformedURIException if p_path contains invalid characters
MalformedURIException::setPath
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void appendPath(String p_addToPath) throws MalformedURIException { if (p_addToPath == null || p_addToPath.trim().length() == 0) { return; } if (!isURIString(p_addToPath)) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_PATH_INVALID_CHAR, new Object[]{p_addToPath})); //"Path contains invalid character!"); } if (m_path == null || m_path.trim().length() == 0) { if (p_addToPath.startsWith("/")) { m_path = p_addToPath; } else { m_path = "/" + p_addToPath; } } else if (m_path.endsWith("/")) { if (p_addToPath.startsWith("/")) { m_path = m_path.concat(p_addToPath.substring(1)); } else { m_path = m_path.concat(p_addToPath); } } else { if (p_addToPath.startsWith("/")) { m_path = m_path.concat(p_addToPath); } else { m_path = m_path.concat("/" + p_addToPath); } } }
Append to the end of the path of this URI. If the current path does not end in a slash and the path to be appended does not begin with a slash, a slash will be appended to the current path before the new segment is added. Also, if the current path ends in a slash and the new segment begins with a slash, the extra slash will be removed before the new segment is appended. @param p_addToPath the new segment to be added to the current path @throws MalformedURIException if p_addToPath contains syntax errors
MalformedURIException::appendPath
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setQueryString(String p_queryString) throws MalformedURIException { if (p_queryString == null) { m_queryString = null; } else if (!isGenericURI()) { throw new MalformedURIException( "Query string can only be set for a generic URI!"); } else if (getPath() == null) { throw new MalformedURIException( "Query string cannot be set when path is null!"); } else if (!isURIString(p_queryString)) { throw new MalformedURIException( "Query string contains invalid character!"); } else { m_queryString = p_queryString; } }
Set the query string for this URI. A non-null value is valid only if this is an URI conforming to the generic URI syntax and the path value is not null. @param p_queryString the query string for this URI @throws MalformedURIException if p_queryString is not null and this URI does not conform to the generic URI syntax or if the path is null
MalformedURIException::setQueryString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public void setFragment(String p_fragment) throws MalformedURIException { if (p_fragment == null) { m_fragment = null; } else if (!isGenericURI()) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_FOR_GENERIC_URI, null)); //"Fragment can only be set for a generic URI!"); } else if (getPath() == null) { throw new MalformedURIException( XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_WHEN_PATH_NULL, null)); //"Fragment cannot be set when path is null!"); } else if (!isURIString(p_fragment)) { throw new MalformedURIException(XMLMessages.createXMLMessage(XMLErrorResources.ER_FRAG_INVALID_CHAR, null)); //"Fragment contains invalid character!"); } else { m_fragment = p_fragment; } }
Set the fragment for this URI. A non-null value is valid only if this is a URI conforming to the generic URI syntax and the path value is not null. @param p_fragment the fragment for this URI @throws MalformedURIException if p_fragment is not null and this URI does not conform to the generic URI syntax or if the path is null
MalformedURIException::setFragment
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public boolean equals(Object p_test) { if (p_test instanceof URI) { URI testURI = (URI) p_test; if (((m_scheme == null && testURI.m_scheme == null) || (m_scheme != null && testURI.m_scheme != null && m_scheme.equals( testURI.m_scheme))) && ((m_userinfo == null && testURI.m_userinfo == null) || (m_userinfo != null && testURI.m_userinfo != null && m_userinfo.equals( testURI.m_userinfo))) && ((m_host == null && testURI.m_host == null) || (m_host != null && testURI.m_host != null && m_host.equals( testURI.m_host))) && m_port == testURI.m_port && ((m_path == null && testURI.m_path == null) || (m_path != null && testURI.m_path != null && m_path.equals( testURI.m_path))) && ((m_queryString == null && testURI.m_queryString == null) || (m_queryString != null && testURI.m_queryString != null && m_queryString.equals( testURI.m_queryString))) && ((m_fragment == null && testURI.m_fragment == null) || (m_fragment != null && testURI.m_fragment != null && m_fragment.equals( testURI.m_fragment)))) { return true; } } return false; }
Determines if the passed-in Object is equivalent to this URI. @param p_test the Object to test for equality. @return true if p_test is a URI with all values equal to this URI, false otherwise
MalformedURIException::equals
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public String toString() { StringBuffer uriSpecString = new StringBuffer(); if (m_scheme != null) { uriSpecString.append(m_scheme); uriSpecString.append(':'); } uriSpecString.append(getSchemeSpecificPart()); return uriSpecString.toString(); }
Get the URI as a string specification. See RFC 2396 Section 5.2. @return the URI string specification
MalformedURIException::toString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public boolean isGenericURI() { // presence of the host (whether valid or empty) means // double-slashes which means generic uri return (m_host != null); }
Get the indicator as to whether this URI uses the "generic URI" syntax. @return true if this URI uses the "generic URI" syntax, false otherwise
MalformedURIException::isGenericURI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public static boolean isConformantSchemeName(String p_scheme) { if (p_scheme == null || p_scheme.trim().length() == 0) { return false; } if (!isAlpha(p_scheme.charAt(0))) { return false; } char testChar; for (int i = 1; i < p_scheme.length(); i++) { testChar = p_scheme.charAt(i); if (!isAlphanum(testChar) && SCHEME_CHARACTERS.indexOf(testChar) == -1) { return false; } } return true; }
Determine whether a scheme conforms to the rules for a scheme name. A scheme is conformant if it starts with an alphanumeric, and contains only alphanumerics, '+','-' and '.'. @param p_scheme The sheme name to check @return true if the scheme is conformant, false otherwise
MalformedURIException::isConformantSchemeName
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
public static boolean isWellFormedAddress(String p_address) { if (p_address == null) { return false; } String address = p_address.trim(); int addrLength = address.length(); if (addrLength == 0 || addrLength > 255) { return false; } if (address.startsWith(".") || address.startsWith("-")) { return false; } // rightmost domain label starting with digit indicates IP address // since top level domain label can only start with an alpha // see RFC 2396 Section 3.2.2 int index = address.lastIndexOf('.'); if (address.endsWith(".")) { index = address.substring(0, index).lastIndexOf('.'); } if (index + 1 < addrLength && isDigit(p_address.charAt(index + 1))) { char testChar; int numDots = 0; // make sure that 1) we see only digits and dot separators, 2) that // any dot separator is preceded and followed by a digit and // 3) that we find 3 dots for (int i = 0; i < addrLength; i++) { testChar = address.charAt(i); if (testChar == '.') { if (!isDigit(address.charAt(i - 1)) || (i + 1 < addrLength &&!isDigit(address.charAt(i + 1)))) { return false; } numDots++; } else if (!isDigit(testChar)) { return false; } } if (numDots != 3) { return false; } } else { // domain labels can contain alphanumerics and '-" // but must start and end with an alphanumeric char testChar; for (int i = 0; i < addrLength; i++) { testChar = address.charAt(i); if (testChar == '.') { if (!isAlphanum(address.charAt(i - 1))) { return false; } if (i + 1 < addrLength &&!isAlphanum(address.charAt(i + 1))) { return false; } } else if (!isAlphanum(testChar) && testChar != '-') { return false; } } } return true; }
Determine whether a string is syntactically capable of representing a valid IPv4 address or the domain name of a network host. A valid IPv4 address consists of four decimal digit groups separated by a '.'. A hostname consists of domain labels (each of which must begin and end with an alphanumeric but may contain '-') separated & by a '.'. See RFC 2396 Section 3.2.2. @param p_address The address string to check @return true if the string is a syntactically valid IPv4 address or hostname
MalformedURIException::isWellFormedAddress
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private static boolean isDigit(char p_char) { return p_char >= '0' && p_char <= '9'; }
Determine whether a char is a digit. @param p_char the character to check @return true if the char is betweeen '0' and '9', false otherwise
MalformedURIException::isDigit
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private static boolean isHex(char p_char) { return (isDigit(p_char) || (p_char >= 'a' && p_char <= 'f') || (p_char >= 'A' && p_char <= 'F')); }
Determine whether a character is a hexadecimal character. @param p_char the character to check @return true if the char is betweeen '0' and '9', 'a' and 'f' or 'A' and 'F', false otherwise
MalformedURIException::isHex
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private static boolean isAlpha(char p_char) { return ((p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z')); }
Determine whether a char is an alphabetic character: a-z or A-Z @param p_char the character to check @return true if the char is alphabetic, false otherwise
MalformedURIException::isAlpha
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
Apache-2.0
private static boolean isAlphanum(char p_char) { return (isAlpha(p_char) || isDigit(p_char)); }
Determine whether a char is an alphanumeric: 0-9, a-z or A-Z @param p_char the character to check @return true if the char is alphanumeric, false otherwise
MalformedURIException::isAlphanum
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/utils/URI.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