Java Code Examples for org.xml.sax.AttributeList#getValue()

The following examples show how to use org.xml.sax.AttributeList#getValue() . 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: XMLSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 2
Source File: XMLSerializer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 3
Source File: SAXCatalogReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 4
Source File: XMLSerializer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 5
Source File: SAXCatalogReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 6
Source File: XMLSerializer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 7
Source File: SAXCatalogReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
        AttributeList atts)
                throws SAXException {

    if (abandonHope) {
        return;
    }

    if (saxParser == null) {
        String prefix = "";
        if (name.indexOf(':') > 0) {
            prefix = name.substring(0, name.indexOf(':'));
        }

        String localName = name;
        if (localName.indexOf(':') > 0) {
            localName = localName.substring(localName.indexOf(':')+1);
        }

        String namespaceURI = null;
        if (prefix.length() == 0) {
            namespaceURI = atts.getValue("xmlns");
        } else {
            namespaceURI = atts.getValue("xmlns:" + prefix);
        }

        String saxParserClass = getCatalogParser(namespaceURI,
                localName);

        if (saxParserClass == null) {
            abandonHope = true;
            if (namespaceURI == null) {
                debug.message(2, "No Catalog parser for " + name);
            } else {
                debug.message(2, "No Catalog parser for "
                        + "{" + namespaceURI + "}"
                        + name);
            }
            return;
        }

        try {
            saxParser = (SAXCatalogParser)
                    ReflectUtil.forName(saxParserClass).newInstance();

            saxParser.setCatalog(catalog);
            saxParser.startDocument();
            saxParser.startElement(name, atts);
        } catch (ClassNotFoundException cnfe) {
            saxParser = null;
            abandonHope = true;
            debug.message(2, cnfe.toString());
        } catch (InstantiationException ie) {
            saxParser = null;
            abandonHope = true;
            debug.message(2, ie.toString());
        } catch (IllegalAccessException iae) {
            saxParser = null;
            abandonHope = true;
            debug.message(2, iae.toString());
        } catch (ClassCastException cce ) {
            saxParser = null;
            abandonHope = true;
            debug.message(2, cce.toString());
        }
    } else {
        saxParser.startElement(name, atts);
    }
}
 
Example 8
Source File: XMLSerializer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 9
Source File: SAXCatalogReader.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 10
Source File: SAXCatalogReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 11
Source File: XMLSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 12
Source File: SAXCatalogReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 13
Source File: XMLSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 14
Source File: SAXCatalogReader.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 15
Source File: XMLSerializer.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 16
Source File: SAXCatalogReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 17
Source File: XMLSerializer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 18
Source File: SAXCatalogReader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}
 
Example 19
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void startElement( String tagName, AttributeList attrs )
throws SAXException
{
    int          i;
    boolean      preserveSpace;
    ElementState state;
    String       name;
    String       value;


    if (DEBUG) {
        System.out.println("==>startElement("+tagName+")");
    }

    try {
        if (_printer == null) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "NoWriterSupplied", null);
            throw new IllegalStateException(msg);
        }

        state = getElementState();
        if (isDocumentState()) {
            // If this is the root element handle it differently.
            // If the first root element in the document, serialize
            // the document's DOCTYPE. Space preserving defaults
            // to that of the output format.
            if (! _started)
                startDocument( tagName );
        } else {
            // For any other element, if first in parent, then
            // close parent's opening tag and use the parnet's
            // space preserving.
            if (state.empty)
                _printer.printText( '>' );
            // Must leave CData section first
            if (state.inCData) {
                _printer.printText( "]]>" );
                state.inCData = false;
            }
            // Indent this element on a new line if the first
            // content of the parent element or immediately
            // following an element.
            if (_indenting && ! state.preserveSpace &&
                ( state.empty || state.afterElement || state.afterComment))
                _printer.breakLine();
        }
        preserveSpace = state.preserveSpace;

        // Do not change the current element state yet.
        // This only happens in endElement().

        _printer.printText( '<' );
        _printer.printText( tagName );
        _printer.indent();

        // For each attribute print it's name and value as one part,
        // separated with a space so the element can be broken on
        // multiple lines.
        if (attrs != null) {
            for (i = 0 ; i < attrs.getLength() ; ++i) {
                _printer.printSpace();
                name = attrs.getName( i );
                value = attrs.getValue( i );
                if (value != null) {
                    _printer.printText( name );
                    _printer.printText( "=\"" );
                    printEscaped( value );
                    _printer.printText( '"' );
                }

                // If the attribute xml:space exists, determine whether
                // to preserve spaces in this and child nodes based on
                // its value.
                if (name.equals( "xml:space" )) {
                    if (value.equals( "preserve" ))
                        preserveSpace = true;
                    else
                        preserveSpace = _format.getPreserveSpace();
                }
            }
        }
        // Now it's time to enter a new element state
        // with the tag name and space preserving.
        // We still do not change the curent element state.
        state = enterElementState( null, null, tagName, preserveSpace );
        state.doCData = _format.isCDataElement( tagName );
        state.unescaped = _format.isNonEscapingElement( tagName );
    } catch (IOException except) {
        throw new SAXException( except );
    }

}
 
Example 20
Source File: SAXCatalogReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * The SAX <code>startElement</code> method.
 *
 * <p>The catalog parser is selected based on the namespace of the
 * first element encountered in the catalog.</p>
 */
public void startElement (String name,
                          AttributeList atts)
  throws SAXException {

  if (abandonHope) {
    return;
  }

  if (saxParser == null) {
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }

    String localName = name;
    if (localName.indexOf(':') > 0) {
      localName = localName.substring(localName.indexOf(':')+1);
    }

    String namespaceURI = null;
    if (prefix.equals("")) {
      namespaceURI = atts.getValue("xmlns");
    } else {
      namespaceURI = atts.getValue("xmlns:" + prefix);
    }

    String saxParserClass = getCatalogParser(namespaceURI,
                                             localName);

    if (saxParserClass == null) {
      abandonHope = true;
      if (namespaceURI == null) {
        debug.message(2, "No Catalog parser for " + name);
      } else {
        debug.message(2, "No Catalog parser for "
                      + "{" + namespaceURI + "}"
                      + name);
      }
      return;
    }

    try {
      saxParser = (SAXCatalogParser)
        ReflectUtil.forName(saxParserClass).newInstance();

      saxParser.setCatalog(catalog);
      saxParser.startDocument();
      saxParser.startElement(name, atts);
    } catch (ClassNotFoundException cnfe) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cnfe.toString());
    } catch (InstantiationException ie) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, ie.toString());
    } catch (IllegalAccessException iae) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, iae.toString());
    } catch (ClassCastException cce ) {
      saxParser = null;
      abandonHope = true;
      debug.message(2, cce.toString());
    }
  } else {
    saxParser.startElement(name, atts);
  }
}