Search in sources :

Example 71 with InputSource

use of org.xml.sax.InputSource in project XobotOS by xamarin.

the class SAXParser method parse.

/**
     * Parse the content of the file specified as XML using the
     * specified {@link org.xml.sax.HandlerBase}.
     * <i> Use of the DefaultHandler version of this method is recommended as
     * the HandlerBase class has been deprecated in SAX 2.0</i>
     *
     * @param f The file containing the XML to parse
     * @param hb The SAX HandlerBase to use.
     *
     * @throws IllegalArgumentException If the File object is null.
     * @throws IOException If any IO errors occur.
     * @throws SAXException If any SAX errors occur during processing.
     *
     * @see org.xml.sax.DocumentHandler
     */
public void parse(File f, HandlerBase hb) throws SAXException, IOException {
    if (f == null) {
        throw new IllegalArgumentException("File cannot be null");
    }
    String escapedURI = FilePathToURI.filepath2URI(f.getAbsolutePath());
    if (DEBUG) {
        System.out.println("Escaped URI = " + escapedURI);
    }
    InputSource input = new InputSource(escapedURI);
    this.parse(input, hb);
}
Also used : InputSource(org.xml.sax.InputSource)

Example 72 with InputSource

use of org.xml.sax.InputSource in project XobotOS by xamarin.

the class SAXParser method parse.

/**
     * 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);
}
Also used : InputSource(org.xml.sax.InputSource)

Example 73 with InputSource

use of org.xml.sax.InputSource in project translationstudio8 by heartsome.

the class MessageParser method htmlToText.

/**
	 * 将 html 格式的文本过滤掉标签.
	 * @param html
	 *            html 格式的字符串
	 * @return String
	 * 			  过滤掉 html 标签后的文本。如果 html 为空,返回空串""
	 */
private String htmlToText(String html) {
    if (html == null) {
        return "";
    }
    DOMFragmentParser parser = new DOMFragmentParser();
    CoreDocumentImpl codeDoc = new CoreDocumentImpl();
    InputSource inSource = new InputSource(new ByteArrayInputStream(html.getBytes()));
    inSource.setEncoding(textCharset);
    DocumentFragment doc = codeDoc.createDocumentFragment();
    try {
        parser.parse(inSource, doc);
    } catch (Exception e) {
        return "";
    }
    textBuffer = new StringBuffer();
    processNode(doc);
    return textBuffer.toString();
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) CoreDocumentImpl(org.apache.xerces.dom.CoreDocumentImpl) DOMFragmentParser(org.cyberneko.html.parsers.DOMFragmentParser) DocumentFragment(org.w3c.dom.DocumentFragment) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 74 with InputSource

use of org.xml.sax.InputSource in project translationstudio8 by heartsome.

the class Xlsx2TmxHelper method parse.

public void parse(InputStream sheetInputStream, ReadOnlySharedStringsTable sharedStringsTable, AbstractWriter tmxWriter) throws ParserConfigurationException, SAXException, IOException {
    InputSource sheetSource = new InputSource(sheetInputStream);
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxFactory.newSAXParser();
    XMLReader sheetParser = saxParser.getXMLReader();
    ContentHandler handler = new XSSFHander(sharedStringsTable);
    sheetParser.setContentHandler(handler);
    sheetParser.parse(sheetSource);
    if (langCodes.isEmpty()) {
        throw new SAXException("EMPTY-LANG-CODE");
    }
    writeEnd();
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 75 with InputSource

use of org.xml.sax.InputSource in project hibernate-orm by hibernate.

the class DTDEntityResolver method resolveOnClassPath.

private InputSource resolveOnClassPath(String publicId, String systemId, String namespace) {
    InputSource source = null;
    String path = "org/hibernate/" + systemId.substring(namespace.length());
    InputStream dtdStream = resolveInHibernateNamespace(path);
    if (dtdStream == null) {
        LOG.debugf("Unable to locate [%s] on classpath", systemId);
        if (systemId.substring(namespace.length()).indexOf("2.0") > -1) {
            LOG.usingOldDtd();
        }
    } else {
        LOG.debugf("Located [%s] in classpath", systemId);
        source = new InputSource(dtdStream);
        source.setPublicId(publicId);
        source.setSystemId(systemId);
    }
    return source;
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream)

Aggregations

InputSource (org.xml.sax.InputSource)1124 StringReader (java.io.StringReader)401 IOException (java.io.IOException)304 Document (org.w3c.dom.Document)282 SAXException (org.xml.sax.SAXException)281 DocumentBuilder (javax.xml.parsers.DocumentBuilder)262 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)213 XMLReader (org.xml.sax.XMLReader)194 Test (org.junit.Test)160 InputStream (java.io.InputStream)158 NodeList (org.w3c.dom.NodeList)145 Element (org.w3c.dom.Element)144 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)143 ByteArrayInputStream (java.io.ByteArrayInputStream)103 SAXParser (javax.xml.parsers.SAXParser)103 SAXSource (javax.xml.transform.sax.SAXSource)95 SAXParserFactory (javax.xml.parsers.SAXParserFactory)90 File (java.io.File)82 Node (org.w3c.dom.Node)82 URL (java.net.URL)65