[richfaces-svn-commits] JBoss Rich Faces SVN: r12307 - in trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd: handler and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jan 16 07:22:51 EST 2009


Author: abelevich
Date: 2009-01-16 07:22:51 -0500 (Fri, 16 Jan 2009)
New Revision: 12307

Added:
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
Removed:
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/elements/
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/DefaultRichHandler.java
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/RichComponentsHandler.java
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ScriptsHandler.java
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/selector/
Modified:
   trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java
Log:


Added: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java	                        (rev 0)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Component.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -0,0 +1,76 @@
+package org.richfaces.cdk.rd;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Component {
+	
+	private String componentName;
+	
+	private  List <String> scripts = new ArrayList<String>();
+	
+	private  List <String> styles =  new ArrayList<String>();
+	
+	
+	public String getComponentName() {
+		return componentName;
+	}
+
+	public void setComponentName(String componentName) {
+		this.componentName = componentName;
+	}
+	
+	public void addScript(String script){
+		scripts.add(script);
+	}
+	
+	public void addStyle(String style){
+		styles.add(style);
+	}
+	
+	public List <String> getStyles() {
+		return this.styles;
+	}
+	
+	public List <String> getScripts() {
+		return this.scripts;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((componentName == null) ? 0 : componentName.hashCode());
+		result = prime * result + ((scripts == null) ? 0 : scripts.hashCode());
+		result = prime * result + ((styles == null) ? 0 : styles.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		final Component other = (Component) obj;
+		if (componentName == null) {
+			if (other.componentName != null)
+				return false;
+		} else if (!componentName.equals(other.componentName))
+			return false;
+		if (scripts == null) {
+			if (other.scripts != null)
+				return false;
+		} else if (!scripts.equals(other.scripts))
+			return false;
+		if (styles == null) {
+			if (other.styles != null)
+				return false;
+		} else if (!styles.equals(other.styles))
+			return false;
+		return true;
+	}
+
+}

Added: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java	                        (rev 0)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/Components.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -0,0 +1,60 @@
+package org.richfaces.cdk.rd;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Components {
+	
+	private String namespace;
+	
+	private List <Component> components = new ArrayList<Component> ();
+
+	public String getNamespace() {
+		return namespace;
+	}
+
+	public void setNamespace(String namespace) {
+		this.namespace = namespace;
+	}
+
+	public void addComponent(Component component) {
+		components.add(component);
+	}
+	
+	public List <Component> getComponents() {
+		return this.components;
+	}
+
+	
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((components == null) ? 0 : components.hashCode());
+		result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		final Components other = (Components) obj;
+		if (components == null) {
+			if (other.components != null)
+				return false;
+		} else if (!components.equals(other.components))
+			return false;
+		if (namespace == null) {
+			if (other.namespace != null)
+				return false;
+		} else if (!namespace.equals(other.namespace))
+			return false;
+		return true;
+	}
+}

