Java Code Examples for org.xml.sax.InputSource#getSystemId()

The following examples show how to use org.xml.sax.InputSource#getSystemId() . These examples are extracted from open source projects. 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
public void parse(InputSource input) throws IOException, SAXException {
    try {
        InputStream s = input.getByteStream();
        if (s == null) {
            String systemId = input.getSystemId();
            if (systemId == null) {
                throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource"));
            }
            parse(systemId);
        } else {
            parse(s);
        }
    } catch (FastInfosetException e) {
        logger.log(Level.FINE, "parsing error", e);
        throw new SAXException(e);
    }
}
 
Example 2
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 3
public void parse(
    InputSource source,
    ContentHandler contentHandler,
    ErrorHandler errorHandler,
    EntityResolver entityResolver )
    throws SAXException, IOException {

    String systemId = source.getSystemId();
    Document dom = forest.get(systemId);

    if(dom==null) {
        // if no DOM tree is built for it,
        // let the fall back parser parse the original document.
        //
        // for example, XSOM parses datatypes.xsd (XML Schema part 2)
        // but this will never be built into the forest.
        fallbackParser.parse( source, contentHandler, errorHandler, entityResolver );
        return;
    }

    scanner.scan( dom, contentHandler );
}
 
Example 4
Source Project: hottub   File: DTDParser.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse a DTD.
 */
public void parse(String uri)
        throws IOException, SAXException {
    InputSource in;

    init();
    // System.out.println ("parse (\"" + uri + "\")");
    in = resolver.resolveEntity(null, uri);

    // If custom resolver punts resolution to parser, handle it ...
    if (in == null) {
        in = Resolver.createInputSource(new java.net.URL(uri), false);

        // ... or if custom resolver doesn't correctly construct the
        // input entity, patch it up enough so relative URIs work, and
        // issue a warning to minimize later confusion.
    } else if (in.getSystemId() == null) {
        warning("P-065", null);
        in.setSystemId(uri);
    }

    parseInternal(in);
}
 
Example 5
/**
   Configure log4j by reading in a log4j.dtd compliant XML
   configuration file.

*/
protected
void doConfigure(final InputSource inputSource, LoggerRepository repository) 
                                        throws FactoryConfigurationError {
    if (inputSource.getSystemId() == null) {
        inputSource.setSystemId("dummy://log4j.dtd");
    }
    ParseAction action = new ParseAction() {
        public Document parse(final DocumentBuilder parser) throws SAXException, IOException {
            return parser.parse(inputSource);
        }
        public String toString() { 
            return "input source [" + inputSource.toString() + "]"; 
        }
    };
    doConfigure(action, repository);
  }
 
Example 6
/**
 * Creates an XMLInputSource from a SAX InputSource.
 */
private XMLInputSource createXMLInputSource(InputSource source, String baseURI) {

    String publicId = source.getPublicId();
    String systemId = source.getSystemId();
    String baseSystemId = baseURI;
    InputStream byteStream = source.getByteStream();
    Reader charStream = source.getCharacterStream();
    String encoding = source.getEncoding();
    XMLInputSource xmlInputSource =
        new XMLInputSource(publicId, systemId, baseSystemId);
    xmlInputSource.setByteStream(byteStream);
    xmlInputSource.setCharacterStream(charStream);
    xmlInputSource.setEncoding(encoding);
    return xmlInputSource;

}
 
Example 7
public void parse(InputSource input) throws IOException, SAXException {
    try {
        InputStream s = input.getByteStream();
        if (s == null) {
            String systemId = input.getSystemId();
            if (systemId == null) {
                throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource"));
            }
            parse(systemId);
        } else {
            parse(s);
        }
    } catch (FastInfosetException e) {
        logger.log(Level.FINE, "parsing error", e);
        throw new SAXException(e);
    }
}
 
Example 8
public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver)

            throws SAXException, IOException {
        String systemId = source.getSystemId();
        Document dom = forest.get(systemId);

        if (dom == null) {
            // if no DOM tree is built for it,
            // let the fall back parser parse the original document.
            //
            // for example, XSOM parses datatypes.xsd (XML Schema part 2)
            // but this will never be built into the forest.
            fallbackParser.parse(source, handler, errorHandler, entityResolver);
            return;
        }

        scanner.scan(dom, handler);

    }
 
