Example usage for org.xml.sax InputSource setSystemId

List of usage examples for org.xml.sax InputSource setSystemId

Introduction

In this page you can find the example usage for org.xml.sax InputSource setSystemId.

Prototype

public void setSystemId(String systemId) 

Source Link

Document

Set the system identifier for this input source.

Usage

From source file:org.apache.servicemix.http.endpoints.HttpSoapConsumerEndpoint.java

protected void validateWsdl1(HttpSoapConsumerMarshaler marshaler) throws Exception {
    InputStream is = wsdl.getInputStream();
    try {/*from  ww  w  .ja  v a 2 s.c  om*/
        InputSource inputSource = new InputSource(is);
        inputSource.setSystemId(wsdl.getURL().toString());
        Definition def = WSDLUtils.createWSDL11Reader().readWSDL(wsdl.getURL().toString(), inputSource);
        if (validateWsdl) {
            WSIBPValidator validator = new WSIBPValidator(def);
            if (!validator.isValid()) {
                throw new DeploymentException("WSDL is not WS-I BP compliant: " + validator.getErrors());
            }
        }
        Service svc;
        if (getService() != null) {
            svc = def.getService(getService());
            if (svc == null) {
                throw new DeploymentException("Could not find service '" + getService() + "' in wsdl");
            }
        } else if (def.getServices().size() == 1) {
            svc = (Service) def.getServices().values().iterator().next();
            setService(svc.getQName());
        } else {
            throw new DeploymentException(
                    "If service is not set, the WSDL must contain a single service definition");
        }
        Port port;
        if (getEndpoint() != null) {
            port = svc.getPort(getEndpoint());
            if (port == null) {
                throw new DeploymentException("Cound not find port '" + getEndpoint()
                        + "' in wsdl for service '" + getService() + "'");
            }
        } else if (svc.getPorts().size() == 1) {
            port = (Port) svc.getPorts().values().iterator().next();
            setEndpoint(port.getName());
        } else {
            throw new DeploymentException("If endpoint is not set, the WSDL service '" + getService()
                    + "' must contain a single port definition");
        }
        SOAPAddress soapAddress = WSDLUtils.getExtension(port, SOAPAddress.class);
        if (soapAddress != null) {
            soapAddress.setLocationURI(getLocationURI());
        } else {
            SOAP12Address soap12Address = WSDLUtils.getExtension(port, SOAP12Address.class);
            if (soap12Address != null) {
                soap12Address.setLocationURI(getLocationURI());
            }
        }
        description = WSDLUtils.getWSDL11Factory().newWSDLWriter().getDocument(def);
        marshaler.setBinding(BindingFactory.createBinding(port));
    } finally {
        is.close();
    }
}

From source file:org.apache.servicemix.http.endpoints.HttpSoapProviderEndpoint.java

protected void validateWsdl1(HttpSoapProviderMarshaler marshaler) throws Exception {
    InputStream is = wsdl.getInputStream();
    try {//from www . jav  a  2 s .co m
        InputSource inputSource = new InputSource(is);
        inputSource.setSystemId(wsdl.getURL().toString());
        Definition def = WSDLUtils.createWSDL11Reader().readWSDL(wsdl.getURL().toString(), inputSource);
        if (validateWsdl) {
            WSIBPValidator validator = new WSIBPValidator(def);
            if (!validator.isValid()) {
                throw new DeploymentException("WSDL is not WS-I BP compliant: " + validator.getErrors());
            }
        }
        Service svc;
        if (getService() != null) {
            svc = def.getService(getService());
            if (svc == null) {
                throw new DeploymentException("Could not find service '" + getService() + "' in wsdl");
            }
        } else if (def.getServices().size() == 1) {
            svc = (Service) def.getServices().values().iterator().next();
            setService(svc.getQName());
        } else {
            throw new DeploymentException(
                    "If service is not set, the WSDL must contain a single service definition");
        }
        Port port;
        if (getEndpoint() != null) {
            port = svc.getPort(getEndpoint());
            if (port == null) {
                throw new DeploymentException("Cound not find port '" + getEndpoint() + "' "
                        + "in wsdl for service '" + getService() + "'");
            }
        } else if (svc.getPorts().size() == 1) {
            port = (Port) svc.getPorts().values().iterator().next();
            setEndpoint(port.getName());
        } else {
            throw new DeploymentException("If endpoint is not set, the WSDL service '" + getService() + "' "
                    + "must contain a single port definition");
        }
        SOAPAddress sa11 = WSDLUtils.getExtension(port, SOAPAddress.class);
        SOAP12Address sa12 = WSDLUtils.getExtension(port, SOAP12Address.class);
        if (getLocationURI() != null) {
            marshaler.setBaseUrl(getLocationURI());
        } else if (sa11 != null) {
            marshaler.setBaseUrl(sa11.getLocationURI());
        } else if (sa12 != null) {
            marshaler.setBaseUrl(sa12.getLocationURI());
        } else {
            throw new DeploymentException(
                    "No locationURI set and no SOAP address defined on port '" + port.getName() + "'");
        }
        description = WSDLUtils.getWSDL11Factory().newWSDLWriter().getDocument(def);
        marshaler.setBinding(BindingFactory.createBinding(port));
    } finally {
        is.close();
    }
}

