Search in sources :

Example 1 with XMLInputSource

use of org.apache.xerces.xni.parser.XMLInputSource in project zm-mailbox by Zimbra.

the class HtmlDefang method defang.

public void defang(Reader htmlReader, boolean neuterImages, Writer out) throws IOException {
    XMLInputSource source = new XMLInputSource(null, null, null, htmlReader, null);
    defang(source, neuterImages, out);
}
Also used : XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource)

Example 2 with XMLInputSource

use of org.apache.xerces.xni.parser.XMLInputSource in project zm-mailbox by Zimbra.

the class HtmlDefang method defang.

public void defang(InputStream html, boolean neuterImages, Writer out) throws IOException {
    XMLInputSource source = new XMLInputSource(null, null, null, html, null);
    defang(source, neuterImages, out);
}
Also used : XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource)

Example 3 with XMLInputSource

use of org.apache.xerces.xni.parser.XMLInputSource in project zm-mailbox by Zimbra.

the class HtmlDetag method detag.

public String detag(String html) {
    StringWriter out = new StringWriter();
    UnescapeWriter writer = new UnescapeWriter(out, "utf-8");
    XMLDocumentFilter[] filters = { this, writer };
    XMLParserConfiguration parser = new HTMLConfiguration();
    parser.setProperty("http://cyberneko.org/html/properties/filters", filters);
    parser.setProperty("http://cyberneko.org/html/properties/names/elems", "match");
    parser.setFeature("http://cyberneko.org/html/features/balance-tags", false);
    parser.setFeature("http://xml.org/sax/features/namespaces", false);
    XMLInputSource source = new XMLInputSource(null, null, null, new StringReader(html), null);
    try {
        parser.parse(source);
    } catch (Exception x) {
        ZimbraLog.misc.warn("Can't detag HTML [" + html + "]");
    }
    //return whatever has been done
    return out.toString();
}
Also used : StringWriter(java.io.StringWriter) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) HTMLConfiguration(org.cyberneko.html.HTMLConfiguration) StringReader(java.io.StringReader) XMLDocumentFilter(org.apache.xerces.xni.parser.XMLDocumentFilter) XMLParserConfiguration(org.apache.xerces.xni.parser.XMLParserConfiguration) IOException(java.io.IOException) XNIException(org.apache.xerces.xni.XNIException)

Example 4 with XMLInputSource

use of org.apache.xerces.xni.parser.XMLInputSource in project intellij-community by JetBrains.

the class ModelGen method loadModel.

public void loadModel(final File... modelRoots) throws Exception {
    XMLEntityResolver resolver = new XMLEntityResolver() {

        public XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException, IOException {
            String esid = xmlResourceIdentifier.getExpandedSystemId();
            if (esid == null) {
                final String location = schemaLocationMap.get(xmlResourceIdentifier.getNamespace());
                if (location != null) {
                    esid = location;
                } else {
                    return null;
                }
            }
            // Util.log("resolving "+esid);
            File f = null;
            for (File root : modelRoots) {
                if (root == null)
                    continue;
                if (root.isDirectory()) {
                    final String fileName = esid.substring(esid.lastIndexOf('/') + 1);
                    f = new File(root, fileName);
                } else {
                    f = root;
                }
            }
            if (f == null || !f.exists()) {
                Util.logerr("unable to resolve: " + esid);
                return null;
            }
            esid = f.getPath();
            return new XMLInputSource(null, esid, null);
        }
    };
    ArrayList<File> files = new ArrayList<>();
    for (File root : modelRoots) {
        ContainerUtil.addAll(files, root.listFiles());
    }
    loader.loadModel(model, files, resolver);
    Util.log(model.jtMap.size() + " java types loaded");
}
Also used : XMLResourceIdentifier(org.apache.xerces.xni.XMLResourceIdentifier) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) ArrayList(java.util.ArrayList) XMLEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver) File(java.io.File)

Example 5 with XMLInputSource

use of org.apache.xerces.xni.parser.XMLInputSource in project gocd by gocd.

the class XmlReader method setInput.

private void setInput(ThreadContext context, InputStream in, IRubyObject url, Options options) {
    this.setState(XML_TEXTREADER_MODE_READING);
    config = this.createReader(context.getRuntime(), options);
    InputSource inputSource = new InputSource();
    ParserContext.setUrl(context, inputSource, url);
    XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null, in, null);
    try {
        config.setInputSource(xmlInputSource);
    } catch (IOException e) {
        throw context.getRuntime().newRuntimeError(e.getMessage());
    }
    this.setState(XML_TEXTREADER_MODE_CLOSED);
}
Also used : InputSource(org.xml.sax.InputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) IOException(java.io.IOException)

Aggregations

XMLInputSource (org.apache.xerces.xni.parser.XMLInputSource)8 IOException (java.io.IOException)4 File (java.io.File)2 StringReader (java.io.StringReader)2 XNIException (org.apache.xerces.xni.XNIException)2 XMLDocumentFilter (org.apache.xerces.xni.parser.XMLDocumentFilter)2 XMLParserConfiguration (org.apache.xerces.xni.parser.XMLParserConfiguration)2 InputSource (org.xml.sax.InputSource)2 HTMLConfiguration (com.googlecode.html.HTMLConfiguration)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 XMLResourceIdentifier (org.apache.xerces.xni.XMLResourceIdentifier)1 XMLEntityResolver (org.apache.xerces.xni.parser.XMLEntityResolver)1