com.sun.org.apache.xml.internal.serializer.utils.Utils Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.serializer.utils.Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SerializerBase.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #2
Source File: SerializerBase.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement) {
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement) {
        if (m_prefixMap != null) {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #3
Source File: SerializerBase.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #4
Source File: SerializerBase.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #5
Source File: SerializerBase.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #6
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if an Text node is well-formed, by checking if it contains invalid
 * XML characters.
 *
 * @param data The contents of the comment node
 */
protected void isTextWellFormed(Text node) {
    // Does the data valid XML character data
    Character invalidChar = isWFXMLChar(node.getData());
    if (invalidChar != null) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_TEXT,
                new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #7
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if an CDATASection node is well-formed, by checking it's data
 * for well-formedness.  Note that the presence of a CDATA termination mark
 * in the contents of a CDATASection is handled by the parameter
 * spli-cdata-sections
 *
 * @param data The contents of the comment node
 */
protected void isCDATASectionWellFormed(CDATASection node) {
    // Does the data valid XML character data
    Character invalidChar = isWFXMLChar(node.getData());
    //if (!isWFXMLChar(node.getData(), invalidChar)) {
    if (invalidChar != null) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_CDATA,
                new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #8
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if an CDATASection node is well-formed, by checking it's data
 * for well-formedness.  Note that the presence of a CDATA termination mark
 * in the contents of a CDATASection is handled by the parameter
 * spli-cdata-sections
 *
 * @param data The contents of the comment node
 */
protected void isCDATASectionWellFormed(CDATASection node) {
    // Does the data valid XML character data
    Character invalidChar = isWFXMLChar(node.getData());
    //if (!isWFXMLChar(node.getData(), invalidChar)) {
    if (invalidChar != null) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_CDATA,
                new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #9
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if an Text node is well-formed, by checking if it contains invalid
 * XML characters.
 *
 * @param data The contents of the comment node
 */
protected void isTextWellFormed(Text node) {
    // Does the data valid XML character data
    Character invalidChar = isWFXMLChar(node.getData());
    if (invalidChar != null) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_TEXT,
                new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #10
Source File: SerializerBase.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #11
Source File: SerializerBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement)
{
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement)
    {
        if (m_prefixMap != null)
        {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX))
            {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #12
Source File: SerializerBase.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the URI of an element or attribute. Note that default namespaces
 * do not apply directly to attributes.
 * @param qname a qualified name
 * @param isElement true if the qualified name is the name of
 * an element.
 * @return returns the namespace URI associated with the qualified name.
 */
public String getNamespaceURI(String qname, boolean isElement) {
    String uri = EMPTYSTRING;
    int col = qname.lastIndexOf(':');
    final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;

    if (!EMPTYSTRING.equals(prefix) || isElement) {
        if (m_prefixMap != null) {
            uri = m_prefixMap.lookupNamespace(prefix);
            if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
                throw new RuntimeException(
                    Utils.messages.createMessage(
                        MsgKey.ER_NAMESPACE_PREFIX,
                        new Object[] { qname.substring(0, col) }  ));
            }
        }
    }
    return uri;
}
 
Example #13
Source File: ToXMLStream.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #14
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if an element node is well-formed, by checking its Name for well-formedness.
 *
 * @param data The contents of the comment node
 * @return a boolean indiacating if the comment is well-formed or not.
 */
protected void isElementWellFormed(Node node) {
    boolean isNameWF = false;
    if ((fFeatures & NAMESPACES) != 0) {
        isNameWF =
            isValidQName(
                node.getPrefix(),
                node.getLocalName(),
                fIsXMLVersion11);
    } else {
        isNameWF = isXMLName(node.getNodeName(), fIsXMLVersion11);
    }

    if (!isNameWF) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME,
                new Object[] { "Element", node.getNodeName()});

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #15
Source File: ToHTMLStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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
 */
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);
    }
}
 
Example #16
Source File: ToXMLStream.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #17
Source File: ToHTMLStream.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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
 */
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);
    }
}
 
Example #18
Source File: ToXMLStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #19
Source File: ToXMLStream.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #20
Source File: ToStream.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 * @param encoding the character encoding
 */
