Java Code Examples for com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter#formatMessage()

The following examples show how to use com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter#formatMessage() . 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: DocumentBuilderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Document parse(InputSource is) throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException(
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
            "jaxp-null-input-source", null));
    }
    if (fSchemaValidator != null) {
        if (fSchemaValidationManager != null) {
            fSchemaValidationManager.reset();
            fUnparsedEntityHandler.reset();
        }
        resetSchemaValidator();
    }
    domParser.parse(is);
    Document doc = domParser.getDocument();
    domParser.dropDocumentReferences();
    return doc;
}
 
Example 2
Source File: XSImplementationImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public XSLoader createXSLoader(StringList versions) throws XSException {
    XSLoader loader = new XSLoaderImpl();
    if (versions == null){
                    return loader;
    }
    for (int i=0; i<versions.getLength();i++){
            if (!versions.item(i).equals("1.0")){
                            String msg =
                                    DOMMessageFormatter.formatMessage(
                                            DOMMessageFormatter.DOM_DOMAIN,
                                            "FEATURE_NOT_SUPPORTED",
                                            new Object[] { versions.item(i) });
                            throw new XSException(XSException.NOT_SUPPORTED_ERR, msg);
            }
    }
    return loader;
}
 
Example 3
Source File: XSImplementationImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public XSLoader createXSLoader(StringList versions) throws XSException {
    XSLoader loader = new XSLoaderImpl();
    if (versions == null){
                    return loader;
    }
    for (int i=0; i<versions.getLength();i++){
            if (!versions.item(i).equals("1.0")){
                            String msg =
                                    DOMMessageFormatter.formatMessage(
                                            DOMMessageFormatter.DOM_DOMAIN,
                                            "FEATURE_NOT_SUPPORTED",
                                            new Object[] { versions.item(i) });
                            throw new XSException(XSException.NOT_SUPPORTED_ERR, msg);
            }
    }
    return loader;
}
 
Example 4
Source File: BaseMarkupSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean reset()
{
    if ( _elementStateCount > 1 ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "ResetInMiddle", null);
        throw new IllegalStateException(msg);
    }
    _prepared = false;
    fCurrentNode = null;
    fStrBuffer.setLength(0);
    return true;
}
 
Example 5
Source File: BaseMarkupSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void setOutputFormat( OutputFormat format )
{
    if ( format == null ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "ArgumentIsNull", new Object[]{"format"});
        throw new NullPointerException(msg);
    }
    _format = format;
    reset();
}
 
Example 6
Source File: SerializerFactoryImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private Serializer getSerializer( OutputFormat format )
{
    if ( _method.equals( Method.XML ) ) {
        return new XMLSerializer( format );
    } else if ( _method.equals( Method.HTML ) ) {
        return new HTMLSerializer( format );
    }  else if ( _method.equals( Method.XHTML ) ) {
        return new XHTMLSerializer( format );
    }  else if ( _method.equals( Method.TEXT ) ) {
        return new TextSerializer();
    } else {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method});
        throw new IllegalStateException(msg);
    }
}
 
Example 7
Source File: SerializerFactoryImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Serializer getSerializer( OutputFormat format )
{
    if ( _method.equals( Method.XML ) ) {
        return new XMLSerializer( format );
    } else if ( _method.equals( Method.HTML ) ) {
        return new HTMLSerializer( format );
    }  else if ( _method.equals( Method.XHTML ) ) {
        return new XHTMLSerializer( format );
    }  else if ( _method.equals( Method.TEXT ) ) {
        return new TextSerializer();
    } else {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method});
        throw new IllegalStateException(msg);
    }
}
 
Example 8
Source File: BaseMarkupSerializer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void setOutputByteStream( OutputStream output )
{
    if ( output == null ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "ArgumentIsNull", new Object[]{"output"});
        throw new NullPointerException(msg);
    }
    _output = output;
    _writer = null;
    reset();
}
 
Example 9
Source File: BaseMarkupSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public boolean reset()
{
    if ( _elementStateCount > 1 ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "ResetInMiddle", null);
        throw new IllegalStateException(msg);
    }
    _prepared = false;
    fCurrentNode = null;
    fStrBuffer.setLength(0);
    return true;
}
 
