Java Code Examples for org.xml.sax.InputSource.setSystemId()

The following are Jave code examples for showing how to use setSystemId() of the org.xml.sax.InputSource class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: Arch.java   Source Code and License Vote up 6 votes
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    log("publicId: " + publicId + " systemId: " + systemId, Project.MSG_VERBOSE);
    
    int idx = systemId.lastIndexOf('/');
    String last = systemId.substring(idx + 1);
    
    if (localDTDs.contains(last)) {
        log("Resolved to embedded DTD");
        InputSource is = new InputSource(Arch.class.getResourceAsStream(last));
        is.setSystemId(systemId);
        return is;
    } else {
        log("Not resolved");
        return null;
    }
}
 
Example 2
Project: openjdk-jdk10   File: DTDParser.java   Source Code and License Vote up 6 votes
/**
 * Parse a DTD.
 */
public void parse(String uri)
        throws IOException, SAXException {
    InputSource inSource;

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

    // If custom resolver punts resolution to parser, handle it ...
    if (inSource == null) {
        inSource = 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 (inSource.getSystemId() == null) {
        warning("P-065", null);
        inSource.setSystemId(uri);
    }

    parseInternal(inSource);
}
 
Example 3
Project: openjdk-jdk10   File: TypeInfoTest.java   Source Code and License Vote up 6 votes
private Element getRoot(String schemaText, String docText) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    InputSource inSchema = new InputSource(new StringReader(schemaText));
    inSchema.setSystemId("schema.xsd");
    dbf.setNamespaceAware(true);
    dbf.setValidating(true);
    dbf.setAttribute(SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    dbf.setAttribute(SCHEMA_SOURCE, inSchema);

    DocumentBuilder parser = dbf.newDocumentBuilder();

    InputSource inSource = new InputSource(new StringReader(docText));
    inSource.setSystemId("doc.xml");
    Document document = parser.parse(inSource);

    return document.getDocumentElement();
}
 
Example 4
Project: asura   File: XMLSchedulingDataProcessor.java   Source Code and License Vote up 6 votes
/**
 * Process the xmlfile named <code>fileName</code> with the given system
 * ID.
 * 
 * @param stream
 *          an input stream containing the xml content.
 * @param systemId
 *          system ID.
 */
public void processStreamAndScheduleJobs(InputStream stream, String systemId, Scheduler sched)
    throws ValidationException, ParserConfigurationException,
        SAXException, XPathException, IOException, SchedulerException,
        ClassNotFoundException, ParseException {

    prepForProcessing();

    log.info("Parsing XML from stream with systemId: " + systemId);

    InputSource is = new InputSource(stream);
    is.setSystemId(systemId);

    process(is);
    executePreProcessCommands(sched);
    scheduleJobs(sched);

    maybeThrowValidationException();
}
 
Example 5
Project: OpenJSharp   File: DTDParser.java   Source Code and License Vote up 6 votes
/**
 * 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 6
Project: lams   File: HyphenationCompoundWordTokenFilterFactory.java   Source Code and License Vote up 6 votes
@Override
public void inform(ResourceLoader loader) throws IOException {
  InputStream stream = null;
  try {
    if (dictFile != null) // the dictionary can be empty.
      dictionary = getWordSet(loader, dictFile, false);
    // TODO: Broken, because we cannot resolve real system id
    // ResourceLoader should also supply method like ClassLoader to get resource URL
    stream = loader.openResource(hypFile);
    final InputSource is = new InputSource(stream);
    is.setEncoding(encoding); // if it's null let xml parser decide
    is.setSystemId(hypFile);
    if (luceneMatchVersion.onOrAfter(Version.LUCENE_4_4_0)) {
      hyphenator = HyphenationCompoundWordTokenFilter.getHyphenationTree(is);
    } else {
      hyphenator = Lucene43HyphenationCompoundWordTokenFilter.getHyphenationTree(is);
    }
  } finally {
    IOUtils.closeWhileHandlingException(stream);
  }
}
 
Example 7
Project: openjdk-jdk10   File: Bug6889654Test.java   Source Code and License Vote up 6 votes
void parse() throws SAXException {
    String xml = "<data>\n<broken/>\u0000</data>";

    try {
        InputSource is = new InputSource(new StringReader(xml));
        is.setSystemId("file:///path/to/some.xml");
        // notice that exception thrown here doesn't include the line number
        // information when reported by JVM -- CR6889654
        SAXParserFactory.newInstance().newSAXParser().parse(is, new DefaultHandler());
    } catch (SAXException e) {
        // notice that this message isn't getting displayed -- CR6889649
        throw new SAXException(MSG, e);
    } catch (ParserConfigurationException pce) {

    } catch (IOException ioe) {

    }

}
 
Example 8
Project: sponge   File: DefaultConfigurationManager.java   Source Code and License Vote up 6 votes
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException {
    if (ConfigurationConstants.CONFIG_SCHEMA.equals(systemId)) {
        InputStream stream = ConfigurationManager.class.getResourceAsStream(ConfigurationConstants.CONFIG_SCHEMA_LOCATION);
        if (stream != null) {
            InputSource source = new InputSource(stream);
            source.setPublicId(publicId);
            source.setSystemId(systemId);

            return source;
        } else {
            throw new SAXException("Cannot find schema " + ConfigurationConstants.CONFIG_SCHEMA);
        }
    }

    return super.resolveEntity(publicId, systemId);
}
 
Example 9
Project: openjdk-jdk10   File: XSLTC.java   Source Code and License Vote up 5 votes
/**
 * Compiles an XSL stylesheet pointed to by a URL
 * @param url An URL containing the input XSL stylesheet
 * @param name The name to assign to the translet class
 */
public boolean compile(URL url, String name) {
    try {
        // Open input stream from URL and wrap inside InputSource
        final InputStream stream = url.openStream();
        final InputSource input = new InputSource(stream);
        input.setSystemId(url.toString());
        return compile(input, name);
    }
    catch (IOException e) {
        _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
        return false;
    }
}
 
Example 10
Project: incubator-netbeans   File: FileEntityResolver.java   Source Code and License Vote up 5 votes
/** Tries to find the entity on system file system.
 */
public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
    if (publicID == null) {
        return null;
    }


    String id = convertPublicId (publicID);
    
    StringBuffer sb = new StringBuffer (200);
    sb.append (ENTITY_PREFIX);
    sb.append (id);
    
    FileObject fo = FileUtil.getConfigFile (sb.toString ());
    if (fo != null) {
        
        // fill in InputSource instance
        
        InputSource in = new InputSource (fo.getInputStream ());
        try {
            Object myPublicID = fo.getAttribute("hint.originalPublicID");  //NOI18N
            if (myPublicID instanceof String) {
                in.setPublicId((String)myPublicID);
            }                
            URL url = fo.getURL();
            in.setSystemId(url.toString());  // we get nasty nbfs: instead nbres: but it is enough                
        } catch (IOException ex) {
            // do no care just no system id
        }
        return in;
    } else {
        return null;
    }
}
 