public void setEncoding(String encoding)
{
    String old = getEncoding();
    super.setEncoding(encoding);
    if (old == null || !old.equals(encoding)) {
       // If we have changed the setting of the
       m_encodingInfo = Encodings.getEncodingInfo(encoding);

       if (encoding != null && m_encodingInfo.name == null) {
           // We tried to get an EncodingInfo for Object for the given
           // encoding, but it came back with an internall null name
           // so the encoding is not supported by the JDK, issue a message.
           String msg = Utils.messages.createMessage(
                           MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ encoding });
           try
           {
                   // Prepare to issue the warning message
                   Transformer tran = super.getTransformer();
                   if (tran != null) {
                           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);
               }
                   else
                           System.out.println(msg);
           }
           catch (Exception e){}
       }
    }
    return;
}
 
Example #21
Source File: ToXMLStream.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #22
Source File: ToXMLStream.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #23
Source File: ToHTMLStream.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 *  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
 */
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);
    }
}
 
Example #24
Source File: ToXMLStream.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #25
Source File: ToStream.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 * @param encoding the character encoding
 */
public void setEncoding(String encoding)
{
    String old = getEncoding();
    super.setEncoding(encoding);
    if (old == null || !old.equals(encoding)) {
       // If we have changed the setting of the
       m_encodingInfo = Encodings.getEncodingInfo(encoding);

       if (encoding != null && m_encodingInfo.name == null) {
           // We tried to get an EncodingInfo for Object for the given
           // encoding, but it came back with an internall null name
           // so the encoding is not supported by the JDK, issue a message.
           String msg = Utils.messages.createMessage(
                           MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ encoding });
           try
           {
                   // Prepare to issue the warning message
                   Transformer tran = super.getTransformer();
                   if (tran != null) {
                           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);
               }
                   else
                           System.out.println(msg);
           }
           catch (Exception e){}
       }
    }
    return;
}
 
Example #26
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if an element node is well-formed, by checking its Name for well-formedness.
 *
 * @param data The contents of the comment node
 * @return a boolean indiacating if the comment is well-formed or not.
 */
protected void isElementWellFormed(Node node) {
    boolean isNameWF = false;
    if ((fFeatures & NAMESPACES) != 0) {
        isNameWF =
            isValidQName(
                node.getPrefix(),
                node.getLocalName(),
                fIsXMLVersion11);
    } else {
        isNameWF = isXMLName(node.getNodeName(), fIsXMLVersion11);
    }

    if (!isNameWF) {
        String msg =
            Utils.messages.createMessage(
                MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME,
                new Object[] { "Element", node.getNodeName()});

        if (fErrorHandler != null) {
            fErrorHandler.handleError(
                new DOMErrorImpl(
                    DOMError.SEVERITY_FATAL_ERROR,
                    msg,
                    MsgKey.ER_WF_INVALID_CHARACTER_IN_NODE_NAME,
                    null,
                    null,
                    null));
        }
    }
}
 
Example #27
Source File: ToXMLStream.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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)
 */
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;
}
 
Example #28
Source File: ToHTMLStream.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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
 */
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);
    }
}
 
Example #29
Source File: ToHTMLStream.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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
 */
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);
    }
}
 
Example #30
Source File: ToStream.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 * @param encoding the character encoding
 */
public void setEncoding(String encoding)
{
    String old = getEncoding();
    super.setEncoding(encoding);
    if (old == null || !old.equals(encoding)) {
       // If we have changed the setting of the
       m_encodingInfo = Encodings.getEncodingInfo(encoding);

       if (encoding != null && m_encodingInfo.name == null) {
           // We tried to get an EncodingInfo for Object for the given
           // encoding, but it came back with an internall null name
           // so the encoding is not supported by the JDK, issue a message.
           String msg = Utils.messages.createMessage(
                           MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ encoding });
           try
           {
                   // Prepare to issue the warning message
                   Transformer tran = super.getTransformer();
                   if (tran != null) {
                           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);
               }
                   else
                           System.out.println(msg);
           }
           catch (Exception e){}
       }
    }
    return;
}