Example usage for javax.xml.transform.dom DOMSource getSystemId

List of usage examples for javax.xml.transform.dom DOMSource getSystemId

Introduction

In this page you can find the example usage for javax.xml.transform.dom DOMSource getSystemId.

Prototype

@Override
public String getSystemId() 

Source Link

Document

Get the base ID (URL or system ID) from where URLs will be resolved.

Usage

From source file:nl.nn.adapterframework.validation.xerces_2_11.XMLSchemaFactory.java

public Schema newSchema(Source[] schemas) throws SAXException {

    // this will let the loader store parsed Grammars into the pool.
    XMLGrammarPoolImplExtension pool = new XMLGrammarPoolImplExtension();
    fXMLGrammarPoolWrapper.setGrammarPool(pool);

    XMLInputSource[] xmlInputSources = new XMLInputSource[schemas.length];
    InputStream inputStream;/*from w ww  .  j  a va  2s  . c o  m*/
    Reader reader;
    for (int i = 0; i < schemas.length; ++i) {
        Source source = schemas[i];
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            String publicId = streamSource.getPublicId();
            String systemId = streamSource.getSystemId();
            inputStream = streamSource.getInputStream();
            reader = streamSource.getReader();
            XMLInputSource xmlInputSource = new XMLInputSource(publicId, systemId, null);
            xmlInputSource.setByteStream(inputStream);
            xmlInputSource.setCharacterStream(reader);
            xmlInputSources[i] = xmlInputSource;
        } else if (source instanceof SAXSource) {
            SAXSource saxSource = (SAXSource) source;
            InputSource inputSource = saxSource.getInputSource();
            if (inputSource == null) {
                throw new SAXException(JAXPValidationMessageFormatter
                        .formatMessage(fXMLSchemaLoader.getLocale(), "SAXSourceNullInputSource", null));
            }
            xmlInputSources[i] = new SAXInputSource(saxSource.getXMLReader(), inputSource);
        } else if (source instanceof DOMSource) {
            DOMSource domSource = (DOMSource) source;
            Node node = domSource.getNode();
            String systemID = domSource.getSystemId();
            xmlInputSources[i] = new DOMInputSource(node, systemID);
        }
        //            else if (source instanceof StAXSource) {
        //                StAXSource staxSource = (StAXSource) source;
        //                XMLEventReader eventReader = staxSource.getXMLEventReader();
        //                if (eventReader != null) {
        //                    xmlInputSources[i] = new StAXInputSource(eventReader);
        //                }
        //                else {
        //                    xmlInputSources[i] = new StAXInputSource(staxSource.getXMLStreamReader());
        //                }
        //            }
        else if (source == null) {
            throw new NullPointerException(JAXPValidationMessageFormatter
                    .formatMessage(fXMLSchemaLoader.getLocale(), "SchemaSourceArrayMemberNull", null));
        } else {
            throw new IllegalArgumentException(
                    JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(),
                            "SchemaFactorySourceUnrecognized", new Object[] { source.getClass().getName() }));
        }
    }

    try {
        fXMLSchemaLoader.loadGrammar(xmlInputSources);
    } catch (XNIException e) {
        // this should have been reported to users already.
        throw Util.toSAXException(e);
    } catch (IOException e) {
        // this hasn't been reported, so do so now.
        SAXParseException se = new SAXParseException(e.getMessage(), null, e);
        if (fErrorHandler != null) {
            fErrorHandler.error(se);
        }
        throw se; // and we must throw it.
    }

    // Clear reference to grammar pool.
    fXMLGrammarPoolWrapper.setGrammarPool(null);

    // Select Schema implementation based on grammar count.
    final int grammarCount = pool.getGrammarCount();
    AbstractXMLSchema schema = null;
    if (fUseGrammarPoolOnly) {
        throw new NotImplementedException("fUseGrammarPoolOnly");
        //            if (grammarCount > 1) {
        //                schema = new XMLSchemaHack(new ReadOnlyGrammarPool(pool));
        //            }
        //            else if (grammarCount == 1) {
        //                Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
        //                schema = new XMLSchemaHack(grammars[0]);
        //            }
        //            else {
        //                schema = new XMLSchemaHack();
        //            }
    } else {
        schema = new XMLSchema(new ReadOnlyGrammarPool(pool), false);
    }
    propagateFeatures(schema);
    return schema;
}

From source file:org.apache.axis2.jaxws.client.dispatch.BaseDispatch.java

private boolean isValidInvocationParam(Object object) {
    String bindingId = endpointDesc.getClientBindingID();

    // If no bindingId was found, use the default.
    if (bindingId == null) {
        bindingId = SOAPBinding.SOAP11HTTP_BINDING;
    }//from  w ww .  j  a va 2  s. com

    // If it's not an HTTP_BINDING, then we can allow for null params,  
    // but only in PAYLOAD mode per JAX-WS Section 4.3.2.
    if (!bindingId.equals(HTTPBinding.HTTP_BINDING)) {
        if (mode.equals(Mode.MESSAGE) && object == null) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNullParamMessageMode"));
        }
    } else {
        // In all cases (PAYLOAD and MESSAGE) we must throw a WebServiceException
        // if the parameter is null and request method is POST or PUT.
        if (object == null && isPOSTorPUTRequest()) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNullParamHttpBinding"));
        }
    }

    if (object instanceof DOMSource) {
        DOMSource ds = (DOMSource) object;
        if (ds.getNode() == null && ds.getSystemId() == null) {
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchBadDOMSource"));
        }
    }

    // If we've gotten this far, then all is good.
    return true;
}

From source file:org.jbpm.bpel.xml.BpelReader.java

public void read(BpelProcessDefinition processDefinition, DOMSource source) {
    // save the document location
    String location = source.getSystemId();
    processDefinition.setLocation(location);

    // prepare a locator of imported documents, relative to the process document location
    ProcessWsdlLocator wsdlLocator = null;
    if (location != null) {
        try {/*from   w w w.j a  va  2s. com*/
            wsdlLocator = new ProcessWsdlLocator(new URI(location));
            wsdlLocator.setProblemHandler(problemHandler);
        } catch (URISyntaxException e) {
            problemHandler.add(new Problem(Problem.LEVEL_ERROR, "source system id is invalid"));
        }
    }

    Element processElem;
    Node node = source.getNode();

    switch (node.getNodeType()) {
    case Node.DOCUMENT_NODE:
        processElem = ((Document) node).getDocumentElement();
        break;
    case Node.ELEMENT_NODE:
        processElem = (Element) node;
        break;
    default:
        problemHandler.add(new Problem(Problem.LEVEL_ERROR,
                "source node must be either an element or a document: " + node));
        return;
    }

    // read process definition
    read(processDefinition, processElem, wsdlLocator);
}