From source file:Validate.java

void parse(String dir, String filename)
        throws FileNotFoundException, IOException, ParserConfigurationException, SAXException {
    try {//  w w w .  j  a  v a  2s . c om
        File f = new File(dir, filename);
        StringBuffer errorBuff = new StringBuffer();
        InputSource input = new InputSource(new FileInputStream(f));
        // Set systemID so parser can find the dtd with a relative URL in the source document.
        input.setSystemId(f.toString());
        SAXParserFactory spfact = SAXParserFactory.newInstance();

        spfact.setValidating(true);
        spfact.setNamespaceAware(true);

        SAXParser parser = spfact.newSAXParser();
        XMLReader reader = parser.getXMLReader();

        //Instantiate inner-class error and lexical handler.
        Handler handler = new Handler(filename, errorBuff);
        reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
        parser.parse(input, handler);

        if (handler.containsDTD && !handler.errorOrWarning) // valid
        {
            buff.append("VALID " + filename + "\n");
            numValidFiles++;
        } else if (handler.containsDTD) // not valid
        {
            buff.append("NOT VALID " + filename + "\n");
            buff.append(errorBuff.toString());
            numInvalidFiles++;
        } else // no DOCTYPE to use for validation
        {
            buff.append("NO DOCTYPE DECLARATION " + filename + "\n");
            numFilesMissingDoctype++;
        }
    } catch (Exception e) // Serious problem!
    {
        buff.append("NOT WELL-FORMED " + filename + ". " + e.getMessage() + "\n");
        numMalformedFiles++;
    } finally {
        numXMLFiles++;
    }
}

From source file:de.micromata.genome.gwiki.page.gspt.taglibs.TagLibraryInfoImpl.java