Added: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java	                        (rev 0)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ComponentsHandler.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -0,0 +1,136 @@
+package org.richfaces.cdk.rd.handler;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.plugin.logging.Log;
+import org.richfaces.cdk.rd.Component;
+import org.richfaces.cdk.rd.Components;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ComponentsHandler extends DefaultHandler{
+	
+		
+//	private Set <PrefixMapping> prefixList = new HashSet<PrefixMapping>();
+//	
+//	private Set <String> userNamespaces = new HashSet<String>();
+//	
+//	public static String RICH_DEFAULT = "http://richfaces.org/rich";
+//	
+//	public static String A4J_DEFAULT = "http://richfaces.org/a4j";
+	
+	private Log log;
+	
+	private List <Components> components;
+	
+	private String tempString;
+	
+	private Set <String> scripts = new HashSet<String>();
+	
+	private Set <String> styles = new HashSet<String>();
+	
+//	@Override
+//	public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
+//		for (PrefixMapping prefix: prefixList) {
+//			
+//			String prefixUri = prefix.getUri();
+//			String qname = prefix.getPrefix();
+//					
+//			if(uri.equals(prefixUri) && name.startsWith(qname)) {
+//				getResult().add(localName);
+//			}
+//		}
+//	}
+	
+//	@Override
+//	public void startPrefixMapping(String prefix, String uri) throws SAXException {
+//		getLog().info("Process mapping: prefix: "  + prefix + " uri: " + uri );
+//		
+//		if (userNamespaces != null && userNamespaces.contains(uri)) {
+//			PrefixMapping prefixMapping = new PrefixMapping(prefix, uri);
+//			addPrefixMapping(prefixMapping);
+//		} 
+		
+//	}
+	@Override
+	public void characters(char[] ch, int start, int length) throws SAXException {
+		tempString = new String(ch, start, length);
+	}
+	
+	@Override
+	public void endElement(String uri, String localName, String name) throws SAXException {
+		for (Components library: components) {
+			if(library.getNamespace().equals(uri)) {
+				List <Component> components = library.getComponents(); 
+				for(Component component : components ){
+					if(localName.equals(component.getComponentName())) {
+						collectScripts(component.getScripts());
+						collectStyles(component.getScripts());
+					}
+				}
+			}
+		}
+	}
+	
+	private void collectStyles(Collection <String> styles) {
+		this.styles.addAll(styles);
+	}
+	
+	private void collectScripts(Collection <String> scripts) {
+		this.scripts.addAll(scripts);
+	}
+	
+	public Set <String> getStyles() {
+		return this.styles;
+	}
+	
+	public Set <String> getScripts() {
+		return this.scripts;
+	}
+		
+	public List<Components> getComponents() {
+		return components;
+	}
+
+	public void setComponents(List<Components> components) {
+		this.components = components;
+	}
+	
+	@Override
+	public void fatalError(SAXParseException e) throws SAXException {
+	}
+		
+	public Log getLog() {
+		return log;
+	}
+
+	public void setLog(Log log) {
+		this.log = log;
+	}
+	
+		
+//	public void addNamespaces(Collection <String>namespaces) {
+//		this.userNamespaces.addAll(namespaces);
+//	}
+//
+//	public Collection <String> getNamespaces() {
+//		if(userNamespaces.isEmpty() || !(userNamespaces.contains(RICH_DEFAULT) && userNamespaces.contains(A4J_DEFAULT))) {
+//			userNamespaces.add(RICH_DEFAULT);
+//			userNamespaces.add(A4J_DEFAULT);
+//		}
+//		return this.userNamespaces;
+//	}
+//
+//	public void addPrefixMapping(PrefixMapping prefixMapping) {
+//		prefixList.add(prefixMapping);
+//	}
+//
+}

Deleted: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/DefaultRichHandler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/DefaultRichHandler.java	2009-01-16 10:58:26 UTC (rev 12306)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/DefaultRichHandler.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -1,39 +0,0 @@
-package org.richfaces.cdk.rd.handler;
-
-import java.util.Set;
-
-import org.apache.maven.plugin.logging.Log;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * @author Anton Belevich
- *
- */
-public abstract class DefaultRichHandler extends DefaultHandler {
-	
-	private Log log;
-	
-	private Set result;
-	
-	public Set getResult() {
-		return result;
-	}
-
-	public void setResult(Set result) {
-		this.result = result;
-	}
-
-	@Override
-	public void fatalError(SAXParseException e) throws SAXException {
-	}
-		
-	public Log getLog() {
-		return log;
-	}
-
-	public void setLog(Log log) {
-		this.log = log;
-	}
-}

Deleted: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/RichComponentsHandler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/RichComponentsHandler.java	2009-01-16 10:58:26 UTC (rev 12306)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/RichComponentsHandler.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -1,68 +0,0 @@
-package org.richfaces.cdk.rd.handler;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.richfaces.cdk.rd.elements.PrefixMapping;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-/**
- * @author Anton Belevich
- *
- */
-public class RichComponentsHandler extends DefaultRichHandler {
-	
-		
-	private Set <PrefixMapping> prefixList = new HashSet<PrefixMapping>();
-	
-	private Set <String> userNamespaces = new HashSet<String>();
-	
-	public static String RICH_DEFAULT = "http://richfaces.org/rich";
-	
-	public static String A4J_DEFAULT = "http://richfaces.org/a4j";
-	
-
-	
-	@Override
-	public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
-		for (PrefixMapping prefix: prefixList) {
-			
-			String prefixUri = prefix.getUri();
-			String qname = prefix.getPrefix();
-					
-			if(uri.equals(prefixUri) && name.startsWith(qname)) {
-				getResult().add(localName);
-			}
-		}
-	}
-	
-	@Override
-	public void startPrefixMapping(String prefix, String uri) throws SAXException {
-		getLog().info("Process mapping: prefix: "  + prefix + " uri: " + uri );
-		
-		if (userNamespaces != null && userNamespaces.contains(uri)) {
-			PrefixMapping prefixMapping = new PrefixMapping(prefix, uri);
-			addPrefixMapping(prefixMapping);
-		} 
-		
-	}
-		
-	public void addNamespaces(Collection <String>namespaces) {
-		this.userNamespaces.addAll(namespaces);
-	}
-
-	public Collection <String> getNamespaces() {
-		if(userNamespaces.isEmpty() || !(userNamespaces.contains(RICH_DEFAULT) && userNamespaces.contains(A4J_DEFAULT))) {
-			userNamespaces.add(RICH_DEFAULT);
-			userNamespaces.add(A4J_DEFAULT);
-		}
-		return this.userNamespaces;
-	}
-
-	public void addPrefixMapping(PrefixMapping prefixMapping) {
-		prefixList.add(prefixMapping);
-	}
-
-}

