List of usage examples for org.xml.sax InputSource setSystemId
public void setSystemId(String systemId)
From source file:com.netxforge.oss2.core.xml.CastorUtils.java
/** * Unmarshal a Castor XML configuration file. Uses Java 5 generics for * return type./* w w w .j ava 2 s. c o m*/ * * @param clazz the class representing the marshalled XML configuration file * @param resource the marshalled XML configuration file to unmarshal * @param preserveWhitespace whether or not to preserve whitespace * @return Unmarshalled object representing XML file * @throws org.exolab.castor.xml.MarshalException if the underlying Castor * Unmarshaller.unmarshal() call throws a org.exolab.castor.xml.MarshalException * @throws org.exolab.castor.xml.ValidationException if the underlying Castor * Unmarshaller.unmarshal() call throws a org.exolab.castor.xml.ValidationException * @throws java.io.IOException if the resource could not be opened */ public static <T> T unmarshal(Class<T> clazz, Resource resource, boolean preserveWhitespace) throws MarshalException, ValidationException, IOException { InputStream in; try { in = resource.getInputStream(); } catch (IOException e) { IOException newE = new IOException( "Failed to open XML configuration file for resource '" + resource + "': " + e); newE.initCause(e); throw newE; } try { InputSource source = new InputSource(in); try { source.setSystemId(resource.getURL().toString()); } catch (Throwable t) { // ignore } return unmarshal(clazz, source, preserveWhitespace); } finally { IOUtils.closeQuietly(in); } }
From source file:com.netxforge.oss2.core.xml.CastorUtils.java
/** * Unmarshal a Castor XML configuration file. Uses Java 5 generics for * return type and throws DataAccessExceptions. * * @param clazz the class representing the marshalled XML configuration file * @param resource the marshalled XML configuration file to unmarshal * @return Unmarshalled object representing XML file * @throws DataAccessException if the resource could not be opened or the * underlying Castor//from ww w . j ava 2 s . c o m * Unmarshaller.unmarshal() call throws a MarshalException or * ValidationException. The underlying exception will be translated * using MarshallingExceptionTranslator and will include information about * the resource from its {@link Resource#toString() toString()} method. */ public static <T> T unmarshalWithTranslatedExceptions(Class<T> clazz, Resource resource, boolean preserveWhitespace) { // TODO It might be useful to add code to test for readability on real files; the code below is from DefaultManualProvisioningDao - dj@opennms.org // if (!importFile.canRead()) { // throw new PermissionDeniedDataAccessException("Unable to read file "+importFile, null); // } InputStream in; try { in = resource.getInputStream(); } catch (IOException e) { throw CASTOR_EXCEPTION_TRANSLATOR .translate("opening XML configuration file for resource '" + resource + "'", e); } try { InputSource source = new InputSource(in); try { source.setSystemId(resource.getURL().toString()); } catch (Throwable t) { /* * resource.getURL() might throw an IOException * (or maybe a DataAccessException, since it's a * RuntimeException), indicating that the resource can't be * represented as a URL. We don't really care so much--we'll * only lose the ability for Castor to include the resource URL * in error messages and for it to directly resolve relative * URLs (which we don't currently use), so we just ignore it. */ } return unmarshal(clazz, source, preserveWhitespace); } catch (MarshalException e) { throw CASTOR_EXCEPTION_TRANSLATOR.translate("unmarshalling XML file for resource '" + resource + "'", e); } catch (ValidationException e) { throw CASTOR_EXCEPTION_TRANSLATOR.translate("unmarshalling XML file for resource '" + resource + "'", e); } finally { IOUtils.closeQuietly(in); } }
From source file:net.sourceforge.dita4publishers.tools.dxp.DitaDxpHelper.java
/** * Extracts only the local dependencies used from a map from a DXP package. * @param zipFile//from w w w .j av a 2 s. c o m * @param mapEntry * @param outputDir * @param dxpOptions * @throws Exception */ private static void extractMap(ZipFile zipFile, ZipEntry mapEntry, File outputDir, MapBosProcessorOptions dxpOptions) throws Exception { Map<URI, Document> domCache = new HashMap<URI, Document>(); if (!dxpOptions.isQuiet()) log.info("Extracting map " + mapEntry.getName() + "..."); BosConstructionOptions bosOptions = new BosConstructionOptions(log, domCache); InputSource source = new InputSource(zipFile.getInputStream(mapEntry)); File dxpFile = new File(zipFile.getName()); URL baseUri = new URL("jar:" + dxpFile.toURI().toURL().toExternalForm() + "!/"); URL mapUrl = new URL(baseUri, mapEntry.getName()); source.setSystemId(mapUrl.toExternalForm()); Document rootMap = DomUtil.getDomForSource(source, bosOptions, false); DitaBoundedObjectSet mapBos = DitaBosHelper.calculateMapBos(bosOptions, log, rootMap); MapCopyingBosVisitor visitor = new MapCopyingBosVisitor(outputDir); visitor.visit(mapBos); if (!dxpOptions.isQuiet()) log.info("Map extracted."); }
From source file:com.wavemaker.tools.ws.XJCCompiler.java
@SuppressWarnings("deprecation") public static S2JJAXBModel createSchemaModel(Map<String, Element> schemas, List<com.wavemaker.tools.io.File> bindingFiles, String packageName, Set<String> auxiliaryClasses, WebServiceType type) throws GenerationException { if (schemas == null || schemas.isEmpty()) { return null; }/*ww w . jav a2s . c o m*/ SchemaCompiler sc = XJC.createSchemaCompiler(); if (type == WebServiceType.SOAP) { // mimic what JAXWS's WsimportTool would do for SEI class name and // JAXB class name collision. ClassNameAllocator allocator = new ClassNameAllocatorImpl( new SimpleClassNameCollector(auxiliaryClasses)); sc.setClassNameAllocator(allocator); } JAXBCompilerErrorListener listener = new JAXBCompilerErrorListener(); sc.setErrorListener(listener); try { Field ncc = sc.getClass().getDeclaredField("NO_CORRECTNESS_CHECK"); ncc.setAccessible(true); ncc.set(sc, true); } catch (Exception e) { throw new GenerationException(e); } if (packageName != null) { sc.setDefaultPackageName(packageName); } for (Entry<String, Element> entry : schemas.entrySet()) { Element schema = entry.getValue(); // need to remove xsd:import or you will get element/type already // defined error during sc.bind() Element updatedSchema = removeImportElement(schema); sc.parseSchema(entry.getKey(), updatedSchema); } if (bindingFiles != null) { for (com.wavemaker.tools.io.File file : bindingFiles) { try { InputSource inputSource = new InputSource(file.getContent().asInputStream()); // cftempfix - if binding files are NOT ALWAYS local files (eg. mongo DB file), we may need to // correctly implement // logic for none-local file case. if (file instanceof LocalFile) { File f = ((LocalFile) file).getLocalFile(); inputSource.setSystemId(f.toURI().toString()); } else { inputSource.setSystemId(ResourceURL.get(file).toURI().toString()); } sc.parseSchema(inputSource); } catch (MalformedURLException e) { throw new GenerationException(e); } catch (URISyntaxException e) { throw new GenerationException(e); } } } Options options = sc.getOptions(); options.target = SpecVersion.V2_1; // suppress generation of package level annotations options.packageLevelAnnotations = false; // generate setter methods for Collection based properties options.activePlugins.add(new com.sun.tools.xjc.addon.collection_setter_injector.PluginImpl()); // replace isXXX with getXXX for Boolean type properties options.activePlugins.add(new com.wavemaker.tools.ws.jaxb.boolean_getter.PluginImpl()); S2JJAXBModel model = sc.bind(); if (listener.hasError) { throw listener.getException(); } return model; }
From source file:net.sf.joost.trax.TrAXHelper.java
/** * Converts a supplied <code>Source</code> to a <code>SAXSource</code>. * @param source The supplied input source * @param errorListener an ErrorListener object * @return a <code>SAXSource</code> *//*from www .ja v a2 s .c om*/ public static SAXSource getSAXSource(Source source, ErrorListener errorListener) throws TransformerException { if (DEBUG) log.debug("getting a SAXSource from a Source"); //SAXSource if (source instanceof SAXSource) { if (DEBUG) log.debug("source is an instance of SAXSource, so simple return"); return (SAXSource) source; } //DOMSource if (source instanceof DOMSource) { if (DEBUG) log.debug("source is an instance of DOMSource"); InputSource is = new InputSource(); Node startNode = ((DOMSource) source).getNode(); Document doc; if (startNode instanceof Document) { doc = (Document) startNode; } else { doc = startNode.getOwnerDocument(); } if (DEBUG) log.debug("using DOMDriver"); DOMDriver driver = new DOMDriver(); driver.setDocument(doc); is.setSystemId(source.getSystemId()); driver.setSystemId(source.getSystemId()); return new SAXSource(driver, is); } //StreamSource if (source instanceof StreamSource) { if (DEBUG) log.debug("source is an instance of StreamSource"); InputSource isource = getInputSourceForStreamSources(source, errorListener); return new SAXSource(isource); } else { String errMsg = "Unknown type of source"; if (log != null) log.error(errMsg); IllegalArgumentException iE = new IllegalArgumentException(errMsg); TransformerConfigurationException tE = new TransformerConfigurationException(iE.getMessage(), iE); if (errorListener != null) errorListener.error(tE); else throw tE; return null; } }
From source file:nl.flotsam.hamcrest.schema.relaxng.ResourceValidator.java
public boolean validate(Verifier verifier, Resource verifiable) throws SAXException, IOException { InputSource source = new InputSource(verifiable.getInputStream()); source.setSystemId(verifiable.getURI().toASCIIString()); return new InputSourceValidator().validate(verifier, source); }
From source file:com.janoz.tvapilib.support.XmlParsingObject.java
protected void parse(AbstractSaxParser parser, InputStream inputStream) { try {/*www . ja v a 2s.c o m*/ InputSource input = new InputSource(inputStream); input.setPublicId(""); input.setSystemId(""); XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(parser); reader.parse(input); } catch (SAXException e) { LOG.info("Error parsing XML data.", e); throw new TvApiException(e.getMessage(), e); } catch (IOException e) { LOG.info("IO error while parsing XML data.", e); throw new TvApiException("IO error while parsing XML data.", e); } }
From source file:org.callimachusproject.xml.XdmNodeFactory.java
public XdmNode parse(String systemId, Reader in) throws SAXException, IOException { if (in == null) return null; try {//from w w w .java2 s . co m InputSource source = new InputSource(in); source.setSystemId(systemId); return parse(source); } finally { in.close(); } }
From source file:org.callimachusproject.xml.XdmNodeFactory.java
public XdmNode parse(String systemId, InputStream in) throws SAXException, IOException { if (in == null) return null; try {/*ww w. jav a 2 s .c o m*/ InputSource source = new InputSource(in); source.setSystemId(systemId); return parse(source); } finally { in.close(); } }
From source file:channellistmaker.listmaker.XmlTvDtdResolver.java
/** * ???????xmltv.dtd????????DocumentBuilder?????????xmltv.dtd??? * ????????null?/* ww w. ja v a 2s . co m*/ */ @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (this.DTD_FILE == null) { LOG.warn("DTD???????"); return null; } else { LOG.trace("DTD????"); } if ((publicId != null && publicId.contains(DTD_NAME)) || (systemId != null && systemId.contains(DTD_NAME))) { LOG.trace("??????"); InputSource source = new InputSource(new FileInputStream(this.DTD_FILE)); source.setPublicId(publicId); source.setSystemId(systemId); return source; } else { LOG.trace("?????" + DTD_NAME + " ?????????"); return null; } }