List of usage examples for javax.xml.transform.stream StreamSource StreamSource
public StreamSource(File f)
From source file:dk.defxws.fedoragsearch.server.GTransformer.java
public Transformer getTransformer(String xsltPath, URIResolver uriResolver, boolean checkInHome) throws Exception { if (cache.containsKey(xsltPath)) { return cache.get(xsltPath); }/*from w ww . j av a 2s . c o m*/ Transformer transformer = null; String xsltPathName = xsltPath + ".xslt"; try { InputStream stylesheet; try { if (checkInHome) { String dirname = Constants.WORKING_DIR + File.separator + "xsl"; File textFile = new File(dirname, xsltPathName); if ((textFile.exists()) && (textFile.canRead())) { stylesheet = new FileInputStream(textFile); } else { stylesheet = this.getClass() .getResourceAsStream("/cz/incad/kramerius/indexer/res/" + xsltPathName); } } else { stylesheet = new FileInputStream(new File(xsltPath)); } } catch (Exception ex) { throw new Exception(xsltPath + " not found"); } TransformerFactory tfactory = TransformerFactory.newInstance(); if (uriResolver != null) { tfactory.setURIResolver(uriResolver); } StreamSource xslt = new StreamSource(stylesheet); transformer = tfactory.newTransformer(xslt); if (uriResolver != null) { transformer.setURIResolver(uriResolver); } } catch (TransformerConfigurationException e) { throw new Exception("getTransformer " + xsltPath + ":\n", e); } catch (TransformerFactoryConfigurationError e) { throw new Exception("getTransformerFactory " + xsltPath + ":\n", e); } if (transformer != null) { cache.put(xsltPath, transformer); } return transformer; }
From source file:org.cleverbus.common.Tools.java
/** * Unmarshals XML into object graph.// w w w . j av a 2s . co m * * @param xml the input string * @param targetClass the target class * @return object graph * @see XmlConverter */ @SuppressWarnings("unchecked") public static <T> T unmarshalFromXml(String xml, Class<T> targetClass) { Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller(); jaxb2.setContextPath(targetClass.getPackage().getName()); return (T) jaxb2.unmarshal(new StreamSource(new StringReader(xml))); }
From source file:be.e_contract.mycarenet.consent.ConsentClient.java
/** * Invokes a method on the eHealthBox consultation web service using the * low-level SOAP payload.//from w ww.j ava 2 s . co m * * @param request * @return */ public String invoke(String request) { Source responseSource = this.dispatch.invoke(new StreamSource(new StringReader(request))); LOG.debug("response Source type: " + responseSource.getClass().getName()); return toString(responseSource); }
From source file:module.signature.util.XAdESValidator.java
private static void loadXAdESSchemas() { if (schemaFactory == null) { schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); }/* w w w .j a v a 2 s .c o m*/ Source[] sources = new StreamSource[3]; sources[0] = new StreamSource( XAdESValidator.class.getResourceAsStream("/resources/" + schemaXmldSigCoreFilename)); sources[1] = new StreamSource( XAdESValidator.class.getResourceAsStream("/resources/" + schemaXAdESv132Filename)); sources[2] = new StreamSource( XAdESValidator.class.getResourceAsStream("/resources/" + schemaXAdESv141Filename)); try { schemaXSD = schemaFactory.newSchema(sources); } catch (SAXException e) { e.printStackTrace(); //joantune: TODO probably should do something differente here!! throw new DomainException("error.loading.XADES.scheme", e); } }
From source file:com.provenance.cloudprovenance.sconverter.PolicyResponseConverter.java
public String XMLpolicyResponse(String XACMLResponse) { StringReader reader;/*ww w . j a v a 2s.c o m*/ StringWriter writer; InputStream fsStylesheetIs; TransformerFactory tFactory; StreamSource stylesource; Transformer transformer; String result; logger.info("XACML response to be converted: " + XACMLResponse); reader = new StringReader(XACMLResponse); writer = new StringWriter(); try { fsStylesheetIs = pathToXACMLtoCprovResponse.getInputStream(); System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); // Use a Transformer for output tFactory = TransformerFactory.newInstance(); stylesource = new StreamSource(fsStylesheetIs); transformer = tFactory.newTransformer(stylesource); transformer.transform(new javax.xml.transform.stream.StreamSource(reader), new javax.xml.transform.stream.StreamResult(writer)); } catch (TransformerException e) { e.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } result = writer.toString(); return result; }
From source file:org.kuali.mobility.knowledgebase.service.KnowledgeBaseServiceImpl.java
private Templates getXslTemplates(String templatesCode) throws Exception { Xsl xsl = xslDao.findXslByCode(templatesCode); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Templates templates = transformerFactory .newTemplates(new StreamSource(new ByteArrayInputStream(xsl.getValue().getBytes()))); // Templates templates = transformerFactory.newTemplates(new StreamSource(new ByteArrayInputStream("test".getBytes()))); return templates; }
From source file:br.com.elotech.sits.service.AbstractService.java
public Object getObjectsToSend(File fileToSend, Node node) throws XmlMappingException, IOException, ParserConfigurationException, SAXException { CastorMarshaller castorMarshallerByXSD = getCastorMarshallerByXSD(node); Source source = new StreamSource(new FileInputStream(fileToSend)); return castorMarshallerByXSD.unmarshal(source); }
From source file:mack.servlets.TransfServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TransformerException { geraXSL();//w w w . j ava 2s . c om geraXML(); Source xmlSource = new StreamSource("/temp/posicao.xml"); File xslFile = new File("/temp/gpx.xsl"); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(new StreamSource(xslFile)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); trans.transform(xmlSource, new StreamResult(bos)); PrintWriter w = new PrintWriter("/temp/posicao_proc.gpx", "UTF-8"); w.print(bos); w.close(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println(new String(bos.toByteArray())); } // response.getWriter().print(bos); // request.getRequestDispatcher("mapaTeste.html").forward(request, response); }
From source file:integration.ExporterTest.java
/** * Applies the transforms to the specified XML file. * * @param inputXML/*from w w w . ja v a2 s .com*/ * The file to transforms. * @param transforms * The collection of transforms. * @return See above. * @throws Exception * Thrown if an error occurred during the transformations. */ private File applyTransforms(File inputXML, List<InputStream> transforms) throws Exception { TransformerFactory factory; Transformer transformer; InputStream stream; InputStream in = null; OutputStream out = null; File output; Iterator<InputStream> i = transforms.iterator(); while (i.hasNext()) { factory = TransformerFactory.newInstance(); stream = i.next(); output = File.createTempFile(RandomStringUtils.random(10), "." + OME_XML); transformer = factory.newTransformer(new StreamSource(stream)); out = new FileOutputStream(output); in = new FileInputStream(inputXML); transformer.transform(new StreamSource(in), new StreamResult(out)); files.add(output); inputXML = output; stream.close(); out.close(); in.close(); } return inputXML; }
From source file:org.openwms.core.configuration.file.XMLPreferenceDaoImpl.java
/** * On bean initialization load all preferences into a Map. *//*from w ww .j a v a 2s .co m*/ @PostConstruct private void loadResources() { if (initialPropertiesExist()) { try { preferences = (Preferences) unmarshaller.unmarshal(new StreamSource(fileResource.getInputStream())); for (AbstractPreference pref : preferences.getAll()) { if (prefs.containsKey(pref.getPrefKey())) { throw new NoUniqueResultException( "Preference with key " + pref.getPrefKey() + " already loaded."); } prefs.put(pref.getPrefKey(), pref); } LOGGER.debug("Loaded {} properties into cache", preferences.getAll().size()); } catch (XmlMappingException xme) { throw new IntegrationLayerException("Exception while unmarshalling from " + fileName, xme); } catch (IOException ioe) { throw new ResourceNotFoundException("Exception while accessing the resource with name " + fileName, ioe); } } }