Author: nbelaevski
Date: 2007-04-27 13:49:29 -0400 (Fri, 27 Apr 2007)
New Revision: 137
Modified:
trunk/a4j-portlet/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/xml/XMLBody.java
trunk/cdk/generator/src/test/java/org/ajax4jsf/builder/xml/XMLBodyTest.java
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AssemblyLibraryMojo.java
Log:
http://jira.jboss.com/jira/browse/AJSF-48 fixed
Property changes on: trunk/a4j-portlet
___________________________________________________________________
Name: svn:ignore
+ target
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/xml/XMLBody.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/xml/XMLBody.java 2007-04-27
16:26:42 UTC (rev 136)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/xml/XMLBody.java 2007-04-27
17:49:29 UTC (rev 137)
@@ -25,6 +25,9 @@
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,6 +45,7 @@
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -163,4 +167,55 @@
}
return serializeNodes(childNodes);
}
+
+ public String getContentUnique(String xpath, String keyXPath, Set<String> keySet)
throws ParsingException{
+ if (keyXPath == null) {
+ return getContent(xpath);
+ } else {
+
+ XPath path = XPathFactory.newInstance().newXPath();
+ NodeList childNodes;
+ try {
+ childNodes = (NodeList) path.evaluate(xpath, xmlDocument,XPathConstants.NODESET);
+
+ List<Node> nodeSet = new ArrayList<Node>();
+
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node node = childNodes.item(i).cloneNode(true);
+
+ String key = serializeNodes((NodeList) path.evaluate(keyXPath, node,
XPathConstants.NODESET));
+ if (!keySet.contains(key)) {
+ keySet.add(key);
+ nodeSet.add(node);
+ }
+ }
+
+ return serializeNodes(new ArrayNodeList(nodeSet.toArray(new Node[nodeSet.size()])));
+
+ } catch (XPathExpressionException e) {
+ throw new ParsingException("Error evaluate xpath",e);
+ }
+ }
+ }
}
+
+class ArrayNodeList implements NodeList {
+ private Node[] nodes;
+
+ public ArrayNodeList(Node[] nodes) {
+ super();
+ this.nodes = nodes;
+ }
+
+ public int getLength() {
+ return nodes.length;
+ }
+
+ public Node item(int index) {
+ if (index < nodes.length) {
+ return this.nodes[index];
+ }
+
+ return null;
+ }
+}
Modified: trunk/cdk/generator/src/test/java/org/ajax4jsf/builder/xml/XMLBodyTest.java
===================================================================
--- trunk/cdk/generator/src/test/java/org/ajax4jsf/builder/xml/XMLBodyTest.java 2007-04-27
16:26:42 UTC (rev 136)
+++ trunk/cdk/generator/src/test/java/org/ajax4jsf/builder/xml/XMLBodyTest.java 2007-04-27
17:49:29 UTC (rev 137)
@@ -166,4 +166,22 @@
}
}
+ public void testGetContentUnique() throws ParsingException {
+ String xml = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
+ + "<!DOCTYPE faces-config PUBLIC \"-//Sun Microsystems, Inc.//DTD
JavaServer Faces Config 1.1//EN\"\n"
+ + "
\"http://java.sun.com/dtd/web-facesconfig_1_1.dtd\">\n"
+ + "<faces-config>\n" +
" <component><test>blabla</test></component><component><test>blabla</test></component><component><test>blabla2</test></component>\n"
+ + "</faces-config>";
+ InputStream in = new ByteArrayInputStream(xml.getBytes());
+ XMLBody body = new XMLBody();
+ body.loadXML(in);
+ try {
+ assertEquals(
+ "<component><test>blabla</test></component><component><test>blabla2</test></component>",
+ body.getContentUnique("/faces-config/component", "test/text()",
null));
+ } catch (ParsingException e) {
+ e.printStackTrace();
+ assertTrue(e.getMessage(),false);
+ }
+ }
}
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AssemblyLibraryMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AssemblyLibraryMojo.java 2007-04-27
16:26:42 UTC (rev 136)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AssemblyLibraryMojo.java 2007-04-27
17:49:29 UTC (rev 137)
@@ -325,18 +325,18 @@
File resourcesConfig = new File(outputDirectory,
"META-INF/resources-config.xml");
mergeXML(models, "META-INF/resources-config.xml",
- RESOURCES_CONFIG_TEMPLATE, null, new VelocityContext(),
- resourcesConfig);
+ RESOURCES_CONFIG_TEMPLATE, "/resource-config/resource",
"name/text()",
+ new VelocityContext(), resourcesConfig);
File tld = new File(outputDirectory, "META-INF/"
+ library.getTaglib().getShortName() + ".tld");
mergeXML(models, includeTld, TLD_TEMPLATE,
- "/taglib/tag | /taglib/listener", new VelocityContext(),
- tld);
+ "/taglib/tag | /taglib/listener",
+ null, new VelocityContext(), tld);
File taglib = new File(outputDirectory, "META-INF/"
+ library.getTaglib().getShortName() + ".taglib.xml");
mergeXML(models, includeTaglib, TAGLIB_TEMPLATE,
"/facelet-taglib/tag | /facelet-taglib/function",
- new VelocityContext(), taglib);
+ null, new VelocityContext(), taglib);
}else {
throw new MojoFailureException("Components library project must have parent pom
with components modules");
}
@@ -411,13 +411,16 @@
* name of velocity template for result file.
* @param commonXpath -
* XPath expression fof common part of result file.
+ * @param keyXPath TODO
+ * @param keySet TODO
* @param context -
* Velocity context for template processing.
* @throws MojoExecutionException
*/
private void mergeXML(List models, String filename, String templateName,
- String commonXpath, VelocityContext context, File target)
+ String commonXpath, String keyXPath, VelocityContext context, File target)
throws MojoExecutionException {
+ Set<String> keySet = new HashSet<String>();
StringBuffer content = new StringBuffer();
List<XMLBody> xmls = new ArrayList<XMLBody>(models.size());
String[] split = filename.split(",");
@@ -441,7 +444,11 @@
configBody.loadXML(new FileInputStream(moduleFacesConfig));
xmls.add(configBody);
if (commonXpath != null) {
- content.append(configBody.getContent(commonXpath));
+ if (keyXPath == null) {
+ content.append(configBody.getContent(commonXpath));
+ } else {
+ content.append(configBody.getContentUnique(commonXpath, keyXPath, keySet));
+ }
} else {
content.append(configBody.getContent());
}