Author: nbelaevski
Date: 2008-01-17 12:47:04 -0500 (Thu, 17 Jan 2008)
New Revision: 5456
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java
Log:
XCSS Parsing for f:resource registration added
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java 2008-01-17
16:48:09 UTC (rev 5455)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java 2008-01-17
17:47:04 UTC (rev 5456)
@@ -32,14 +32,19 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.ajax4jsf.builder.config.BuilderConfig;
import org.ajax4jsf.builder.config.ComponentBean;
-import org.ajax4jsf.builder.config.ComponentBaseBean;
import org.ajax4jsf.builder.config.RendererBean;
import org.ajax4jsf.templatecompiler.builder.CompilationContext;
import org.ajax4jsf.templatecompiler.builder.CompilationException;
@@ -50,6 +55,9 @@
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderResourceElement;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
/**
* @author Nick - mailto:nbelaevski@exadel.com
@@ -260,7 +268,7 @@
try {
// Put common properties
- ResourcesConfigGeneratorBean bean = new ResourcesConfigGeneratorBean();
+ final ResourcesConfigGeneratorBean bean = new ResourcesConfigGeneratorBean();
List<ComponentBean> components = config.getComponents();
for (ComponentBean componentBean : components) {
@@ -274,9 +282,57 @@
addResources(bean, rendererBean, config);
}
+ Set<String> pathResourcesSet = new
LinkedHashSet<String>(bean.getPathResources().values());
+ for (Iterator<String> iterator = pathResourcesSet.iterator(); iterator
+ .hasNext();) {
+ String resourcePath = iterator.next();
+
+ if (resourcePath != null && resourcePath.endsWith(".xcss")) {
+ debug("XCSS file detected: " + resourcePath);
+
+ InputStream resourceStream = getClassLoader().getResourceAsStream(resourcePath);
+ if (resourceStream != null) {
+ debug("XCSS file exists in classpath");
+
+ try {
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ SAXParser parser = parserFactory.newSAXParser();
+ parser.parse(resourceStream, new DefaultHandler() {
+ @Override
+ public void startElement(String uri,
+ String localName, String name,
+ Attributes attributes)
+ throws SAXException {
+
+ super.startElement(uri, localName, name, attributes);
+
+ if ("f:resource".equals(name)) {
+ String value = attributes.getValue("f:key");
+
+ if (value != null) {
+ debug("Adding resource: " + value);
+
+ addResource(value, "", bean);
+ }
+ }
+ }
+ });
+
+ } finally {
+ try {
+ resourceStream.close();
+ } catch (IOException e) {
+ getLog().error(e.getLocalizedMessage(), e);
+ }
+ }
+ }
+ }
+ }
+
context.put("classResources", bean.getClassResources());
context.put("pathResources", bean.getPathResources());
context.put("resourcesConfig", this);
+
File configFile = getResourcesConfig();
File javaDir = configFile.getParentFile();
if (!javaDir.exists()) {
Show replies by date