protected void loadTagLibary(String uri) {
    Digester dig = new Digester();
    dig.setClassLoader(Thread.currentThread().getContextClassLoader());
    dig.setValidating(false);/* w w w. j av  a 2 s.c  om*/
    final EntityResolver parentResolver = dig.getEntityResolver();
    dig.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

            InputStream is = null;
            if (StringUtils.equals(systemId, "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd") == true
                    || StringUtils.equals(publicId,
                            "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN") == true) {
                is = loadLocalDtd("web-jsptaglibrary_1_1.dtd");

            } else if (StringUtils.equals(systemId, "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd") == true
                    || StringUtils.equals(publicId,
                            "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN") == true) {
                is = loadLocalDtd("web-jsptaglibrary_1_2.dtd");
            }
            if (is == null) {
                if (parentResolver == null) {
                    GWikiLog.error("Cannot resolve entity: " + systemId);
                    return null;
                }
                return parentResolver.resolveEntity(publicId, systemId);
            }
            InputSource source = new InputSource(is);
            source.setPublicId(publicId);
            source.setSystemId(systemId);
            return source;
        }
    });
    dig.addCallMethod("taglib/tlib-version", "setTlibversion", 0);
    dig.addCallMethod("taglib/tlibversion", "setTlibversion", 0);
    dig.addCallMethod("taglib/jsp-version", "setJspversion", 0);
    dig.addCallMethod("taglib/jspversion", "setJspversion", 0);
    dig.addCallMethod("taglib/short-name", "setShortname", 0);
    dig.addCallMethod("taglib/shortname", "setShortname", 0);
    dig.addObjectCreate("taglib/tag", TagTmpInfo.class);
    dig.addCallMethod("taglib/tag/name", "setTagName", 0);
    dig.addCallMethod("taglib/tag/description", "setInfoString", 0);
    dig.addCallMethod("taglib/tag/tag-class", "setTagClassName", 0);
    dig.addCallMethod("taglib/tag/tagclass", "setTagClassName", 0);

    dig.addCallMethod("taglib/tag/body-content", "setBodycontent", 0);
    dig.addCallMethod("taglib/tag/bodycontent", "setBodycontent", 0);

    dig.addObjectCreate("taglib/tag/attribute", TagTmpAttributeInfo.class);
    dig.addCallMethod("taglib/tag/attribute/name", "setName", 0);
    dig.addCallMethod("taglib/tag/attribute/required", "setRequired", 0);
    dig.addCallMethod("taglib/tag/attribute/rtexprvalue", "setRtexprvalue", 0);
    dig.addSetNext("taglib/tag/attribute", "addAttributeInfo");
    dig.addSetNext("taglib/tag", "addTag");

    dig.push(this);
    try {
        InputStream is = loadImpl(uri);
        if (is == null) {
            throw new RuntimeException("could not load tld '" + uri + "'");
        }
        /*
         * ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); String text =
         * Converter.stringFromBytes(baos.toByteArray()); dig.parse(new StringReader(text));
         */
        dig.parse(is);
        rework();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.xmlcalabash.library.UnescapeMarkup.java

public void gorun() throws SaxonApiException {
    super.gorun();

    String contentType = getOption(_content_type, "application/xml");
    String defCharset = HttpUtils.getCharset(contentType);
    contentType = HttpUtils.baseContentType(contentType);

    if (getOption(_namespace) != null) {
        namespace = getOption(_namespace).getString();
    }/*from   w w  w . ja  va  2 s .c  o  m*/

    String encoding = null;
    if (getOption(_encoding) != null) {
        encoding = getOption(_encoding).getString();
    }

    String charset = null;
    if (getOption(_charset) == null) {
        charset = defCharset;
    } else {
        charset = getOption(_charset).getString();
    }

    XdmNode doc = source.read(stepContext);

    String escapedContent = null;
    if ("base64".equals(encoding)) {
        if (charset == null) {
            throw XProcException.stepError(10);
        }
        escapedContent = decodeBase64(doc, charset);
    } else if (encoding != null) {
        throw new XProcException(step.getNode(), "Unexpected encoding: " + encoding);
    } else {
        escapedContent = extractText(doc);
    }

    TreeWriter tree = new TreeWriter(runtime);
    tree.startDocument(doc.getBaseURI());

    XdmSequenceIterator iter = doc.axisIterator(Axis.CHILD);
    XdmNode child = (XdmNode) iter.next();
    while (child.getNodeKind() != XdmNodeKind.ELEMENT) {
        tree.addSubtree(child);
        child = (XdmNode) iter.next();
    }
    tree.addStartElement(child);
    tree.addAttributes(child);
    tree.startContent();

    if ("text/html".equals(contentType)) {
        XdmNode tagDoc = null;
        if ("tagsoup".equals(runtime.htmlParser())) {
            tagDoc = tagSoup(escapedContent);
        } else {
            tagDoc = parseHTML(escapedContent);
        }
        if (namespace == null) {
            tree.addSubtree(tagDoc);
        } else {
            remapDefaultNamespace(tree, tagDoc);
        }
    } else if ("application/json".equals(contentType) || "text/json".equals(contentType)) {
        JSONTokener jt = new JSONTokener(escapedContent);
        XdmNode jsonDoc = JSONtoXML.convert(runtime.getProcessor(), jt, runtime.jsonFlavor());
        tree.addSubtree(jsonDoc);
    } else if (!"application/xml".equals(contentType)) {
        throw XProcException.stepError(51);
    } else {
        // Put a wrapper around it so that it doesn't have to have a single root...
        escapedContent = "<wrapper>" + escapedContent + "</wrapper>";

        StringReader sr = new StringReader(escapedContent);

        // Make sure the nodes in the unescapedContent get the right base URI
        InputSource is = new InputSource(sr);
        is.setSystemId(doc.getBaseURI().toASCIIString());

        XdmNode unesc = runtime.parse(is);

        // Now ignore the wrapper that we added...
        XdmNode dummyWrapper = S9apiUtils.getDocumentElement(unesc);
        XdmSequenceIterator realNodes = dummyWrapper.axisIterator(Axis.CHILD);
        while (realNodes.hasNext()) {
            unesc = (XdmNode) realNodes.next();
            if (namespace == null) {
                tree.addSubtree(unesc);
            } else {
                remapDefaultNamespace(tree, unesc);
            }
        }
    }

    tree.addEndElement();
    tree.endDocument();
    result.write(stepContext, tree.getResult());
}

From source file:com.netspective.commons.xml.ParseContext.java

public InputSource createInputSource(String text) {
    this.sourceText = text;
    InputSource is = new InputSource(new StringReader(text));
    is.setSystemId("text://");
    return is;//from  w  w w .  j av a 2  s .  co  m
}

From source file:com.netspective.commons.xml.ParseContext.java

public InputSource createInputSource(Resource resource) throws IOException {
    this.sourceResource = resource;

    InputStream stream = resource.getResourceAsStream();
    if (stream != null) {
        InputSource inputSource = new InputSource(stream);
        inputSource.setSystemId(resource.getSystemId());

        this.inputSrcTracker = new URLTracker();
        ((URLTracker) this.inputSrcTracker).setUrl(resource.getResource());
        if (parentSrcTracker != null)
            this.inputSrcTracker.setParent(parentSrcTracker);

        return inputSource;
    } else/* w  w  w .  jav  a2 s.  co  m*/
        throw new IOException("Resource '" + resource.getSystemId() + "' not found. ClassPath is "
                + System.getProperty("java.class.path") + ".");
}

From source file:com.netspective.commons.xml.ParseContext.java

public InputSource createInputSource(File srcFile) throws FileNotFoundException {
    String uri = "file:" + srcFile.getAbsolutePath().replace('\\', '/');
    for (int index = uri.indexOf('#'); index != -1; index = uri.indexOf('#')) {
        uri = uri.substring(0, index) + "%23" + uri.substring(index + 1);
    }// www.j  a v  a  2  s  .  co  m

    activeFileInputStream = new FileInputStream(srcFile);
    BufferedInputStream inputStream = new BufferedInputStream(activeFileInputStream);
    InputSource inputSource = new InputSource(inputStream);
    inputSource.setSystemId(uri);

    this.inputSrcTracker = new FileTracker();
    ((FileTracker) this.inputSrcTracker).setFile(srcFile);
    if (parentSrcTracker != null)
        this.inputSrcTracker.setParent(parentSrcTracker);
    this.sourceFile = srcFile;

    return inputSource;
}

From source file:com.netspective.commons.xml.ParseContext.java

public InputSource createInputSource(File jarFile, ZipEntry jarFileEntry)
        throws FileNotFoundException, IOException {
    this.sourceFile = jarFile;
    this.sourceJarEntry = jarFileEntry;
    this.sourceJarFile = new ZipFile(jarFile);

    InputStream stream = sourceJarFile.getInputStream(jarFileEntry);
    if (stream != null) {
        InputSource inputSource = new InputSource(stream);
        inputSource.setSystemId(sourceJarFile.getName() + "!" + jarFileEntry.getName());

        this.inputSrcTracker = new FileTracker();
        ((FileTracker) this.inputSrcTracker).setFile(jarFile);
        if (parentSrcTracker != null)
            this.inputSrcTracker.setParent(parentSrcTracker);

        return inputSource;
    } else//from ww w .j a  v  a  2 s . co  m
        throw new FileNotFoundException("Zip entry '" + jarFileEntry.getName() + "' not found in zip file '"
                + jarFile.getAbsolutePath() + "'.");
}

From source file:crawlercommons.sitemaps.SiteMapParserSAX.java

/**
 * Decompress the gzipped content and process the resulting XML Sitemap.
 * //  w  w w.  j a  v  a2 s. co m
 * @param url
 *            - URL of the gzipped content
 * @param response
 *            - Gzipped content
 * @return the site map
 * @throws UnknownFormatException
 *             if there is an error parsing the gzip
 * @throws IOException
 *             if there is an error reading in the gzip {@link java.net.URL}
 */
protected AbstractSiteMap processGzippedXML(URL url, byte[] response)
        throws IOException, UnknownFormatException {

    LOG.debug("Processing gzipped XML");

    InputStream is = new ByteArrayInputStream(response);

    // Remove .gz ending
    String xmlUrl = url.toString().replaceFirst("\\.gz$", "");
    LOG.debug("XML url = {}", xmlUrl);

    BOMInputStream decompressed = new BOMInputStream(new GZIPInputStream(is));
    InputSource in = new InputSource(decompressed);
    in.setSystemId(xmlUrl);
    return processXml(url, in);
}