List of usage examples for org.xml.sax InputSource getSystemId
public String getSystemId()
From source file:org.castor.mapping.MappingUnmarshaller.java
/** * Internal recursive loading method. This method will load the mapping document into a mapping * object and load all the included mapping along the way into a single collection. * * @param mapping The mapping instance.//from ww w .j a v a 2 s . c om * @param resolver The entity resolver to use. May be null. * @param source The input source. * @throws MappingException The mapping file is invalid. */ private void loadMappingInternal(final Mapping mapping, final DTDResolver resolver, final InputSource source) throws MappingException { // Clear all the cached resolvers, so they can be reconstructed a // second time based on the new mappings loaded _registry.clear(); Object id = source.getSystemId(); if (id == null) { id = source.getByteStream(); } if (id != null) { // check that the mapping has already been processed if (mapping.processed(id)) { return; } // mark the mapping as being processed mapping.markAsProcessed(id); } MappingRoot root = mapping.getRoot(); _idResolver.setMapping(root); try { // Load the specificed mapping source Unmarshaller unm = new Unmarshaller(MappingRoot.class); unm.setValidation(false); unm.setEntityResolver(resolver); unm.setClassLoader(Mapping.class.getClassLoader()); unm.setIDResolver(_idResolver); unm.setUnmarshalListener(new MappingUnmarshallListener(this, mapping, resolver)); MappingRoot loaded = (MappingRoot) unm.unmarshal(source); // Load all the included mapping by reference // -- note: this is just for processing any // -- includes which may have previously failed // -- using the IncludeListener...and to // -- report any potential errors. Enumeration includes = loaded.enumerateInclude(); while (includes.hasMoreElements()) { Include include = (Include) includes.nextElement(); if (!mapping.processed(include.getHref())) { try { loadMappingInternal(mapping, resolver, include.getHref()); } catch (Exception ex) { throw new MappingException(ex); } } } // gather "class" tags Enumeration<? extends ClassMapping> classMappings = loaded.enumerateClassMapping(); while (classMappings.hasMoreElements()) { root.addClassMapping(classMappings.nextElement()); } // gather "key-generator" tags Enumeration<? extends KeyGeneratorDef> keyGeneratorDefinitions = loaded.enumerateKeyGeneratorDef(); while (keyGeneratorDefinitions.hasMoreElements()) { root.addKeyGeneratorDef(keyGeneratorDefinitions.nextElement()); } // gather "field-handler" tags Enumeration<? extends FieldHandlerDef> fieldHandlerDefinitions = loaded.enumerateFieldHandlerDef(); while (fieldHandlerDefinitions.hasMoreElements()) { root.addFieldHandlerDef(fieldHandlerDefinitions.nextElement()); } } catch (Exception ex) { throw new MappingException(ex); } }
From source file:org.cobra_grendel.html.parser.DocumentBuilderImpl.java
/** * Creates a document without parsing it so it can be used for incremental rendering. * /*ww w. j ava2 s . c o m*/ * @param is * The input source, which may be an instance of {@link org.cobra_grendel.html.parser.InputSourceImpl}. */ public Document createDocument(final InputSource is, final int transactionId) throws SAXException, IOException { String charset = is.getEncoding(); if (charset == null) { charset = "US-ASCII"; } String uri = is.getSystemId(); if (uri == null) { LOGGER.warn("parse(): InputSource has no SystemId (URI); document item URLs will not be resolvable."); } InputStream in = is.getByteStream(); WritableLineReader wis; if (in != null) { wis = new WritableLineReader(new InputStreamReader(in, charset)); } else { Reader reader = is.getCharacterStream(); if (reader != null) { wis = new WritableLineReader(reader); } else { throw new IllegalArgumentException("InputSource has neither a byte stream nor a character stream"); } } HTMLDocumentImpl document = new HTMLDocumentImpl(bcontext, rcontext, wis, uri, transactionId); return document; }
From source file:org.dita2indesign.indesign.builders.InDesignFromDitaMapBuilder.java
/** * @param publicationMapSource // w w w. j a va 2 s . co m * @param inDesignTemplateSource * @return */ public InDesignDocument buildMapDocument(InputSource inDesignTemplateSource, InputSource publicationMapSource, Map2InDesignOptions options) throws Exception { if (log.isDebugEnabled()) log.debug("buildIssueDocument(): inDesignTemplate=\"" + inDesignTemplateSource.getSystemId() + "\", publicationMap=\"" + publicationMapSource.getSystemId() + "\""); // Load the template then clone it to make our starting doc. InDesignDocument template = new InDesignDocument(inDesignTemplateSource); InDesignDocument doc = new InDesignDocument(template); Document mapDoc = DataUtil.constructNonValidatingDtdUsingDocumentBuilder().parse(publicationMapSource); if (mapDoc == null) { throw new Exception("Failed to parse issue \"" + publicationMapSource.getSystemId() + "\"."); } // Look for articles and add them to the InDesign document: addTopicsToDocument(doc, mapDoc, options); generateInCopyArticlesForTopics(mapDoc, options); return doc; }
From source file:org.eclipse.rdf4j.rio.rdfxml.RDFXMLParser.java
private void parse(InputSource inputSource) throws IOException, RDFParseException, RDFHandlerException { clear();//w w w . j a va2 s .c o m try { documentURI = inputSource.getSystemId(); saxFilter.setParseStandAloneDocuments( getParserConfig().get(XMLParserSettings.PARSE_STANDALONE_DOCUMENTS)); // saxFilter.clear(); saxFilter.setDocumentURI(documentURI); XMLReader xmlReader; if (getParserConfig().isSet(XMLParserSettings.CUSTOM_XML_READER)) { xmlReader = getParserConfig().get(XMLParserSettings.CUSTOM_XML_READER); } else { xmlReader = XMLReaderFactory.createXMLReader(); } xmlReader.setContentHandler(saxFilter); xmlReader.setErrorHandler(this); // Set all compulsory feature settings, using the defaults if they are // not explicitly set for (RioSetting<Boolean> aSetting : getCompulsoryXmlFeatureSettings()) { try { xmlReader.setFeature(aSetting.getKey(), getParserConfig().get(aSetting)); } catch (SAXNotRecognizedException e) { reportWarning(String.format("%s is not a recognized SAX feature.", aSetting.getKey())); } catch (SAXNotSupportedException e) { reportWarning(String.format("%s is not a supported SAX feature.", aSetting.getKey())); } } // Set all compulsory property settings, using the defaults if they are // not explicitly set for (RioSetting<?> aSetting : getCompulsoryXmlPropertySettings()) { try { xmlReader.setProperty(aSetting.getKey(), getParserConfig().get(aSetting)); } catch (SAXNotRecognizedException e) { reportWarning(String.format("%s is not a recognized SAX property.", aSetting.getKey())); } catch (SAXNotSupportedException e) { reportWarning(String.format("%s is not a supported SAX property.", aSetting.getKey())); } } // Check for any optional feature settings that are explicitly set in // the parser config for (RioSetting<Boolean> aSetting : getOptionalXmlFeatureSettings()) { try { if (getParserConfig().isSet(aSetting)) { xmlReader.setFeature(aSetting.getKey(), getParserConfig().get(aSetting)); } } catch (SAXNotRecognizedException e) { reportWarning(String.format("%s is not a recognized SAX feature.", aSetting.getKey())); } catch (SAXNotSupportedException e) { reportWarning(String.format("%s is not a supported SAX feature.", aSetting.getKey())); } } // Check for any optional property settings that are explicitly set in // the parser config for (RioSetting<?> aSetting : getOptionalXmlPropertySettings()) { try { if (getParserConfig().isSet(aSetting)) { xmlReader.setProperty(aSetting.getKey(), getParserConfig().get(aSetting)); } } catch (SAXNotRecognizedException e) { reportWarning(String.format("%s is not a recognized SAX property.", aSetting.getKey())); } catch (SAXNotSupportedException e) { reportWarning(String.format("%s is not a supported SAX property.", aSetting.getKey())); } } xmlReader.parse(inputSource); } catch (SAXParseException e) { Exception wrappedExc = e.getException(); if (wrappedExc == null) { reportFatalError(e, e.getLineNumber(), e.getColumnNumber()); } else { reportFatalError(wrappedExc, e.getLineNumber(), e.getColumnNumber()); } } catch (SAXException e) { Exception wrappedExc = e.getException(); if (wrappedExc == null) { reportFatalError(e); } else if (wrappedExc instanceof RDFParseException) { throw (RDFParseException) wrappedExc; } else if (wrappedExc instanceof RDFHandlerException) { throw (RDFHandlerException) wrappedExc; } else { reportFatalError(wrappedExc); } } finally { // Clean up saxFilter.clear(); xmlLang = null; elementStack.clear(); usedIDs.clear(); clear(); } }
From source file:org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.java
/** * Transform using an InputSource rather than a URL * //from w w w.j a v a 2s.c o m * @param inputsource the InputSource to use * @param res the Result * @throws TransformationException if an error occurred during transformation */ public void transform(InputSource inputsource, Result res) throws TransformationException { try { if (th == null) {// no stylesheets have been added, so try to use embedded... SAXSource saxSource = new SAXSource(inputsource); Source src = saxSource; String media = null, title = null, charset = null; src = tFactory.getAssociatedStylesheet(src, media, title, charset); if (src != null) { addStylesheet(src, null, Collections.EMPTY_MAP, new Properties()); } else { throw new TransformationException( Messages.getString("JAXPSAXProcessorInvoker.7") + inputsource.getSystemId()); //$NON-NLS-1$ } } th.setResult(res); log.info(Messages.getString("JAXPSAXProcessorInvoker.8")); //$NON-NLS-1$ reader.parse(inputsource); log.info(Messages.getString("JAXPSAXProcessorInvoker.9")); //$NON-NLS-1$ } catch (Exception e) { throw new TransformationException(e.getMessage(), e); } }
From source file:org.exist.collections.Collection.java
private InputSource closeShieldInputSource(final InputSource source) { final InputSource protectedInputSource = new InputSource(); protectedInputSource.setEncoding(source.getEncoding()); protectedInputSource.setSystemId(source.getSystemId()); protectedInputSource.setPublicId(source.getPublicId()); if (source.getByteStream() != null) { //TODO consider AutoCloseInputStream final InputStream closeShieldByteStream = new CloseShieldInputStream(source.getByteStream()); protectedInputSource.setByteStream(closeShieldByteStream); }/*from w w w. ja v a2 s. c o m*/ if (source.getCharacterStream() != null) { //TODO consider AutoCloseReader final Reader closeShieldReader = new CloseShieldReader(source.getCharacterStream()); protectedInputSource.setCharacterStream(closeShieldReader); } return protectedInputSource; }
From source file:org.exist.collections.MutableCollection.java
private InputSource closeShieldInputSource(final InputSource source) { final InputSource protectedInputSource = new InputSource(); protectedInputSource.setEncoding(source.getEncoding()); protectedInputSource.setSystemId(source.getSystemId()); protectedInputSource.setPublicId(source.getPublicId()); if (source.getByteStream() != null) { //TODO consider AutoCloseInputStream final InputStream closeShieldByteStream = new CloseShieldInputStream(source.getByteStream()); protectedInputSource.setByteStream(closeShieldByteStream); }//from w w w.ja va2s . c om if (source.getCharacterStream() != null) { //TODO consider AutoCloseReader final Reader closeShieldReader = new CloseShieldReader(source.getCharacterStream()); protectedInputSource.setCharacterStream(closeShieldReader); } return protectedInputSource; }
From source file:org.exolab.castor.mapping.Mapping.java
/** * Loads the mapping from the specified URL. If an entity resolver was specified, will use the * entity resolver to resolve the URL. This method is also used to load mappings referenced from * another mapping or configuration file. * * @param url The URL of the mapping file. * @param type The source type.//from ww w . ja v a 2 s . c o m * @throws IOException An error occured when reading the mapping file. * @throws MappingException The mapping file is invalid. */ public void loadMapping(final String url, final String type) throws IOException, MappingException { String location = url; if (_resolver.getBaseURL() == null) { setBaseURL(location); location = URIUtils.getRelativeURI(location); } try { InputSource source = _resolver.resolveEntity(null, location); if (source == null) { source = new InputSource(location); } if (source.getSystemId() == null) { source.setSystemId(location); } LOG.info(Messages.format("mapping.loadingFrom", location)); loadMapping(source, type); } catch (SAXException ex) { throw new MappingException(ex); } }
From source file:org.jbpm.bpel.xml.BpelReader.java
/** * Reads a BPEL document into a process definition. * @param processDefinition the definition to read into * @param source an input source pointing to the BPEL document *//*w w w .jav a 2s .c om*/ public void read(BpelProcessDefinition processDefinition, InputSource source) { DocumentBuilder documentBuilder = XmlUtil.getDocumentBuilder(); // capture parse errors in our problem handler documentBuilder.setErrorHandler(problemHandler.asSaxErrorHandler()); // save the document location String location = source.getSystemId(); processDefinition.setLocation(location); try { // parse content Document document = documentBuilder.parse(source); // halt on parse errors if (problemHandler.getProblemCount() > 0) return; // prepare a locator of imported documents, relative to the process document location ProcessWsdlLocator wsdlLocator = null; if (location != null) { try { wsdlLocator = new ProcessWsdlLocator(new URI(location)); wsdlLocator.setProblemHandler(problemHandler); } catch (URISyntaxException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "source system identifier is invalid: " + location, e)); } } // read process definition read(processDefinition, document.getDocumentElement(), wsdlLocator); } catch (SAXException e) { problemHandler .add(new Problem(Problem.LEVEL_ERROR, "bpel document contains invalid xml: " + location, e)); } catch (IOException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "bpel document is not readable: " + location, e)); } finally { // reset error handling behavior documentBuilder.setErrorHandler(null); } }
From source file:org.jbpm.bpel.xml.DeploymentDescriptorReader.java
public void read(DeploymentDescriptor deploymentDescriptor, InputSource source) { // get the thread-local parser DocumentBuilder builder = XmlUtil.getDocumentBuilder(); // install our problem handler as document parser's error handler builder.setErrorHandler(problemHandler.asSaxErrorHandler()); try {// w w w .ja v a2s .c o m // parse content Document descriptorDoc = builder.parse(source); // halt on parse errors if (problemHandler.getProblemCount() > 0) return; Element descriptorElem = descriptorDoc.getDocumentElement(); // global scope readScope(descriptorElem, deploymentDescriptor); // target namespace String targetNamespace = XmlUtil.getAttribute(descriptorElem, BpelConstants.ATTR_TARGET_NAMESPACE); if (targetNamespace != null) deploymentDescriptor.setTargetNamespace(targetNamespace); // version String version = XmlUtil.getAttribute(descriptorElem, BpelConstants.ATTR_VERSION); if (version != null) deploymentDescriptor.setVersion(Integer.valueOf(version)); // service catalogs Element catalogsElem = XmlUtil.getElement(descriptorElem, BpelConstants.NS_DEPLOYMENT_DESCRIPTOR, BpelConstants.ELEM_SERVICE_CATALOGS); if (catalogsElem != null) { ServiceCatalog catalog = readServiceCatalogs(catalogsElem, source.getSystemId()); deploymentDescriptor.setServiceCatalog(catalog); } } catch (SAXException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "application descriptor contains invalid xml", e)); } catch (IOException e) { problemHandler.add(new Problem(Problem.LEVEL_ERROR, "application descriptor is not readable", e)); } finally { // reset error handling behavior builder.setErrorHandler(null); } }