Search in sources :

Example 6 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)

Example 7 with XMLInputSource

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

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)

Example 8 with XMLInputSource

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

the class XmlResourceResolver method resolveEntity.

@Override
@Nullable
public XMLInputSource resolveEntity(XMLResourceIdentifier xmlResourceIdentifier) throws XNIException, IOException {
    String publicId = xmlResourceIdentifier.getLiteralSystemId() != null ? xmlResourceIdentifier.getLiteralSystemId() : xmlResourceIdentifier.getNamespace();
    if (publicId != null) {
        try {
            String userDir = new File(System.getProperty("user.dir")).toURI().getPath();
            String publicIdPath = new URI(publicId).getPath();
            if (publicIdPath.startsWith(userDir)) {
                publicId = publicIdPath.substring(publicIdPath.indexOf(userDir) + userDir.length());
            }
        } catch (Exception e) {
        }
    }
    PsiFile psiFile = resolve(xmlResourceIdentifier.getBaseSystemId(), publicId);
    if (psiFile == null && xmlResourceIdentifier.getBaseSystemId() != null) {
        psiFile = ExternalResourceManager.getInstance().getResourceLocation(xmlResourceIdentifier.getBaseSystemId(), myFile, null);
    }
    if (psiFile == null && xmlResourceIdentifier.getLiteralSystemId() != null && xmlResourceIdentifier.getNamespace() != null) {
        psiFile = resolve(xmlResourceIdentifier.getBaseSystemId(), publicId = xmlResourceIdentifier.getNamespace());
    }
    if (psiFile == null) {
        if (publicId != null && publicId.contains(":/")) {
            try {
                myErrorReporter.processError(new SAXParseException(XmlErrorMessages.message("xml.validate.external.resource.is.not.registered", publicId), publicId, null, 0, 0), ValidateXmlActionHandler.ProblemType.ERROR);
            } catch (SAXException ignore) {
            }
            final XMLInputSource source = new XMLInputSource(xmlResourceIdentifier);
            source.setPublicId(publicId);
            source.setCharacterStream(new StringReader(""));
            return source;
        }
        return null;
    }
    XMLInputSource source = new XMLInputSource(xmlResourceIdentifier);
    if (xmlResourceIdentifier.getLiteralSystemId() == null) {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
            final String url = VfsUtilCore.fixIDEAUrl(virtualFile.getUrl());
            source.setBaseSystemId(url);
            source.setSystemId(url);
        }
    }
    source.setPublicId(publicId);
    source.setCharacterStream(new StringReader(psiFile.getText()));
    return source;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) SAXParseException(org.xml.sax.SAXParseException) StringReader(java.io.StringReader) PsiFile(com.intellij.psi.PsiFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) URI(java.net.URI) XNIException(org.apache.xerces.xni.XNIException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) Nullable(org.jetbrains.annotations.Nullable)

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