You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2006/10/18 23:16:54 UTC
svn commit: r465414 -
/incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java
Author: awiner
Date: Wed Oct 18 16:16:52 2006
New Revision: 465414
URL: http://svn.apache.org/viewvc?view=rev&rev=465414
Log:
Add support for a transformStylesheet property, which is the name of an XSLT stylesheet in src/main/conf that will be applied as the final step of faces-config.xml generation. This can be used to implement any final fixup of the output.
Modified:
incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java
Modified: incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java?view=diff&rev=465414&r1=465413&r2=465414
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java (original)
+++ incubator/adffaces/trunk/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateFacesConfigMojo.java Wed Oct 18 16:16:52 2006
@@ -21,6 +21,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import java.util.Iterator;
import java.util.LinkedList;
@@ -143,7 +144,20 @@
// metadata is represented compatibly with JSF 1.1 syntax.
targetFile.delete();
targetFile.getParentFile().mkdirs();
- Result mergedResult = new StreamResult(new FileOutputStream(targetFile));
+
+ File tmpFile = null;
+ OutputStream resultStream;
+ if (transformStylesheet != null)
+ {
+ tmpFile = File.createTempFile("generate-faces-config", null);
+ resultStream = new FileOutputStream(tmpFile);
+ }
+ else
+ {
+ resultStream = new FileOutputStream(targetFile);
+ }
+
+ Result mergedResult = new StreamResult(resultStream);
URL xslURL = getClass().getResource("resources/transform.xsl");
InputStream xsl = xslURL.openStream();
@@ -152,7 +166,33 @@
transformer.setParameter("packageContains", packageContains);
transformer.setParameter("typePrefix", typePrefix);
transformer.transform(mergedSource, mergedResult);
+ resultStream.close();
+ // OK, if there's a transformSylesheet, we've written
+ // the output to a temporary file, now transform it again.
+ // =-=FIXME AdamWiner: no, this is not the smartest and
+ // fastest way to do it. But after finding out
+ // that XMLFilter apparently doesn't support XSL parameters,
+ // and running into a bizarre "illegal processing instruction:
+ // saxon:warning" error message when using chained handlers, I got
+ // tired of trying to be smart. This is good enough.
+ if (transformStylesheet != null)
+ {
+ StreamSource tmpSource = new StreamSource(tmpFile);
+ StreamSource transformSource = new StreamSource(
+ new File(configDirectory, transformStylesheet));
+ Transformer finalTransform =
+ transFactory.newTransformer(transformSource);
+ FileOutputStream finalOut = new FileOutputStream(targetFile);
+ Result finalResult =
+ new StreamResult(finalOut);
+
+ finalTransform.transform(tmpSource, finalResult);
+ finalOut.close();
+ tmpFile.delete();
+ }
+
+
targetFile.setReadOnly();
getLog().info("Generated " + targetPath);
@@ -220,4 +260,12 @@
* @required
*/
private String typePrefix;
+
+ /**
+ * Name of an XSLT stylesheet in src/main/conf that will be applied
+ * as the final step. This can be used to implement any final fixup
+ * of the output.
+ * @parameter
+ */
+ private String transformStylesheet;
}