Example 10
Source File: SerializerFactoryImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Serializer getSerializer( OutputFormat format )
{
    if ( _method.equals( Method.XML ) ) {
        return new XMLSerializer( format );
    } else if ( _method.equals( Method.HTML ) ) {
        return new HTMLSerializer( format );
    }  else if ( _method.equals( Method.XHTML ) ) {
        return new XHTMLSerializer( format );
    }  else if ( _method.equals( Method.TEXT ) ) {
        return new TextSerializer();
    } else {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method});
        throw new IllegalStateException(msg);
    }
}
 
Example 11
Source File: DOMParserImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static DOMException newFeatureNotFoundError(String name) {
    String msg =
        DOMMessageFormatter.formatMessage (
                DOMMessageFormatter.DOM_DOMAIN,
                "FEATURE_NOT_FOUND",
                new Object[] { name });
    return new DOMException (DOMException.NOT_FOUND_ERR, msg);
}
 
Example 12
Source File: BaseMarkupSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void setOutputByteStream( OutputStream output )
{
    if ( output == null ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "ArgumentIsNull", new Object[]{"output"});
        throw new NullPointerException(msg);
    }
    _output = output;
    _writer = null;
    reset();
}
 
Example 13
Source File: DOMParserImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static DOMException newTypeMismatchError(String name) {
    String msg =
        DOMMessageFormatter.formatMessage (
                DOMMessageFormatter.DOM_DOMAIN,
                "TYPE_MISMATCH_ERR",
                new Object[] { name });
    return new DOMException (DOMException.TYPE_MISMATCH_ERR, msg);
}
 
Example 14
Source File: DocumentBuilderImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set any DocumentBuilderFactory attributes of our underlying DOMParser
 *
 * Note: code does not handle possible conflicts between DOMParser
 * attribute names and JAXP specific attribute names,
 * eg. DocumentBuilderFactory.setValidating()
 */
private void setDocumentBuilderFactoryAttributes(Hashtable dbfAttrs)
    throws SAXNotSupportedException, SAXNotRecognizedException
{
    if (dbfAttrs == null) {
        // Nothing to do
        return;
    }

    Iterator entries = dbfAttrs.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        String name = (String) entry.getKey();
        Object val = entry.getValue();
        if (val instanceof Boolean) {
            // Assume feature
            domParser.setFeature(name, ((Boolean)val).booleanValue());
        } else {
            // Assume property
            if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
                // JAXP 1.2 support
                //None of the properties will take effect till the setValidating(true) has been called
                if ( W3C_XML_SCHEMA.equals(val) ) {
                    if( isValidating() ) {
                        domParser.setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
                        // this should allow us not to emit DTD errors, as expected by the
                        // spec when schema validation is enabled
                        domParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    }
                 }
             } else if(JAXP_SCHEMA_SOURCE.equals(name)){
                if( isValidating() ) {
                    String value=(String)dbfAttrs.get(JAXP_SCHEMA_LANGUAGE);
                    if(value !=null && W3C_XML_SCHEMA.equals(value)){
                        domParser.setProperty(name, val);
                    }else{
                        throw new IllegalArgumentException(
                            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
                            "jaxp-order-not-supported",
                            new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
                    }
                 }
              } else {
                 //check if the property is managed by security manager
                 if (fSecurityManager == null ||
                         !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, val)) {
                     //check if the property is managed by security property manager
                     if (fSecurityPropertyMgr == null ||
                             !fSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, val)) {
                         //fall back to the existing property manager
                         domParser.setProperty(name, val);
                     }
                 }

              }
         }
    }
}
 
Example 15
Source File: BaseMarkupSerializer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected void prepare()
    throws IOException
{
    if ( _prepared )
        return;

    if ( _writer == null && _output == null ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "NoWriterSupplied", null);
        throw new IOException(msg);
    }
    // If the output stream has been set, use it to construct
    // the writer. It is possible that the serializer has been
    // reused with the same output stream and different encoding.

    _encodingInfo = _format.getEncodingInfo();

    if ( _output != null ) {
        _writer = _encodingInfo.getWriter(_output);
    }

    if ( _format.getIndenting() ) {
        _indenting = true;
        _printer = new IndentPrinter( _writer, _format );
    } else {
        _indenting = false;
        _printer = new Printer( _writer, _format );
    }

    ElementState state;

    _elementStateCount = 0;
    state = _elementStates[ 0 ];
    state.namespaceURI = null;
    state.localName = null;
    state.rawName = null;
    state.preserveSpace = _format.getPreserveSpace();
    state.empty = true;
    state.afterElement = false;
    state.afterComment = false;
    state.doCData = state.inCData = false;
    state.prefixes = null;

    _docTypePublicId = _format.getDoctypePublic();
    _docTypeSystemId = _format.getDoctypeSystem();
    _started = false;
    _prepared = true;
}
 