Deleted: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ScriptsHandler.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ScriptsHandler.java	2009-01-16 10:58:26 UTC (rev 12306)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/handler/ScriptsHandler.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -1,47 +0,0 @@
-package org.richfaces.cdk.rd.handler;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class ScriptsHandler extends DefaultRichHandler {
-		
-	private Set lookUpResources; 
-	
-	private boolean collect = false;
-	
-	private String temp;
-	
-	
-	public ScriptsHandler(Set lookUpResources) {
-		this.lookUpResources = lookUpResources;
-	}
-	
-	@Override
-	public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
-	}		
-	
-	@Override
-	public void characters(char[] ch, int start, int length) throws SAXException {
-		temp = new String(ch,start,length);
-	}
-	
-	@Override
-	public void endElement(String uri, String localName, String name) throws SAXException {
-		
-		if(name.equalsIgnoreCase("name")) {
-			if(lookUpResources.contains(temp)) {
-				collect = true;
-			} else {
-				collect = false;
-			}
-		} 
-		
-		if(name.equalsIgnoreCase("script") && collect) {
-			getResult().add(temp);
-		}	
-	}
-	
-}

Modified: trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java
===================================================================
--- trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java	2009-01-16 10:58:26 UTC (rev 12306)
+++ trunk/sandbox/cdk/maven-resource-dependency-plugin/src/main/java/org/richfaces/cdk/rd/mojo/CreateScriptMojo.java	2009-01-16 12:22:51 UTC (rev 12307)
@@ -23,16 +23,18 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import org.apache.commons.digester.Digester;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemManager;
 import org.apache.commons.vfs.VFS;
@@ -47,14 +49,11 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.codehaus.plexus.util.DirectoryScanner;
+import org.richfaces.cdk.rd.Component;
+import org.richfaces.cdk.rd.Components;
 import org.richfaces.cdk.rd.JarResourceScanner;
-import org.richfaces.cdk.rd.handler.DefaultRichHandler;
-import org.richfaces.cdk.rd.handler.RichComponentsHandler;
-import org.richfaces.cdk.rd.handler.ScriptsHandler;
-import org.richfaces.cdk.rd.selector.ResourceSelector;
-import org.richfaces.cdk.rd.selector.RichResourceSelector;
+import org.richfaces.cdk.rd.handler.ComponentsHandler;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotSupportedException;
 
 /**
  * @author Anton Belevich
@@ -134,11 +133,12 @@
 	public void execute() throws MojoExecutionException {
 		try {
 			
-			Set <String> components = findComponents(webSourceDirectory);
 			Artifact richfaces = getUIArifact(project);
 			FileObject jarRichfaces = resolveArtifact(richfaces);
-			FileObject [] richConfigs = resolveConfigsFromJar(jarRichfaces);
-			Set result = selectScriptResources(richConfigs,components);		
+			FileObject [] configs = resolveConfigsFromJar(jarRichfaces);
+			List components = processConfigs(configs, new ArrayList());
+			Set <String> result = findComponents(webSourceDirectory, components);
+//			Set result = selectScriptResources(richConfigs,components);		
 			
 			for (Iterator iterator = result.iterator(); iterator.hasNext();) {
 				getLog().info("collect: " + iterator.next());
@@ -149,85 +149,72 @@
 		
 	}
 	
-	public Set findComponents (File webSourceDir) {
+	public List processConfigs(FileObject [] configs, List collector) {
+		for (FileObject config: configs) {
+			Digester digester = new Digester();
+			digester.addObjectCreate("components", Components.class);
+			digester.addCallMethod("components/namespace", "setNamespace", 0);
+			digester.addObjectCreate("components/component", Component.class);
+			digester.addCallMethod("components/component/name", "setComponentName",0);
+			digester.addCallMethod("components/component/scripts/script", "addScript",0);
+			digester.addCallMethod("components/component/styles/styles", "addStyle",0);
+			digester.addSetNext("components/component", "addComponent");
+			
+			try {
+				collector.add(digester.parse(config.getContent().getInputStream()));
+			} catch (SAXException e) {
+				getLog().error(e);
+			} catch (IOException e) {
+				getLog().error(e);
+			}
+		}
+		return collector;
+	}
+	
+	public Set findComponents (File webSourceDir, List components) {
 		
-		ResourceSelector richSelector = null; 
-		
 		DirectoryScanner scanner = new DirectoryScanner();
 		scanner.setBasedir(webSourceDir);
 		scanner.setIncludes(new String []{"**/*.xhtml"});
 		scanner.addDefaultExcludes();
 		scanner.scan();
 		String [] collectedFiles =  scanner.getIncludedFiles();
