javax.xml.transform.Transformer#getErrorListener ( )源码实例Demo

下面列出了javax.xml.transform.Transformer#getErrorListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: ToStream.java
/**
 * 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;
}
 
源代码2 项目: jdk1.8-source-analysis   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码3 项目: TencentKona-8   文件: ToStream.java
/**
 * 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;
}
 
源代码4 项目: openjdk-8   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码5 项目: hottub   文件: ToStream.java
/**
 * 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;
}
 
源代码6 项目: jdk8u60   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码7 项目: openjdk-8-source   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码8 项目: openjdk-jdk8u   文件: ToStream.java
/**
 * 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;
}
 
源代码9 项目: openjdk-jdk8u   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码10 项目: j2objc   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码11 项目: Bytecoder   文件: ToXMLStream.java
/**
 * 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;
}
 
源代码12 项目: jdk1.8-source-analysis   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码13 项目: TencentKona-8   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码14 项目: jdk8u60   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码15 项目: openjdk-8-source   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码16 项目: j2objc   文件: ToXMLStream.java
/**
 * 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
 */
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;                
        }             
    }
}
 
源代码17 项目: openjdk-jdk8u   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码18 项目: openjdk-jdk9   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}
 
源代码20 项目: Bytecoder   文件: ToXMLStream.java
/**
 * 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
 */
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 (Exception e){}
    }
}