Example 9
/**
 * Parse a DTD.
 */
public void parse(String uri)
        throws IOException, SAXException {
    InputSource in;

    init();
    // System.out.println ("parse (\"" + uri + "\")");
    in = resolver.resolveEntity(null, uri);

    // If custom resolver punts resolution to parser, handle it ...
    if (in == null) {
        in = Resolver.createInputSource(new java.net.URL(uri), false);

        // ... or if custom resolver doesn't correctly construct the
        // input entity, patch it up enough so relative URIs work, and
        // issue a warning to minimize later confusion.
    } else if (in.getSystemId() == null) {
        warning("P-065", null);
        in.setSystemId(uri);
    }

    parseInternal(in);
}
 
Example 10
Source Project: netbeans   File: Util.java    License: Apache License 2.0 5 votes vote down vote up
public static FileObject toFileObject(InputSource src) {
   try {
       String sysId = src.getSystemId();
       return FileUtil.toFileObject(new File(new URI(sysId)));
   } catch (URISyntaxException ex) {
       LOG.log(Level.WARNING, "File URI malformed", ex);
       return null;
   }
}
 
Example 11
public SAXInputSource(XMLReader reader, InputSource inputSource) {
    super(inputSource != null ? inputSource.getPublicId() : null,
            inputSource != null ? inputSource.getSystemId() : null, null);
    if (inputSource != null) {
        setByteStream(inputSource.getByteStream());
        setCharacterStream(inputSource.getCharacterStream());
        setEncoding(inputSource.getEncoding());
    }
    fInputSource = inputSource;
    fXMLReader = reader;
}
 
Example 12
public static void setSystemId(InputSource inputSource, URL contextUrl, String input) {
	if (inputSource.getSystemId() == null) {
		String systemId = XmlUtils.getSystemId(contextUrl, input);
		if (systemId != null) {
			inputSource.setSystemId(systemId);
		}
	}
}
 
Example 13
private boolean parseSomeSetup(InputSource source)
        throws SAXException, IOException, IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.InstantiationException
{
        if(fConfigSetInput!=null)
        {
                // Obtain input from SAX inputSource object, construct XNI version of
                // that object. Logic adapted from Xerces2.
                Object[] parms1={source.getPublicId(),source.getSystemId(),null};
                Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
                Object[] parmsa={source.getByteStream()};
                fConfigSetByteStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getCharacterStream();
                fConfigSetCharStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getEncoding();
                fConfigSetEncoding.invoke(xmlsource,parmsa);

                // Bugzilla5272 patch suggested by Sandy Gao.
                // Has to be reflection to run with Xerces2
                // after compilation against Xerces1. or vice
                // versa, due to return type mismatches.
                Object[] noparms=new Object[0];
                fReset.invoke(fIncrementalParser,noparms);

                parmsa[0]=xmlsource;
                fConfigSetInput.invoke(fPullParserConfig,parmsa);

                // %REVIEW% Do first pull. Should we instead just return true?
                return parseSome();
        }
        else
        {
                Object[] parm={source};
                Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
                return ((Boolean)ret).booleanValue();
        }
}
 
Example 14
/**
 * Loads a configuration file from the specified input source.
 *
 * @param source the input source
 * @throws ConfigurationException if an error occurs
 */
private void load(final InputSource source) throws ConfigurationException
{
    if (locator == null)
    {
        throw new ConfigurationException("Load operation not properly "
                + "initialized! Do not call read(InputStream) directly,"
                + " but use a FileHandler to load a configuration.");
    }

    try
    {
        final URL sourceURL = locator.getSourceURL();
        if (sourceURL != null)
        {
            source.setSystemId(sourceURL.toString());
        }

        final DocumentBuilder builder = createDocumentBuilder();
        final Document newDocument = builder.parse(source);
        final Document oldDocument = getDocument();
        initProperties(XMLDocumentHelper.forSourceDocument(newDocument),
                oldDocument == null);
    }
    catch (final SAXParseException spe)
    {
        throw new ConfigurationException("Error parsing " + source.getSystemId(), spe);
    }
    catch (final Exception e)
    {
        this.getLogger().debug("Unable to load the configuration: " + e);
        throw new ConfigurationException("Unable to load the configuration", e);
    }
}
 