Example 16
Source File: BaseMarkupSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
protected void prepare()
    throws IOException
{
    if ( _prepared )
        return;

    if ( _writer == null && _output == null ) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
                                                       "NoWriterSupplied", null);
        throw new IOException(msg);
    }
    // If the output stream has been set, use it to construct
    // the writer. It is possible that the serializer has been
    // reused with the same output stream and different encoding.

    _encodingInfo = _format.getEncodingInfo();

    if ( _output != null ) {
        _writer = _encodingInfo.getWriter(_output);
    }

    if ( _format.getIndenting() ) {
        _indenting = true;
        _printer = new IndentPrinter( _writer, _format );
    } else {
        _indenting = false;
        _printer = new Printer( _writer, _format );
    }

    ElementState state;

    _elementStateCount = 0;
    state = _elementStates[ 0 ];
    state.namespaceURI = null;
    state.localName = null;
    state.rawName = null;
    state.preserveSpace = _format.getPreserveSpace();
    state.empty = true;
    state.afterElement = false;
    state.afterComment = false;
    state.doCData = state.inCData = false;
    state.prefixes = null;

    _docTypePublicId = _format.getDoctypePublic();
    _docTypeSystemId = _format.getDoctypeSystem();
    _started = false;
    _prepared = true;
}
 
Example 17
Source File: DOMParserImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a resource identified by an
 * <code>LSInput</code>.
 *
 */
public Document parse (LSInput is) throws LSException {

    // need to wrap the LSInput with an XMLInputSource
    XMLInputSource xmlInputSource = dom2xmlInputSource (is);
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (xmlInputSource);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e) {
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
               DOMErrorImpl error = new DOMErrorImpl ();
               error.fException = e;
               error.fMessage = e.getMessage ();
               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
               fErrorHandler.getErrorHandler().handleError (error);
            }
            if (DEBUG) {
               e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 18
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 19
Source File: DOMParserImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Parse an XML document from a resource identified by an
 * <code>LSInput</code>.
 *
 */
public Document parse (LSInput is) throws LSException {

    // need to wrap the LSInput with an XMLInputSource
    XMLInputSource xmlInputSource = dom2xmlInputSource (is);
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (xmlInputSource);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e) {
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
               DOMErrorImpl error = new DOMErrorImpl ();
               error.fException = e;
               error.fMessage = e.getMessage ();
               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
               fErrorHandler.getErrorHandler().handleError (error);
            }
            if (DEBUG) {
               e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}
 
Example 20
Source File: DOMParserImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document from a resource identified by an
 * <code>LSInput</code>.
 *
 */
public Document parse (LSInput is) throws LSException {

    // need to wrap the LSInput with an XMLInputSource
    XMLInputSource xmlInputSource = dom2xmlInputSource (is);
    if ( fBusy ) {
        String msg = DOMMessageFormatter.formatMessage (
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_STATE_ERR",null);
        throw new DOMException ( DOMException.INVALID_STATE_ERR,msg);
    }

    try {
        currentThread = Thread.currentThread();
                    fBusy = true;
        parse (xmlInputSource);
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            //reset interrupt state
            abortNow = false;
            Thread.interrupted();
        }
    } catch (Exception e) {
        fBusy = false;
        if (abortNow && currentThread.isInterrupted()) {
            Thread.interrupted();
        }
        if (abortNow) {
            abortNow = false;
            restoreHandlers();
            return null;
        }
        // Consume this exception if the user
        // issued an interrupt or an abort.
        if (e != Abort.INSTANCE) {
            if (!(e instanceof XMLParseException) && fErrorHandler != null) {
               DOMErrorImpl error = new DOMErrorImpl ();
               error.fException = e;
               error.fMessage = e.getMessage ();
               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
               fErrorHandler.getErrorHandler().handleError (error);
            }
            if (DEBUG) {
               e.printStackTrace ();
            }
            throw (LSException) DOMUtil.createLSException(LSException.PARSE_ERR, e).fillInStackTrace();
        }
    }
    Document doc = getDocument();
    dropDocumentReferences();
    return doc;
}