Author: nbelaevski
Date: 2008-04-09 15:50:51 -0400 (Wed, 09 Apr 2008)
New Revision: 7721
Removed:
branches/3.1.x/ui/inputnumber-slider/src/main/config/resources/
branches/3.1.x/ui/menu-components/src/main/config/resources/
branches/3.1.x/ui/scrollableDataTable/src/main/config/resources/
branches/3.1.x/ui/tabPanel/src/main/config/resources/
branches/3.1.x/ui/tree/src/main/config/resources/
Modified:
branches/3.1.x/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java
Log:
http://jira.jboss.com/jira/browse/RF-1716
Modified:
branches/3.1.x/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java
===================================================================
---
branches/3.1.x/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java 2008-04-09
18:34:05 UTC (rev 7720)
+++
branches/3.1.x/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ResourcesConfigGenerator.java 2008-04-09
19:50:51 UTC (rev 7721)
@@ -27,19 +27,26 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
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.ParserConfigurationException;
+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 +57,10 @@
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.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
/**
* @author Nick - mailto:nbelaevski@exadel.com
@@ -61,6 +72,8 @@
private File resourcesConfig;
private File templatesDirectory;
+ private static final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+
public ResourcesConfigGenerator(JSFGeneratorConfiguration task, Logger log) {
super(task, log);
}
@@ -254,13 +267,57 @@
}
}
+ private void parseXCSSResource(String resourcePath, final ResourcesConfigGeneratorBean
bean) throws SAXException, IOException, ParserConfigurationException {
+ InputStream resourceStream = getClassLoader().getResourceAsStream(resourcePath);
+ if (resourceStream != null) {
+ debug("XCSS file exists in classpath");
+
+ try {
+ 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);
+ }
+ }
+ } else {
+ getLog().error("Resource " + resourcePath + " hasn't been
found!");
+ }
+ }
+
+ private boolean isXCSSPath(String resourcePath) {
+ return resourcePath != null && resourcePath.endsWith(".xcss");
+ }
+
public void createFiles(BuilderConfig config) throws GeneratorException {
VelocityContext context = new VelocityContext();
Template template = getTemplate();
try {
// Put common properties
- ResourcesConfigGeneratorBean bean = new ResourcesConfigGeneratorBean();
+ final ResourcesConfigGeneratorBean bean = new ResourcesConfigGeneratorBean();
List<ComponentBean> components = config.getComponents();
for (ComponentBean componentBean : components) {
@@ -274,9 +331,73 @@
addResources(bean, rendererBean, config);
}
+ String includedContent = getIncludeContent();
+ if (includedContent != null && includedContent.length() != 0) {
+ String parseableContent = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?><resource-config>" + includedContent +
+ "</resource-config>";
+
+ SAXParser parser = parserFactory.newSAXParser();
+ parser.parse(new InputSource(new StringReader(parseableContent)), new
DefaultHandler() {
+ private StringBuilder path;
+
+ @Override
+ public void startElement(String uri,
+ String localName, String name,
+ Attributes attributes)
+ throws SAXException {
+
+ super.startElement(uri, localName, name, attributes);
+
+ if ("path".equals(name)) {
+ this.path = new StringBuilder();
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ if (this.path != null) {
+ this.path.append(ch, start, length);
+ }
+ };
+
+ @Override
+ public void endElement(String uri, String localName, String name) throws
SAXException {
+ super.endElement(uri, localName, name);
+
+ if ("resource".equals(name)) {
+ if (this.path != null && this.path.length() != 0) {
+ String resourcePath = this.path.toString().trim();
+ if (isXCSSPath(resourcePath)) {
+ debug("XCSS file detected: " + resourcePath);
+ try {
+ parseXCSSResource(resourcePath, bean);
+ } catch (IOException e) {
+ throw new SAXException(e.getLocalizedMessage(), e);
+ } catch (ParserConfigurationException e) {
+ throw new SAXException(e.getLocalizedMessage(), e);
+ }
+ }
+ }
+ this.path = null;
+ }
+ }
+ });
+ }
+
+ Set<String> pathResourcesSet = new
LinkedHashSet<String>(bean.getPathResources().values());
+ for (Iterator<String> iterator = pathResourcesSet.iterator(); iterator
+ .hasNext();) {
+ String resourcePath = iterator.next();
+
+ if (isXCSSPath(resourcePath)) {
+ debug("XCSS file detected: " + resourcePath);
+ parseXCSSResource(resourcePath, bean);
+ }
+ }
+
context.put("classResources", bean.getClassResources());
context.put("pathResources", bean.getPathResources());
context.put("resourcesConfig", this);
+
File configFile = getResourcesConfig();
File javaDir = configFile.getParentFile();
if (!javaDir.exists()) {