-	
-		try { 
+
+		ComponentsHandler handler = new ComponentsHandler();
+	  	handler.setLog(getLog());
+	  	handler.setComponents(components);
+
+	  	try { 
+			
 			SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
 			saxParserFactory.setNamespaceAware(true);
 			SAXParser saxParser = saxParserFactory.newSAXParser();
-			saxParser.setProperty("http://apache.org/xml/features/continue-after-fatal-error", true);
-
-		  	RichComponentsHandler handler = new RichComponentsHandler();
-		  	handler.setLog(getLog());
-		  	handler.setResult(new HashSet());
-	  	  	handler.addNamespaces(namespaces);
-	  	  	
-	  	  	richSelector = new RichResourceSelector(saxParser,handler);
 		
 	  	  	for(String processFile : collectedFiles) {
 				File file = new File(webSourceDir,processFile); 
 				if(file.exists()) {
 					getLog().info("process file: " + file.getName());
-					richSelector.select(file);
+					try {
+						saxParser.parse(file, handler);
+					} catch (SAXException e) {
+						getLog().error(e);
+					} catch (IOException e) {
+						getLog().error(e);
+					}
 				}	
 			}
 	  	  	
-		} catch (SAXNotSupportedException e) {
+		} catch (FactoryConfigurationError  e) {
 			getLog().error(e);
-		} catch (SAXException e) {
-			getLog().error(e);
 		} catch (ParserConfigurationException e) {
 			getLog().error(e);
-		} catch (IOException e) {
+		} catch (SAXException e){
 			getLog().error(e);
 		}
-		
-		Set result = null;
-		if (richSelector != null) {
-			result = richSelector.getResult(); 
-		} 
-		
-		return  result;
-	}
 	
-	
-	public Set selectScriptResources (FileObject[] richConfigs, Set components) {
-		Set result = null; 
-				
-		SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
-		try {
-			SAXParser saxParser = saxParserFactory.newSAXParser();
-			DefaultRichHandler handler = new ScriptsHandler(components);
-			handler.setLog(getLog());
-			handler.setResult(new HashSet());
-			RichResourceSelector selector = new RichResourceSelector(saxParser,handler);
-			
-			for (FileObject dependency: richConfigs) {
-				selector.select(dependency.getContent().getInputStream());
-			}
-			
-			result = selector.getResult();
-		
-		}catch(SAXException e) {
-			getLog().error(e);
-		}catch(ParserConfigurationException e) {
-			getLog().error(e);
-		}catch (IOException e) {
-			getLog().error(e);
-		}
-			
-		return result;
+		return  handler.getScripts();
 	}
-	
+		
 	protected Artifact getUIArifact (MavenProject project) {
 		
 		Model model = project.getModel();
@@ -274,7 +261,7 @@
 		return jarFileObject;
 	}
 	
-	public FileObject [] resolveConfigsFromJar(FileObject jarFileObject) throws MojoExecutionException{
+	public FileObject [] resolveConfigsFromJar(FileObject jarFileObject) {
 		FileObject [] result =  new FileObject[0];
 		
 		try {
@@ -287,7 +274,6 @@
 		} catch (IOException e) {
 			getLog().error(e);
 		}
-		
 		return result;
 	}
 	




More information about the richfaces-svn-commits mailing list