Java Code Examples for javax.xml.transform.Transformer.reset()

The following are Jave code examples for showing how to use reset() of the javax.xml.transform.Transformer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alvisnlp   File: XMLWriter2ForINIST.java   View Source Code Vote up 5 votes
@Override
    public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
        try {
        	Logger logger = getLogger(ctx);
            TransformerFactory factory = TransformerFactory.newInstance();
            InputStream is = xslTransform.getInputStream();
            Source transformerSource = new StreamSource(is);
            Transformer transformer = factory.newTransformer(transformerSource);
            is.close();
            transformer.setErrorListener(new ListingErrorHandler());

            libraryResolver = getLibraryResolver(ctx);
            Evaluator roots = libraryResolver.resolveNullable(this.roots);
            Evaluator fileName = this.fileName.resolveExpressions(libraryResolver);
            EvaluationContext evalCtx = new EvaluationContext(logger);

            for (Element root : Iterators.loop(getRoots(roots, evalCtx, corpus))) {
                transformer.reset();

                Document doc = XMLUtils.docBuilder.newDocument();
                doc.setUserData(ELEMENT_USER_DATA, root, null);
//				org.w3c.dom.Element elt = getElementProxy(doc, root);
//				doc.appendChild(elt);
                Source source = new DOMSource(doc);

                String fileNameString = fileName.evaluateString(evalCtx, root);
//                System.out.println("creating file: " + fileNameString);
                File outFile = new File(outDir, fileNameString);
                Result result = new StreamResult(outFile);

                transformer.transform(source, result);
            }
        } catch (DOMException | TransformerException | IOException e) {
            rethrow(e);
        }
    }
 
Example 2
Project: alvisnlp   File: XMLReader.java   View Source Code Vote up 5 votes
private void processFile(ProcessingContext<Corpus> ctx, Logger logger, Corpus corpus, InputStream file, Transformer transformer) throws ModuleException, IOException {
   	try {
   		String name = sourcePath.getStreamName(file);
   		logger.finer("reading: " + name);
   		transformer.reset();
   		transformer.setParameter(SOURCE_PATH_PARAMETER, name);
   		transformer.setParameter(SOURCE_BASENAME_PARAMETER, new File(name).getName());
   		transformer.setParameter(XML_READER_CONTEXT_PARAMETER, new XMLReaderContext(this, corpus));
   		Source source = getSource(ctx, file);
   		doTransform(ctx, transformer, source);
   	}
   	catch (TransformerException|SAXException|ParserConfigurationException e) {
   		rethrow(e);
	}
}
 
Example 3
Project: alvisnlp   File: XMLWriter.java   View Source Code Vote up 5 votes
@Override
	public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
		try {
	    	Logger logger = getLogger(ctx);
	    	EVALUATION_CONTEXT = new EvaluationContext(logger);
			Transformer transformer = getTransformer(ctx);

			XMLWriterResolvedObjects resObj = getResolvedObjects();
	        EvaluationContext evalCtx = new EvaluationContext(logger);
	        
	        outDir.mkdirs();
			for (Element root : Iterators.loop(getRoots(evalCtx, corpus))) {
				transformer.reset();
				
				Document doc = XMLUtils.docBuilder.newDocument();
				doc.setUserData(ELEMENT_USER_DATA, root, null);
//				org.w3c.dom.Element elt = getElementProxy(doc, root);
//				doc.appendChild(elt);
				Source source = new DOMSource(doc);
				
				String fileNameString = resObj.fileName.evaluateString(evalCtx, root);
				File outFile = new File(outDir, fileNameString);
				Result result = new StreamResult(outFile);

				doTransform(ctx, transformer, source, result);
			}
		}
		catch (DOMException|TransformerException|IOException e) {
			rethrow(e);
		}
	}