Example 11
Project: openjdk-jdk10   File: XSLTC.java   Source Code and License Vote up 5 votes
/**
 * Compiles an XSL stylesheet pointed to by a URL
 * @param url An URL containing the input XSL stylesheet
 */
public boolean compile(URL url) {
    try {
        // Open input stream from URL and wrap inside InputSource
        final InputStream stream = url.openStream();
        final InputSource input = new InputSource(stream);
        input.setSystemId(url.toString());
        return compile(input, _className);
    }
    catch (IOException e) {
        _parser.reportError(Constants.FATAL, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
        return false;
    }
}
 
Example 12
Project: openjdk-jdk10   File: SAXFilterFactoryImpl.java   Source Code and License Vote up 5 votes
public InputSource resolveEntity(String publicid, String sysId) {
    if (sysId.equals("http://astro.com/stylesheets/toptemplate")) {
        InputSource retval = new InputSource(TOPTEMPLXSL);
        retval.setSystemId(filenameToURL(TOPTEMPLXSL));
        return retval;
    } else {
        return null; // use default behavior
    }
}
 
Example 13
Project: openjdk-jdk10   File: AbstractUnmarshallerImpl.java   Source Code and License Vote up 5 votes
private static InputSource streamSourceToInputSource( StreamSource ss ) {
    InputSource is = new InputSource();
    is.setSystemId( ss.getSystemId() );
    is.setByteStream( ss.getInputStream() );
    is.setCharacterStream( ss.getReader() );

    return is;
}
 
Example 14
Project: openjdk-jdk10   File: ValidatorHandlerImpl.java   Source Code and License Vote up 5 votes
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
Example 15
Project: apache-tomcat-7.0.73-with-comment   File: Digester.java   Source Code and License Vote up 5 votes
/**
 * Parse the content of the specified file using this Digester.  Returns
 * the root element from the object stack (if any).
 *
 * @param file File containing the XML data to be parsed
 *
 * @exception IOException if an input/output error occurs
 * @exception SAXException if a parsing exception occurs
 */
public Object parse(File file) throws IOException, SAXException {

    configure();
    InputSource input = new InputSource(new FileInputStream(file));
    input.setSystemId("file://" + file.getAbsolutePath());
    getXMLReader().parse(input);
    return (root);

}
 
Example 16
Project: openjdk-jdk10   File: URIResolverTest.java   Source Code and License Vote up 5 votes
/**
 * This is to test the URIResolver.resolve() method when a transformer is
 * created using SAXSource. style-sheet file has xsl:import in it.
 *
 * @throws Exception If any errors occur.
 */
@Test
public static void resolver06() throws Exception {
    try (FileInputStream fis = new FileInputStream(XSL_IMPORT_FILE)){
        URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
        TransformerFactory tfactory = TransformerFactory.newInstance();
        tfactory.setURIResolver(resolver);
        InputSource is = new InputSource(fis);
        is.setSystemId(SYSTEM_ID);
        SAXSource saxSource = new SAXSource(is);
        assertNotNull(tfactory.newTransformer(saxSource));
    }
}
 
Example 17
Project: openjdk-jdk10   File: XmlUtil.java   Source Code and License Vote up 5 votes
private static InputSource toInputSource(StreamSource src) {
    InputSource is = new InputSource();
    is.setByteStream(src.getInputStream());
    is.setCharacterStream(src.getReader());
    is.setPublicId(src.getPublicId());
    is.setSystemId(src.getSystemId());
    return is;
}
 
Example 18
Project: openjdk-jdk10   File: WsimportOptions.java   Source Code and License Vote up 5 votes
private InputSource absolutize(InputSource is) {
    // absolutize all the system IDs in the input,
    // so that we can map system IDs to DOM trees.
    try {
        URL baseURL = new File(".").getCanonicalFile().toURL();
        is.setSystemId(new URL(baseURL, is.getSystemId()).toExternalForm());
    } catch (IOException e) {
        // ignore
    }
    return is;
}
 
Example 19
Project: openjdk-jdk10   File: SAXParser.java   Source Code and License Vote up 3 votes
/**
 * Parse the content of the given {@link java.io.InputStream}
 * instance as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is InputStream containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 * @param systemId The systemId which is needed for resolving relative URIs.
 *
 * @throws IllegalArgumentException If the given InputStream is null.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler version of this method instead.
 */
public void parse(
    InputStream is,
    DefaultHandler dh,
    String systemId)
    throws SAXException, IOException {
    if (is == null) {
        throw new IllegalArgumentException("InputStream cannot be null");
    }

    InputSource input = new InputSource(is);
    input.setSystemId(systemId);
    this.parse(input, dh);
}
 
Example 20
Project: OpenJSharp   File: XSLTC.java   Source Code and License Vote up 2 votes
/**
 * Compiles an XSL stylesheet passed in through an InputStream
 * @param stream An InputStream that will pass in the stylesheet contents
 * @param name The name of the translet class to generate
 * @return 'true' if the compilation was successful
 */
public boolean compile(InputStream stream, String name) {
    final InputSource input = new InputSource(stream);
    input.setSystemId(name); // We have nothing else!!!
    return compile(input, name);
}