From: <hei...@us...> - 2011-03-30 12:14:39
|
Revision: 7567 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=7567&view=rev Author: heikkidoeleman Date: 2011-03-30 12:14:32 +0000 (Wed, 30 Mar 2011) Log Message: ----------- #492 : CSW 2.0.2 ElementName processing broken Modified Paths: -------------- branches/2.6.x/jeeves/src/main/java/jeeves/utils/TransformerFactoryFactory.java branches/2.6.x/jeeves/src/main/java/jeeves/utils/Xml.java Modified: branches/2.6.x/jeeves/src/main/java/jeeves/utils/TransformerFactoryFactory.java =================================================================== --- branches/2.6.x/jeeves/src/main/java/jeeves/utils/TransformerFactoryFactory.java 2011-03-30 12:13:57 UTC (rev 7566) +++ branches/2.6.x/jeeves/src/main/java/jeeves/utils/TransformerFactoryFactory.java 2011-03-30 12:14:32 UTC (rev 7567) @@ -58,6 +58,9 @@ } public static TransformerFactory getTransformerFactory() throws TransformerConfigurationException { + if(factory == null) { + init(null); + } debug("TransformerFactoryFactory: " +factory.getClass().getName()); debug("TransformerFactoryFactory: produces transformer implementation " +factory.newTransformer().getClass().getName()); return factory; Modified: branches/2.6.x/jeeves/src/main/java/jeeves/utils/Xml.java =================================================================== --- branches/2.6.x/jeeves/src/main/java/jeeves/utils/Xml.java 2011-03-30 12:13:57 UTC (rev 7566) +++ branches/2.6.x/jeeves/src/main/java/jeeves/utils/Xml.java 2011-03-30 12:14:32 UTC (rev 7567) @@ -179,6 +179,21 @@ return (Element)resXml.getDocument().getRootElement().detach(); } + /** + * Transforms an xml tree into another using a stylesheet on disk. + * + * @param xml document to transform + * @param xslt transformation + * @return result + * @throws Exception hmm + */ + public static Element transform(Element xml, Source xslt) throws Exception + { + JDOMResult resXml = new JDOMResult(); + transform(xml, xslt, resXml, null); + return (Element)resXml.getDocument().getRootElement().detach(); + } + //-------------------------------------------------------------------------- /** Transform an xml tree into another using a stylesheet on disk and pass * parameters */ @@ -208,15 +223,27 @@ //-------------------------------------------------------------------------- /** Transform an xml tree putting the result to a stream with optional parameters */ - public static void transform(Element xml, String styleSheetPath, Result result, Map<String,String> params) throws Exception - { + public static void transform(Element xml, String styleSheetPath, Result result, Map<String,String> params) throws Exception { File styleSheet = new File(styleSheetPath); - Source srcXml = new JDOMSource(new Document((Element)xml.detach())); Source srcSheet = new StreamSource(styleSheet); + transform(xml, srcSheet, result, params); + } + /** + * Transforms an xml tree putting the result to a stream with optional parameters. + * + * @param xml document to be transformed + * @param xslt transformation to use + * @param result result + * @param params parameters + * @throws Exception hmm + */ + public static void transform(Element xml, Source xslt, Result result, Map<String,String> params) throws Exception { + Source srcXml = new JDOMSource(new Document((Element)xml.detach())); + // Dear old saxon likes to yell loudly about each and every XSLT 1.0 // stylesheet so switch it off but trap any exceptions because this - // code is run on transformers other than saxon + // code is run on transformers other than saxon TransformerFactory transFact = TransformerFactoryFactory.getTransformerFactory(); try { transFact.setAttribute(FeatureKeys.VERSION_WARNING,false); @@ -229,7 +256,7 @@ System.out.println("WARNING: transformerfactory doesnt like saxon attributes!"); //e.printStackTrace(); } finally { - Transformer t = transFact.newTransformer(srcSheet); + Transformer t = transFact.newTransformer(xslt); if (params != null) { for (String param : params.keySet()) { t.setParameter(param,params.get(param)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |