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 void endDocument() throws org.xml.sax.SAXException { flushPending(); if (m_doIndent && !m_isprevtext) { try { outputLineSep(); } catch(IOException e) { throw new SAXException(e); } } flushWriter(); if (m_tracer != null) super.fireEndDoc(); }
Receive notification of the end of a document. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @throws org.xml.sax.SAXException
ToXMLStream::endDocument
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void startPreserving() throws org.xml.sax.SAXException { // Not sure this is really what we want. -sb m_preserves.push(true); m_ispreserve = true; }
Starts a whitespace preserving section. All characters printed within a preserving section are printed without indentation and without consolidating multiple spaces. This is equivalent to the <tt>xml:space=&quot;preserve&quot;</tt> attribute. Only XML and HTML serializers need to support this method. <p> The contents of the whitespace preserving section will be delivered through the regular <tt>characters</tt> event. @throws org.xml.sax.SAXException
ToXMLStream::startPreserving
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void endPreserving() throws org.xml.sax.SAXException { // Not sure this is really what we want. -sb m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop(); }
Ends a whitespace preserving section. @see #startPreserving @throws org.xml.sax.SAXException
ToXMLStream::endPreserving
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { if (m_inEntityRef) return; flushPending(); if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING)) { startNonEscaping(); } else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING)) { endNonEscaping(); } else { try { if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } else if (m_needToCallStartDocument) startDocumentInternal(); if (shouldIndent()) indent(); final java.io.Writer writer = m_writer; writer.write("<?"); writer.write(target); if (data.length() > 0 && !Character.isSpaceChar(data.charAt(0))) writer.write(' '); int indexOfQLT = data.indexOf("?>"); if (indexOfQLT >= 0) { // See XSLT spec on error recovery of "?>" in PIs. if (indexOfQLT > 0) { writer.write(data.substring(0, indexOfQLT)); } writer.write("? >"); // add space between. if ((indexOfQLT + 2) < data.length()) { writer.write(data.substring(indexOfQLT + 2)); } } else { writer.write(data); } writer.write('?'); writer.write('>'); /* * Don't write out any indentation whitespace now, * because there may be non-whitespace text after this. * * Simply mark that at this point if we do decide * to indent that we should * add a newline on the end of the current line before * the indentation at the start of the next line. */ m_startNewLine = true; } catch(IOException e) { throw new SAXException(e); } } if (m_tracer != null) super.fireEscapingEvent(target, data); }
Receive notification of a processing instruction. @param target The processing instruction target. @param data The processing instruction data, or null if none was supplied. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @throws org.xml.sax.SAXException
ToXMLStream::processingInstruction
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void entityReference(String name) throws org.xml.sax.SAXException { if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } try { if (shouldIndent()) indent(); final java.io.Writer writer = m_writer; writer.write('&'); writer.write(name); writer.write(';'); } catch(IOException e) { throw new SAXException(e); } if (m_tracer != null) super.fireEntityReference(name); }
Receive notivication of a entityReference. @param name The name of the entity. @throws org.xml.sax.SAXException
ToXMLStream::entityReference
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void addUniqueAttribute(String name, String value, int flags) throws SAXException { if (m_elemContext.m_startTagOpen) { try { final String patchedName = patchName(name); final java.io.Writer writer = m_writer; if ((flags & NO_BAD_CHARS) > 0 && m_xmlcharInfo.onlyQuotAmpLtGt) { // "flags" has indicated that the characters // '>' '<' '&' and '"' are not in the value and // m_htmlcharInfo has recorded that there are no other // entities in the range 32 to 127 so we write out the // value directly writer.write(' '); writer.write(patchedName); writer.write("=\""); writer.write(value); writer.write('"'); } else { writer.write(' '); writer.write(patchedName); writer.write("=\""); writeAttrString(writer, value, this.getEncoding()); writer.write('"'); } } catch (IOException e) { throw new SAXException(e); } } }
This method is used to add an attribute to the currently open element. The caller has guaranted that this attribute is unique, which means that it not been seen before and will not be seen again. @param name the qualified name of the attribute @param value the value of the attribute which can contain only ASCII printable characters characters in the range 32 to 127 inclusive. @param flags the bit values of this integer give optimization information.
ToXMLStream::addUniqueAttribute
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void addAttribute( String uri, String localName, String rawName, String type, String value, boolean xslAttribute) throws SAXException { if (m_elemContext.m_startTagOpen) { boolean was_added = addAttributeAlways(uri, localName, rawName, type, value, xslAttribute); /* * We don't run this block of code if: * 1. The attribute value was only replaced (was_added is false). * 2. The attribute is from an xsl:attribute element (that is handled * in the addAttributeAlways() call just above. * 3. The name starts with "xmlns", i.e. it is a namespace declaration. */ if (was_added && !xslAttribute && !rawName.startsWith("xmlns")) { String prefixUsed = ensureAttributesNamespaceIsDeclared( uri, localName, rawName); if (prefixUsed != null && rawName != null && !rawName.startsWith(prefixUsed)) { // use a different raw name, with the prefix used in the // generated namespace declaration rawName = prefixUsed + ":" + localName; } } addAttributeAlways(uri, localName, rawName, type, value, xslAttribute); } else { /* * The startTag is closed, yet we are adding an attribute? * * Section: 7.1.3 Creating Attributes Adding an attribute to an * element after a PI (for example) has been added to it is an * error. The attributes can be ignored. The spec doesn't explicitly * say this is disallowed, as it does for child elements, but it * makes sense to have the same treatment. * * We choose to ignore the attribute which is added too late. */ // Generate a warning of the ignored attributes // Create the warning message String msg = Utils.messages.createMessage( MsgKey.ER_ILLEGAL_ATTRIBUTE_POSITION,new Object[]{ localName }); try { // Prepare to issue the warning message Transformer tran = super.getTransformer(); ErrorListener errHandler = tran.getErrorListener(); // Issue the warning message if (null != errHandler && m_sourceLocator != null) errHandler.warning(new TransformerException(msg, m_sourceLocator)); else System.out.println(msg); } catch (TransformerException e){ // A user defined error handler, errHandler, may throw // a TransformerException if it chooses to, and if it does // we will wrap it with a SAXException and re-throw. // Of course if the handler throws another type of // exception, like a RuntimeException, then that is OK too. SAXException se = new SAXException(e); throw se; } } }
Add an attribute to the current element. @param uri the URI associated with the element name @param localName local part of the attribute name @param rawName prefix:localName @param type @param value the value of the attribute @param xslAttribute true if this attribute is from an xsl:attribute, false if declared within the elements opening tag. @throws SAXException
ToXMLStream::addAttribute
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void endElement(String elemName) throws SAXException { endElement(null, null, elemName); }
@see ExtendedContentHandler#endElement(String)
ToXMLStream::endElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void namespaceAfterStartElement( final String prefix, final String uri) throws SAXException { // hack for XSLTC with finding URI for default namespace if (m_elemContext.m_elementURI == null) { String prefix1 = getPrefixPart(m_elemContext.m_elementName); if (prefix1 == null && EMPTYSTRING.equals(prefix)) { // the elements URI is not known yet, and it // doesn't have a prefix, and we are currently // setting the uri for prefix "", so we have // the uri for the element... lets remember it m_elemContext.m_elementURI = uri; } } startPrefixMapping(prefix,uri,false); return; }
This method is used to notify the serializer of a namespace mapping (or node) that applies to the current element whose startElement() call has already been seen. The official SAX startPrefixMapping(prefix,uri) is to define a mapping for a child element that is soon to be seen with a startElement() call. The official SAX call does not apply to the current element, hence the reason for this method.
ToXMLStream::namespaceAfterStartElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
protected boolean pushNamespace(String prefix, String uri) { try { if (m_prefixMap.pushNamespace( prefix, uri, m_elemContext.m_currentElemDepth)) { startPrefixMapping(prefix, uri); return true; } } catch (SAXException e) { // falls through } return false; }
From XSLTC Declare a prefix to point to a namespace URI. Inform SAX handler if this is a new prefix mapping.
ToXMLStream::pushNamespace
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public boolean reset() { boolean wasReset = false; if (super.reset()) { // Make this call when resetToXMLStream does // something. // resetToXMLStream(); wasReset = true; } return wasReset; }
Try's to reset the super class and reset this class for re-use, so that you don't need to create a new serializer (mostly for performance reasons). @return true if the class was successfuly reset.
ToXMLStream::reset
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
private void resetToXMLStream() { // This is an empty method, but is kept for future use // as a place holder for a location to reset fields // defined within this class return; }
Reset all of the fields owned by ToStream class
ToXMLStream::resetToXMLStream
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
private String getXMLVersion() { String xmlVersion = getVersion(); if(xmlVersion == null || xmlVersion.equals(XMLVERSION10)) { xmlVersion = XMLVERSION10; } else if(xmlVersion.equals(XMLVERSION11)) { xmlVersion = XMLVERSION11; } else { String msg = Utils.messages.createMessage( MsgKey.ER_XML_VERSION_NOT_SUPPORTED,new Object[]{ xmlVersion }); try { // Prepare to issue the warning message Transformer tran = super.getTransformer(); ErrorListener errHandler = tran.getErrorListener(); // Issue the warning message if (null != errHandler && m_sourceLocator != null) errHandler.warning(new TransformerException(msg, m_sourceLocator)); else System.out.println(msg); } catch (Exception e){} xmlVersion = XMLVERSION10; } return xmlVersion; }
This method checks for the XML version of output document. If XML version of output document is not specified, then output document is of version XML 1.0. If XML version of output doucment is specified, but it is not either XML 1.0 or XML 1.1, a warning message is generated, the XML Version of output document is set to XML 1.0 and processing continues. @return string (XML version)
ToXMLStream::getXMLVersion
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToXMLStream.java
Apache-2.0
public void setSpecialEscapeURLs(boolean bool) { m_specialEscapeURLs = bool; }
Tells if the formatter should use special URL escaping. @param bool True if URLs should be specially escaped with the %xx form.
ToHTMLStream::setSpecialEscapeURLs
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void setOmitMetaTag(boolean bool) { m_omitMetaTag = bool; }
Tells if the formatter should omit the META tag. @param bool True if the META tag should be omitted.
ToHTMLStream::setOmitMetaTag
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void setOutputFormat(Properties format) { /* * If "format" does not contain the property * S_USE_URL_ESCAPING, then don't set this value at all, * just leave as-is rather than explicitly setting it. */ String value; value = format.getProperty(OutputPropertiesFactory.S_USE_URL_ESCAPING); if (value != null) { m_specialEscapeURLs = OutputPropertyUtils.getBooleanProperty( OutputPropertiesFactory.S_USE_URL_ESCAPING, format); } /* * If "format" does not contain the property * S_OMIT_META_TAG, then don't set this value at all, * just leave as-is rather than explicitly setting it. */ value = format.getProperty(OutputPropertiesFactory.S_OMIT_META_TAG); if (value != null) { m_omitMetaTag = OutputPropertyUtils.getBooleanProperty( OutputPropertiesFactory.S_OMIT_META_TAG, format); } super.setOutputFormat(format); }
Specifies an output format for this serializer. It the serializer has already been associated with an output format, it will switch to the new format. This method should not be called while the serializer is in the process of serializing a document. This method can be called multiple times before starting the serialization of a particular result-tree. In principle all serialization parameters can be changed, with the exception of method="html" (it must be method="html" otherwise we shouldn't even have a ToHTMLStream object here!) @param format The output format or serialzation parameters to use.
ToHTMLStream::setOutputFormat
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private final boolean getSpecialEscapeURLs() { return m_specialEscapeURLs; }
Tells if the formatter should use special URL escaping. @return True if URLs should be specially escaped with the %xx form.
ToHTMLStream::getSpecialEscapeURLs
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private final boolean getOmitMetaTag() { return m_omitMetaTag; }
Tells if the formatter should omit the META tag. @return True if the META tag should be omitted.
ToHTMLStream::getOmitMetaTag
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public static final ElemDesc getElemDesc(String name) { /* this method used to return m_dummy when name was null * but now it doesn't check and and requires non-null name. */ Object obj = m_elementFlags.get(name); if (null != obj) return (ElemDesc)obj; return m_dummy; }
Get a description of the given element. @param name non-null name of element, case insensitive. @return non-null reference to ElemDesc, which may be m_dummy if no element description matches the given name.
ToHTMLStream::getElemDesc
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private ElemDesc getElemDesc2(String name) { Object obj = m_htmlInfo.get2(name); if (null != obj) return (ElemDesc)obj; return m_dummy; }
Calls to this method could be replaced with calls to getElemDesc(name), but this one should be faster.
ToHTMLStream::getElemDesc2
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public ToHTMLStream() { super(); // we are just constructing this thing, no output properties // have been used, so we will set the right default for // indenting anyways m_doIndent = true; m_charInfo = m_htmlcharInfo; // initialize namespaces m_prefixMap = new NamespaceMappings(); }
Default constructor.
ToHTMLStream::ToHTMLStream
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
protected void startDocumentInternal() throws org.xml.sax.SAXException { super.startDocumentInternal(); m_needToCallStartDocument = false; m_needToOutputDocTypeDecl = true; m_startNewLine = false; setOmitXMLDeclaration(true); }
Receive notification of the beginning of a document. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @throws org.xml.sax.SAXException
ToHTMLStream::startDocumentInternal
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private void outputDocTypeDecl(String name) throws SAXException { if (true == m_needToOutputDocTypeDecl) { String doctypeSystem = getDoctypeSystem(); String doctypePublic = getDoctypePublic(); if ((null != doctypeSystem) || (null != doctypePublic)) { final java.io.Writer writer = m_writer; try { writer.write("<!DOCTYPE "); writer.write(name); if (null != doctypePublic) { writer.write(" PUBLIC \""); writer.write(doctypePublic); writer.write('"'); } if (null != doctypeSystem) { if (null == doctypePublic) writer.write(" SYSTEM \""); else writer.write(" \""); writer.write(doctypeSystem); writer.write('"'); } writer.write('>'); outputLineSep(); } catch(IOException e) { throw new SAXException(e); } } } m_needToOutputDocTypeDecl = false; }
This method should only get called once. If a DOCTYPE declaration needs to get written out, it will be written out. If it doesn't need to be written out, then the call to this method has no effect.
ToHTMLStream::outputDocTypeDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void endDocument() throws org.xml.sax.SAXException { flushPending(); if (m_doIndent && !m_isprevtext) { try { outputLineSep(); } catch(IOException e) { throw new SAXException(e); } } flushWriter(); if (m_tracer != null) super.fireEndDoc(); }
Receive notification of the end of a document. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @throws org.xml.sax.SAXException
ToHTMLStream::endDocument
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void startElement( String namespaceURI, String localName, String name, Attributes atts) throws org.xml.sax.SAXException { ElemContext elemContext = m_elemContext; // clean up any pending things first if (elemContext.m_startTagOpen) { closeStartTag(); elemContext.m_startTagOpen = false; } else if (m_cdataTagOpen) { closeCDATA(); m_cdataTagOpen = false; } else if (m_needToCallStartDocument) { startDocumentInternal(); m_needToCallStartDocument = false; } if (m_needToOutputDocTypeDecl) { String n = name; if (n == null || n.length() == 0) { // If the lexical QName is not given // use the localName in the DOCTYPE n = localName; } outputDocTypeDecl(n); } // if this element has a namespace then treat it like XML if (null != namespaceURI && namespaceURI.length() > 0) { super.startElement(namespaceURI, localName, name, atts); return; } try { // getElemDesc2(name) is faster than getElemDesc(name) ElemDesc elemDesc = getElemDesc2(name); int elemFlags = elemDesc.getFlags(); // deal with indentation issues first if (m_doIndent) { boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0; if (m_ispreserve) m_ispreserve = false; else if ( (null != elemContext.m_elementName) && (!m_inBlockElem || isBlockElement) /* && !isWhiteSpaceSensitive */ ) { m_startNewLine = true; indent(); } m_inBlockElem = !isBlockElement; } // save any attributes for later processing if (atts != null) addAttributes(atts); m_isprevtext = false; final java.io.Writer writer = m_writer; writer.write('<'); writer.write(name); if (m_tracer != null) firePseudoAttributes(); if ((elemFlags & ElemDesc.EMPTY) != 0) { // an optimization for elements which are expected // to be empty. m_elemContext = elemContext.push(); /* XSLTC sometimes calls namespaceAfterStartElement() * so we need to remember the name */ m_elemContext.m_elementName = name; m_elemContext.m_elementDesc = elemDesc; return; } else { elemContext = elemContext.push(namespaceURI,localName,name); m_elemContext = elemContext; elemContext.m_elementDesc = elemDesc; elemContext.m_isRaw = (elemFlags & ElemDesc.RAW) != 0; } if ((elemFlags & ElemDesc.HEADELEM) != 0) { // This is the <HEAD> element, do some special processing closeStartTag(); elemContext.m_startTagOpen = false; if (!m_omitMetaTag) { if (m_doIndent) indent(); writer.write( "<META http-equiv=\"Content-Type\" content=\"text/html; charset="); String encoding = getEncoding(); String encode = Encodings.getMimeEncoding(encoding); writer.write(encode); writer.write("\">"); } } } catch (IOException e) { throw new SAXException(e); } }
Receive notification of the beginning of an element. @param namespaceURI @param localName @param name The element type name. @param atts The attributes attached to the element, if any. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see #endElement @see org.xml.sax.AttributeList
ToHTMLStream::startElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void endElement( final String namespaceURI, final String localName, final String name) throws org.xml.sax.SAXException { // deal with any pending issues if (m_cdataTagOpen) closeCDATA(); // if the element has a namespace, treat it like XML, not HTML if (null != namespaceURI && namespaceURI.length() > 0) { super.endElement(namespaceURI, localName, name); return; } try { ElemContext elemContext = m_elemContext; final ElemDesc elemDesc = elemContext.m_elementDesc; final int elemFlags = elemDesc.getFlags(); final boolean elemEmpty = (elemFlags & ElemDesc.EMPTY) != 0; // deal with any indentation issues if (m_doIndent) { final boolean isBlockElement = (elemFlags&ElemDesc.BLOCK) != 0; boolean shouldIndent = false; if (m_ispreserve) { m_ispreserve = false; } else if (m_doIndent && (!m_inBlockElem || isBlockElement)) { m_startNewLine = true; shouldIndent = true; } if (!elemContext.m_startTagOpen && shouldIndent) indent(elemContext.m_currentElemDepth - 1); m_inBlockElem = !isBlockElement; } final java.io.Writer writer = m_writer; if (!elemContext.m_startTagOpen) { writer.write("</"); writer.write(name); writer.write('>'); } else { // the start-tag open when this method was called, // so we need to process it now. if (m_tracer != null) super.fireStartElem(name); // the starting tag was still open when we received this endElement() call // so we need to process any gathered attributes NOW, before they go away. int nAttrs = m_attributes.getLength(); if (nAttrs > 0) { processAttributes(m_writer, nAttrs); // clear attributes object for re-use with next element m_attributes.clear(); } if (!elemEmpty) { // As per Dave/Paul recommendation 12/06/2000 // if (shouldIndent) // writer.write('>'); // indent(m_currentIndent); writer.write("></"); writer.write(name); writer.write('>'); } else { writer.write('>'); } } // clean up because the element has ended if ((elemFlags & ElemDesc.WHITESPACESENSITIVE) != 0) m_ispreserve = true; m_isprevtext = false; // fire off the end element event if (m_tracer != null) super.fireEndElem(name); // OPTIMIZE-EMPTY if (elemEmpty) { // a quick exit if the HTML element had no children. // This block of code can be removed if the corresponding block of code // in startElement() also labeled with "OPTIMIZE-EMPTY" is also removed m_elemContext = elemContext.m_prev; return; } // some more clean because the element has ended. if (!elemContext.m_startTagOpen) { if (m_doIndent && !m_preserves.isEmpty()) m_preserves.pop(); } m_elemContext = elemContext.m_prev; // m_isRawStack.pop(); } catch (IOException e) { throw new SAXException(e); } }
Receive notification of the end of an element. @param namespaceURI @param localName @param name The element type name @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
ToHTMLStream::endElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
protected void processAttribute( java.io.Writer writer, String name, String value, ElemDesc elemDesc) throws IOException { writer.write(' '); if ( ((value.length() == 0) || value.equalsIgnoreCase(name)) && elemDesc != null && elemDesc.isAttrFlagSet(name, ElemDesc.ATTREMPTY)) { writer.write(name); } else { // %REVIEW% %OPT% // Two calls to single-char write may NOT // be more efficient than one to string-write... writer.write(name); writer.write("=\""); if ( elemDesc != null && elemDesc.isAttrFlagSet(name, ElemDesc.ATTRURL)) writeAttrURI(writer, value, m_specialEscapeURLs); else writeAttrString(writer, value, this.getEncoding()); writer.write('"'); } }
Process an attribute. @param writer The writer to write the processed output to. @param name The name of the attribute. @param value The value of the attribute. @param elemDesc The description of the HTML element that has this attribute. @throws org.xml.sax.SAXException
ToHTMLStream::processAttribute
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private boolean isASCIIDigit(char c) { return (c >= '0' && c <= '9'); }
Tell if a character is an ASCII digit.
ToHTMLStream::isASCIIDigit
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private static String makeHHString(int i) { String s = Integer.toHexString(i).toUpperCase(); if (s.length() == 1) { s = "0" + s; } return s; }
Make an integer into an HH hex value. Does no checking on the size of the input, since this is only meant to be used locally by writeAttrURI. @param i must be a value less than 255. @return should be a two character string.
ToHTMLStream::makeHHString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
private boolean isHHSign(String str) { boolean sign = true; try { char r = (char) Integer.parseInt(str, 16); } catch (NumberFormatException e) { sign = false; } return sign; }
Dmitri Ilyin: Makes sure if the String is HH encoded sign. @param str must be 2 characters long @return true or false
ToHTMLStream::isHHSign
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void writeAttrURI( final java.io.Writer writer, String string, boolean doURLEscaping) throws IOException { // http://www.ietf.org/rfc/rfc2396.txt says: // A URI is always in an "escaped" form, since escaping or unescaping a // completed URI might change its semantics. Normally, the only time // escape encodings can safely be made is when the URI is being created // from its component parts; each component may have its own set of // characters that are reserved, so only the mechanism responsible for // generating or interpreting that component can determine whether or // not escaping a character will change its semantics. Likewise, a URI // must be separated into its components before the escaped characters // within those components can be safely decoded. // // ...So we do our best to do limited escaping of the URL, without // causing damage. If the URL is already properly escaped, in theory, this // function should not change the string value. final int end = string.length(); if (end > m_attrBuff.length) { m_attrBuff = new char[end*2 + 1]; } string.getChars(0,end, m_attrBuff, 0); final char[] chars = m_attrBuff; int cleanStart = 0; int cleanLength = 0; char ch = 0; for (int i = 0; i < end; i++) { ch = chars[i]; if ((ch < 32) || (ch > 126)) { if (cleanLength > 0) { writer.write(chars, cleanStart, cleanLength); cleanLength = 0; } if (doURLEscaping) { // Encode UTF16 to UTF8. // Reference is Unicode, A Primer, by Tony Graham. // Page 92. // Note that Kay doesn't escape 0x20... // if(ch == 0x20) // Not sure about this... -sb // { // writer.write(ch); // } // else if (ch <= 0x7F) { writer.write('%'); writer.write(makeHHString(ch)); } else if (ch <= 0x7FF) { // Clear low 6 bits before rotate, put high 4 bits in low byte, // and set two high bits. int high = (ch >> 6) | 0xC0; int low = (ch & 0x3F) | 0x80; // First 6 bits, + high bit writer.write('%'); writer.write(makeHHString(high)); writer.write('%'); writer.write(makeHHString(low)); } else if (Encodings.isHighUTF16Surrogate(ch)) // high surrogate { // I'm sure this can be done in 3 instructions, but I choose // to try and do it exactly like it is done in the book, at least // until we are sure this is totally clean. I don't think performance // is a big issue with this particular function, though I could be // wrong. Also, the stuff below clearly does more masking than // it needs to do. // Clear high 6 bits. int highSurrogate = ((int) ch) & 0x03FF; // Middle 4 bits (wwww) + 1 // "Note that the value of wwww from the high surrogate bit pattern // is incremented to make the uuuuu bit pattern in the scalar value // so the surrogate pair don't address the BMP." int wwww = ((highSurrogate & 0x03C0) >> 6); int uuuuu = wwww + 1; // next 4 bits int zzzz = (highSurrogate & 0x003C) >> 2; // low 2 bits int yyyyyy = ((highSurrogate & 0x0003) << 4) & 0x30; // Get low surrogate character. ch = chars[++i]; // Clear high 6 bits. int lowSurrogate = ((int) ch) & 0x03FF; // put the middle 4 bits into the bottom of yyyyyy (byte 3) yyyyyy = yyyyyy | ((lowSurrogate & 0x03C0) >> 6); // bottom 6 bits. int xxxxxx = (lowSurrogate & 0x003F); int byte1 = 0xF0 | (uuuuu >> 2); // top 3 bits of uuuuu int byte2 = 0x80 | (((uuuuu & 0x03) << 4) & 0x30) | zzzz; int byte3 = 0x80 | yyyyyy; int byte4 = 0x80 | xxxxxx; writer.write('%'); writer.write(makeHHString(byte1)); writer.write('%'); writer.write(makeHHString(byte2)); writer.write('%'); writer.write(makeHHString(byte3)); writer.write('%'); writer.write(makeHHString(byte4)); } else { int high = (ch >> 12) | 0xE0; // top 4 bits int middle = ((ch & 0x0FC0) >> 6) | 0x80; // middle 6 bits int low = (ch & 0x3F) | 0x80; // First 6 bits, + high bit writer.write('%'); writer.write(makeHHString(high)); writer.write('%'); writer.write(makeHHString(middle)); writer.write('%'); writer.write(makeHHString(low)); } } else if (escapingNotNeeded(ch)) { writer.write(ch); } else { writer.write("&#"); writer.write(Integer.toString(ch)); writer.write(';'); } // In this character range we have first written out any previously accumulated // "clean" characters, then processed the current more complicated character, // which may have incremented "i". // We now we reset the next possible clean character. cleanStart = i + 1; } // Since http://www.ietf.org/rfc/rfc2396.txt refers to the URI grammar as // not allowing quotes in the URI proper syntax, nor in the fragment // identifier, we believe that it's OK to double escape quotes. else if (ch == '"') { // If the character is a '%' number number, try to avoid double-escaping. // There is a question if this is legal behavior. // Dmitri Ilyin: to check if '%' number number is invalid. It must be checked if %xx is a sign, that would be encoded // The encoded signes are in Hex form. So %xx my be in form %3C that is "<" sign. I will try to change here a little. // if( ((i+2) < len) && isASCIIDigit(stringArray[i+1]) && isASCIIDigit(stringArray[i+2]) ) // We are no longer escaping '%' if (cleanLength > 0) { writer.write(chars, cleanStart, cleanLength); cleanLength = 0; } // Mike Kay encodes this as &#34;, so he may know something I don't? if (doURLEscaping) writer.write("%22"); else writer.write("&quot;"); // we have to escape this, I guess. // We have written out any clean characters, then the escaped '%' and now we // We now we reset the next possible clean character. cleanStart = i + 1; } else if (ch == '&') { // HTML 4.01 reads, "Authors should use "&amp;" (ASCII decimal 38) // instead of "&" to avoid confusion with the beginning of a character // reference (entity reference open delimiter). if (cleanLength > 0) { writer.write(chars, cleanStart, cleanLength); cleanLength = 0; } writer.write("&amp;"); cleanStart = i + 1; } else { // no processing for this character, just count how // many characters in a row that we have that need no processing cleanLength++; } } // are there any clean characters at the end of the array // that we haven't processed yet? if (cleanLength > 1) { // if the whole string can be written out as-is do so // otherwise write out the clean chars at the end of the // array if (cleanStart == 0) writer.write(string); else writer.write(chars, cleanStart, cleanLength); } else if (cleanLength == 1) { // a little optimization for 1 clean character // (we could have let the previous if(...) handle them all) writer.write(ch); } }
Write the specified <var>string</var> after substituting non ASCII characters, with <CODE>%HH</CODE>, where HH is the hex of the byte value. @param string String to convert to XML format. @param doURLEscaping True if we should try to encode as per http://www.ietf.org/rfc/rfc2396.txt. @throws org.xml.sax.SAXException if a bad surrogate pair is detected.
ToHTMLStream::writeAttrURI
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void writeAttrString( final java.io.Writer writer, String string, String encoding) throws IOException { final int end = string.length(); if (end > m_attrBuff.length) { m_attrBuff = new char[end * 2 + 1]; } string.getChars(0, end, m_attrBuff, 0); final char[] chars = m_attrBuff; int cleanStart = 0; int cleanLength = 0; char ch = 0; for (int i = 0; i < end; i++) { ch = chars[i]; // System.out.println("SPECIALSSIZE: "+SPECIALSSIZE); // System.out.println("ch: "+(int)ch); // System.out.println("m_maxCharacter: "+(int)m_maxCharacter); // System.out.println("m_attrCharsMap[ch]: "+(int)m_attrCharsMap[ch]); if (escapingNotNeeded(ch) && (!m_charInfo.shouldMapAttrChar(ch))) { cleanLength++; } else if ('<' == ch || '>' == ch) { cleanLength++; // no escaping in this case, as specified in 15.2 } else if ( ('&' == ch) && ((i + 1) < end) && ('{' == chars[i + 1])) { cleanLength++; // no escaping in this case, as specified in 15.2 } else { if (cleanLength > 0) { writer.write(chars,cleanStart,cleanLength); cleanLength = 0; } int pos = accumDefaultEntity(writer, ch, i, chars, end, false, true); if (i != pos) { i = pos - 1; } else { if (Encodings.isHighUTF16Surrogate(ch)) { writeUTF16Surrogate(ch, chars, i, end); i++; // two input characters processed // this increments by one and the for() // loop itself increments by another one. } // The next is kind of a hack to keep from escaping in the case // of Shift_JIS and the like. /* else if ((ch < m_maxCharacter) && (m_maxCharacter == 0xFFFF) && (ch != 160)) { writer.write(ch); // no escaping in this case } else */ String outputStringForChar = m_charInfo.getOutputStringForChar(ch); if (null != outputStringForChar) { writer.write(outputStringForChar); } else if (escapingNotNeeded(ch)) { writer.write(ch); // no escaping in this case } else { writer.write("&#"); writer.write(Integer.toString(ch)); writer.write(';'); } } cleanStart = i + 1; } } // end of for() // are there any clean characters at the end of the array // that we haven't processed yet? if (cleanLength > 1) { // if the whole string can be written out as-is do so // otherwise write out the clean chars at the end of the // array if (cleanStart == 0) writer.write(string); else writer.write(chars, cleanStart, cleanLength); } else if (cleanLength == 1) { // a little optimization for 1 clean character // (we could have let the previous if(...) handle them all) writer.write(ch); } }
Writes the specified <var>string</var> after substituting <VAR>specials</VAR>, and UTF-16 surrogates for character references <CODE>&amp;#xnn</CODE>. @param string String to convert to XML format. @param encoding CURRENTLY NOT IMPLEMENTED. @throws org.xml.sax.SAXException
ToHTMLStream::writeAttrString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void characters(char chars[], int start, int length) throws org.xml.sax.SAXException { if (m_elemContext.m_isRaw) { try { // Clean up some pending issues. if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } m_ispreserve = true; writeNormalizedChars(chars, start, length, false, m_lineSepUse); // time to generate characters event if (m_tracer != null) super.fireCharEvent(chars, start, length); return; } catch (IOException ioe) { throw new org.xml.sax.SAXException( Utils.messages.createMessage(MsgKey.ER_OIERROR,null),ioe); } } else { super.characters(chars, start, length); } }
Receive notification of character data. <p>The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.</p> <p>The application must not attempt to read from the array outside of the specified range.</p> <p>Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).</p> @param chars The characters from the XML document. @param start The start position in the array. @param length The number of characters to read from the array. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see #ignorableWhitespace @see org.xml.sax.Locator @throws org.xml.sax.SAXException
ToHTMLStream::characters
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException { if ((null != m_elemContext.m_elementName) && (m_elemContext.m_elementName.equalsIgnoreCase("SCRIPT") || m_elemContext.m_elementName.equalsIgnoreCase("STYLE"))) { try { if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } m_ispreserve = true; if (shouldIndent()) indent(); // writer.write(ch, start, length); writeNormalizedChars(ch, start, length, true, m_lineSepUse); } catch (IOException ioe) { throw new org.xml.sax.SAXException( Utils.messages.createMessage( MsgKey.ER_OIERROR, null), ioe); //"IO error", ioe); } } else { super.cdata(ch, start, length); } }
Receive notification of cdata. <p>The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.</p> <p>The application must not attempt to read from the array outside of the specified range.</p> <p>Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).</p> @param ch The characters from the XML document. @param start The start position in the array. @param length The number of characters to read from the array. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @see #ignorableWhitespace @see org.xml.sax.Locator @throws org.xml.sax.SAXException
ToHTMLStream::cdata
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void processingInstruction(String target, String data) throws org.xml.sax.SAXException { // Process any pending starDocument and startElement first. flushPending(); // Use a fairly nasty hack to tell if the next node is supposed to be // unescaped text. if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING)) { startNonEscaping(); } else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING)) { endNonEscaping(); } else { try { // clean up any pending things first if (m_elemContext.m_startTagOpen) { closeStartTag(); m_elemContext.m_startTagOpen = false; } else if (m_cdataTagOpen) { closeCDATA(); } else if (m_needToCallStartDocument) { startDocumentInternal(); } /* * Perhaps processing instructions can be written out in HTML before * the DOCTYPE, in which case this could be emitted with the * startElement call, that knows the name of the document element * doing it right. */ if (true == m_needToOutputDocTypeDecl) outputDocTypeDecl("html"); // best guess for the upcoming element if (shouldIndent()) indent(); final java.io.Writer writer = m_writer; //writer.write("<?" + target); writer.write("<?"); writer.write(target); if (data.length() > 0 && !Character.isSpaceChar(data.charAt(0))) writer.write(' '); //writer.write(data + ">"); // different from XML writer.write(data); // different from XML writer.write('>'); // different from XML // Always output a newline char if not inside of an // element. The whitespace is not significant in that // case. if (m_elemContext.m_currentElemDepth <= 0) outputLineSep(); m_startNewLine = true; } catch(IOException e) { throw new SAXException(e); } } // now generate the PI event if (m_tracer != null) super.fireEscapingEvent(target, data); }
Receive notification of a processing instruction. @param target The processing instruction target. @param data The processing instruction data, or null if none was supplied. @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception. @throws org.xml.sax.SAXException
ToHTMLStream::processingInstruction
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void entityReference(String name) throws org.xml.sax.SAXException { try { final java.io.Writer writer = m_writer; writer.write('&'); writer.write(name); writer.write(';'); } catch(IOException e) { throw new SAXException(e); } }
Receive notivication of a entityReference. @param name non-null reference to entity name string. @throws org.xml.sax.SAXException
ToHTMLStream::entityReference
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public final void endElement(String elemName) throws SAXException { endElement(null, null, elemName); }
@see ExtendedContentHandler#endElement(String)
ToHTMLStream::endElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void processAttributes(java.io.Writer writer, int nAttrs) throws IOException,SAXException { /* * process the collected attributes */ for (int i = 0; i < nAttrs; i++) { processAttribute( writer, m_attributes.getQName(i), m_attributes.getValue(i), m_elemContext.m_elementDesc); } }
Process the attributes, which means to write out the currently collected attributes to the writer. The attributes are not cleared by this method @param writer the writer to write processed attributes to. @param nAttrs the number of attributes in m_attributes to be processed @throws org.xml.sax.SAXException
ToHTMLStream::processAttributes
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
protected void closeStartTag() throws SAXException { try { // finish processing attributes, time to fire off the start element event if (m_tracer != null) super.fireStartElem(m_elemContext.m_elementName); int nAttrs = m_attributes.getLength(); if (nAttrs>0) { processAttributes(m_writer, nAttrs); // clear attributes object for re-use with next element m_attributes.clear(); } m_writer.write('>'); /* At this point we have the prefix mappings now, so * lets determine if the current element is specified in the cdata- * section-elements list. */ if (m_CdataElems != null) // if there are any cdata sections m_elemContext.m_isCdataSection = isCdataSection(); if (m_doIndent) { m_isprevtext = false; m_preserves.push(m_ispreserve); } } catch(IOException e) { throw new SAXException(e); } }
For the enclosing elements starting tag write out out any attributes followed by ">". At this point we also mark if this element is a cdata-section-element. @throws org.xml.sax.SAXException
ToHTMLStream::closeStartTag
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void namespaceAfterStartElement(String prefix, String uri) throws SAXException { // hack for XSLTC with finding URI for default namespace if (m_elemContext.m_elementURI == null) { String prefix1 = getPrefixPart(m_elemContext.m_elementName); if (prefix1 == null && EMPTYSTRING.equals(prefix)) { // the elements URI is not known yet, and it // doesn't have a prefix, and we are currently // setting the uri for prefix "", so we have // the uri for the element... lets remember it m_elemContext.m_elementURI = uri; } } startPrefixMapping(prefix,uri,false); }
This method is used when a prefix/uri namespace mapping is indicated after the element was started with a startElement() and before and endElement(). startPrefixMapping(prefix,uri) would be used before the startElement() call. @param uri the URI of the namespace @param prefix the prefix associated with the given URI. @see ExtendedContentHandler#namespaceAfterStartElement(String, String)
ToHTMLStream::namespaceAfterStartElement
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void endDTD() throws org.xml.sax.SAXException { m_inDTD = false; /* for ToHTMLStream the DOCTYPE is entirely output in the * startDocumentInternal() method, so don't do anything here */ }
Report the end of DTD declarations. @throws org.xml.sax.SAXException The application may raise an exception. @see #startDTD
ToHTMLStream::endDTD
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void attributeDecl( String eName, String aName, String type, String valueDefault, String value) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer }
This method does nothing.
ToHTMLStream::attributeDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void elementDecl(String name, String model) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer }
This method does nothing.
ToHTMLStream::elementDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void internalEntityDecl(String name, String value) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer }
This method does nothing.
ToHTMLStream::internalEntityDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void externalEntityDecl( String name, String publicId, String systemId) throws SAXException { // The internal DTD subset is not serialized by the ToHTMLStream serializer }
This method does nothing.
ToHTMLStream::externalEntityDecl
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public void addUniqueAttribute(String name, String value, int flags) throws SAXException { try { final java.io.Writer writer = m_writer; if ((flags & NO_BAD_CHARS) > 0 && m_htmlcharInfo.onlyQuotAmpLtGt) { // "flags" has indicated that the characters // '>' '<' '&' and '"' are not in the value and // m_htmlcharInfo has recorded that there are no other // entities in the range 0 to 127 so we write out the // value directly writer.write(' '); writer.write(name); writer.write("=\""); writer.write(value); writer.write('"'); } else if ( (flags & HTML_ATTREMPTY) > 0 && (value.length() == 0 || value.equalsIgnoreCase(name))) { writer.write(' '); writer.write(name); } else { writer.write(' '); writer.write(name); writer.write("=\""); if ((flags & HTML_ATTRURL) > 0) { writeAttrURI(writer, value, m_specialEscapeURLs); } else { writeAttrString(writer, value, this.getEncoding()); } writer.write('"'); } } catch (IOException e) { throw new SAXException(e); } }
This method is used to add an attribute to the currently open element. The caller has guaranted that this attribute is unique, which means that it not been seen before and will not be seen again. @param name the qualified name of the attribute @param value the value of the attribute which can contain only ASCII printable characters characters in the range 32 to 127 inclusive. @param flags the bit values of this integer give optimization information.
ToHTMLStream::addUniqueAttribute
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Trie() { m_Root = new Node(); m_lowerCaseOnly = false; }
Construct the trie that has a case insensitive search.
Trie::Trie
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Trie(boolean lowerCaseOnly) { m_Root = new Node(); m_lowerCaseOnly = lowerCaseOnly; }
Construct the trie given the desired case sensitivity with the key. @param lowerCaseOnly true if the search keys are to be loser case only, not case insensitive.
Trie::Trie
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Object put(String key, Object value) { final int len = key.length(); if (len > m_charBuffer.length) { // make the biggest buffer ever needed in get(String) m_charBuffer = new char[len]; } Node node = m_Root; for (int i = 0; i < len; i++) { Node nextNode = node.m_nextChar[Character.toLowerCase(key.charAt(i))]; if (nextNode != null) { node = nextNode; } else { for (; i < len; i++) { Node newNode = new Node(); if (m_lowerCaseOnly) { // put this value into the tree only with a lower case key node.m_nextChar[Character.toLowerCase( key.charAt(i))] = newNode; } else { // put this value into the tree with a case insensitive key node.m_nextChar[Character.toUpperCase( key.charAt(i))] = newNode; node.m_nextChar[Character.toLowerCase( key.charAt(i))] = newNode; } node = newNode; } break; } } Object ret = node.m_Value; node.m_Value = value; return ret; }
Put an object into the trie for lookup. @param key must be a 7-bit ASCII string @param value any java object. @return The old object that matched key, or null.
Trie::put
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Object get(final String key) { final int len = key.length(); /* If the name is too long, we won't find it, this also keeps us * from overflowing m_charBuffer */ if (m_charBuffer.length < len) return null; Node node = m_Root; switch (len) // optimize the look up based on the number of chars { // case 0 looks silly, but the generated bytecode runs // faster for lookup of elements of length 2 with this in // and a fair bit faster. Don't know why. case 0 : { return null; } case 1 : { final char ch = key.charAt(0); if (ch < ALPHA_SIZE) { node = node.m_nextChar[ch]; if (node != null) return node.m_Value; } return null; } // comment out case 2 because the default is faster // case 2 : // { // final char ch0 = key.charAt(0); // final char ch1 = key.charAt(1); // if (ch0 < ALPHA_SIZE && ch1 < ALPHA_SIZE) // { // node = node.m_nextChar[ch0]; // if (node != null) // { // // if (ch1 < ALPHA_SIZE) // { // node = node.m_nextChar[ch1]; // if (node != null) // return node.m_Value; // } // } // } // return null; // } default : { for (int i = 0; i < len; i++) { // A thread-safe way to loop over the characters final char ch = key.charAt(i); if (ALPHA_SIZE <= ch) { // the key is not 7-bit ASCII so we won't find it here return null; } node = node.m_nextChar[ch]; if (node == null) return null; } return node.m_Value; } } }
Get an object that matches the key. @param key must be a 7-bit ASCII string @return The object that matches the key, or null.
Trie::get
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
Node() { m_nextChar = new Node[ALPHA_SIZE]; m_Value = null; }
Constructor, creates a Node[ALPHA_SIZE].
Node::Node
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Trie(Trie existingTrie) { // copy some fields from the existing Trie into this one. m_Root = existingTrie.m_Root; m_lowerCaseOnly = existingTrie.m_lowerCaseOnly; // get a buffer just big enough to hold the longest key in the table. int max = existingTrie.getLongestKeyLength(); m_charBuffer = new char[max]; }
Construct the trie from another Trie. Both the existing Trie and this new one share the same table for lookup, and it is assumed that the table is fully populated and not changing anymore. @param existingTrie the Trie that this one is a copy of.
Node::Trie
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public Object get2(final String key) { final int len = key.length(); /* If the name is too long, we won't find it, this also keeps us * from overflowing m_charBuffer */ if (m_charBuffer.length < len) return null; Node node = m_Root; switch (len) // optimize the look up based on the number of chars { // case 0 looks silly, but the generated bytecode runs // faster for lookup of elements of length 2 with this in // and a fair bit faster. Don't know why. case 0 : { return null; } case 1 : { final char ch = key.charAt(0); if (ch < ALPHA_SIZE) { node = node.m_nextChar[ch]; if (node != null) return node.m_Value; } return null; } default : { /* Copy string into array. This is not thread-safe because * it modifies the contents of m_charBuffer. If multiple * threads were to use this Trie they all would be * using this same array (not good). So this * method is not thread-safe, but it is faster because * converting to a char[] and looping over elements of * the array is faster than a String's charAt(i). */ key.getChars(0, len, m_charBuffer, 0); for (int i = 0; i < len; i++) { final char ch = m_charBuffer[i]; if (ALPHA_SIZE <= ch) { // the key is not 7-bit ASCII so we won't find it here return null; } node = node.m_nextChar[ch]; if (node == null) return null; } return node.m_Value; } } }
Get an object that matches the key. This method is faster than get(), but is not thread-safe. @param key must be a 7-bit ASCII string @return The object that matches the key, or null.
Node::get2
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public int getLongestKeyLength() { return m_charBuffer.length; }
Get the length of the longest key used in the table.
Node::getLongestKeyLength
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
Apache-2.0
public WriterToUTF8Buffered(OutputStream out) { m_os = out; // get 3 extra bytes to make buffer overflow checking simpler and faster // we won't have to keep checking for a few extra characters m_outputBytes = new byte[BYTES_MAX + 3]; // Big enough to hold the input chars that will be transformed // into output bytes in m_ouputBytes. m_inputChars = new char[CHARS_MAX + 2]; count = 0; // the old body of this constructor, before the buffersize was changed to a constant // this(out, 8*1024); }
Create an buffered UTF-8 writer. @param out the underlying output stream. @throws UnsupportedEncodingException
WriterToUTF8Buffered::WriterToUTF8Buffered
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void write(final int c) throws IOException { /* If we are close to the end of the buffer then flush it. * Remember the buffer can hold a few more bytes than BYTES_MAX */ if (count >= BYTES_MAX) flushBuffer(); if (c < 0x80) { m_outputBytes[count++] = (byte) (c); } else if (c < 0x800) { m_outputBytes[count++] = (byte) (0xc0 + (c >> 6)); m_outputBytes[count++] = (byte) (0x80 + (c & 0x3f)); } else if (c < 0x10000) { m_outputBytes[count++] = (byte) (0xe0 + (c >> 12)); m_outputBytes[count++] = (byte) (0x80 + ((c >> 6) & 0x3f)); m_outputBytes[count++] = (byte) (0x80 + (c & 0x3f)); } else { m_outputBytes[count++] = (byte) (0xf0 + (c >> 18)); m_outputBytes[count++] = (byte) (0x80 + ((c >> 12) & 0x3f)); m_outputBytes[count++] = (byte) (0x80 + ((c >> 6) & 0x3f)); m_outputBytes[count++] = (byte) (0x80 + (c & 0x3f)); } }
Write a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. <p> Subclasses that intend to support efficient single-character output should override this method. @param c int specifying a character to be written. @exception IOException If an I/O error occurs
WriterToUTF8Buffered::write
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void write(final char chars[], final int start, final int length) throws java.io.IOException { // We multiply the length by three since this is the maximum length // of the characters that we can put into the buffer. It is possible // for each Unicode character to expand to three bytes. int lengthx3 = 3*length; if (lengthx3 >= BYTES_MAX - count) { // The requested length is greater than the unused part of the buffer flushBuffer(); if (lengthx3 > BYTES_MAX) { /* * The requested length exceeds the size of the buffer. * Cut the buffer up into chunks, each of which will * not cause an overflow to the output buffer m_outputBytes, * and make multiple recursive calls. * Be careful about integer overflows in multiplication. */ int split = length/CHARS_MAX; final int chunks; if (length % CHARS_MAX > 0) chunks = split + 1; else chunks = split; int end_chunk = start; for (int chunk = 1; chunk <= chunks; chunk++) { int start_chunk = end_chunk; end_chunk = start + (int) ((((long) length) * chunk) / chunks); // Adjust the end of the chunk if it ends on a high char // of a Unicode surrogate pair and low char of the pair // is not going to be in the same chunk final char c = chars[end_chunk - 1]; int ic = chars[end_chunk - 1]; if (c >= 0xD800 && c <= 0xDBFF) { // The last Java char that we were going // to process is the first of a // Java surrogate char pair that // represent a Unicode character. if (end_chunk < start + length) { // Avoid spanning by including the low // char in the current chunk of chars. end_chunk++; } else { /* This is the last char of the last chunk, * and it is the high char of a high/low pair with * no low char provided. * TODO: error message needed. * The char array incorrectly ends in a high char * of a high/low surrogate pair, but there is * no corresponding low as the high is the last char */ end_chunk--; } } int len_chunk = (end_chunk - start_chunk); this.write(chars,start_chunk, len_chunk); } return; } } final int n = length+start; final byte[] buf_loc = m_outputBytes; // local reference for faster access int count_loc = count; // local integer for faster access int i = start; { /* This block could be omitted and the code would produce * the same result. But this block exists to give the JIT * a better chance of optimizing a tight and common loop which * occurs when writing out ASCII characters. */ char c; for(; i < n && (c = chars[i])< 0x80 ; i++ ) buf_loc[count_loc++] = (byte)c; } for (; i < n; i++) { final char c = chars[i]; if (c < 0x80) buf_loc[count_loc++] = (byte) (c); else if (c < 0x800) { buf_loc[count_loc++] = (byte) (0xc0 + (c >> 6)); buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f)); } /** * The following else if condition is added to support XML 1.1 Characters for * UTF-8: [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]* * Unicode: [1101 10ww] [wwzz zzyy] (high surrogate) * [1101 11yy] [yyxx xxxx] (low surrogate) * * uuuuu = wwww + 1 */ else if (c >= 0xD800 && c <= 0xDBFF) { char high, low; high = c; i++; low = chars[i]; buf_loc[count_loc++] = (byte) (0xF0 | (((high + 0x40) >> 8) & 0xf0)); buf_loc[count_loc++] = (byte) (0x80 | (((high + 0x40) >> 2) & 0x3f)); buf_loc[count_loc++] = (byte) (0x80 | ((low >> 6) & 0x0f) + ((high << 4) & 0x30)); buf_loc[count_loc++] = (byte) (0x80 | (low & 0x3f)); } else { buf_loc[count_loc++] = (byte) (0xe0 + (c >> 12)); buf_loc[count_loc++] = (byte) (0x80 + ((c >> 6) & 0x3f)); buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f)); } } // Store the local integer back into the instance variable count = count_loc; }
Write a portion of an array of characters. @param chars Array of characters @param start Offset from which to start writing characters @param length Number of characters to write @exception IOException If an I/O error occurs @throws java.io.IOException
WriterToUTF8Buffered::write
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void write(final String s) throws IOException { // We multiply the length by three since this is the maximum length // of the characters that we can put into the buffer. It is possible // for each Unicode character to expand to three bytes. final int length = s.length(); int lengthx3 = 3*length; if (lengthx3 >= BYTES_MAX - count) { // The requested length is greater than the unused part of the buffer flushBuffer(); if (lengthx3 > BYTES_MAX) { /* * The requested length exceeds the size of the buffer, * so break it up in chunks that don't exceed the buffer size. */ final int start = 0; int split = length/CHARS_MAX; final int chunks; if (length % CHARS_MAX > 0) chunks = split + 1; else chunks = split; int end_chunk = 0; for (int chunk = 1; chunk <= chunks; chunk++) { int start_chunk = end_chunk; end_chunk = start + (int) ((((long) length) * chunk) / chunks); s.getChars(start_chunk,end_chunk, m_inputChars,0); int len_chunk = (end_chunk - start_chunk); // Adjust the end of the chunk if it ends on a high char // of a Unicode surrogate pair and low char of the pair // is not going to be in the same chunk final char c = m_inputChars[len_chunk - 1]; if (c >= 0xD800 && c <= 0xDBFF) { // Exclude char in this chunk, // to avoid spanning a Unicode character // that is in two Java chars as a high/low surrogate end_chunk--; len_chunk--; if (chunk == chunks) { /* TODO: error message needed. * The String incorrectly ends in a high char * of a high/low surrogate pair, but there is * no corresponding low as the high is the last char * Recover by ignoring this last char. */ } } this.write(m_inputChars,0, len_chunk); } return; } } s.getChars(0, length , m_inputChars, 0); final char[] chars = m_inputChars; final int n = length; final byte[] buf_loc = m_outputBytes; // local reference for faster access int count_loc = count; // local integer for faster access int i = 0; { /* This block could be omitted and the code would produce * the same result. But this block exists to give the JIT * a better chance of optimizing a tight and common loop which * occurs when writing out ASCII characters. */ char c; for(; i < n && (c = chars[i])< 0x80 ; i++ ) buf_loc[count_loc++] = (byte)c; } for (; i < n; i++) { final char c = chars[i]; if (c < 0x80) buf_loc[count_loc++] = (byte) (c); else if (c < 0x800) { buf_loc[count_loc++] = (byte) (0xc0 + (c >> 6)); buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f)); } /** * The following else if condition is added to support XML 1.1 Characters for * UTF-8: [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]* * Unicode: [1101 10ww] [wwzz zzyy] (high surrogate) * [1101 11yy] [yyxx xxxx] (low surrogate) * * uuuuu = wwww + 1 */ else if (c >= 0xD800 && c <= 0xDBFF) { char high, low; high = c; i++; low = chars[i]; buf_loc[count_loc++] = (byte) (0xF0 | (((high + 0x40) >> 8) & 0xf0)); buf_loc[count_loc++] = (byte) (0x80 | (((high + 0x40) >> 2) & 0x3f)); buf_loc[count_loc++] = (byte) (0x80 | ((low >> 6) & 0x0f) + ((high << 4) & 0x30)); buf_loc[count_loc++] = (byte) (0x80 | (low & 0x3f)); } else { buf_loc[count_loc++] = (byte) (0xe0 + (c >> 12)); buf_loc[count_loc++] = (byte) (0x80 + ((c >> 6) & 0x3f)); buf_loc[count_loc++] = (byte) (0x80 + (c & 0x3f)); } } // Store the local integer back into the instance variable count = count_loc; }
Write a string. @param s String to be written @exception IOException If an I/O error occurs
WriterToUTF8Buffered::write
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void flushBuffer() throws IOException { if (count > 0) { m_os.write(m_outputBytes, 0, count); count = 0; } }
Flush the internal buffer @throws IOException
WriterToUTF8Buffered::flushBuffer
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void flush() throws java.io.IOException { flushBuffer(); m_os.flush(); }
Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. @exception IOException If an I/O error occurs @throws java.io.IOException
WriterToUTF8Buffered::flush
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public void close() throws java.io.IOException { flushBuffer(); m_os.close(); }
Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect. @exception IOException If an I/O error occurs @throws java.io.IOException
WriterToUTF8Buffered::close
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
public OutputStream getOutputStream() { return m_os; }
Get the output stream where the events will be serialized to. @return reference to the result stream, or null of only a writer was set.
WriterToUTF8Buffered::getOutputStream
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/WriterToUTF8Buffered.java
Apache-2.0
static public final Properties getDefaultMethodProperties(String method) { String fileName = null; Properties defaultProperties = null; // According to this article : Double-check locking does not work // http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html try { synchronized (m_synch_object) { if (null == m_xml_properties) // double check { fileName = PROP_FILE_XML; m_xml_properties = loadPropertiesFile(fileName, null); } } if (method.equals(Method.XML)) { defaultProperties = m_xml_properties; } else if (method.equals(Method.HTML)) { if (null == m_html_properties) // double check { fileName = PROP_FILE_HTML; m_html_properties = loadPropertiesFile(fileName, m_xml_properties); } defaultProperties = m_html_properties; } else if (method.equals(Method.TEXT)) { if (null == m_text_properties) // double check { fileName = PROP_FILE_TEXT; m_text_properties = loadPropertiesFile(fileName, m_xml_properties); if (null == m_text_properties.getProperty(OutputKeys.ENCODING)) { String mimeEncoding = Encodings.getMimeEncoding(null); m_text_properties.put( OutputKeys.ENCODING, mimeEncoding); } } defaultProperties = m_text_properties; } else if (method.equals(Method.UNKNOWN)) { if (null == m_unknown_properties) // double check { fileName = PROP_FILE_UNKNOWN; m_unknown_properties = loadPropertiesFile(fileName, m_xml_properties); } defaultProperties = m_unknown_properties; } else { // TODO: Calculate res file from name. defaultProperties = m_xml_properties; } } catch (IOException ioe) { throw new WrappedRuntimeException( Utils.messages.createMessage( MsgKey.ER_COULD_NOT_LOAD_METHOD_PROPERTY, new Object[] { fileName, method }), ioe); } // wrap these cached defaultProperties in a new Property object just so // that the caller of this method can't modify the default values return new Properties(defaultProperties); }
Creates an empty OutputProperties with the property key/value defaults specified by a property file. The method argument is used to construct a string of the form output_[method].properties (for instance, output_html.properties). The output_xml.properties file is always used as the base. <p>Anything other than 'text', 'xml', and 'html', will use the output_xml.properties file.</p> @param method non-null reference to method name. @return Properties object that holds the defaults for the given method.
OutputPropertiesFactory::getDefaultMethodProperties
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/OutputPropertiesFactory.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/OutputPropertiesFactory.java
Apache-2.0
static private String fixupPropertyString(String s, boolean doClipping) { int index; if (doClipping && s.startsWith(S_XSLT_PREFIX)) { s = s.substring(S_XSLT_PREFIX_LEN); } if (s.startsWith(S_XALAN_PREFIX)) { s = S_BUILTIN_EXTENSIONS_UNIVERSAL + s.substring(S_XALAN_PREFIX_LEN); } if ((index = s.indexOf("\\u003a")) > 0) { String temp = s.substring(index + 6); s = s.substring(0, index) + ":" + temp; } return s; }
Fix up a string in an output properties file according to the rules of {@link #loadPropertiesFile}. @param s non-null reference to string that may need to be fixed up. @return A new string if fixup occured, otherwise the s argument.
(anonymous)::fixupPropertyString
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/OutputPropertiesFactory.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/OutputPropertiesFactory.java
Apache-2.0
public boolean isInEncoding(char ch) { if (m_encoding == null) { m_encoding = new EncodingImpl(); // One could put alternate logic in here to // instantiate another object that implements the // InEncoding interface. For example if the JRE is 1.4 or up // we could have an object that uses JRE 1.4 methods } return m_encoding.isInEncoding(ch); }
This is not a public API. It returns true if the char in question is in the encoding. @param ch the char in question. <p> This method is not a public API. @xsl.usage internal
EncodingInfo::isInEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
public boolean isInEncoding(char high, char low) { if (m_encoding == null) { m_encoding = new EncodingImpl(); // One could put alternate logic in here to // instantiate another object that implements the // InEncoding interface. For example if the JRE is 1.4 or up // we could have an object that uses JRE 1.4 methods } return m_encoding.isInEncoding(high, low); }
This is not a public API. It returns true if the character formed by the high/low pair is in the encoding. @param high a char that the a high char of a high/low surrogate pair. @param low a char that is the low char of a high/low surrogate pair. <p> This method is not a public API. @xsl.usage internal
EncodingInfo::isInEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
public EncodingInfo(String name, String javaName, char highChar) { this.name = name; this.javaName = javaName; this.m_highCharInContiguousGroup = highChar; }
Create an EncodingInfo object based on the ISO name and Java name. If both parameters are null any character will be considered to be in the encoding. This is useful for when the serializer is in temporary output state, and has no assciated encoding. @param name reference to the ISO name. @param javaName reference to the Java encoding name. @param highChar The char for which characters at or below this value are definately in the encoding, although for characters above this point they might be in the encoding.
EncodingInfo::EncodingInfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
private static boolean inEncoding(char ch, String encoding) { boolean isInEncoding; try { char cArray[] = new char[1]; cArray[0] = ch; // Construct a String from the char String s = new String(cArray); // Encode the String into a sequence of bytes // using the given, named charset. byte[] bArray = s.getBytes(encoding); isInEncoding = inEncoding(ch, bArray); } catch (Exception e) { isInEncoding = false; // If for some reason the encoding is null, e.g. // for a temporary result tree, we should just // say that every character is in the encoding. if (encoding == null) isInEncoding = true; } return isInEncoding; }
This is heart of the code that determines if a given character is in the given encoding. This method is probably expensive, and the answer should be cached. <p> This method is not a public API, and should only be used internally within the serializer. @param ch the char in question, that is not a high char of a high/low surrogate pair. @param encoding the Java name of the enocding. @xsl.usage internal
EncodingImpl::inEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
private static boolean inEncoding(char high, char low, String encoding) { boolean isInEncoding; try { char cArray[] = new char[2]; cArray[0] = high; cArray[1] = low; // Construct a String from the char String s = new String(cArray); // Encode the String into a sequence of bytes // using the given, named charset. byte[] bArray = s.getBytes(encoding); isInEncoding = inEncoding(high,bArray); } catch (Exception e) { isInEncoding = false; } return isInEncoding; }
This is heart of the code that determines if a given high/low surrogate pair forms a character that is in the given encoding. This method is probably expensive, and the answer should be cached. <p> This method is not a public API, and should only be used internally within the serializer. @param high the high char of a high/low surrogate pair. @param low the low char of a high/low surrogate pair. @param encoding the Java name of the encoding. @xsl.usage internal
EncodingImpl::inEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
private static boolean inEncoding(char ch, byte[] data) { final boolean isInEncoding; // If the string written out as data is not in the encoding, // the output is not specified according to the documentation // on the String.getBytes(encoding) method, // but we do our best here. if (data==null || data.length == 0) { isInEncoding = false; } else { if (data[0] == 0) isInEncoding = false; else if (data[0] == '?' && ch != '?') isInEncoding = false; /* * else if (isJapanese) { * // isJapanese is really * // ( "EUC-JP".equals(javaName) * // || "EUC_JP".equals(javaName) * // || "SJIS".equals(javaName) ) * * // Work around some bugs in JRE for Japanese * if(data[0] == 0x21) * isInEncoding = false; * else if (ch == 0xA5) * isInEncoding = false; * else * isInEncoding = true; * } */ else { // We don't know for sure, but it looks like it is in the encoding isInEncoding = true; } } return isInEncoding; }
This method is the core of determining if character is in the encoding. The method is not foolproof, because s.getBytes(encoding) has specified behavior only if the characters are in the specified encoding. However this method tries it's best. @param ch the char that was converted using getBytes, or the first char of a high/low pair that was converted. @param data the bytes written out by the call to s.getBytes(encoding); @return true if the character is in the encoding.
EncodingImpl::inEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
public final char getHighChar() { return m_highCharInContiguousGroup; }
This method exists for performance reasons. <p> Except for '\u0000', if a char is less than or equal to the value returned by this method then it in the encoding. <p> The characters in an encoding are not contiguous, however there is a lowest group of chars starting at '\u0001' upto and including the char returned by this method that are all in the encoding. So the char returned by this method essentially defines the lowest contiguous group. <p> chars above the value returned might be in the encoding, but chars at or below the value returned are definately in the encoding. <p> In any case however, the isInEncoding(char) method can be used regardless of the value of the char returned by this method. <p> If the value returned is '\u0000' it means that every character must be tested with an isInEncoding method {@link #isInEncoding(char)} or {@link #isInEncoding(char, char)} for surrogate pairs. <p> This method is not a public API. @xsl.usage internal
EncodingImpl::getHighChar
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/EncodingInfo.java
Apache-2.0
static Writer getWriter(OutputStream output, String encoding) throws UnsupportedEncodingException { for (int i = 0; i < _encodings.length; ++i) { if (_encodings[i].name.equalsIgnoreCase(encoding)) { try { String javaName = _encodings[i].javaName; OutputStreamWriter osw = new OutputStreamWriter(output,javaName); return osw; } catch (java.lang.IllegalArgumentException iae) // java 1.1.8 { // keep trying } catch (UnsupportedEncodingException usee) { // keep trying } } } try { return new OutputStreamWriter(output, encoding); } catch (java.lang.IllegalArgumentException iae) // java 1.1.8 { throw new UnsupportedEncodingException(encoding); } }
Returns a writer for the specified encoding based on an output stream. <p> This is not a public API. @param output The output stream @param encoding The encoding MIME name, not a Java name for the encoding. @return A suitable writer @throws UnsupportedEncodingException There is no convertor to support this encoding @xsl.usage internal
Encodings::getWriter
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static EncodingInfo getEncodingInfo(String encoding) { EncodingInfo ei; String normalizedEncoding = toUpperCaseFast(encoding); ei = (EncodingInfo) _encodingTableKeyJava.get(normalizedEncoding); if (ei == null) ei = (EncodingInfo) _encodingTableKeyMime.get(normalizedEncoding); if (ei == null) { // We shouldn't have to do this, but just in case. ei = new EncodingInfo(null,null, '\u0000'); } return ei; }
Returns the EncodingInfo object for the specified encoding, never null, although the encoding name inside the returned EncodingInfo object will be if we can't find a "real" EncodingInfo for the encoding. <p> This is not a public API. @param encoding The encoding @return The object that is used to determine if characters are in the given encoding. @xsl.usage internal
Encodings::getEncodingInfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
public static boolean isRecognizedEncoding(String encoding) { EncodingInfo ei; String normalizedEncoding = encoding.toUpperCase(); ei = (EncodingInfo) _encodingTableKeyJava.get(normalizedEncoding); if (ei == null) ei = (EncodingInfo) _encodingTableKeyMime.get(normalizedEncoding); if (ei != null) return true; return false; }
Determines if the encoding specified was recognized by the serializer or not. @param encoding The encoding @return boolean - true if the encoding was recognized else false
Encodings::isRecognizedEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static private String toUpperCaseFast(final String s) { boolean different = false; final int mx = s.length(); char[] chars = new char[mx]; for (int i=0; i < mx; i++) { char ch = s.charAt(i); // is the character a lower case ASCII one? if ('a' <= ch && ch <= 'z') { // a cheap and fast way to uppercase that is good enough ch = (char) (ch + ('A' - 'a')); different = true; // the uppercased String is different } chars[i] = ch; } // A little optimization, don't call String.valueOf() if // the uppercased string is the same as the input string. final String upper; if (different) upper = String.valueOf(chars); else upper = s; return upper; }
A fast and cheap way to uppercase a String that is only made of printable ASCII characters. <p> This is not a public API. @param s a String of ASCII characters @return an uppercased version of the input String, possibly the same String. @xsl.usage internal
Encodings::toUpperCaseFast
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static String getMimeEncoding(String encoding) { if (null == encoding) { try { // Get the default system character encoding. This may be // incorrect if they passed in a writer, but right now there // seems to be no way to get the encoding from a writer. encoding = System.getProperty("file.encoding", "UTF8"); if (null != encoding) { /* * See if the mime type is equal to UTF8. If you don't * do that, then convertJava2MimeEncoding will convert * 8859_1 to "ISO-8859-1", which is not what we want, * I think, and I don't think I want to alter the tables * to convert everything to UTF-8. */ String jencoding = (encoding.equalsIgnoreCase("Cp1252") || encoding.equalsIgnoreCase("ISO8859_1") || encoding.equalsIgnoreCase("8859_1") || encoding.equalsIgnoreCase("UTF8")) ? DEFAULT_MIME_ENCODING : convertJava2MimeEncoding(encoding); encoding = (null != jencoding) ? jencoding : DEFAULT_MIME_ENCODING; } else { encoding = DEFAULT_MIME_ENCODING; } } catch (SecurityException se) { encoding = DEFAULT_MIME_ENCODING; } } else { encoding = convertJava2MimeEncoding(encoding); } return encoding; }
Get the proper mime encoding. From the XSLT recommendation: "The encoding attribute specifies the preferred encoding to use for outputting the result tree. XSLT processors are required to respect values of UTF-8 and UTF-16. For other values, if the XSLT processor does not support the specified encoding it may signal an error; if it does not signal an error it should use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding whose name does not match the EncName production of the XML Recommendation [XML]. If no encoding attribute is specified, then the XSLT processor should use either UTF-8 or UTF-16." <p> This is not a public API. @param encoding Reference to java-style encoding string, which may be null, in which case a default will be found. @return The ISO-style encoding string, or null if failure. @xsl.usage internal
Encodings::getMimeEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
private static String convertJava2MimeEncoding(String encoding) { EncodingInfo enc = (EncodingInfo) _encodingTableKeyJava.get(toUpperCaseFast(encoding)); if (null != enc) return enc.name; return encoding; }
Try the best we can to convert a Java encoding to a XML-style encoding. <p> This is not a public API. @param encoding non-null reference to encoding string, java style. @return ISO-style encoding string. @xsl.usage internal
Encodings::convertJava2MimeEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
public static String convertMime2JavaEncoding(String encoding) { for (int i = 0; i < _encodings.length; ++i) { if (_encodings[i].name.equalsIgnoreCase(encoding)) { return _encodings[i].javaName; } } return encoding; }
Try the best we can to convert a Java encoding to a XML-style encoding. <p> This is not a public API. @param encoding non-null reference to encoding string, java style. @return ISO-style encoding string. <p> This method is not a public API. @xsl.usage internal
Encodings::convertMime2JavaEncoding
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
private static EncodingInfo[] loadEncodingInfo() { try { InputStream is; SecuritySupport ss = SecuritySupport.getInstance(); is = ss.getResourceAsStream(ObjectFactory.findClassLoader(), ENCODINGS_FILE); // j2objc: if resource wasn't found, load defaults from string. if (is == null) { is = new ByteArrayInputStream( ENCODINGS_FILE_STR.getBytes(StandardCharsets.UTF_8)); } Properties props = new Properties(); if (is != null) { props.load(is); is.close(); } else { // Seems to be no real need to force failure here, let the // system do its best... The issue is not really very critical, // and the output will be in any case _correct_ though maybe not // always human-friendly... :) // But maybe report/log the resource problem? // Any standard ways to report/log errors (in static context)? } int totalEntries = props.size(); List encodingInfo_list = new ArrayList(); Enumeration keys = props.keys(); for (int i = 0; i < totalEntries; ++i) { String javaName = (String) keys.nextElement(); String val = props.getProperty(javaName); int len = lengthOfMimeNames(val); String mimeName; char highChar; if (len == 0) { // There is no property value, only the javaName, so try and recover mimeName = javaName; highChar = '\u0000'; // don't know the high code point, will need to test every character } else { try { // Get the substring after the Mime names final String highVal = val.substring(len).trim(); highChar = (char) Integer.decode(highVal).intValue(); } catch( NumberFormatException e) { highChar = 0; } String mimeNames = val.substring(0, len); StringTokenizer st = new StringTokenizer(mimeNames, ","); for (boolean first = true; st.hasMoreTokens(); first = false) { mimeName = st.nextToken(); EncodingInfo ei = new EncodingInfo(mimeName, javaName, highChar); encodingInfo_list.add(ei); _encodingTableKeyMime.put(mimeName.toUpperCase(), ei); if (first) _encodingTableKeyJava.put(javaName.toUpperCase(), ei); } } } // Convert the Vector of EncodingInfo objects into an array of them, // as that is the kind of thing this method returns. EncodingInfo[] ret_ei = new EncodingInfo[encodingInfo_list.size()]; encodingInfo_list.toArray(ret_ei); return ret_ei; } catch (java.net.MalformedURLException mue) { throw new org.apache.xml.serializer.utils.WrappedRuntimeException(mue); } catch (java.io.IOException ioe) { throw new org.apache.xml.serializer.utils.WrappedRuntimeException(ioe); } }
Load a list of all the supported encodings. System property "encodings" formatted using URL syntax may define an external encodings list. Thanks to Sergey Ushakov for the code contribution! @xsl.usage internal
Encodings::loadEncodingInfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
private static int lengthOfMimeNames(String val) { // look for the space preceding the optional high char int len = val.indexOf(' '); // If len is zero it means the optional part is not there, so // the value must be all Mime names, so set the length appropriately if (len < 0) len = val.length(); return len; }
Get the length of the Mime names within the property value @param val The value of the property, which should contain a comma separated list of Mime names, followed optionally by a space and the high char value @return
Encodings::lengthOfMimeNames
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static boolean isHighUTF16Surrogate(char ch) { return ('\uD800' <= ch && ch <= '\uDBFF'); }
Return true if the character is the high member of a surrogate pair. <p> This is not a public API. @param ch the character to test @xsl.usage internal
Encodings::isHighUTF16Surrogate
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static boolean isLowUTF16Surrogate(char ch) { return ('\uDC00' <= ch && ch <= '\uDFFF'); }
Return true if the character is the low member of a surrogate pair. <p> This is not a public API. @param ch the character to test @xsl.usage internal
Encodings::isLowUTF16Surrogate
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static int toCodePoint(char highSurrogate, char lowSurrogate) { int codePoint = ((highSurrogate - 0xd800) << 10) + (lowSurrogate - 0xdc00) + 0x10000; return codePoint; }
Return the unicode code point represented by the high/low surrogate pair. <p> This is not a public API. @param highSurrogate the high char of the high/low pair @param lowSurrogate the low char of the high/low pair @xsl.usage internal
Encodings::toCodePoint
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static int toCodePoint(char ch) { int codePoint = ch; return codePoint; }
Return the unicode code point represented by the char. A bit of a dummy method, since all it does is return the char, but as an int value. <p> This is not a public API. @param ch the char. @xsl.usage internal
Encodings::toCodePoint
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
static public char getHighChar(String encoding) { final char highCodePoint; EncodingInfo ei; String normalizedEncoding = toUpperCaseFast(encoding); ei = (EncodingInfo) _encodingTableKeyJava.get(normalizedEncoding); if (ei == null) ei = (EncodingInfo) _encodingTableKeyMime.get(normalizedEncoding); if (ei != null) highCodePoint = ei.getHighChar(); else highCodePoint = 0; return highCodePoint; }
Characters with values at or below the high code point are in the encoding. Code point values above this one may or may not be in the encoding, but lower ones certainly are. <p> This is for performance. @param encoding The encoding @return The code point for which characters at or below this code point are in the encoding. Characters with higher code point may or may not be in the encoding. A value of zero is returned if the high code point is unknown. <p> This method is not a public API. @xsl.usage internal
Encodings::getHighChar
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/Encodings.java
Apache-2.0
private CharInfo() { this.array_of_bits = createEmptySetOfIntegers(65535); this.firstWordNotUsed = 0; this.shouldMapAttrChar_ASCII = new boolean[ASCII_MAX]; this.shouldMapTextChar_ASCII = new boolean[ASCII_MAX]; this.m_charKey = new CharKey(); // Not set here, but in a constructor that uses this one // this.m_charToString = new Hashtable(); this.onlyQuotAmpLtGt = true; return; }
A base constructor just to explicitly create the fields, with the exception of m_charToString which is handled by the constructor that delegates base construction to this one. <p> m_charToString is not created here only for performance reasons, to avoid creating a Hashtable that will be replaced when making a mutable copy, {@link #mutableCopyOf(CharInfo)}.
CharInfo::CharInfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private boolean defineEntity(String name, char value) { StringBuffer sb = new StringBuffer("&"); sb.append(name); sb.append(';'); String entityString = sb.toString(); boolean extra = defineChar2StringMapping(entityString, value); return extra; }
Defines a new character reference. The reference's name and value are supplied. Nothing happens if the character reference is already defined. <p>Unlike internal entities, character references are a string to single character mapping. They are used to map non-ASCII characters both on parsing and printing, primarily for HTML documents. '&amp;lt;' is an example of a character reference.</p> @param name The entity's name @param value The entity's value @return true if the mapping is not one of: <ul> <li> '<' to "&lt;" <li> '>' to "&gt;" <li> '&' to "&amp;" <li> '"' to "&quot;" </ul>
CharInfo::defineEntity
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
String getOutputStringForChar(char value) { // CharKey m_charKey = new CharKey(); //Alternative to synchronized m_charKey.setChar(value); return (String) m_charToString.get(m_charKey); }
Map a character to a String. For example given the character '>' this method would return the fully decorated entity name "&lt;". Strings for entity references are loaded from a properties file, but additional mappings defined through calls to defineChar2String() are possible. Such entity reference mappings could be over-ridden. This is reusing a stored key object, in an effort to avoid heap activity. Unfortunately, that introduces a threading risk. Simplest fix for now is to make it a synchronized method, or to give up the reuse; I see very little performance difference between them. Long-term solution would be to replace the hashtable with a sparse array keyed directly from the character's integer value; see DTM's string pool for a related solution. @param value The character that should be resolved to a String, e.g. resolve '>' to "&lt;". @return The String that the character is mapped to, or null if not found. @xsl.usage internal
CharInfo::getOutputStringForChar
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
final boolean shouldMapAttrChar(int value) { // for performance try the values in the boolean array first, // this is faster access than the BitSet for common ASCII values if (value < ASCII_MAX) return shouldMapAttrChar_ASCII[value]; // rather than java.util.BitSet, our private // implementation is faster (and less general). return get(value); }
Tell if the character argument that is from an attribute value has a mapping to a String. @param value the value of a character that is in an attribute value @return true if the character should have any special treatment, such as when writing out entity references. @xsl.usage internal
CharInfo::shouldMapAttrChar
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
final boolean shouldMapTextChar(int value) { // for performance try the values in the boolean array first, // this is faster access than the BitSet for common ASCII values if (value < ASCII_MAX) return shouldMapTextChar_ASCII[value]; // rather than java.util.BitSet, our private // implementation is faster (and less general). return get(value); }
Tell if the character argument that is from a text node has a mapping to a String, for example to map '<' to "&lt;". @param value the value of a character that is in a text node @return true if the character has a mapping to a String, such as when writing out entity references. @xsl.usage internal
CharInfo::shouldMapTextChar
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
static CharInfo getCharInfo(String entitiesFileName, String method) { CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName); if (charInfo != null) { return mutableCopyOf(charInfo); } // try to load it internally - cache try { charInfo = getCharInfoBasedOnPrivilege(entitiesFileName, method, true); // Put the common copy of charInfo in the cache, but return // a copy of it. m_getCharInfoCache.put(entitiesFileName, charInfo); return mutableCopyOf(charInfo); } catch (Exception e) {} // try to load it externally - do not cache try { return getCharInfoBasedOnPrivilege(entitiesFileName, method, false); } catch (Exception e) {} String absoluteEntitiesFileName; if (entitiesFileName.indexOf(':') < 0) { absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName); } else { try { absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURI(entitiesFileName, null); } catch (TransformerException te) { throw new WrappedRuntimeException(te); } } return getCharInfoBasedOnPrivilege(entitiesFileName, method, false); }
Factory that reads in a resource file that describes the mapping of characters to entity references. Resource files must be encoded in UTF-8 and have a format like: <pre> # First char # is a comment Entity numericValue quot 34 amp 38 </pre> (Note: Why don't we just switch to .properties files? Oct-01 -sc) @param entitiesResource Name of entities resource file that should be loaded, which describes that mapping of characters to entity references. @param method the output method type, which should be one of "xml", "html", "text"... @xsl.usage internal
CharInfo::getCharInfo
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private static CharInfo mutableCopyOf(CharInfo charInfo) { CharInfo copy = new CharInfo(); int max = charInfo.array_of_bits.length; System.arraycopy(charInfo.array_of_bits,0,copy.array_of_bits,0,max); copy.firstWordNotUsed = charInfo.firstWordNotUsed; max = charInfo.shouldMapAttrChar_ASCII.length; System.arraycopy(charInfo.shouldMapAttrChar_ASCII,0,copy.shouldMapAttrChar_ASCII,0,max); max = charInfo.shouldMapTextChar_ASCII.length; System.arraycopy(charInfo.shouldMapTextChar_ASCII,0,copy.shouldMapTextChar_ASCII,0,max); // utility field copy.m_charKey is already created in the default constructor copy.m_charToString = (HashMap) charInfo.m_charToString.clone(); copy.onlyQuotAmpLtGt = charInfo.onlyQuotAmpLtGt; return copy; }
Create a mutable copy of the cached one. @param charInfo The cached one. @return
CharInfo::mutableCopyOf
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private static int arrayIndex(int i) { return (i >> SHIFT_PER_WORD); }
Returns the array element holding the bit value for the given integer @param i the integer that might be in the set of integers
CharInfo::arrayIndex
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private static int bit(int i) { int ret = (1 << (i & LOW_ORDER_BITMASK)); return ret; }
For a given integer in the set it returns the single bit value used within a given word that represents whether the integer is in the set or not.
CharInfo::bit
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private int[] createEmptySetOfIntegers(int max) { firstWordNotUsed = 0; // an optimization int[] arr = new int[arrayIndex(max - 1) + 1]; return arr; }
Creates a new empty set of integers (characters) @param max the maximum integer to be in the set.
CharInfo::createEmptySetOfIntegers
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private final void set(int i) { setASCIItextDirty(i); setASCIIattrDirty(i); int j = (i >> SHIFT_PER_WORD); // this word is used int k = j + 1; if(firstWordNotUsed < k) // for optimization purposes. firstWordNotUsed = k; array_of_bits[j] |= (1 << (i & LOW_ORDER_BITMASK)); }
Adds the integer (character) to the set of integers. @param i the integer to add to the set, valid values are 0, 1, 2 ... up to the maximum that was specified at the creation of the set.
CharInfo::set
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private final boolean get(int i) { boolean in_the_set = false; int j = (i >> SHIFT_PER_WORD); // wordIndex(i) // an optimization here, ... a quick test to see // if this integer is beyond any of the words in use if(j < firstWordNotUsed) in_the_set = (array_of_bits[j] & (1 << (i & LOW_ORDER_BITMASK)) ) != 0; // 0L for 64 bit words return in_the_set; }
Return true if the integer (character)is in the set of integers. This implementation uses an array of integers with 32 bits per integer. If a bit is set to 1 the corresponding integer is in the set of integers. @param i an integer that is tested to see if it is the set of integers, or not.
CharInfo::get
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private boolean extraEntity(String outputString, int charToMap) { boolean extra = false; if (charToMap < ASCII_MAX) { switch (charToMap) { case '"' : // quot if (!outputString.equals("&quot;")) extra = true; break; case '&' : // amp if (!outputString.equals("&amp;")) extra = true; break; case '<' : // lt if (!outputString.equals("&lt;")) extra = true; break; case '>' : // gt if (!outputString.equals("&gt;")) extra = true; break; default : // other entity in range 0 to 127 extra = true; } } return extra; }
This method returns true if there are some non-standard mappings to entities other than quot, amp, lt, gt, and its only purpose is for performance. @param charToMap The value of the character that is mapped to a String @param outputString The String to which the character is mapped, usually an entity reference such as "&lt;". @return true if the mapping is not one of: <ul> <li> '<' to "&lt;" <li> '>' to "&gt;" <li> '&' to "&amp;" <li> '"' to "&quot;" </ul>
CharInfo::extraEntity
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private void setASCIItextDirty(int j) { if (0 <= j && j < ASCII_MAX) { shouldMapTextChar_ASCII[j] = true; } }
If the character is in the ASCII range then mark it as needing replacement with a String on output if it occurs in a text node. @param ch
CharInfo::setASCIItextDirty
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0
private void setASCIIattrDirty(int j) { if (0 <= j && j < ASCII_MAX) { shouldMapAttrChar_ASCII[j] = true; } }
If the character is in the ASCII range then mark it as needing replacement with a String on output if it occurs in a attribute value. @param ch
CharInfo::setASCIIattrDirty
java
google/j2objc
xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
https://github.com/google/j2objc/blob/master/xalan/third_party/android/platform/external/apache-xml/src/main/java/org/apache/xml/serializer/CharInfo.java
Apache-2.0