Example 15
Source Project: cxf   File: AbstractWrapperWSDLLocator.java    License: Apache License 2.0 5 votes vote down vote up
public InputSource getBaseInputSource() {
    InputSource is = parent.getBaseInputSource();
    fromParent = true;
    if (is == null) {
        is = getInputSource();
        fromParent = false;
    } else {
        baseUri = is.getSystemId();
    }
    last = is;

    return is;
}
 
Example 16
/**
 * Constructs an input source from a SAX InputSource
 * object.
 *
 * @param inputSource  a SAX InputSource
 * @param isCreatedByResolver a flag to indicate whether the source is
 * created by a resolver
 */
public XMLInputSource(InputSource inputSource, boolean isCreatedByResolver) {
    fPublicId = inputSource.getPublicId();
    fSystemId = inputSource.getSystemId();
    fByteStream = inputSource.getByteStream();
    fCharStream = inputSource.getCharacterStream();
    fEncoding = inputSource.getEncoding();
    fIsCreatedByResolver = isCreatedByResolver;
}
 
Example 17
public SAXInputSource(XMLReader reader, InputSource inputSource) {
    super(inputSource != null ? inputSource.getPublicId() : null,
            inputSource != null ? inputSource.getSystemId() : null, null);
    if (inputSource != null) {
        setByteStream(inputSource.getByteStream());
        setCharacterStream(inputSource.getCharacterStream());
        setEncoding(inputSource.getEncoding());
    }
    fInputSource = inputSource;
    fXMLReader = reader;
}
 
Example 18
private boolean parseSomeSetup(InputSource source)
        throws SAXException, IOException, IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.InstantiationException
{
        if(fConfigSetInput!=null)
        {
                // Obtain input from SAX inputSource object, construct XNI version of
                // that object. Logic adapted from Xerces2.
                Object[] parms1={source.getPublicId(),source.getSystemId(),null};
                Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
                Object[] parmsa={source.getByteStream()};
                fConfigSetByteStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getCharacterStream();
                fConfigSetCharStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getEncoding();
                fConfigSetEncoding.invoke(xmlsource,parmsa);

                // Bugzilla5272 patch suggested by Sandy Gao.
                // Has to be reflection to run with Xerces2
                // after compilation against Xerces1. or vice
                // versa, due to return type mismatches.
                Object[] noparms=new Object[0];
                fReset.invoke(fIncrementalParser,noparms);

                parmsa[0]=xmlsource;
                fConfigSetInput.invoke(fPullParserConfig,parmsa);

                // %REVIEW% Do first pull. Should we instead just return true?
                return parseSome();
        }
        else
        {
                Object[] parm={source};
                Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
                return ((Boolean)ret).booleanValue();
        }
}
 
Example 19
private boolean parseSomeSetup(InputSource source)
        throws SAXException, IOException, IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException,
                                 java.lang.InstantiationException
{
        if(fConfigSetInput!=null)
        {
                // Obtain input from SAX inputSource object, construct XNI version of
                // that object. Logic adapted from Xerces2.
                Object[] parms1={source.getPublicId(),source.getSystemId(),null};
                Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
                Object[] parmsa={source.getByteStream()};
                fConfigSetByteStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getCharacterStream();
                fConfigSetCharStream.invoke(xmlsource,parmsa);
                parmsa[0]=source.getEncoding();
                fConfigSetEncoding.invoke(xmlsource,parmsa);

                // Bugzilla5272 patch suggested by Sandy Gao.
                // Has to be reflection to run with Xerces2
                // after compilation against Xerces1. or vice
                // versa, due to return type mismatches.
                Object[] noparms=new Object[0];
                fReset.invoke(fIncrementalParser,noparms);

                parmsa[0]=xmlsource;
                fConfigSetInput.invoke(fPullParserConfig,parmsa);

                // %REVIEW% Do first pull. Should we instead just return true?
                return parseSome();
        }
        else
        {
                Object[] parm={source};
                Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
                return ((Boolean)ret).booleanValue();
        }
}
 
Example 20
private InputSource resolvedEntity(InputSource entity) {
    String msg = "Resolved to: " + entity.getSystemId() + ".";
    LOGGER.debug(msg);
    return entity;
}