Code example for Transformer

Methods: setParameter, setURIResolver, transform

0
			Source source = null;
			String uri = pkg.getBaseURI() + path;
			Document doc = pkg.getDom(path);
			source = new DOMSource(doc);
			Transformer transformer = templates.newTransformer();
			transformer.setURIResolver(pkg.getURIResolver());
 
			transformer.setParameter("sourceURL", uri);
			transformer.setParameter("sourceBaseURL", pkg.getBaseURI() + "/");
 
			uri = result.getSystemId();
			if (uri != null) {
				transformer.setParameter("targetURL", uri);
				int i = uri.lastIndexOf('/');
				if (i > 0) {
					uri = uri.substring(0, i + 1);
					transformer.setParameter("targetBaseURL", uri);
				} 
			} 
			DocumentType doctype = doc.getDoctype();
			if (doctype != null) {
				if (doctype.getPublicId() != null) {
					transformer.setParameter("publicType", doctype.getPublicId());
				} 
				if (doctype.getSystemId() != null) {
					transformer.setParameter("systemType", doctype.getSystemId());
				} 
			} 
 
			transformer.transform(source, result);
		} catch (Exception ex) {
			Logger.getLogger(OdfXMLHelper.class.getName()).log(Level.SEVERE, null, ex);
			ex.printStackTrace();
		} 
	}