Author: alexsmirnov
Date: 2007-06-28 16:26:00 -0400 (Thu, 28 Jun 2007)
New Revision: 1390
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/AntCompilationContext.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/TemplateCompilerTask.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/AbstractCompilationContext.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationContext.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationException.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/StringUtils.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/TemplateCompiler.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/Variable.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/CompiledEL.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELParser.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ICompiledEL.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/IELCompiler.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/Attribute.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/BodyElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/DeclarationElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsArray.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsFactory.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/JSTLElementsFactory.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/RootElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElementBase.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CDATAElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CommentElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLAttributes.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLTags.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HtmlAttributesFactory.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/PIElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/TextElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/HtmlAttribute.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/PassThruWithExclusions.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Declaration.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectiveInclude.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectivePage.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Expression.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Scriptlet.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ForEachTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/IFTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/SetTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FCallTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FClientIDTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FInsertChildren.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FResourceTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderResourceElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderScriptsElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderStylesElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/InsertComponent.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/Parameter.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/ParameterProcessor.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/UInsertFacetTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/VcpBodyTemplateElement.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/CallbackListener.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/ReducedHTMLParser.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/AntFileResourceLoader.java
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/BuilderContext.java
branches/refactor1/cdk/generator/src/main/java/readme.txt
branches/refactor1/cdk/generator/src/main/resources/META-INF/plexus/
branches/refactor1/cdk/generator/src/main/resources/META-INF/plexus/components.xml
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/VM_global_library.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeBegin.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeChildren.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeEnd.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_1.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_2.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/HTMLElement.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/IFElement.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/headerResource.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertCall.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertChildren.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertComponent.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertFacet.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertResource.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/set.vm
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/tags.bin
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/velocity.properties
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/ant/
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/ant/velocity.properties
branches/refactor1/cdk/generator/src/test/java/org/ajax4jsf/AppTest.java
branches/refactor1/cdk/pom.xml
Log:
projects refactored
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/AntCompilationContext.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/AntCompilationContext.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/AntCompilationContext.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.ant;
+
+import org.ajax4jsf.templatecompiler.builder.AbstractCompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.apache.tools.ant.Project;
+import org.apache.velocity.Template;
+
+/**
+ * @author shura
+ *
+ */
+public class AntCompilationContext extends AbstractCompilationContext {
+
+
+ private Project project;
+
+ TemplateCompilerTask task;
+
+
+
+ /**
+ * @param loader
+ * @throws CompilationException
+ */
+ public AntCompilationContext(TemplateCompilerTask task, ClassLoader loader) throws
CompilationException {
+ super(loader);
+ this.task = task;
+ this.project = task.getProject();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.builder.CompilationContext#debug(java.lang.String)
+ */
+ public void debug(String content) {
+ project.log(content, Project.MSG_DEBUG);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#debug(java.lang.String,
java.lang.Throwable)
+ */
+ public void debug(String content, Throwable error) {
+ project.log(content, Project.MSG_DEBUG);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.builder.CompilationContext#error(java.lang.String)
+ */
+ public void error(String content) {
+ project.log(content, Project.MSG_ERR);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#error(java.lang.String,
java.lang.Throwable)
+ */
+ public void error(String content, Throwable error) {
+ project.log(content, Project.MSG_ERR);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#info(java.lang.String)
+ */
+ public void info(String content) {
+ project.log(content, Project.MSG_INFO);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#info(java.lang.String,
java.lang.Throwable)
+ */
+ public void info(String content, Throwable error) {
+ project.log(content, Project.MSG_INFO);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#warn(java.lang.String)
+ */
+ public void warn(String content) {
+ project.log(content, Project.MSG_WARN);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.builder.CompilationContext#warn(java.lang.String,
java.lang.Throwable)
+ */
+ public void warn(String content, Throwable error) {
+ project.log(content, Project.MSG_INFO);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.builder.CompilationContext#getTemplate(java.lang.String)
+ */
+ public Template getTemplate(String name) throws CompilationException {
+ return task.getTemplate(name);
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/TemplateCompilerTask.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/TemplateCompilerTask.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/ant/TemplateCompilerTask.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,380 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.ant;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.InputStream;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.builder.TemplateCompiler;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+/**
+ * Task template compiler.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/26 20:48:56 $
+ *
+ */
+public class TemplateCompilerTask extends Task implements FilenameFilter {
+ final private static String regexComponent = "^(.*)\\.xhtml$";
+
+ final private static Pattern patternComponent = Pattern
+ .compile(regexComponent);
+
+
+ private final static String TEMPLATE_FILE_EXT = ".xhtml";
+
+ /**
+ * classpath for load component/renderer classes for introspection.
+ */
+ private Path classPath;
+
+ private File srcDir;
+
+ private File destDir;
+
+ protected Vector filesets = new Vector();
+
+
+ /**
+ * Default constructor
+ *
+ * @throws Exception
+ */
+ public TemplateCompilerTask() throws Exception {
+ super();
+
+ }
+
+ /**
+ * getting srcDir
+ *
+ * @return Returns the destDir
+ */
+ public File getSrcdir() {
+ return this.srcDir;
+ }
+
+ /**
+ * setting a srcDir
+ *
+ * @param destDir
+ * The srcDir to set.
+ */
+ public void setSrcdir(File srcDir) {
+ this.srcDir = srcDir;
+ }
+
+ /**
+ * getting a destDit
+ *
+ * @return Returns the destDir.
+ */
+ public File getDestdir() {
+ return this.destDir;
+ }
+
+ /**
+ * setting a destDir
+ *
+ * @param destDir
+ * The destDir to set.
+ */
+ public void setDestdir(File destDir) {
+ this.destDir = destDir;
+ }
+
+ /**
+ * Generate java class name from template filename
+ *
+ * @param fileTemplateName
+ * a string contain template filename
+ * @return string contain java class name
+ */
+ public String generateJavaClassName(final String fileTemplateName) {
+
+ String strJavaClassName = "Unknown";
+
+ Matcher mather = patternComponent.matcher(fileTemplateName);
+
+ if (mather.find()) {
+ strJavaClassName = mather.group(1);
+ } // if
+
+ return strJavaClassName;
+ }
+
+ /**
+ *
+ * @param sFileTemplate
+ */
+ public void processTemplate(String sFileTemplate) {
+ // Generate java class name
+
+ ClassLoader loader = getClassLoader();
+
+ try {
+
+ CompilationContext componentBean = new AntCompilationContext(this,loader);
+ TemplateCompiler templateCompiler = new TemplateCompiler();
+
+ // componentBean.setDefaultVariables();
+
+ InputStream inputStream = null;
+ File inputFile = new File(sFileTemplate);
+ String sF = inputFile.getName().toString();
+
+ componentBean.setFullClassName(generateJavaClassName(sF));
+
+ inputStream = new FileInputStream(inputFile);
+
+ templateCompiler.processing(inputStream, componentBean);
+
+ String resultPath = componentBean.getComponentFileName() + ".java";
+ File javaFile = new File(getDestdir(), resultPath);
+ File javaDir = javaFile.getParentFile();
+ if (!javaDir.exists()) {
+ javaDir.mkdirs();
+ } // try
+
+ if (javaFile.exists()) {
+ javaFile.delete();
+ } // if
+
+ Writer out = new BufferedWriter(new FileWriter(javaFile));
+
+ templateCompiler.generateCode(componentBean, out);
+
+ out.flush();
+ out.close();
+ } catch (FileNotFoundException e) {
+ throw new BuildException(e);
+ } catch (Exception e) {
+ throw new BuildException(
+ "Error create new Component Java file, message "
+ + e.getLocalizedMessage(), e);
+ } // catch
+ }
+
+ public ClassLoader getClassLoader() {
+ ClassLoader loader = getProject().createClassLoader(this.classPath);
+ if (null == loader) {
+ loader = this.getClass().getClassLoader();
+ }
+ return loader;
+ }
+
+ /**
+ * Adds a set of files to copy.
+ *
+ * @param set
+ * a set of files to copy
+ */
+ public void addFileset(FileSet set) {
+ this.filesets.addElement(set);
+ }
+
+ final private static String VELOCITY_PROPERTIES = "velocity.properties";
+
+
+ private VelocityEngine engine;
+
+ private Map<String, Template> _templates = new HashMap<String, Template>();
+
+
+ public void init() throws BuildException {
+ super.init();
+ Properties velocityProperties = new Properties();
+ try {
+ InputStream streamVelosityProperties =
TemplateCompilerTask.class.getResourceAsStream(VELOCITY_PROPERTIES);
+ velocityProperties.load(streamVelosityProperties);
+ engine = new VelocityEngine();
+ engine.init(velocityProperties);
+ } catch(Exception e){
+ throw new BuildException("Error init velocity engine",e);
+ }
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() throws BuildException {
+ ArrayList arrayFiles = new ArrayList();
+
+ if (getSrcdir() != null) {
+ String directory = getSrcdir().toString();
+ String[] files = new File(directory).list(this);
+ for (int i = 0; i < files.length; i++) {
+ arrayFiles.add(directory + File.separatorChar + files[i]);
+ } // for
+ }
+
+ if (this.filesets.size() == 1) {
+ // deal with the filesets
+ for (int i = 0; i < this.filesets.size(); i++) {
+ FileSet fs = (FileSet) this.filesets.elementAt(i);
+ DirectoryScanner ds = null;
+ try {
+ ds = fs.getDirectoryScanner(getProject());
+ } catch (BuildException e) {
+ if (!e.getMessage().endsWith(" not found.")) {
+ throw e;
+ } else {
+ log("Warning: " + e.getMessage());
+ continue;
+ }
+ }
+
+ File fromDir = fs.getDir(getProject());
+
+ String[] srcFiles = ds.getIncludedFiles();
+
+ for (int j = 0; j < srcFiles.length; j++) {
+ String tempFile = fromDir.getAbsolutePath().toString()
+ + File.separator + srcFiles[j];
+ arrayFiles.add(tempFile);
+ }
+ }
+
+ }
+
+ if (arrayFiles.size() == 0) {
+ log("Empty list");
+ } else {
+ for (Iterator iter = arrayFiles.iterator(); iter.hasNext();) {
+ String file = (String) iter.next();
+ log("Processing file :'" + file + "'");
+ processTemplate(file);
+ }
+ }
+
+ }
+
+ /**
+ * Tests if a specified file should be included in a file list.
+ *
+ * @param dir
+ * the directory in which the file was found.
+ * @param name
+ * the name of the file.
+ * @return true if and only if the name should be included in the file list;
+ * false otherwise.
+ */
+ public boolean accept(File dir, String name) {
+ if (name.endsWith(TEMPLATE_FILE_EXT)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the classpath to be used for this compilation.
+ *
+ * @return Returns the classpath.
+ */
+ public Path getClasspath() {
+ return this.classPath;
+ }
+
+ /**
+ * Set the classpath to be used for this compilation
+ *
+ * @param classpath
+ * an Ant Path object containing the compilation classpath.
+ */
+ public void setClasspath(Path classpath) {
+ if (null == this.classPath) {
+ this.classPath = classpath;
+ } else {
+ this.classPath.add(classpath);
+ }
+ }
+
+ /**
+ * Adds a reference to a classpath defined elsewhere.
+ *
+ * @param ref
+ * a reference to a classpath
+ */
+ public void setClasspathRef(Reference ref) {
+ createClasspath().setRefid(ref);
+ }
+
+ /**
+ * Add a path to the classpath
+ *
+ * @return a class path to be configured
+ */
+ public Path createClasspath() {
+ Path classpath = new Path(getProject());
+ if (null == this.classPath) {
+ this.classPath = classpath;
+ } else {
+ this.classPath.add(classpath);
+ }
+ return classpath;
+ }
+
+ public Template getTemplate(String name) throws CompilationException {
+ Template template = _templates.get(name);
+ if(null == template){
+ try {
+ template = engine.getTemplate(name);
+ } catch (ResourceNotFoundException e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ } catch (ParseErrorException e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ } catch (Exception e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ }
+ _templates.put(name, template);
+ }
+ return template;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/AbstractCompilationContext.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/AbstractCompilationContext.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/AbstractCompilationContext.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,496 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+import java.beans.PropertyDescriptor;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.ElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElement;
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.w3c.dom.Node;
+
+/**
+ * Component Beam.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:42 $
+ *
+ */
+public abstract class AbstractCompilationContext implements CompilationContext {
+ final private static String VCPBODY = "VCPBODY";
+
+ final private static String regexComponent = "(.*)" + VCPBODY +
"(.*)"
+ + VCPBODY + "(.*)";
+
+ final private static Pattern patternComponent = Pattern.compile(
+ regexComponent, Pattern.UNIX_LINES + Pattern.DOTALL);
+
+ private final static String DEFAULT_BASE_CLASS =
"org.ajax4jsf.framework.renderer.RendererBase";
+
+ private String packageName;
+
+ private String className;
+
+ private String baseClassName;
+
+ private ArrayList<String> declarations;
+
+ private ArrayList<String> imports;
+
+ private String[] EncodeBegin;
+
+ private String[] EncodeEnd;
+
+ private String[] EncodeChildren;
+
+ private HashMap<String, Class> variables = new HashMap<String, Class>();
+
+ private static String[] defaultImports = new String[] {
+ "java.util.Iterator", "java.util.Collection",
+ "java.io.IOException", "javax.faces.component.UIComponent",
+ "javax.faces.context.FacesContext",
+ "javax.faces.context.ResponseWriter",
+ "org.ajax4jsf.framework.renderer.ComponentsVariableResolver",
+ "org.ajax4jsf.framework.renderer.ComponentVariables" };
+
+ private TemplateElement tree;
+
+ private ArrayList<ElementsFactory> elementFactories = new
ArrayList<ElementsFactory>();
+
+
+ /**
+ * Name of UIComponent class for this template - can be used for get properties and
methods by introspection.
+ */
+ private String componentClass;
+
+
+ /**
+ * Ant Task related classloader for loat UIComponent and Renderer classes for
introspection.
+ */
+ private ClassLoader classLoader;
+
+
+ public AbstractCompilationContext() {
+ this.baseClassName = DEFAULT_BASE_CLASS;
+ this.declarations = new ArrayList<String>();
+ this.imports = new ArrayList<String>();
+ this.imports.addAll(Arrays.asList(defaultImports));
+ // Init default elements factory.
+ this.elementFactories.add(new A4JRendererElementsFactory());
+ }
+
+ /**
+ * @param loader
+ * @throws CompilationException
+ */
+ public AbstractCompilationContext(ClassLoader loader) throws CompilationException {
+ this();
+ this.classLoader = loader;
+ setDefaultVariables();
+ }
+
+
+ public void addElementsFactory(ElementsFactory factory) {
+ elementFactories.add(0, factory);
+ }
+ /**
+ * @param componentClass
+ * The componentClass to set.
+ * @throws CompilationException
+ */
+ public void setComponentClass(String componentClass)
+ throws CompilationException {
+ this.componentClass = componentClass;
+ addVariable("component", componentClass);
+ }
+
+ /**
+ * set a package name
+ */
+ public void setPackageName(final String packageName) {
+ this.packageName = packageName;
+ }
+
+ /**
+ * set a class name
+ */
+ public void setClassName(final String className) {
+ this.className = className;
+ }
+
+ /**
+ *
+ * @param fullClassName
+ */
+ public void setFullClassName(final String fullClassName) {
+ int dotIndex = fullClassName.lastIndexOf(".");
+
+ String tempPackageName = "";
+ String tempClassName = fullClassName;
+
+ if (dotIndex != -1) {
+ tempPackageName = fullClassName.substring(0, dotIndex);
+ tempClassName = fullClassName.substring(dotIndex + 1);
+ } // if
+
+ setPackageName(tempPackageName);
+ setClassName(tempClassName);
+
+ }
+
+ public void setBaseclass(String baseclassName) throws CompilationException {
+ this.baseClassName = baseclassName;
+ addVariable("this", baseclassName);
+ }
+
+ // ------
+
+ /**
+ * @return package name
+ */
+ public String getPackageName() {
+ return this.packageName;
+ }
+
+ /**
+ * @return base class package name
+ */
+ public String getBaseclassPackageName() {
+ String packageName = null;
+ int dotIndex = this.baseClassName.lastIndexOf(".");
+
+ if (dotIndex != -1) {
+ packageName = this.baseClassName.substring(0, dotIndex);
+ }
+
+ return packageName;
+ }
+
+ /**
+ * @return class name
+ */
+ public String getClassName() {
+ return this.className;
+ }
+
+ /**
+ * @return base class package name
+ */
+ public String getBaseclassName() {
+ String className = null;
+
+ if ((this.baseClassName != null) && (this.baseClassName.length() != 0)) {
+ int dotIndex = this.baseClassName.lastIndexOf(".");
+
+ if (dotIndex != -1) {
+ className = this.baseClassName.substring(dotIndex + 1);
+ } else {
+ className = this.baseClassName;
+ }
+ }
+
+ return className;
+ }
+
+ /**
+ * @return full class name with package name
+ */
+ public String getFullClassName() {
+ StringBuffer buf = new StringBuffer();
+
+ if ((this.packageName != null) && (this.packageName.length() != 0)) {
+ buf.append(this.packageName);
+ buf.append('.');
+ }
+
+ buf.append(this.className);
+
+ return buf.toString();
+ }
+
+ /**
+ * @return base class package name
+ */
+ public String getFullBaseclass() {
+ return this.baseClassName;
+ }
+
+ /**
+ * @return
+ */
+ public String getComponentFileName() {
+ return getFullClassName().replace('.', '/');
+ }
+
+ /**
+ * @return Returns the componentClass.
+ */
+ public String getComponentClass() {
+ String returnStr = this.componentClass;
+
+ // if ( (componentClass != null) && ( !
+ // componentClass.endsWith(".class")) ) {
+ // returnStr = componentClass + ".class";
+ // }
+
+ return returnStr;
+ }
+
+ /**
+ * return class loader
+ */
+ public ClassLoader getClassLoader() {
+ return this.classLoader;
+ }
+
+ /**
+ * @return string array contain declarations
+ */
+ public String[] getDeclarations() {
+ return this.declarations.toArray(new String[0]);
+ }
+
+ /**
+ * @return string array contain declarations
+ */
+ public String[] getImports() {
+ return this.imports.toArray(new String[0]);
+ }
+
+ public void addToImport(String className) {
+ this.imports.add(className);
+ }
+
+ public void addToDeclaration(String declaration) {
+ this.declarations.add(declaration);
+ }
+
+ /**
+ * Add variable with type String
+ *
+ * @param variableName
+ * @throws CompilationException
+ */
+ public void addVariable(String variableName) throws CompilationException {
+ addVariable(variableName, "java.lang.String");
+ }
+
+ public void addVariable(String variableName, Class clazz) {
+ this.variables.put(variableName, clazz);
+ }
+
+ public void addVariable(String variableName, String typeName)
+ throws CompilationException {
+ try {
+ Class clazz = loadClass(typeName);
+ this.variables.put(variableName, clazz);
+ } catch (ClassNotFoundException e) {
+// error("Error create variable "+variableName+" with type
"+typeName, e);
+ throw new CompilationException("Error create renderer variable
"+variableName+" with type "+typeName, e);
+ }
+ }
+
+ public boolean containsVariable(String variableName) {
+ return this.variables.containsKey(variableName);
+ }
+
+ public Class getVariableType(String variableName) {
+ return this.variables.get(variableName);
+ }
+
+ public Class loadClass(String className) throws ClassNotFoundException {
+ Class clazz = null;
+ try {
+ clazz = this.classLoader.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ System.err.println("ClassNotFoundException message: "
+ + e.getMessage());
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+
+ if (null == clazz) {
+ System.out.println("Error load class: " + className);
+ throw new ClassNotFoundException();
+ }
+ return clazz;
+ }
+
+ public void setDefaultVariables() throws CompilationException {
+ addVariable("component", "javax.faces.component.UIComponent");
+ addVariable("context", "javax.faces.context.FacesContext");
+ addVariable("writer", "javax.faces.context.ResponseWriter");
+ // addLocalVariable("component",
"javax.faces.component.UIComponent" );
+ addVariable("variables",
+ "org.ajax4jsf.framework.renderer.ComponentVariables");
+ }
+
+ public Class getMethodReturnedClass(Class clazz, String methodName,
+ Class[] parametersTypes) {
+ Class returnedType = null;
+ System.out.println("class : " + clazz.getName() + "\n\t method : "
+ + methodName + "\n\t paramTypes : "
+ + Arrays.asList(parametersTypes).toString());
+
+ Method method = MethodUtils.getMatchingAccessibleMethod(clazz,
+ methodName, parametersTypes);
+
+ if (null != method) {
+ returnedType = method.getReturnType();
+ System.out.println("Method found, return type : "
+ + returnedType.getName());
+ } else {
+ System.out.println("Method not found");
+ }
+
+ return returnedType;
+ }
+
+ public PropertyDescriptor getPropertyDescriptor(Class clazz,
+ String propertyName) {
+ PropertyDescriptor returnValue = null;
+
+ PropertyDescriptor[] propertyDescriptors = PropertyUtils
+ .getPropertyDescriptors(clazz);
+
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ if (descriptor.getName().equals(propertyName)) {
+ returnValue = descriptor;
+ break;
+ }
+ }
+
+ return returnValue;
+ }
+
+ /**
+ *
+ */
+ public String[] getEncodeBegin() {
+ return this.EncodeBegin;
+ }
+
+ /**
+ *
+ */
+ public String[] getEncodeChild() {
+ return this.EncodeChildren;
+ }
+
+ /**
+ *
+ */
+ public String[] getEncodeEnd() {
+ return this.EncodeEnd;
+ }
+
+ public void setCode(String code) {
+
+ Matcher matcher = patternComponent.matcher(code);
+
+ String strEncodeBegin;
+ String strEncodeChildren;
+ String strEncodeEnd;
+
+ if (matcher.find()) {
+ strEncodeBegin = matcher.group(1);
+ strEncodeChildren = matcher.group(2);
+ strEncodeEnd = matcher.group(3);
+ } else {
+ strEncodeBegin = "";
+ strEncodeChildren = "";
+ strEncodeEnd = code;
+ }
+
+ if ((strEncodeBegin != null) && (strEncodeBegin.length() != 0)) {
+ this.EncodeBegin = strEncodeBegin.split(";\n");
+ }
+
+ if ((strEncodeChildren != null) && (strEncodeChildren.length() != 0)) {
+ this.EncodeChildren = strEncodeChildren.split(";\n");
+ }
+
+ if ((strEncodeEnd != null) && (strEncodeEnd.length() != 0)) {
+ this.EncodeEnd = strEncodeEnd.split(";\n");
+ }
+
+ }
+
+ /**
+ * @return the tree
+ */
+ public TemplateElement getTree() {
+ return this.tree;
+ }
+
+ /**
+ * @param tree the tree to set
+ */
+ public void setTree(TemplateElement tree) {
+ this.tree = tree;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.builder.CompilationContext#getProcessor(org.w3c.dom.Node)
+ */
+ public TemplateElement getProcessor(Node nodeElement) throws CompilationException {
+ for (Iterator<ElementsFactory> iter = elementFactories.listIterator();
iter.hasNext();) {
+ ElementsFactory factory = iter.next();
+ TemplateElement processor = factory.getProcessor(nodeElement, this);
+ if(null != processor){
+ return processor;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.builder.CompilationContext#processTemplate(java.lang.String,
org.apache.velocity.VelocityContext)
+ */
+ public String processTemplate(String name, VelocityContext context) throws
CompilationException {
+ StringWriter out = new StringWriter();
+ try {
+ getTemplate(name).merge(context, out);
+ } catch (ResourceNotFoundException e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ } catch (ParseErrorException e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ } catch (Exception e) {
+ throw new CompilationException(e.getLocalizedMessage());
+ }
+ return out.toString();
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationContext.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationContext.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationContext.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,148 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+import java.beans.PropertyDescriptor;
+
+import org.ajax4jsf.templatecompiler.elements.TemplateElement;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.Node;
+
+/**
+ * Component Beam.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:42 $
+ *
+ */
+public interface CompilationContext {
+ public void setComponentClass(String componentClass)
+ throws CompilationException;
+
+ public void setPackageName(final String packageName);
+
+ public void setClassName(final String className);
+
+ public void setFullClassName(final String fullClassName);
+
+ public void setBaseclass(String baseclassName) throws CompilationException;
+
+ public void setCode(String code);
+
+ public void addToImport(String className);
+
+ public void addToDeclaration(String declaration);
+
+ public ClassLoader getClassLoader();
+
+ public String getPackageName();
+
+ public String getBaseclassPackageName();
+
+ public String getClassName();
+
+ public String getBaseclassName();
+
+ public String getFullClassName();
+
+ public String getFullBaseclass();
+
+ public String getComponentFileName();
+
+ public String getComponentClass();
+
+ public String[] getDeclarations();
+
+ public String[] getImports();
+
+ /**
+ *
+ * @return
+ */
+ public String[] getEncodeBegin();
+
+ /**
+ *
+ * @return
+ */
+ public String[] getEncodeChild();
+
+ /**
+ *
+ * @return
+ */
+ public String[] getEncodeEnd();
+
+ /**
+ * Add variable
+ *
+ * @param variableName
+ * @throws CompilationException
+ */
+ public void addVariable(String variableName) throws CompilationException;
+
+ public void addVariable(String variableName, Class clazz);
+
+ public void addVariable(String variableName, String typeName)
+ throws CompilationException;
+
+ public boolean containsVariable(String variableName);
+
+ public Class getVariableType(String variableName);
+
+ public void setDefaultVariables() throws CompilationException;
+
+ public Class loadClass(String className) throws ClassNotFoundException;
+
+ public Class getMethodReturnedClass(Class clazz, String methodName,
+ Class[] parametersTypes);
+
+ public PropertyDescriptor getPropertyDescriptor(Class clazz,
+ String propertyName);
+
+ public TemplateElement getTree();
+
+ public void setTree(TemplateElement tree);
+
+
+ public abstract TemplateElement getProcessor(final Node nodeElement
+ ) throws CompilationException;
+
+// public abstract Attribute getAttributeProcessor(final Node attribute
+// ) throws CompilationException;
+
+ public abstract Template getTemplate(String name) throws CompilationException;
+
+ public abstract String processTemplate(String name, VelocityContext context) throws
CompilationException;
+
+ public void debug(String content);
+ public void debug(String content,Throwable error);
+ public void info(String content);
+ public void info(String content,Throwable error);
+ public void warn(String content);
+ public void warn(String content,Throwable error);
+ public void error(String content);
+ public void error(String content,Throwable error);
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationException.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationException.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/CompilationException.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,67 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+/**
+ * @author shura
+ *
+ */
+public class CompilationException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6045782920008419804L;
+
+ /**
+ *
+ */
+ public CompilationException() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public CompilationException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public CompilationException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public CompilationException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/StringUtils.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/StringUtils.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/StringUtils.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,123 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+/**
+ * String utilites.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:21 $
+ *
+ */
+public class StringUtils {
+ private static final int HEX_DIFF = 'A' - '9' - 1;
+
+ static public String getEscapedString(final String text) {
+ StringBuffer buf = new StringBuffer();
+
+ int i = 0;
+ while (i < text.length()) {
+ char c = text.charAt(i);
+ if (isalnum(c)) {
+ buf.append(c);
+ } else {
+ switch (c) {
+ case '"':
+ buf.append("\\\"");
+ break;
+ case '\n':
+ buf.append("\\n");
+ break;
+ default:
+ buf.append(c);
+ break;
+ }
+ }
+ i++;
+ }
+ return buf.toString();
+ }
+
+ /*
+ * static public String getEscapedString( final String text ) {
+ *
+ * StringBuffer buf = new StringBuffer();
+ *
+ * int i = 0; while ( i < text.length() ) { char c = text.charAt(i); if (
+ * isalnum( c ) ) buf.append( c ); else { switch (c) { case '@': case
'*':
+ * case '-': case '_': //case '+': case '.': case
'/': buf.append( c );
+ * break; default: buf.append( hex(c) ); break; } } i++; } return
+ * buf.toString(); }
+ */
+ /**
+ * Convert a <code>char</code> to a "<code>%hh</code>"
string.
+ *
+ * @param c
+ * char to convert
+ * @return <code>%hh</code> representation of char.
+ */
+ public static String hex(char c) {
+ int lsi = (c & 0x0F) + '0';
+ char lsd = (char) (lsi + ((lsi > '9') ? HEX_DIFF : 0));
+ int msi = (c >> 4) + '0';
+ char msd = (char) (msi + ((msi > '9') ? HEX_DIFF : 0));
+
+ return "%" + msd + lsd;
+ }
+
+ /**
+ * Returns true if the char isalpha() or isdigit().
+ */
+ public static boolean isalnum(char c) {
+ return (isalpha(c) || isdigit(c));
+ }
+
+ /**
+ * Returns true if the char isupper() or islower().
+ */
+ public static boolean isalpha(char c) {
+ return (isupper(c) || islower(c));
+ }
+
+ /**
+ * Returns true if the char is from 'A' to 'Z' inclusive.
+ */
+ public static boolean isupper(char c) {
+ return ((c >= 'A') && (c <= 'Z'));
+ }
+
+ /**
+ * Returns true if the char is from 'a' to 'z' inclusive.
+ */
+ public static boolean islower(char c) {
+ return ((c >= 'a') && (c <= 'z'));
+ }
+
+ /**
+ * Returns true if the char is from '0' to '9' inclusive.
+ */
+ public static boolean isdigit(char c) {
+ return ((c >= '0') && (c <= '9'));
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/TemplateCompiler.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/TemplateCompiler.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/TemplateCompiler.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,171 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.ajax4jsf.templatecompiler.elements.TemplateElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Template compiler.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/26 20:48:43 $
+ *
+ */
+public class TemplateCompiler {
+ final private static String CLASS_ATTRIBUTE = "class";
+
+ final private static String BASECLASS_ATTRIBUTE = "baseclass";
+
+ final private static String COMPONENT_CLASS_ATTRIBUTE = "component";
+
+ public static final String TEMPLATES_TEMPLATECOMPILER_PATH =
"META-INF/templates/templatecompiler";
+
+ public static final String TEMPLATES_PATH = "META-INF/templates";
+
+ final private static String TEMPLATE_FILE = "ComponentTemplate.vm";
+
+// private TreeCollectionElement treeElements = new TreeCollectionElement();
+
+ /**
+ * Processing input, contain a template
+ *
+ * @param input
+ * InputStream contain template
+ * @param componentBean
+ * @throws CompilationException
+ */
+ public void processing(InputStream input, CompilationContext componentBean)
+ throws CompilationException {
+
+ try {
+ Document xmlDocument = parseXml(input);
+
+ // Get Root xmlElement
+ Element rootElement = xmlDocument.getDocumentElement();
+
+ // Get Attributes
+ NamedNodeMap attributes = rootElement.getAttributes();
+ if (attributes != null) {
+ Node attributeClass = attributes.getNamedItem(CLASS_ATTRIBUTE);
+ if (attributeClass != null) {
+ componentBean.setFullClassName(attributeClass
+ .getNodeValue());
+ }
+ Node attributeBaseclass = attributes
+ .getNamedItem(BASECLASS_ATTRIBUTE);
+ if (attributeBaseclass != null) {
+ String nodeValue = attributeBaseclass.getNodeValue();
+ componentBean.setBaseclass(nodeValue);
+ }
+ // Name of base class for UIComponent rendered by template
+ Node componentClass = attributes
+ .getNamedItem(COMPONENT_CLASS_ATTRIBUTE);
+ if (componentClass != null) {
+ String nodeValue = componentClass.getNodeValue();
+ componentBean.setComponentClass(nodeValue);
+ }
+ }
+
+ componentBean.setTree(parseElement(rootElement,
+ componentBean));
+
+
+ } catch (Exception e) {
+ throw new CompilationException(e);
+ }
+ }
+
+ /**
+ * @param input
+ * @return
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ protected Document parseXml(InputStream input) throws ParserConfigurationException,
SAXException, IOException {
+ // Create Document Builder Factory
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory
+ .newInstance();
+
+ // Create Document Builder
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+
+ // open and parse XML-file
+ Document xmlDocument = docBuilder.parse(input);
+ return xmlDocument;
+ }
+
+ public void generateCode(CompilationContext componentBean,Writer out) throws
CompilationException {
+
+ try {
+ out.write(componentBean.getTree().toCode());
+ } catch (IOException e) {
+ throw new CompilationException(e);
+ }
+
+
+ }
+ /**
+ *
+ * @param element
+ * @param context
+ * @return
+ * @throws CompilationException
+ */
+ private TemplateElement parseElement(Node element,
+ CompilationContext context) throws CompilationException {
+ TemplateElement templateElement = null;
+ templateElement = context.getProcessor(element);
+
+ if (templateElement == null) {
+ return null;
+ }
+
+
+ if (!templateElement.isSkipBody()) {
+ NodeList subNodes = element.getChildNodes();
+
+ for (int iElement = 0; iElement != subNodes.getLength(); iElement++) {
+ Node subElement = subNodes.item(iElement);
+ templateElement.addSubElement(parseElement(subElement,
+ context));
+ } // for
+ }// if
+ return templateElement;
+
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/Variable.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/Variable.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/builder/Variable.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.builder;
+
+/**
+ * Interface for local and global variable references in EL expressions.
+ *
+ * @author shura
+ *
+ */
+public interface Variable {
+
+ public Class getType();
+
+ public String getName();
+
+ public String getReference();
+
+ public boolean isGlobal();
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/CompiledEL.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/CompiledEL.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/CompiledEL.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,143 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.el;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * @author yukhovich
+ *
+ */
+public class CompiledEL implements ICompiledEL {
+
+ class containedClass {
+ private Class type;
+
+ private String code;
+
+ public containedClass(String code, Class type) {
+ this.code = code;
+ this.type = type;
+ }
+
+ public Class getType() {
+ return this.type;
+ }
+
+ public String getCode() {
+ return this.code;
+ }
+
+ }
+
+ private ArrayList childs = new ArrayList();
+
+ private Class type;
+
+ private String code;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.el.ICompiledEL#getJavaCode()
+ */
+ public String getJavaCode() {
+ int i = 0;
+
+ ArrayList tmp = new ArrayList();
+ boolean bString = false;
+
+ for (Iterator iter = this.childs.iterator(); iter.hasNext(); i++) {
+ ICompiledEL element = (ICompiledEL) iter.next();
+
+ String tmpCode = element.getJavaCode();
+
+ if (null != element.getType()) {
+ if (String.class.isAssignableFrom(element.getType())) {
+ bString = true;
+ }
+
+ tmp.add(new containedClass(tmpCode, element.getType()));
+ }
+ }
+
+ if (null != this.code) {
+
+ if (String.class.isAssignableFrom(this.type)) {
+ bString = true;
+ }
+
+ tmp.add(new containedClass(this.code, this.type));
+ }
+
+ StringBuffer buf = new StringBuffer();
+
+ for (Iterator iter = tmp.iterator(); iter.hasNext();) {
+ containedClass element = (containedClass) iter.next();
+
+ if (String.class.isAssignableFrom(element.getType())) {
+ buf.append(element.getCode());
+ } else {
+ if (bString) {
+ buf.append("ConvertToString(").append(element.getCode())
+ .append(")");
+ }
+ }
+ if (iter.hasNext()) {
+ buf.append(" + ");
+ }
+
+ }
+
+ if (bString) {
+ this.type = String.class;
+ } else {
+ this.type = Object.class;
+ }
+
+ return buf.toString();
+ }
+
+ public void addChild(ICompiledEL child) {
+ this.childs.add(child);
+ }
+
+ public void setJavaCode(String string) {
+ setJavaCode(string, java.lang.String.class);
+ }
+
+ public void setJavaCode(String string, Class type) {
+ this.code = string;
+ this.type = type;
+
+ }
+
+ public void setString(String str) {
+ setJavaCode("\"" + str + "\"");
+ }
+
+ public Class getType() {
+ return this.type;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,508 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.el;
+
+import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.PropertyNotFoundException;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.StringUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+
+import com.sun.el.parser.ArithmeticNode;
+import com.sun.el.parser.AstBracketSuffix;
+import com.sun.el.parser.AstDeferredExpression;
+import com.sun.el.parser.AstDiv;
+import com.sun.el.parser.AstDotSuffix;
+import com.sun.el.parser.AstFunction;
+import com.sun.el.parser.AstIdentifier;
+import com.sun.el.parser.AstInteger;
+import com.sun.el.parser.AstLiteralExpression;
+import com.sun.el.parser.AstMinus;
+import com.sun.el.parser.AstMod;
+import com.sun.el.parser.AstMult;
+import com.sun.el.parser.AstPlus;
+import com.sun.el.parser.AstString;
+import com.sun.el.parser.AstValue;
+import com.sun.el.parser.ELParser;
+import com.sun.el.parser.Node;
+
+/**
+ * Compiler EL-expressions.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:12 $
+ *
+ */
+public class ELCompiler implements IELCompiler {
+
+ Map functionsMap = new HashMap();
+
+ static {
+ }
+
+ /**
+ *
+ */
+ public ELCompiler() {
+ super();
+ resetVariables();
+ }
+
+ /**
+ *
+ */
+ public void resetVariables() {
+ // maps.put("context", "javax.faces.context.FacesContext" );
+ // maps.put("component", "javax.faces.component.UIComponent" );
+ // maps.put("a4jSkin", "org.ajax4jsf.framework.skin.Skin" );
+
+ this.functionsMap.put("a4jSkin:getParameter",
+ "org.ajax4jsf.framework.skin.getParameter");
+ }
+
+ public String compileEL(String expression, CompilationContext componentBean) {
+ Node node = ELParser.parse(expression);
+ StringBuffer sbMain = new StringBuffer();
+ processNode(node, sbMain, componentBean);
+ return sbMain.toString();
+ }
+
+ /**
+ * Processing node
+ *
+ * @param node
+ * @param sbMain
+ * @param componentBean
+ */
+ private void processNode(Node node, StringBuffer sbMain,
+ CompilationContext componentBean) {
+ int numChildren = node.jjtGetNumChildren();
+
+ boolean bNeedConversion = false;
+ for (int i = 0; i < numChildren; i++) {
+ Node childNode = node.jjtGetChild(i);
+ if (childNode instanceof AstLiteralExpression) {
+ bNeedConversion = true;
+ break;
+ }
+ }
+
+ for (int i = 0; i < numChildren; i++) {
+ Node childNode = node.jjtGetChild(i);
+
+ if (childNode instanceof AstLiteralExpression) {
+ if (childNode.getImage() != null) {
+ if (i > 0) {
+ sbMain.append(" + ");
+ }
+ sbMain.append("\"");
+ sbMain.append(StringUtils.getEscapedString(childNode
+ .getImage()));
+ sbMain.append("\"");
+
+ if (i < (numChildren - 1)) {
+ sbMain.append(" + ");
+ }
+ }
+ } else {
+ if (bNeedConversion) {
+ sbMain.append("convertToString(");
+ }
+ boolean processing = processingNode(childNode, sbMain,
+ componentBean);
+ if (!processing) {
+ processNode(childNode, sbMain, componentBean);
+ }
+ if (bNeedConversion) {
+ sbMain.append(")");
+ }
+ }
+
+ }
+ }
+
+ /**
+ *
+ * @param node
+ * @param sbMain
+ * @param componentBean
+ * @param cMain
+ * @return
+ */
+ public boolean processingNode(Node node, StringBuffer sbMain,
+ CompilationContext componentBean) {
+ boolean returnValue = false;
+ if (node instanceof ArithmeticNode) {
+ returnValue = processingArithmeticNode((ArithmeticNode) node,
+ sbMain, componentBean);
+ } else if (node instanceof AstIdentifier) {
+ returnValue = processingIdentifier((AstIdentifier) node, sbMain,
+ componentBean);
+ } else if (node instanceof AstValue) {
+ returnValue = processingValue((AstValue) node, sbMain,
+ componentBean);
+ } else if (node instanceof AstInteger) {
+ returnValue = processingInteger((AstInteger) node, sbMain);
+ } else if (node instanceof AstString) {
+ returnValue = processingString((AstString) node, sbMain);
+ } else if (node instanceof AstFunction) {
+ returnValue = processingFunction((AstFunction) node, sbMain,
+ componentBean);
+ } else if (node instanceof AstDeferredExpression) {
+
+ } else {
+ StringBuffer sb = new StringBuffer();
+ sb.append(node.toString());
+ sb.append(" (");
+ sb.append(node.getClass().getName());
+ sb.append(")");
+ System.out.println(sb.toString());
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Processing arithmetic node
+ *
+ * @param node
+ * @param sb
+ * @param cMain
+ * @return
+ */
+ private boolean processingArithmeticNode(ArithmeticNode node,
+ StringBuffer sb, CompilationContext componentBean) {
+ StringBuffer sb1 = new StringBuffer();
+ StringBuffer sb2 = new StringBuffer();
+
+ boolean returnValue = false;
+
+ Node node1 = node.jjtGetChild(0);
+
+ if (node1 != null) {
+ if (!(returnValue = processingNode(node.jjtGetChild(0), sb1,
+ componentBean))) {
+ System.out.println("Error processing node1: "
+ + node.jjtGetChild(0).getImage());
+ }
+ }
+
+ if (!(returnValue = processingNode(node.jjtGetChild(1), sb2,
+ componentBean))) {
+ System.out.println("Error processing node2: "
+ + node.jjtGetChild(1).getImage());
+ }
+
+ if (returnValue) {
+ if (node1 != null) {
+ sb.append(" ( ");
+ }
+
+ sb.append(sb1);
+
+ if (node instanceof AstDiv) {
+ sb.append(" / ");
+ } else if (node instanceof AstMult) {
+ sb.append(" * ");
+ } else if (node instanceof AstMod) {
+ sb.append(" % ");
+ } else if (node instanceof AstPlus) {
+ sb.append(" + ");
+ } else if (node instanceof AstMinus) {
+ sb.append(" - ");
+ }
+
+ sb.append(sb2);
+
+ if (node1 != null) {
+ sb.append(" ) ");
+ }
+ }
+ return returnValue;
+ }
+
+ /**
+ * Processing node contain integer
+ *
+ * @param node
+ * @param sb
+ * @return
+ */
+ private boolean processingInteger(AstInteger node, StringBuffer sb) {
+ sb.append(node.getImage());
+ return true;
+ }
+
+ /**
+ * Processing node contain string
+ *
+ * @param node
+ * @param sb
+ * @return
+ */
+ private boolean processingString(AstString node, StringBuffer sb) {
+ sb.append("\"");
+ sb.append(node.getString());
+ sb.append("\"");
+ return true;
+ }
+
+ /**
+ *
+ * @param node
+ * @param sb
+ * @return
+ */
+ private boolean processingFunction(AstFunction node, StringBuffer sb,
+ CompilationContext componentBean) {
+
+ System.out.println("Processing function : " + node.getPrefix());
+ System.out.println("Processing function : " + node.getLocalName());
+ System.out.println("Processing function : " + node.getOutputName());
+
+ if (node.getPrefix().equals("this")) {
+ sb.append(node.getLocalName());
+ sb.append("(");
+ int numChildren = node.jjtGetNumChildren();
+ for (int i = 0; i < numChildren; i++) {
+ Node childNode = node.jjtGetChild(i);
+ StringBuffer buf = new StringBuffer();
+ processingNode(childNode, buf, componentBean);
+ if (i != 0) {
+ sb.append(",");
+ }
+ sb.append(buf);
+ }
+ sb.append(")");
+ } else {
+ String functionName = node.getOutputName();
+ if (this.functionsMap.containsKey(functionName)) {
+ sb.append(this.functionsMap.get(functionName));
+ sb.append("(");
+ int numChildren = node.jjtGetNumChildren();
+ for (int i = 0; i < numChildren; i++) {
+ Node childNode = node.jjtGetChild(i);
+ StringBuffer buf = new StringBuffer();
+ processingNode(childNode, buf, componentBean);
+ if (i != 0) {
+ sb.append(",");
+ }
+ sb.append(buf);
+ }
+ sb.append(")");
+ } // if
+ } // else
+ return true;
+ }
+
+ /**
+ *
+ * @param node
+ * @param sb
+ * @return
+ */
+ private boolean processingIdentifier(AstIdentifier node, StringBuffer sb,
+ CompilationContext componentBean) {
+ String variableName = node.getImage();
+ if (componentBean.containsVariable(variableName)) {
+ sb.append(variableName);
+ } else {
+ sb.append("variables.getVariable(\"");
+ sb.append(variableName);
+ sb.append("\")");
+ }
+
+ return true;
+ }
+
+ /**
+ *
+ * @param basketSuffix
+ * @return
+ */
+ private String processingBracketSuffix(AstBracketSuffix basketSuffix,
+ CompilationContext componentBean) {
+ StringBuffer sb = new StringBuffer();
+ Node node = basketSuffix.jjtGetChild(0);
+ if (node instanceof AstIdentifier) {
+ processingIdentifier((AstIdentifier) node, sb, componentBean);
+ } else if (node instanceof AstInteger) {
+ // sb.append("new Integer(");
+ sb.append(node.getImage());
+ // sb.append(")");
+ } else if (node instanceof AstString) {
+ AstString stringNode = (AstString) node;
+ sb.append("\"");
+ sb.append(stringNode.getString());
+ sb.append("\"");
+ } else {
+ sb.append("\"");
+ sb.append(node.getImage());
+ sb.append("\"");
+ }
+ return sb.toString();
+ }
+
+ /**
+ *
+ * @param clazz
+ * @param propertyName
+ * @return
+ */
+ private PropertyDescriptor getPropertyDescriptor(Class clazz,
+ String propertyName) {
+ PropertyDescriptor returnValue = null;
+
+ PropertyDescriptor[] propertyDescriptors = PropertyUtils
+ .getPropertyDescriptors(clazz);
+
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ if (descriptor.getName().equals(propertyName)) {
+ returnValue = descriptor;
+ break;
+ }
+ }
+
+ return returnValue;
+ }
+
+ private boolean processingValue(AstValue node, StringBuffer sb,
+ CompilationContext componentBean) {
+ String lastIndexValue = "NULL";
+ String lastVariableType = null;
+ ArrayList names = new ArrayList();
+
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ StringBuffer sb1 = new StringBuffer();
+ Node subChild = node.jjtGetChild(i);
+
+ if (subChild instanceof AstIdentifier) {
+ String variableName = subChild.getImage();
+ if (componentBean.containsVariable(variableName)) {
+ lastVariableType = componentBean.getVariableType(
+ variableName).getName();
+ names.add(variableName);
+ } else {
+ processingIdentifier((AstIdentifier) subChild, sb1,
+ componentBean);
+ }
+ } else if (subChild instanceof AstDotSuffix) {
+ String propertyName = subChild.getImage();
+ System.out.println("Object: " + lastVariableType
+ + ", property: " + propertyName);
+
+ if (lastVariableType != null) {
+ try {
+
+ Class clazz = componentBean.loadClass(lastVariableType);
+
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(
+ clazz, propertyName);
+
+ if (propertyDescriptor == null) {
+ throw new PropertyNotFoundException("property: "
+ + propertyName + " not found in class: "
+ + lastVariableType);
+ }
+
+ System.out.println("propertyObject: "
+ + propertyDescriptor.getPropertyType()
+ .getName());
+ StringBuffer tmpbuf = new StringBuffer();
+ tmpbuf.append(propertyDescriptor.getReadMethod()
+ .getName());
+ tmpbuf.append("()");
+ names.add(tmpbuf.toString());
+
+ lastVariableType = propertyDescriptor.getPropertyType()
+ .getName();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ } else {
+
+ sb1.append("getProperty(");
+ sb1.append(lastIndexValue);
+ sb1.append(",");
+ sb1.append("\"");
+ sb1.append(subChild.getImage());
+ sb1.append("\")");
+ }
+ } else if (subChild instanceof AstBracketSuffix) {
+ String bracketSuffix = processingBracketSuffix(
+ (AstBracketSuffix) subChild, componentBean);
+
+ if (lastVariableType != null) {
+ StringBuffer tmpbuf = new StringBuffer();
+ if (lastVariableType.startsWith("[L")) {
+ tmpbuf.append("[");
+ tmpbuf.append(bracketSuffix);
+ tmpbuf.append("]");
+ names.add(tmpbuf.toString());
+ }
+
+ if ((lastVariableType.compareTo("java.util.List") == 0)
+ || (lastVariableType.compareTo("java.util.Map") == 0)) {
+ tmpbuf.append("get(");
+ tmpbuf.append(bracketSuffix);
+ tmpbuf.append(")");
+ names.add(tmpbuf.toString());
+ }
+ } else {
+
+ sb1.append("getElelmentByIndex(");
+ sb1.append(lastIndexValue);
+ sb1.append(",");
+ sb1.append(bracketSuffix);
+ sb1.append(")");
+ }
+
+ }
+
+ }
+
+ if (names.size() != 0) {
+ StringBuffer tmpbuf = new StringBuffer();
+ for (Iterator iter = names.iterator(); iter.hasNext();) {
+ String element = (String) iter.next();
+ if (tmpbuf.length() != 0) {
+ tmpbuf.append(".");
+ }
+ tmpbuf.append(element);
+ }
+ sb.append(tmpbuf.toString());
+ } else {
+ sb.append(lastIndexValue);
+ }
+
+ return true;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELParser.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELParser.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELParser.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,94 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.el;
+
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.StringUtils;
+
+/**
+ * EL-parser.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:12 $
+ *
+ */
+public class ELParser {
+ private static final String SIMPLE_EXPRESSION = "\"%s\"";
+
+ private static ELParser elParser;
+
+ private IELCompiler elCompiler;
+
+ private ELParser() {
+ this.elCompiler = new ELCompiler();
+ }
+
+ private static ELParser getInstance() {
+ if (elParser == null) {
+ elParser = new ELParser();
+ }
+ return elParser;
+ }
+
+ public static String compileEL(String expression,
+ CompilationContext componentBean) {
+ return getInstance().getCompiledEL(expression, componentBean);
+ }
+
+ /**
+ *
+ * @param expression
+ * @return
+ */
+ public String getCompiledEL(String expression, CompilationContext componentBean) {
+ String returnValue;
+ if (isVBExpression(expression)) {
+ returnValue = this.elCompiler.compileEL(expression, componentBean);
+ } else {
+ Object[] parameters = new Object[1];
+ parameters[0] = StringUtils.getEscapedString(expression);
+ returnValue = new Formatter().format(SIMPLE_EXPRESSION, parameters)
+ .toString();
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Determine whether String is a value binding expression or not.
+ */
+ public static boolean isVBExpression(String expression) {
+ if (null == expression) {
+ return false;
+ }
+ int start = 0;
+ // check to see if attribute has an expression
+ if (((start = expression.indexOf("#{")) != -1)
+ && (start < expression.indexOf('}'))) {
+ return true;
+ }
+ return false;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ICompiledEL.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ICompiledEL.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ICompiledEL.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.el;
+
+/**
+ * @author yukhovich
+ *
+ */
+public interface ICompiledEL {
+ public void addChild(ICompiledEL child);
+
+ public String getJavaCode();
+
+ public Class getType();
+
+ public void setJavaCode(String string);
+
+ public void setJavaCode(String string, Class type);
+
+ public void setString(String escapedString);
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/IELCompiler.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/IELCompiler.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/IELCompiler.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,35 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.el;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+
+/**
+ * EL-parser.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:12 $
+ */
+public interface IELCompiler {
+ public String compileEL(String expression, CompilationContext componentBean);
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,166 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.html.CDATAElement;
+import org.ajax4jsf.templatecompiler.elements.html.CommentElement;
+import org.ajax4jsf.templatecompiler.elements.html.PIElement;
+import org.ajax4jsf.templatecompiler.elements.html.TextElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.HeaderScriptsElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.HeaderStylesElement;
+import org.w3c.dom.Node;
+
+/**
+ * Tag processors factory.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * maksimkaszynski $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:44 $
+ *
+ */
+public class A4JRendererElementsFactory implements ElementsFactory {
+
+ public static final String TEMPLATES_PATH = "META-INF/templates";
+
+ public static final String TEMPLATES_TEMPLATECOMPILER_PATH =
TEMPLATES_PATH+"/templatecompiler";
+
+ private final static String DEFAULT_CLASS_ELEMENT_PROCESSOR =
"org.ajax4jsf.templatecompiler.elements.html.HTMLElement";
+
+ private final static Class[] paramClasses = new Class[] { Node.class,
+ CompilationContext.class };
+
+ private final static HashMap<String, String> mapClasses = new HashMap<String,
String>();
+
+ static {
+ mapClasses
+ .put("c:set",
+ "org.ajax4jsf.templatecompiler.elements.std.SetTemplateElement");
+ mapClasses.put("c:if",
+ "org.ajax4jsf.templatecompiler.elements.std.IFTemplateElement");
+ mapClasses
+ .put("c:forEach",
+ "org.ajax4jsf.templatecompiler.elements.std.ForEachTemplateElement");
+ mapClasses
+ .put("f:clientid",
+ "org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement");
+ mapClasses
+ .put("f:clientId",
+ "org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement");
+ mapClasses.put("f:insertComponent",
+ "org.ajax4jsf.templatecompiler.elements.vcp.InsertComponent");
+
+ mapClasses
+ .put("f:call",
+ "org.ajax4jsf.templatecompiler.elements.vcp.FCallTemplateElement");
+ mapClasses
+ .put("f:resource",
+ "org.ajax4jsf.templatecompiler.elements.vcp.FResourceTemplateElement");
+
+ mapClasses
+ .put("u:insertFacet",
+ "org.ajax4jsf.templatecompiler.elements.vcp.UInsertFacetTemplateElement");
+
+ mapClasses
+ .put("vcp:body",
+ "org.ajax4jsf.templatecompiler.elements.vcp.VcpBodyTemplateElement");
+ mapClasses.put("vcp:mock", "");
+
+ mapClasses.put("jsp:scriptlet",
+ "org.ajax4jsf.templatecompiler.elements.jsp.Scriptlet");
+ mapClasses.put("jsp:declaration",
+ "org.ajax4jsf.templatecompiler.elements.jsp.Declaration");
+ mapClasses.put("jsp:directive.page",
+ "org.ajax4jsf.templatecompiler.elements.jsp.DirectivePage");
+ mapClasses.put("jsp:expression",
+ "org.ajax4jsf.templatecompiler.elements.jsp.Expression");
+ mapClasses.put("h:styles", HeaderStylesElement.class.getName());
+ mapClasses.put("h:scripts", HeaderScriptsElement.class.getName());
+ mapClasses.put("f:template", RootElement.class.getName());
+ mapClasses.put("f:root", RootElement.class.getName());
+ mapClasses.put("jsp:root", RootElement.class.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.elements.ElementsFactory#getProcessor(org.w3c.dom.Node,
org.ajax4jsf.templatecompiler.builder.CompilationContext)
+ */
+ public TemplateElement getProcessor(final Node nodeElement,
+ final CompilationContext componentBean) throws CompilationException {
+ TemplateElement returnValue = null;
+
+ short nodeType = nodeElement.getNodeType();
+ if (Node.CDATA_SECTION_NODE == nodeType) {
+ returnValue =new CDATAElement(nodeElement, componentBean);
+ } else if (Node.TEXT_NODE == nodeType) {
+ returnValue =new TextElement(nodeElement, componentBean);
+ } else if (Node.COMMENT_NODE == nodeType) {
+ returnValue =new CommentElement(nodeElement, componentBean);
+ } else if (Node.PROCESSING_INSTRUCTION_NODE == nodeType) {
+ returnValue =new PIElement(nodeElement, componentBean);
+ } else if (Node.ELEMENT_NODE == nodeType) {
+ String className = (String) mapClasses.get(nodeElement.getNodeName());
+
+ if (className == null) {
+ className = DEFAULT_CLASS_ELEMENT_PROCESSOR;
+ }
+
+ if (!className.equals("")) {
+ Class class1;
+ try {
+ System.out.println("loading class: " + className);
+
+ class1 = Class.forName(className);
+ Object[] objects = new Object[2];
+ objects[0] = nodeElement;
+ objects[1] = componentBean;
+
+ returnValue = (TemplateElement) class1.getConstructor(
+ paramClasses).newInstance(objects);
+ } catch (InstantiationException e) {
+ throw new CompilationException("InstantiationException: "
+ + e.getLocalizedMessage(), e);
+ } catch (IllegalAccessException e) {
+ throw new CompilationException("IllegalAccessException: "
+ + e.getLocalizedMessage(), e);
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ throw new CompilationException("InvocationTargetException: "
+ + e.getMessage(), e);
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ throw new CompilationException(" error loading class: "
+ + e.getLocalizedMessage());
+ }
+ }
+ }
+ return returnValue;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/Attribute.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/Attribute.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/Attribute.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+/**
+ * Interface for HTLM-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/02/26 20:48:44 $
+ *
+ */
+public interface Attribute {
+ public void copyValues(final Attribute src);
+
+ public String getName();
+
+ public String getValue();
+
+ public String getCode();
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/BodyElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/BodyElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/BodyElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,31 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+/**
+ * Marker interface for central body element ( for renderer, contain encodeChildren
method content )
+ * @author shura
+ *
+ */
+public interface BodyElement {
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/DeclarationElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/DeclarationElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/DeclarationElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,32 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+/**
+ * Marker interdace for {@link TemplateElement} processed as declaration, outside
+ * of encode... methods
+ * @author shura
+ *
+ */
+public interface DeclarationElement {
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsArray.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsArray.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsArray.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,55 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+
+/**
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:45 $
+ *
+ */
+class ElementsArray extends ArrayList<TemplateElement> {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public String toCode() throws CompilationException {
+ StringBuffer buf = new StringBuffer();
+
+ Iterator<TemplateElement> i = iterator();
+ boolean hasNext = i.hasNext();
+ while (hasNext) {
+ TemplateElement o = i.next();
+ if (o != null) {
+ buf.append(o.toCode());
+ }
+ hasNext = i.hasNext();
+ } // while
+ return buf.toString();
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsFactory.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsFactory.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/ElementsFactory.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,37 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public interface ElementsFactory {
+
+ public abstract TemplateElement getProcessor(final Node nodeElement,
+ final CompilationContext componentBean) throws CompilationException;
+
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/JSTLElementsFactory.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/JSTLElementsFactory.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/JSTLElementsFactory.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,43 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class JSTLElementsFactory implements ElementsFactory {
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.templatecompiler.elements.ElementsFactory#getProcessor(org.w3c.dom.Node,
org.ajax4jsf.templatecompiler.builder.CompilationContext)
+ */
+ public TemplateElement getProcessor(Node nodeElement,
+ CompilationContext componentBean) throws CompilationException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/RootElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/RootElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/RootElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,196 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.vcp.VcpBodyTemplateElement;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class RootElement extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/ComponentTemplate.vm";
+ private static final String ENCODE_BEGIN_TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/EncodeBegin.vm";
+ private static final String ENCODE_END_TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/EncodeEnd.vm";
+ private static final String ENCODE_CHILDREN_TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/EncodeChildren.vm";
+
+ final private static String regexComponent = "(.*)" +
VcpBodyTemplateElement.STR_VCB_BODY + "(.*)"
+ + VcpBodyTemplateElement.STR_VCB_BODY + "(.*)";
+
+ final private static Pattern patternComponent = Pattern.compile(
+ regexComponent, Pattern.UNIX_LINES + Pattern.DOTALL);
+
+ /**
+ * @param element
+ * @param componentBean
+ */
+ public RootElement(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+ // TODO apply global attributes
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("component", this.getComponentBean());
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElementBase#toCode()
+ */
+ public String toCode() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("component", this.getComponentBean());
+ StringBuffer code = new StringBuffer();
+ String beginElement = this.getBeginElement();
+ if (null != beginElement) {
+ code.append(beginElement);
+ code.append("\n");
+ }
+ StringBuffer declarationsCode = new StringBuffer();
+ StringBuffer methodCode = new StringBuffer();
+ for (ListIterator<TemplateElement> iter = getSubElements().listIterator();
iter.hasNext();) {
+ TemplateElement element = iter.next();
+ String toCode = element.toCode();
+ if(element instanceof DeclarationElement){
+ declarationsCode.append(toCode);
+ } /*else if(element instanceof BodyElement){
+ // All collected code put to encodeBegin method.
+ if (methodCode.length()>0) {
+ context.put("body", methodCode.toString());
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeBeginTemplateName(), context));
+ }
+ // If body contain any code, create encodeChildren method.
+ if (toCode.length()>0) {
+ context.put("body", toCode);
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeChildrenTemplateName(), context));
+ }
+ methodCode = new StringBuffer();
+ } */
+ else {
+ methodCode.append(toCode);
+ }
+ }
+
+ if (methodCode.length()>0) {
+
+ Matcher matcher = patternComponent.matcher(methodCode);
+
+ String strEncodeBegin;
+ String strEncodeChildren;
+ String strEncodeEnd;
+
+ if (matcher.find()) {
+ strEncodeBegin = matcher.group(1);
+ // put content before body element to encodeBegin
+ if (strEncodeBegin.trim().length()>0) {
+ context.put("body", strEncodeBegin);
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeBeginTemplateName(), context));
+ }
+ strEncodeChildren = matcher.group(2);
+ if (strEncodeChildren.trim().length()>0 ) {
+ // put content of body element
+ context.put("body", strEncodeChildren);
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeChildrenTemplateName(), context));
+ }
+
+ strEncodeEnd = matcher.group(3);
+ if(strEncodeEnd.trim().length()>0){
+ // All code after body put to encodeEnd method.
+ context.put("body", strEncodeEnd);
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeEndTemplateName(), context));
+ }
+ } else {
+ // All collected code put to encodeEnd method.
+ context.put("body", methodCode.toString());
+ code.append(this.getComponentBean().processTemplate(
+ getEncodeEndTemplateName(), context));
+ }
+ }
+ if(declarationsCode.length()>0){
+ code.append(declarationsCode);
+ }
+ String endElement = this.getEndElement();
+ if (endElement != null) {
+ code.append(endElement);
+ code.append("\n");
+ }
+ return code.toString();
+ }
+
+ /**
+ * @return
+ */
+ protected String getEncodeBeginTemplateName() {
+ return ENCODE_BEGIN_TEMPLATE;
+ }
+
+ /**
+ * @return
+ */
+ protected String getEncodeEndTemplateName() {
+ return ENCODE_END_TEMPLATE;
+ }
+ /**
+ * @return
+ */
+ protected String getEncodeChildrenTemplateName() {
+ return ENCODE_CHILDREN_TEMPLATE;
+ }
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() throws CompilationException {
+ // TODO Auto-generated method stub
+ return "\n}";
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,51 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import java.util.ArrayList;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+
+/**
+ * Intarace for tag processors.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:43 $
+ *
+ */
+public interface TemplateElement {
+ public String getBeginElement() throws CompilationException;
+
+ public String getEndElement() throws CompilationException;
+
+ public boolean isSkipBody();
+
+ public void addSubElement(TemplateElement e);
+
+ public String toCode() throws CompilationException;
+
+ /**
+ * @return the subElements
+ */
+ public ArrayList<TemplateElement> getSubElements();
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElementBase.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElementBase.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/TemplateElementBase.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,93 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.Node;
+
+/**
+ * Abstract base class for tag processors.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:44 $
+ */
+public abstract class TemplateElementBase implements TemplateElement {
+
+
+ private CompilationContext componentBean;
+
+ private ElementsArray subElements = new ElementsArray();
+
+
+ public TemplateElementBase(final Node element,
+ final CompilationContext componentBean) {
+ this.componentBean = componentBean;
+ };
+
+ public boolean isSkipBody() {
+ // by default, children process by compiler.
+ return false;
+ }
+
+ public void addSubElement(TemplateElement e) {
+ this.subElements.add(e);
+ }
+
+ public String toCode() throws CompilationException {
+ StringBuffer buf = new StringBuffer();
+
+ String beginElement = this.getBeginElement();
+ if (null != beginElement) {
+ buf.append(beginElement);
+ buf.append("\n");
+ }
+
+ if (this.subElements.size() != 0) {
+ buf.append(this.subElements.toCode());
+ }
+
+ String endElement = this.getEndElement();
+ if (endElement != null) {
+ buf.append(endElement);
+ buf.append("\n");
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * @return the componentBean
+ */
+ public CompilationContext getComponentBean() {
+ return componentBean;
+ }
+
+ /**
+ * @return the subElements
+ */
+ public ElementsArray getSubElements() {
+ return this.subElements;
+ }
+
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CDATAElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CDATAElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CDATAElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class CDATAElement extends TemplateElementBase {
+
+ private String htmlText;
+
+ public CDATAElement(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+ this.htmlText = element.getNodeValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() {
+ StringBuffer retValue = new StringBuffer();
+ if ((null != this.htmlText) && (this.htmlText.length() > 0)) {
+ retValue.append(" writer.write(\"<![CDATA[\");\n");
+ retValue.append(" writer.write(convertToString(").append(
+ ELParser.compileEL(this.htmlText, this.getComponentBean()))
+ .append("));\n");
+ retValue.append(" writer.write(\"]]>\");\n");
+ }
+ return retValue.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() {
+ // Do nothitg - text not have childs
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CommentElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CommentElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/CommentElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,70 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class CommentElement extends TemplateElementBase {
+
+ private String htmlText;
+
+ public CommentElement(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+ this.htmlText = element.getNodeValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() {
+ String retValue = null;
+ if ((null != this.htmlText) && (this.htmlText.length() > 0)) {
+ Object[] params = { ELParser.compileEL(this.htmlText, this.getComponentBean()) };
+ retValue = new Formatter().format(
+ "writer.writeComment(convertToString(%s));\n", params)
+ .toString();
+ }
+ return retValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() {
+ // Do nothitg - text not have childs
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLAttributes.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLAttributes.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLAttributes.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,63 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.ajax4jsf.templatecompiler.elements.Attribute;
+
+/**
+ * Processing HTLM-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:41 $
+ *
+ */
+public class HTMLAttributes {
+ private LinkedHashMap attributesMap = new LinkedHashMap();
+
+
+ public void addAttribute(String nameAttribute, String valueAttribute) {
+
+ Attribute attribute = HtmlAttributesFactory.getProcessor(
+ nameAttribute, valueAttribute);
+
+ if (attribute != null) {
+ Attribute oldElemet = (Attribute) this.attributesMap.get(attribute
+ .getName());
+
+ if (oldElemet != null) {
+ oldElemet.copyValues(attribute);
+ } else {
+ this.attributesMap.put(attribute.getName(), attribute);
+ }
+ } else {
+ System.out.println("attribute is null");
+ }
+ }
+
+ public Map getAttributes() {
+ return this.attributesMap;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,191 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing template HTLM-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:42 $
+ *
+ */
+public class HTMLElement extends TemplateElementBase {
+ final static private String PRE_TAG_NAME = "pre";
+
+ private static final String PASS_THRU_ATTR = "x:passThruWithExclusions";
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH
+ + "/HTMLElement.vm";
+
+ private String htmlTag;
+
+ private String htmlText;
+
+ private HTMLAttributes htmlAttributes = new HTMLAttributes();
+
+ private ArrayList passThruAttributes = null;
+
+ private CompilationContext componentBean;
+
+ /**
+ *
+ * @param element
+ * @param variables
+ */
+ public HTMLElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ this.passThruAttributes = null;
+ this.htmlTag = element.getNodeName();
+ this.componentBean = componentBean;
+ processingAttributes(element.getAttributes());
+ }
+
+ /**
+ * @return string contain
+ * @throws CompilationException
+ */
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("htmlTag", this.htmlTag);
+ context.put("htmlAttributes", this.htmlAttributes.getAttributes());
+ context.put("passThruAttributes", this.passThruAttributes);
+ if (this.htmlText != null) {
+ context.put("htmlText", this.htmlText);
+ }
+ return this.componentBean.processTemplate(getTemplateName(), context);
+
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ // TODO Auto-generated method stub
+ return TEMPLATE;
+ }
+
+ /**
+ * @return
+ */
+ public String getEndElement() {
+ String sReturnValue;
+
+ Object[] objects = new Object[1];
+ objects[0] = this.htmlTag;
+
+ sReturnValue = new
Formatter().format("writer.endElement(\"%s\");",
+ objects).toString();
+ return sReturnValue;
+ }
+
+ /**
+ *
+ * @param attributes
+ */
+ public void processingAttributes(NamedNodeMap attributes) {
+ if (attributes == null) {
+ return;
+ }
+
+ for (int iElement = 0; iElement != attributes.getLength(); iElement++) {
+ Node attribute = attributes.item(iElement);
+ String attributeName = attribute.getNodeName();
+ String attributeValue = attribute.getNodeValue();
+
+ if (attributeName.equals(PASS_THRU_ATTR)) {
+ processingPassThruAtrribute(attributeValue);
+ } else {
+ this.htmlAttributes.addAttribute(attributeName, ELParser
+ .compileEL(attributeValue, this.componentBean));
+ }
+
+ } // for
+ }
+
+ /**
+ *
+ * @param listPassThruAttributes
+ */
+ private void processingPassThruAtrribute(String listPassThruAttributes) {
+ this.passThruAttributes = new ArrayList();
+ ArrayList tempPassThruAttributes = HTMLTags.getAttributes(this.htmlTag);
+
+ String[] excludeAttributes = listPassThruAttributes.split(",");
+
+ Arrays.sort(excludeAttributes);
+
+ for (int i = 0; i < tempPassThruAttributes.size(); i++) {
+ String attr = (String) tempPassThruAttributes.get(i);
+
+ int iTemp = Arrays.binarySearch(excludeAttributes, attr);
+
+ if (iTemp < 0) {
+ this.passThruAttributes.add(attr);
+ } // if
+
+ } // for
+
+ Collections.sort(this.passThruAttributes);
+ }
+
+ /**
+ * Set a body text for HTML-tag
+ *
+ * @param nodeText
+ */
+ public void setText(final String nodeText) {
+ String tempStr = null;
+ // if TAG is not PRE test do not trim
+ if (nodeText.trim().length() != 0) {
+ if (this.htmlTag.compareToIgnoreCase(PRE_TAG_NAME) == 0) {
+ tempStr = nodeText;
+ } else {
+ tempStr = nodeText.trim();
+ }
+ }
+
+ if (null != tempStr) {
+ if (null == this.htmlText) {
+ this.htmlText = ELParser.compileEL(tempStr, this.componentBean);
+ } else {
+ this.htmlText = this.htmlText
+ + ELParser.compileEL(tempStr, this.componentBean);
+ }
+ }
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLTags.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLTags.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HTMLTags.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,73 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * @author yukhovich
+ *
+ */
+public class HTMLTags {
+ private static final String TEMPLATES_TEMPLATECOMPILER_TAGS_BIN =
"META-INF/templates/templatecompiler/tags.bin";
+
+ private static HashMap tags;
+
+ private static boolean b = false;
+
+ static {
+
+ InputStream is = HTMLTags.class.getClassLoader().getResourceAsStream(
+ TEMPLATES_TEMPLATECOMPILER_TAGS_BIN);
+ try {
+ ObjectInputStream in = new ObjectInputStream(is);
+
+ tags = (HashMap) in.readObject();
+
+ in.close();
+
+ b = true;
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static boolean getS() {
+ return b;
+ }
+
+ public static ArrayList getAttributes(String tagName) {
+ if (b) {
+ return (ArrayList) tags.get(tagName);
+ } else {
+ return null;
+ }
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HtmlAttributesFactory.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HtmlAttributesFactory.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/HtmlAttributesFactory.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,93 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+
+import org.ajax4jsf.templatecompiler.elements.Attribute;
+
+/**
+ * Factory for processing HTLM-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/02/26 20:48:42 $
+ *
+ */
+public class HtmlAttributesFactory {
+ private final static String DEFAULT_CLASS_ATTRIBUTE_PROCESSOR =
"org.ajax4jsf.templatecompiler.elements.html.attribute.HtmlAttribute";
+
+ private final static Class[] paramClasses = new Class[] { String.class,
+ String.class };
+
+ private final static HashMap mapClasses = new HashMap();
+
+ static {
+ // mapClasses.put("x:passThruWithExclusions",
+ //
"org.ajax4jsf.templatecompiler.elements.html.attribute.PassThruWithExclusions");
+ mapClasses.put("x:otherParameters", "");
+ }
+
+ public static Attribute getProcessor(String attributeName,
+ String attributeValue) {
+ Attribute returnValue = null;
+
+ String className = (String) mapClasses.get(attributeName);
+
+ if (className == null) {
+ className = DEFAULT_CLASS_ATTRIBUTE_PROCESSOR;
+ }
+
+ if (!className.equals("")) {
+ Class class1;
+ try {
+ class1 = Class.forName(className);
+ try {
+ try {
+ Object[] objects = new Object[2];
+ objects[0] = attributeName;
+ objects[1] = attributeValue;
+ returnValue = (Attribute) class1.getConstructor(
+ paramClasses).newInstance(objects);
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ } catch (ClassNotFoundException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ return returnValue;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/PIElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/PIElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/PIElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,68 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class PIElement extends TemplateElementBase {
+
+ private String htmlText;
+
+ public PIElement(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+ this.htmlText = element.getNodeValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() {
+ StringBuffer retValue = new StringBuffer();
+ if ((null != this.htmlText) && (this.htmlText.length() > 0)) {
+ retValue.append(" writer.write(\"<![CDATA[\");\n");
+ retValue.append(" writer.write(").append(
+ ELParser.compileEL(this.htmlText,
this.getComponentBean())).append(");\n");
+ retValue.append(" writer.write(\"]]>\");\n");
+ }
+ return null; // retValue.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() {
+ // Do nothitg - text not have childs
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/TextElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/TextElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/TextElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,70 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html;
+
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * @author shura
+ *
+ */
+public class TextElement extends TemplateElementBase {
+
+ private String htmlText;
+
+ public TextElement(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+ this.htmlText = element.getNodeValue().trim();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getBeginElement()
+ */
+ public String getBeginElement() {
+ String retValue = null;
+ if ((null != this.htmlText) && (this.htmlText.length() > 0)) {
+ Object[] params = { ELParser.compileEL(this.htmlText, this.getComponentBean()) };
+ retValue = new Formatter().format(
+ "writer.writeText(convertToString(%s),null);\n", params)
+ .toString();
+ }
+ return retValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.templatecompiler.elements.TemplateElement#getEndElement()
+ */
+ public String getEndElement() {
+ // Do nothitg - text not have childs
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/HtmlAttribute.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/HtmlAttribute.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/HtmlAttribute.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,109 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html.attribute;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.ajax4jsf.templatecompiler.elements.Attribute;
+
+/**
+ * Processing template simple HTLM-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/02/26 20:48:55 $
+ *
+ */
+public class HtmlAttribute implements Attribute {
+ final private static String regexAttributeName = "x:(.*)";
+
+ final private static Pattern patternAttributeName = Pattern
+ .compile(regexAttributeName);
+
+ private String name;
+
+ private String value;
+
+ private boolean isNoRewrite;
+
+ /**
+ *
+ * @param attributeName
+ * @param attributeValue
+ */
+ public HtmlAttribute(String attributeName, String attributeValue) {
+ Matcher mather = patternAttributeName.matcher(attributeName);
+
+ if (mather.find()) {
+ this.name = mather.group(1);
+ this.isNoRewrite = true;
+ } else {
+ this.name = attributeName;
+ this.isNoRewrite = false;
+ }
+ this.value = attributeValue;
+ }
+
+ /**
+ *
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ *
+ */
+ public String getValue() {
+ return this.value;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean isNoRewrite() {
+ return this.isNoRewrite;
+ }
+
+ /**
+ * copy values from
+ *
+ * @param src
+ */
+ public void copyValues(final Attribute src) {
+ if (src instanceof HtmlAttribute) {
+
+ if (!isNoRewrite()) {
+ this.value = ((HtmlAttribute) src).getValue();
+ this.isNoRewrite = ((HtmlAttribute) src).isNoRewrite();
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public String getCode() {
+ return null;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/PassThruWithExclusions.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/PassThruWithExclusions.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/html/attribute/PassThruWithExclusions.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,79 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.html.attribute;
+
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.elements.Attribute;
+
+/**
+ * Processing template PassThruWithExclusions-attributes.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/26 20:48:55 $
+ *
+ */
+public class PassThruWithExclusions implements Attribute {
+ private String name;
+
+ private String value;
+
+ public PassThruWithExclusions(String attributeName, String attributeValue) {
+ this.name = attributeName;
+ this.value = attributeValue;
+ }
+
+ public void copyValues(Attribute src) {
+ if (src instanceof PassThruWithExclusions) {
+ this.value = ((PassThruWithExclusions) src).getValue();
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public String getCode() {
+ String sReturnValue;
+
+ if (this.value.length() == 0) {
+ sReturnValue = "getUtils().encodePassThru(context, component);";
+ } else {
+ Object[] objects = new Object[1];
+ objects[0] = this.value;
+
+ sReturnValue = new Formatter()
+ .format(
+ "getUtils().encodePassThruWithExclusions(context, component,
\"%s\");",
+ objects).toString();
+
+ }
+
+ return sReturnValue;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Declaration.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Declaration.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Declaration.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,56 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.jsp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * Processing jsp:declaration-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:41 $
+ */
+public class Declaration extends TemplateElementBase {
+
+ public Declaration(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ if (element.getTextContent().length() != 0) {
+ componentBean.addToDeclaration(element.getTextContent());
+ }
+ }
+
+ public String getBeginElement() {
+ return null;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+ public boolean isSkipBody() {
+ // content processed by element
+ return true;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectiveInclude.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectiveInclude.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectiveInclude.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,51 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.jsp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * Processing jsp:directive.include-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:40 $
+ */
+public class DirectiveInclude extends TemplateElementBase {
+
+ public DirectiveInclude(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ System.out.println("text:" + element.getTextContent());
+ }
+
+ public String getBeginElement() {
+ return null;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectivePage.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectivePage.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/DirectivePage.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,71 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.jsp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing jsp:directive.page-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:52 $
+ */
+public class DirectivePage extends TemplateElementBase {
+ private static final String EXTENDS_ATTRIBUTE = "extends";
+
+ private static final String IMPORT_ATTRIBUTE = "import";
+
+ public DirectivePage(Node element, CompilationContext componentBean)
+ throws DOMException, CompilationException {
+ super(element, componentBean);
+
+ NamedNodeMap nnm = element.getAttributes();
+
+ Node nodeExtends = nnm.getNamedItem(EXTENDS_ATTRIBUTE);
+ if ((null != nodeExtends) && (nodeExtends.getNodeValue().length() != 0)) {
+ componentBean.setBaseclass(nodeExtends.getNodeValue());
+ }
+
+ Node nodeImports = nnm.getNamedItem(IMPORT_ATTRIBUTE);
+ if ((null != nodeImports) && (nodeImports.getNodeValue().length() != 0)) {
+ String[] imports = nodeImports.getNodeValue().split("\\,");
+ for (int i = 0; i < imports.length; i++) {
+ componentBean.addToImport(imports[i].trim());
+ } // for
+ } // if
+ }
+
+ public String getBeginElement() {
+ return null;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Expression.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Expression.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Expression.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,58 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.jsp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * Processing jsp:expression-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:41 $
+ */
+public class Expression extends TemplateElementBase {
+ private String expressionText;
+
+ public Expression(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ if (element.getTextContent().length() != 0) {
+ this.expressionText = element.getTextContent();
+ }
+ }
+
+ public String getBeginElement() {
+ return this.expressionText;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+ public boolean isSkipBody() {
+ // no content must be processed.
+ return true;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Scriptlet.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Scriptlet.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/jsp/Scriptlet.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,58 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.jsp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * Processing jsp:scriplet-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:17:41 $
+ */
+public class Scriptlet extends TemplateElementBase {
+ private String scripletText;
+
+ public Scriptlet(Node element, CompilationContext componentBean) {
+ super(element, componentBean);
+
+ if (element.getTextContent().length() != 0) {
+ this.scripletText = element.getTextContent();
+ }
+ }
+
+ public String getBeginElement() {
+ return this.scripletText;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+ public boolean isSkipBody() {
+ // text content processed by element
+ return true;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ForEachTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ForEachTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ForEachTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,120 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.std;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing c:forEach-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/26 20:48:39 $
+ */
+public class ForEachTemplateElement extends TemplateElementBase {
+ private static int indexForCollection = 0;
+
+ private static final String ATTRIBUTE_FROM = "begin";
+
+ private static final String ATTRIBUTE_TO = "end";
+
+ private String strItems;
+
+ private String strFrom;
+
+ private String strTo;
+
+ private String strThisVariable;
+
+ public ForEachTemplateElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ NamedNodeMap nnm = element.getAttributes();
+
+ Node varItem = nnm.getNamedItem("var");
+ this.strThisVariable = varItem.getNodeValue();
+
+ Node items = nnm.getNamedItem("items");
+ if (items != null) {
+ this.strItems = ELParser.compileEL(items.getNodeValue(), componentBean);
+ } else {
+ Node fromItem = nnm.getNamedItem(ATTRIBUTE_FROM);
+ Node toItem = nnm.getNamedItem(ATTRIBUTE_TO);
+
+ this.strFrom = ELParser
+ .compileEL(fromItem.getNodeValue(), componentBean);
+ this.strTo = ELParser.compileEL(toItem.getNodeValue(), componentBean);
+ }
+ }
+
+ /**
+ * @throws CompilationException
+ *
+ */
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ String templateName;
+ if (this.strItems != null) {
+ indexForCollection++;
+ templateName = getTemplate1Name();//"FORElement_1.vm");
+ context.put("items", this.strItems);
+ context.put("index", new Integer(indexForCollection));
+ } else {
+ templateName = getTemplate2Name();//"FORElement_2.vm");
+ context.put("from", this.strFrom);
+ context.put("to", this.strTo);
+ }
+
+ context.put("item", this.strThisVariable);
+ return this.getComponentBean().processTemplate(templateName, context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplate2Name() {
+ return
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/FORElement_1.vm";
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplate1Name() {
+ return
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/FORElement_2.vm";
+ }
+
+ /**
+ *
+ */
+ public String getEndElement() {
+ return "}";
+ }
+
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/IFTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/IFTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/IFTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,73 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.std;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing c:if-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:39 $
+ */
+public class IFTemplateElement extends TemplateElementBase {
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/IFElement.vm";
+ private String sExpression;
+
+
+ public IFTemplateElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ NamedNodeMap nnm = element.getAttributes();
+ String strTempExpression = nnm.getNamedItem("test").getNodeValue();
+ ;
+
+ this.sExpression = ELParser.compileEL(strTempExpression, componentBean);
+ }
+
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+
+ context.put("if", this.sExpression);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return "}";
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/SetTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/SetTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/SetTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,87 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.std;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing c:set-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:39 $
+ */
+public class SetTemplateElement extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/set.vm";
+
+ private String strThisVariable;
+
+ private String strExpression;
+
+
+ public SetTemplateElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ String strTempExpression;
+
+ NamedNodeMap nnm = element.getAttributes();
+ String sVariableName = nnm.getNamedItem("var").getNodeValue();
+ Node value = nnm.getNamedItem("value");
+
+ if (value != null) {
+ strTempExpression = value.getNodeValue();
+ } else {
+ strTempExpression = element.getTextContent();
+ }
+
+ this.strThisVariable = sVariableName;
+
+ this.strExpression = ELParser.compileEL(strTempExpression, componentBean);
+ }
+
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("variable", this.strThisVariable);
+ context.put("expression", this.strExpression);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FCallTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FCallTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FCallTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,323 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import java.beans.PropertyDescriptor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:call-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:47 $
+ */
+public class FCallTemplateElement extends TemplateElementBase {
+ private String functionName;
+
+ private String variable;
+
+ private String fullFunctionName;
+
+ private boolean useOnlyEnumeratingParaments;
+
+ private final static String FUNCTION_DELIMITER = "\\.";
+
+ private final static String VAR_ATTRIBUTE_NAME = "var";
+
+ private final static String FUNCTION_NAME_ATTRIBUTE_NAME = "name";
+
+ private final static String USE_ONLY_THIS_PARAMETERS =
"use_only_this_parameters";
+
+ private final static String[][] PARAM_NAMES = new String[][] {
+ { "context" }, { "context", "component" } };
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/insertCall.vm";
+
+
+ private ArrayList parameters;
+
+ public FCallTemplateElement(final Node element,
+ final CompilationContext componentBean) throws CompilationException {
+ super(element, componentBean);
+
+ this.useOnlyEnumeratingParaments = false;
+
+ NamedNodeMap nnm = element.getAttributes();
+ Node functionNameNode = nnm.getNamedItem(FUNCTION_NAME_ATTRIBUTE_NAME);
+
+ if (functionNameNode != null) {
+ this.functionName = functionNameNode.getNodeValue();
+ } else {
+ throw new CompilationException("function name is not set");
+ }
+
+ Node nodeUseOnlyThisParameters = nnm
+ .getNamedItem(USE_ONLY_THIS_PARAMETERS);
+ if (nodeUseOnlyThisParameters != null) {
+ this.useOnlyEnumeratingParaments = Boolean
+ .getBoolean(nodeUseOnlyThisParameters.getNodeValue());
+ } // if
+
+ // read name of variable if need
+ Node variableName = nnm.getNamedItem(VAR_ATTRIBUTE_NAME);
+ if (variableName != null) {
+ this.variable = variableName.getNodeValue();
+ } // if
+
+ // read name of parameters if need
+ ParameterProcessor parameterProcessor = new ParameterProcessor(element,
+ componentBean);
+
+ this.parameters = parameterProcessor.getParameters();
+ System.out.println(this.parameters);
+
+ List decodeFunctionName = null;
+
+ decodeFunctionName = Arrays.asList(this.functionName
+ .split(FUNCTION_DELIMITER));
+ if (null == decodeFunctionName) {
+ decodeFunctionName = new ArrayList();
+ decodeFunctionName.add(this.functionName);
+ }
+
+ ArrayList functionNames = new ArrayList();
+ String lastClassName = componentBean.getFullBaseclass();
+
+ for (Iterator iter = decodeFunctionName.iterator(); iter.hasNext();) {
+ String elementFunction = (String) iter.next();
+
+ try {
+ System.out.println("Try to load class : " + lastClassName);
+
+ Class clazz = componentBean.loadClass(lastClassName);
+
+ if (!iter.hasNext()) {
+ String method = getMethod(clazz, elementFunction);
+ if (method != null) {
+ System.out.println(method);
+ functionNames.add(method);
+ } else {
+ System.out.println("Method " + elementFunction
+ + " not found in class : " + lastClassName);
+ throw new CompilationException();
+ }
+
+ } else {
+ //
+ // Probing properties !!!!
+ //
+
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(
+ clazz, elementFunction);
+
+ if (propertyDescriptor != null) {
+ functionNames.add(propertyDescriptor.getReadMethod()
+ .getName()
+ + "()");
+ System.out.println("Property " + elementFunction
+ + " mapped to function : "
+ + propertyDescriptor.getReadMethod().getName());
+ lastClassName = propertyDescriptor.getPropertyType()
+ .getName();
+ } else {
+ System.out.println("Property " + elementFunction
+ + " not found in class : " + lastClassName);
+ throw new CompilationException();
+ }
+ }
+
+ } catch (Throwable e) {
+
+ System.out.println("Error load class : " + lastClassName + ", "
+ + e.getLocalizedMessage());
+ e.printStackTrace();
+ throw new CompilationException("Error load class : "
+ + lastClassName, e);
+ }
+
+ }
+
+ StringBuffer tmpbuf = new StringBuffer();
+ for (Iterator iter = functionNames.iterator(); iter.hasNext();) {
+ String tmpElement = (String) iter.next();
+ if (tmpbuf.length() != 0) {
+ tmpbuf.append(".");
+ }
+ tmpbuf.append(tmpElement);
+ }
+ this.fullFunctionName = tmpbuf.toString();
+
+ }
+
+ /**
+ *
+ * @param clazz
+ * @param propertyName
+ * @return
+ */
+ private PropertyDescriptor getPropertyDescriptor(Class clazz,
+ String propertyName) {
+ PropertyDescriptor returnValue = null;
+
+ PropertyDescriptor[] propertyDescriptors = PropertyUtils
+ .getPropertyDescriptors(clazz);
+
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ if (descriptor.getName().equals(propertyName)) {
+ returnValue = descriptor;
+ break;
+ }
+ }
+
+ return returnValue;
+ }
+
+ /**
+ *
+ * @param clazz
+ * @param propertyName
+ * @return
+ */
+ private String getMethod(Class clazz, String methodName)
+ throws ClassNotFoundException {
+ String returnValue = null;
+
+ Class[][] arrayParametersTypes = null;
+ if (this.useOnlyEnumeratingParaments) {
+ arrayParametersTypes = new Class[1][this.parameters.size()];
+ for (int i = 0; i < this.parameters.size(); i++) {
+ arrayParametersTypes[0][i] = ((Parameter) this.parameters
+ .get(i)).getType();
+ }
+
+ } else {
+
+ arrayParametersTypes = new Class[PARAM_NAMES.length + 1][];
+
+ for (int i = 0; i < arrayParametersTypes.length; i++) {
+ int addlength = 0;
+ if (i < PARAM_NAMES.length) {
+ addlength = PARAM_NAMES[i].length;
+ }
+
+ arrayParametersTypes[i] = new Class[addlength
+ + this.parameters.size()];
+ }
+
+ for (int i = 0; i < PARAM_NAMES.length; i++) {
+ for (int j = 0; j < PARAM_NAMES[i].length; j++) {
+ arrayParametersTypes[i][j] = this.getComponentBean()
+ .getVariableType(PARAM_NAMES[i][j]);
+ }
+ }
+
+ for (int i = 0; i < arrayParametersTypes.length; i++) {
+ int shift = 0;
+ if (i < PARAM_NAMES.length) {
+ shift = PARAM_NAMES[i].length;
+ }
+
+ for (int j = 0; j < this.parameters.size(); j++) {
+ Parameter parameter = (Parameter) this.parameters.get(j);
+ arrayParametersTypes[i][shift + j] = parameter.getType();
+ }
+ }
+
+ }
+
+ for (int i = 0; i < arrayParametersTypes.length; i++) {
+ if (null != this.getComponentBean().getMethodReturnedClass(clazz, methodName,
+ arrayParametersTypes[i])) {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append(methodName);
+ buffer.append("(");
+
+ int shift = 0;
+ if (i < PARAM_NAMES.length) {
+ shift = PARAM_NAMES[i].length;
+ }
+
+ for (int j = 0; j < arrayParametersTypes[i].length; j++) {
+ if (j > 0) {
+ buffer.append(", ");
+ }
+ if ((i < PARAM_NAMES.length) && (j < PARAM_NAMES[i].length)) {
+ buffer.append(PARAM_NAMES[i][j]);
+ } else {
+ Parameter parameter = (Parameter) this.parameters.get(j
+ - shift);
+ String tmp = ELParser.compileEL(parameter.getValue(),
+ this.getComponentBean());
+ buffer.append(tmp);
+ }
+ }
+ buffer.append(")");
+ returnValue = buffer.toString();
+ break;
+ }
+ } // for
+
+ return returnValue;
+ }
+
+ /**
+ * @throws CompilationException
+ *
+ */
+ public String getBeginElement() throws CompilationException {
+
+ VelocityContext context = new VelocityContext();
+ context.put("variableName", this.variable);
+ context.put("function", this.fullFunctionName);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ /**
+ *
+ */
+ public String getEndElement() {
+ return null;
+ }
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FClientIDTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FClientIDTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FClientIDTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import java.util.Formatter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:cliendId-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/21 17:16:20 $
+ */
+public class FClientIDTemplateElement extends TemplateElementBase {
+ private String strThisVariable;
+
+ private Class type;
+
+ public FClientIDTemplateElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+ NamedNodeMap nnm = element.getAttributes();
+ String sVariableName = nnm.getNamedItem("var").getNodeValue();
+
+ this.strThisVariable = sVariableName;
+
+ Class[] parameters = new Class[1];
+ parameters[0] = componentBean.getVariableType("context");
+
+ this.type = componentBean.getMethodReturnedClass(componentBean
+ .getVariableType("component"), "getClientId", parameters);
+
+ componentBean.addVariable(this.strThisVariable, this.type);
+ }
+
+ public String getBeginElement() {
+ String sReturnValue;
+
+ // Object[] objects = new Object[1];
+ // objects[0] = strThisVariable;
+
+ // sReturnValue = new Formatter().
+ // format(
+ //
"variables.setVariable(\"%s\",component.getClientId(context));",
+ // objects).toString();
+ Object[] objects = new Object[2];
+ objects[0] = this.type.getName();
+ objects[1] = this.strThisVariable;
+ sReturnValue = new Formatter().format(
+ "%s %s = component.getClientId(context);", objects).toString();
+ return sReturnValue;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FInsertChildren.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FInsertChildren.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FInsertChildren.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:insertChildren-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:48 $
+ */
+public class FInsertChildren extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/insertChildren.vm";
+
+ private static int numberOfIndex = 0;
+
+ private String indexExpression;
+
+ private String varExpression;
+
+
+ public FInsertChildren(Node element, final CompilationContext componentBean) {
+ super(element, componentBean);
+ NamedNodeMap nnm = element.getAttributes();
+ Node value = nnm.getNamedItem("index");
+
+ this.indexExpression = null;
+ this.varExpression = null;
+
+ if (value != null) {
+ this.indexExpression = value.getNodeValue();
+ } else {
+ value = nnm.getNamedItem("var");
+ if (value != null) {
+ this.varExpression = value.getNodeValue();
+ } // if
+ } // if
+
+ }
+
+ public String getBeginElement() throws CompilationException {
+ numberOfIndex++;
+
+ VelocityContext context = new VelocityContext();
+
+ context.put("indexChildren", new Integer(numberOfIndex));
+ context.put("ELIndex", this.indexExpression);
+ context.put("ELVar", this.varExpression);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FResourceTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FResourceTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/FResourceTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:resource-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/26 20:48:48 $
+ */
+public class FResourceTemplateElement extends TemplateElementBase {
+ private final static String VAR_ATTRIBUTE_NAME = "var";
+
+ private final static String NAME_ATTRIBUTE_NAME = "name";
+
+ private String name;
+
+ private String variable;
+
+ public FResourceTemplateElement(Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+ NamedNodeMap nnm = element.getAttributes();
+
+ Node classNode = nnm.getNamedItem(NAME_ATTRIBUTE_NAME);
+ Node variableNode = nnm.getNamedItem(VAR_ATTRIBUTE_NAME);
+
+ if (classNode != null) {
+ this.name = classNode.getNodeValue();
+ }
+
+ if (variableNode != null) {
+ this.variable = variableNode.getNodeValue();
+ }
+
+ }
+
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("variable", this.variable);
+ context.put("resourceURI", this.name);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/insertResource.vm";
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVariable() {
+ return variable;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderResourceElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderResourceElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderResourceElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,151 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.Node;
+
+/**
+ * @author Maksim Kaszynski Utility element for HeaderResourceRenderer-based
+ * templates Creates getXxx() methods with values set within it body
+ *
+ * Example <code>
+ *
<h:styles>/org/ajax4jsf/resource/style.css,/org/ajax4jsf/resource/style2.css</h:styles>
+ * </code>
+ * results in <br>
+ * <code>
+ * private final InternetResource[] styles = {
+ * getResource("/org/ajax4jsf/resource/style.css"),
+ * getResource(/org/ajax4jsf/resource/style2.css")
+ * };
+ *
+ * protected InternetResource [] getStyles() {
+ * return styles;
+ * }
+ * </code>
+ */
+public abstract class HeaderResourceElement extends TemplateElementBase {
+
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/headerResource.vm";
+
+ private static final String NEW = "new ";
+
+ private String[] keys;
+
+ private String[] resourcePaths;
+
+ public HeaderResourceElement(Node element, CompilationContext componentBean)
+ throws CompilationException {
+ super(element, componentBean);
+ String resourcesAsString = element.getTextContent();
+ if (resourcesAsString != null) {
+ StringTokenizer tokenizer = new StringTokenizer(resourcesAsString,
+ "\r\n\t,;");
+ List paths = new ArrayList(tokenizer.countTokens());
+ List keyz = new ArrayList(tokenizer.countTokens());
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ String path;
+
+ if (token.startsWith(NEW)) {
+ keyz.add(token);
+ int idx = token.indexOf('(');
+ if (idx != -1) {
+ path = token.substring(0, idx).substring(NEW.length()).trim();
+ } else {
+ path = token.substring(NEW.length()).trim();
+ }
+ } else {
+ keyz.add("getResource(\"" + token + "\")");
+ path = token;
+ }
+
+ paths.add(path);
+ }
+ this.keys = (String[]) keyz.toArray(new String[keyz.size()]);
+ this.resourcePaths = (String[]) paths.toArray(new String[paths.size()]);
+ }
+ componentBean
+ .addToImport("org.ajax4jsf.framework.resource.InternetResource");
+ componentBean.addToDeclaration(getContent());
+ }
+
+ private String getterMethodName(String propName) {
+ return "get" + Character.toUpperCase(propName.charAt(0))
+ + propName.substring(1);
+ }
+
+ protected String getGetterModifier() {
+ return "protected";
+ }
+
+ protected abstract String getPropertyName();
+
+ public String getBeginElement() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private String getContent() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ String propertyName = getPropertyName();
+
+ if (this.keys != null) {
+ context.put("resourceKeys", this.keys);
+ }
+
+ context.put("propertyGetterName", getterMethodName(propertyName));
+ context.put("property", propertyName);
+ context.put("getterModifier", getGetterModifier());
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isSkipBody() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public String[] getResourcePaths() {
+ return resourcePaths;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderScriptsElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderScriptsElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderScriptsElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,52 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.Node;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class HeaderScriptsElement extends HeaderResourceElement {
+
+ /**
+ * @param element
+ * @param componentBean
+ * @throws CompilationException
+ */
+ public HeaderScriptsElement(Node element, CompilationContext componentBean) throws
CompilationException {
+ super(element, componentBean);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.templatecompiler.elements.vcp.HeaderResourceElement#getPropertyName()
+ */
+ protected String getPropertyName() {
+ return "scripts";
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderStylesElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderStylesElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/HeaderStylesElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,42 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.Node;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class HeaderStylesElement extends HeaderResourceElement {
+
+ public HeaderStylesElement(Node element, CompilationContext componentBean) throws
CompilationException {
+ super(element, componentBean);
+ }
+
+ protected String getPropertyName() {
+ return "styles";
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/InsertComponent.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/InsertComponent.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/InsertComponent.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,89 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:insertComponent-tag.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:47 $
+ */
+public class InsertComponent extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/insertComponent.vm";
+
+ private static int numberOfIndex = 0;
+
+ private String indexExpression;
+
+ private String valueExpression;
+
+ public InsertComponent(Node element, final CompilationContext componentBean) {
+ super(element, componentBean);
+ NamedNodeMap nnm = element.getAttributes();
+ Node value = nnm.getNamedItem("index");
+
+ this.indexExpression = null;
+ this.valueExpression = null;
+
+ if (value != null) {
+ this.indexExpression = value.getNodeValue();
+ } else {
+ value = nnm.getNamedItem("value");
+ this.valueExpression = ELParser.compileEL(value.getNodeValue(),
+ componentBean);
+ } // if
+
+ }
+
+ public String getBeginElement() throws CompilationException {
+ numberOfIndex++;
+
+ VelocityContext context = new VelocityContext();
+
+ // context.put("indexChildren", new Integer(numberOfIndex));
+ // context.put("ELIndex", indexExpression);
+ context.put("value", this.valueExpression);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/Parameter.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/Parameter.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/Parameter.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,75 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+/**
+ * container class for storing information about f:parameter-tags.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:26 $
+ */
+public class Parameter {
+ private String value;
+
+ private Class type;
+
+ /**
+ *
+ * @param value
+ * @param type
+ */
+ public Parameter(final String value) {
+ this(value, String.class);
+ }
+
+ /**
+ *
+ * @param value
+ * @param type
+ */
+ public Parameter(final String value, final Class type) {
+ this.value = value;
+ this.type = type;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Class getType() {
+
+ return this.type;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getValue() {
+ return this.value;
+ }
+
+ public String toString() {
+ return "\n\tvalue: " + this.value + "\n\ttype: " + this.type;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/ParameterProcessor.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/ParameterProcessor.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/ParameterProcessor.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,94 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import java.util.ArrayList;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Processing f:parameter-tags.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author:
+ * alexeyyukhovich $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:47 $
+ */
+public class ParameterProcessor {
+ private final static String PARAMETER_NODE_NAME = "f:parameter";
+
+ private final static String PARAMETER_NODE_VALUE = "value";
+
+ private final static String PARAMETER_NODE_TYPE = "type";
+
+ private ArrayList arrayParameters = new ArrayList();
+
+ public ParameterProcessor(final Node element, CompilationContext componentBean)
+ throws CompilationException {
+ NodeList childNodes = element.getChildNodes();
+ if (childNodes != null) {
+ for (int iElement = 0; iElement < childNodes.getLength(); iElement++) {
+ Node childNode = childNodes.item(iElement);
+ if ((childNode.getNodeType() == Node.ELEMENT_NODE)
+ && (childNode.getNodeName().equals(PARAMETER_NODE_NAME))) {
+
+ element.removeChild(childNode);
+
+ NamedNodeMap attributes = childNode.getAttributes();
+
+ if (attributes != null) {
+ Node nodeValue = attributes
+ .getNamedItem(PARAMETER_NODE_VALUE);
+ Node nodeType = attributes
+ .getNamedItem(PARAMETER_NODE_TYPE);
+
+ if (nodeValue != null) {
+ Parameter param = null;
+
+ if (null != nodeType) {
+ Class parameterType;
+ try {
+ parameterType = componentBean
+ .loadClass(nodeType.getNodeValue());
+ } catch (ClassNotFoundException e) {
+ throw new CompilationException();
+ }
+ param = new Parameter(nodeValue.getNodeValue(),
+ parameterType);
+ } else {
+ param = new Parameter(nodeValue.getNodeValue());
+ }
+ this.arrayParameters.add(param);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public ArrayList getParameters() {
+ return this.arrayParameters;
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/UInsertFacetTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/UInsertFacetTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/UInsertFacetTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,77 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import java.io.StringWriter;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing f:insertFacet-tags.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/26 20:48:48 $
+ */
+public class UInsertFacetTemplateElement extends TemplateElementBase {
+ private static int numberOfFaced = 0;
+
+ private String nameOfElement;
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/insertFacet.vm";
+
+ public UInsertFacetTemplateElement(Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ NamedNodeMap nnm = element.getAttributes();
+ Node value = nnm.getNamedItem("name");
+ this.nameOfElement = value.getNodeValue();
+ }
+
+ public String getBeginElement() throws CompilationException {
+
+ numberOfFaced++;
+
+ VelocityContext context = new VelocityContext();
+ StringWriter strW = new StringWriter();
+ context.put("index", new Integer(numberOfFaced));
+ context.put("FacetName", this.nameOfElement);
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/VcpBodyTemplateElement.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/VcpBodyTemplateElement.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/vcp/VcpBodyTemplateElement.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.vcp;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.elements.BodyElement;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.w3c.dom.Node;
+
+/**
+ * Processing vcp:body-tags.
+ *
+ * @author ayukhovich(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.3 $ $Date: 2007/02/26 20:48:46 $
+ */
+public class VcpBodyTemplateElement extends TemplateElementBase implements BodyElement {
+ public final static String STR_VCB_BODY = "VCPBODY";
+
+ public VcpBodyTemplateElement(Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+ }
+
+ public String getBeginElement() {
+ return STR_VCB_BODY;
+ }
+
+ public String getEndElement() {
+ return STR_VCB_BODY;
+ }
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/CallbackListener.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/CallbackListener.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/CallbackListener.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,59 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.utils;
+
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Martin Marinschek
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:39 $ <p/> $Log:
+ * CallbackListener.java,v $ Revision 1.1 2006/07/05 08:53:39
+ * alexsmirnov Refactor filter system ( move different functions for
+ * different classes ). Fix encoding for AJAX responses - forced to
+ * UTF-8 Fix issue #5 from tracker Fix error message for xml parsing.
+ *
+ */
+public interface CallbackListener {
+ void openedStartTag(int charIndex, int tagIdentifier);
+
+ void closedStartTag(int charIndex, int tagIdentifier);
+
+ void openedEndTag(int charIndex, int tagIdentifier);
+
+ void closedEndTag(int charIndex, int tagIdentifier);
+
+ void attribute(int charIndex, int tagIdentifier, String key, String value);
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/ReducedHTMLParser.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/ReducedHTMLParser.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/utils/ReducedHTMLParser.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,624 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.utils;
+
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A class which detects the open/close tags in an HTML document and reports
+ * them to a listener class.
+ * <p>
+ * This is unfortunately necessary when using JSF with JSP, as tags in the body
+ * of the document can need to output commands into the document at points
+ * earlier than the tag occurred (particularly into the document HEAD section).
+ * This can only be implemented by buffering the response and post-processing it
+ * to find the relevant HTML tags and modifying the buffer as needed.
+ * <p>
+ * This class tries to do the parsing as quickly as possible; many of the
+ * details of HTML are not relevant for the purposes this class is used for.
+ *
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:39 $
+ */
+public class ReducedHTMLParser {
+ // IMPLEMENTATION NOTE:
+ //
+ // Many of the methods on this class are package-scope. This is intended
+ // solely for the purpose of unit-testing. This class does not expect
+ // other classes in this package to access its methods.
+
+ private static final Log log = LogFactory.getLog(ReducedHTMLParser.class);
+
+ public static final int BODY_TAG = 0;
+
+ public static final int HEAD_TAG = 1;
+
+ public static final int SCRIPT_TAG = 2;
+
+ private static final int STATE_READY = 0;
+
+ private static final int STATE_IN_COMMENT = 1;
+
+ private static final int STATE_IN_TAG = 2;
+
+ private static final int STATE_IN_MARKED_SECTION = 3;
+
+ private static final int STATE_EXPECTING_ETAGO = 4;
+
+ private int _offset;
+
+ private int _lineNumber;
+
+ private CharSequence _seq;
+
+ private CallbackListener _listener;
+
+ public static void parse(CharSequence seq, CallbackListener l) {
+ new ReducedHTMLParser(seq, l).parse();
+ }
+
+ /**
+ * Constructor, package-scope for unit testing.
+ *
+ * @param s
+ * is the sequence of chars to parse.
+ * @param l
+ * is the listener to invoke callbacks on.
+ */
+ ReducedHTMLParser(CharSequence s, CallbackListener l) {
+ this._seq = s;
+ this._listener = l;
+ }
+
+ /**
+ * Return true if there are no more characters to parse.
+ */
+ boolean isFinished() {
+ return this._offset >= this._seq.length();
+ }
+
+ int getCurrentLineNumber() {
+ return this._lineNumber;
+ }
+
+ /**
+ * Advance the current parse position over any whitespace characters.
+ */
+ void consumeWhitespace() {
+ boolean crSeen = false;
+
+ while (this._offset < this._seq.length()) {
+ char c = this._seq.charAt(this._offset);
+ if (!Character.isWhitespace(c)) {
+ break;
+ }
+
+ // Track line number for error messages.
+ if (c == '\r') {
+ ++this._lineNumber;
+ crSeen = true;
+ } else if ((c == '\n') && !crSeen) {
+ ++this._lineNumber;
+ } else {
+ crSeen = false;
+ }
+
+ ++this._offset;
+ }
+ }
+
+ /**
+ * Eat up a sequence of non-whitespace characters and return them.
+ */
+ String consumeNonWhitespace() {
+ int wordStart = this._offset;
+ while (this._offset < this._seq.length()) {
+ char c = this._seq.charAt(this._offset);
+ if (Character.isWhitespace(c)) {
+ break;
+ }
+ ++this._offset;
+ }
+ if (wordStart == this._offset) {
+ return null;
+ } else {
+ return this._seq.subSequence(wordStart, this._offset).toString();
+ }
+ }
+
+ /**
+ * If the next chars in the input sequence exactly match the specified
+ * string then skip over them and return true.
+ * <p>
+ * If there is not a match then leave the current parse position unchanged
+ * and return false.
+ *
+ * @param s
+ * is the exact string to match.
+ * @return true if the input contains exactly the param s
+ */
+ boolean consumeMatch(String s) {
+ if (this._offset + s.length() > this._seq.length()) {
+ // seq isn't long enough to contain the specified string
+ return false;
+ }
+
+ int i = 0;
+ while (i < s.length()) {
+ if (this._seq.charAt(this._offset + i) == s.charAt(i)) {
+ ++i;
+ } else {
+ return false;
+ }
+ }
+
+ this._offset += i;
+ return true;
+ }
+
+ /**
+ * Eat up a sequence of chars which form a valid XML element name.
+ * <p>
+ * TODO: implement this properly in compliance with spec
+ */
+ String consumeElementName() {
+ consumeWhitespace();
+ int nameStart = this._offset;
+ while (!isFinished()) {
+ boolean ok = false;
+ char c = this._seq.charAt(this._offset);
+ if (Character.isLetterOrDigit(this._seq.charAt(this._offset))) {
+ ok = true;
+ } else if (c == '_') {
+ ok = true;
+ } else if (c == '-') {
+ ok = true;
+ } else if (c == ':') {
+ ok = true;
+ }
+
+ if (!ok) {
+ break;
+ }
+
+ ++this._offset;
+ }
+
+ if (nameStart == this._offset) {
+ return null;
+ } else {
+ return this._seq.subSequence(nameStart, this._offset).toString();
+ }
+ }
+
+ /**
+ * Eat up a sequence of chars which form a valid XML attribute name.
+ * <p>
+ * TODO: implement this properly in compliance with spec
+ */
+ String consumeAttrName() {
+ // for now, assume elements and attributes have same rules
+ return consumeElementName();
+ }
+
+ /**
+ * Eat up a string which is terminated with the specified quote character.
+ * This means handling escaped quote chars within the string.
+ * <p>
+ * This method assumes that the leading quote has already been consumed.
+ */
+ String consumeString(char quote) {
+ // TODO: should we consider a string to be terminated by a newline?
+ // that would help with runaway strings but I think that multiline
+ // strings *are* allowed...
+ //
+ // TODO: detect newlines within strings and increment lineNumber.
+ // This isn't so important, though; they aren't common and being a
+ // few lines out in an error message isn't serious either.
+ StringBuffer stringBuf = new StringBuffer();
+ boolean escaping = false;
+ while (!isFinished()) {
+ char c = this._seq.charAt(this._offset);
+ ++this._offset;
+ if (c == quote) {
+ if (!escaping) {
+ break;
+ } else {
+ stringBuf.append(c);
+ escaping = false;
+ }
+ } else if (c == '\\') {
+ if (escaping) {
+ // append a real backslash
+ stringBuf.append(c);
+ escaping = false;
+ } else {
+ escaping = true;
+ }
+ } else {
+ stringBuf.append(c);
+ }
+ }
+ return stringBuf.toString();
+ }
+
+ /**
+ * Assuming we have already encountered "attrname=", consume the value part
+ * of the attribute definition. Note that unlike XML, HTML doesn't have to
+ * quote its attribute values.
+ *
+ * @return the attribute value. If the attr-value was quoted, the returned
+ * value will not include the quote chars.
+ */
+ String consumeAttrValue() {
+ consumeWhitespace();
+ if (consumeMatch("'")) {
+ return consumeString('\'');
+ } else if (consumeMatch("\"")) {
+ return consumeString('"');
+ } else {
+ return consumeNonWhitespace();
+ }
+ }
+
+ /**
+ * Discard all characters in the input until one in the specified string
+ * (character-set) is found.
+ *
+ * @param s
+ * is a set of characters that should not be discarded.
+ */
+ void consumeExcept(String s) {
+ boolean crSeen = false;
+
+ while (this._offset < this._seq.length()) {
+ char c = this._seq.charAt(this._offset);
+ if (s.indexOf(c) >= 0) {
+ // char is in the exception set
+ return;
+ }
+
+ // Track line number for error messages.
+ if (c == '\r') {
+ ++this._lineNumber;
+ crSeen = true;
+ } else if ((c == '\n') && !crSeen) {
+ ++this._lineNumber;
+ } else {
+ crSeen = false;
+ }
+
+ // Track line number for error messages.
+ if (c == '\r') {
+ ++this._lineNumber;
+ crSeen = true;
+ } else if ((c == '\n') && !crSeen) {
+ ++this._lineNumber;
+ } else {
+ crSeen = false;
+ }
+
+ ++this._offset;
+ }
+ }
+
+ /**
+ * Process the entire input buffer, invoking callbacks on the listener
+ * object as appropriate.
+ */
+ void parse() {
+ int state = STATE_READY;
+
+ int currentTagStart = -1;
+ String currentTagName = null;
+
+ this._lineNumber = 1;
+ this._offset = 0;
+ int lastOffset = this._offset - 1;
+ while (this._offset < this._seq.length()) {
+ // Sanity check; each pass through this loop must increase the
+ // offset.
+ // Failure to do this means a hang situation has occurred.
+ if (this._offset <= lastOffset) {
+ // throw new RuntimeException("Infinite loop detected in
+ // ReducedHTMLParser");
+ log
+ .error("Infinite loop detected in ReducedHTMLParser; parsing skipped");
+ // return;
+ }
+ lastOffset = this._offset;
+
+ if (state == STATE_READY) {
+ // in this state, nothing but "<" has any significance
+ consumeExcept("<");
+ if (isFinished()) {
+ break;
+ }
+
+ if (consumeMatch("<!--")) {
+ // Note that whitespace is *not* permitted in <!--
+ state = STATE_IN_COMMENT;
+ } else if (consumeMatch("<![")) {
+ // Start of a "marked section", eg "<![CDATA" or
+ // "<![INCLUDE" or "<![IGNORE". These always terminate
+ // with "]]>"
+ log.debug("Marked section found at line "
+ + getCurrentLineNumber());
+ state = STATE_IN_MARKED_SECTION;
+ } else if (consumeMatch("<!DOCTYPE")) {
+ log
+ .debug("DOCTYPE found at line "
+ + getCurrentLineNumber());
+ // we don't need to actually do anything here; the
+ // tag can't contain a bare "<", so the first "<"
+ // indicates the start of the next real tag.
+ //
+ // TODO: Handle case where the DOCTYPE includes an internal
+ // DTD. In
+ // that case there *will* be embedded < chars in the
+ // document. However
+ // that's very unlikely to be used in a JSF page, so this is
+ // pretty low
+ // priority.
+ } else if (consumeMatch("<?")) {
+ // xml processing instruction or <!DOCTYPE> tag
+ // we don't need to actually do anything here; the
+ // tag can't contain a bare "<", so the first "<"
+ // indicates the start of the next real tag.
+ log.debug("PI found at line " + getCurrentLineNumber());
+ } else if (consumeMatch("</")) {
+ if (!processEndTag()) {
+ // message already logged
+ return;
+ }
+
+ // stay in state READY
+ state = STATE_READY;
+ } else if (consumeMatch("<")) {
+ // We can't tell the user that the tag has closed until
+ // after we have
+ // processed any attributes and found the real end of the
+ // tag. So save
+ // the current info until the end of this tag.
+ currentTagStart = this._offset - 1;
+ currentTagName = consumeElementName();
+ if (currentTagName == null) {
+ log
+ .warn("Invalid HTML; bare lessthan sign found at line "
+ + getCurrentLineNumber());
+ // remain in STATE_READY; this isn't really the start of
+ // an xml element.
+ } else {
+ state = STATE_IN_TAG;
+ }
+ } else {
+ // should never get here
+ throw new Error("Internal error at line "
+ + getCurrentLineNumber());
+ }
+
+ continue;
+ }
+
+ if (state == STATE_IN_COMMENT) {
+ // TODO: handle "-- >", which is a valid way to close a
+ // comment according to the specs.
+
+ // in this state, nothing but "--" has any significance
+ consumeExcept("-");
+ if (isFinished()) {
+ break;
+ }
+
+ if (consumeMatch("-->")) {
+ state = STATE_READY;
+ } else {
+ // false call; hyphen is not end of comment
+ consumeMatch("-");
+ }
+
+ continue;
+ }
+
+ if (state == STATE_IN_TAG) {
+ consumeWhitespace();
+
+ if (consumeMatch("/>")) {
+ // ok, end of element
+ state = STATE_READY;
+ closedTag(currentTagStart, this._offset, currentTagName);
+
+ // and reset vars just in case...
+ currentTagStart = -1;
+ currentTagName = null;
+ } else if (consumeMatch(">")) {
+ if (currentTagName.equalsIgnoreCase("script")
+ || currentTagName.equalsIgnoreCase("style")) {
+ // We've just started a special tag which can contain
+ // anything except
+ // the ETAGO marker ("</"). See
+ //
http://www.w3.org/TR/REC-html40/appendix/notes.html#notes-specifying-data
+ state = STATE_EXPECTING_ETAGO;
+ } else {
+ state = STATE_READY;
+ }
+
+ // end of open tag, but not end of element
+ openedTag(currentTagStart, this._offset, currentTagName);
+
+ // and reset vars just in case...
+ currentTagStart = -1;
+ currentTagName = null;
+ } else {
+ // xml attribute
+ String attrName = consumeAttrName();
+ if (attrName == null) {
+ // Oops, we found something quite unexpected in this
+ // tag.
+ // The best we can do is probably to drop back to
+ // looking
+ // for "/>", though that does risk us misinterpreting
+ // the
+ // contents of an attribute's associated string value.
+ log
+ .warn("Invalid tag found: unexpected input while looking for attr name or
'/>'"
+ + " at line " + getCurrentLineNumber());
+ state = STATE_EXPECTING_ETAGO;
+ // and consume one character
+ ++this._offset;
+ } else {
+ consumeWhitespace();
+
+ // html can have "stand-alone" attributes with no
+ // following equals sign
+ if (consumeMatch("=")) {
+ String attrValue = consumeAttrValue();
+ }
+ }
+ }
+
+ continue;
+ }
+
+ if (state == STATE_IN_MARKED_SECTION) {
+ // in this state, nothing but "]]>" has any significance
+ consumeExcept("]");
+ if (isFinished()) {
+ break;
+ }
+
+ if (consumeMatch("]]>")) {
+ state = STATE_READY;
+ } else {
+ // false call; ] is not end of cdata section
+ consumeMatch("]");
+ }
+
+ continue;
+ }
+
+ if (state == STATE_EXPECTING_ETAGO) {
+ // The term "ETAGO" is the official spec term for "</".
+ consumeExcept("<");
+ if (isFinished()) {
+ log
+ .debug("Malformed input page; input terminated while tag not closed.");
+ break;
+ }
+
+ if (consumeMatch("</")) {
+ if (!processEndTag()) {
+ return;
+ }
+ state = STATE_READY;
+ } else {
+ // false call; < does not start an ETAGO
+ consumeMatch("<");
+ }
+
+ continue;
+ }
+ }
+ }
+
+ /**
+ * Invoked when "</" has been seen in the input, this method handles
the
+ * parsing of the end tag and the invocation of the appropriate callback
+ * method.
+ *
+ * @return true if the tag was successfully parsed, and false if there was a
+ * fatal parsing error.
+ */
+ private boolean processEndTag() {
+ int tagStart = this._offset - 2;
+ String tagName = consumeElementName();
+ consumeWhitespace();
+ if (!consumeMatch(">")) {
+ log.error("Malformed end tag at line " + getCurrentLineNumber()
+ + "; skipping parsing");
+ return false;
+ }
+
+ // inform user that the tag has been closed
+ closedTag(tagStart, this._offset, tagName);
+
+ // We can't verify that the tag names balance because this is HTML
+ // we are processing, not XML.
+ return true;
+ }
+
+ /**
+ * Invoke a callback method to inform the listener that we have found a
+ * start tag.
+ *
+ * @param startOffset
+ * @param endOffset
+ * @param tagName
+ */
+ void openedTag(int startOffset, int endOffset, String tagName) {
+ // log.debug("Found open tag at " + startOffset + ":" + endOffset +
":"
+ // + tagName);
+
+ if ("head".equalsIgnoreCase(tagName)) {
+ this._listener.openedStartTag(startOffset, HEAD_TAG);
+ this._listener.closedStartTag(endOffset, HEAD_TAG);
+ } else if ("body".equalsIgnoreCase(tagName)) {
+ this._listener.openedStartTag(startOffset, BODY_TAG);
+ this._listener.closedStartTag(endOffset, BODY_TAG);
+ } else if ("script".equalsIgnoreCase(tagName)) {
+ this._listener.openedStartTag(startOffset, SCRIPT_TAG);
+ this._listener.closedStartTag(endOffset, SCRIPT_TAG);
+ }
+ }
+
+ void closedTag(int startOffset, int endOffset, String tagName) {
+ // log.debug("Found close tag at " + startOffset + ":" + endOffset
+ ":"
+ // + tagName);
+
+ if ("head".equalsIgnoreCase(tagName)) {
+ this._listener.openedEndTag(startOffset, HEAD_TAG);
+ this._listener.closedEndTag(endOffset, HEAD_TAG);
+ } else if ("body".equalsIgnoreCase(tagName)) {
+ this._listener.openedEndTag(startOffset, BODY_TAG);
+ this._listener.closedEndTag(endOffset, BODY_TAG);
+ } else if ("script".equalsIgnoreCase(tagName)) {
+ this._listener.openedEndTag(startOffset, SCRIPT_TAG);
+ this._listener.closedEndTag(endOffset, SCRIPT_TAG);
+ }
+ }
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/AntFileResourceLoader.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/AntFileResourceLoader.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/AntFileResourceLoader.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,118 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.velocity;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+
+/**
+ * Load resource from file, name prepared by Ant
+ *
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:34 $
+ *
+ */
+public class AntFileResourceLoader extends ResourceLoader {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
+ */
+ public void init(ExtendedProperties arg0) {
+ this.rsvc.info("AntFileResourceLoader : initialization starting.");
+ this.rsvc.info("AntFileResourceLoader : initialization complete.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.velocity.runtime.resource.loader.ResourceLoader#getResourceStream(java.lang.String)
+ */
+ public InputStream getResourceStream(String templateName)
+ throws ResourceNotFoundException {
+ /*
+ * Make sure we have a valid templateName.
+ */
+ if ((templateName == null) || (templateName.length() == 0)) {
+ /*
+ * If we don't get a properly formed templateName then there's not
+ * much we can do. So we'll forget about trying to search any more
+ * paths for the template.
+ */
+ throw new ResourceNotFoundException(
+ "Need to specify a file name or file path!");
+ }
+ try {
+ this.rsvc.info("AntFileResourceLoader : attempt to load file "
+ + templateName);
+ File file = new File(templateName);
+
+ if (file.canRead()) {
+ return new BufferedInputStream(new FileInputStream(file
+ .getAbsolutePath()));
+ } else {
+ String msg = "AntFileResourceLoader Error: can not read file "
+ + templateName;
+
+ throw new ResourceNotFoundException(msg);
+ }
+ } catch (FileNotFoundException fnfe) {
+ /*
+ * log and convert to a general Velocity ResourceNotFoundException
+ */
+ String msg = "AntFileResourceLoader Error: file not found "
+ + templateName;
+
+ throw new ResourceNotFoundException(msg);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.velocity.runtime.resource.loader.ResourceLoader#isSourceModified(org.apache.velocity.runtime.resource.Resource)
+ */
+ public boolean isSourceModified(Resource arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(org.apache.velocity.runtime.resource.Resource)
+ */
+ public long getLastModified(Resource arg0) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Added:
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/BuilderContext.java
===================================================================
---
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/BuilderContext.java
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/velocity/BuilderContext.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,89 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.velocity;
+
+import org.apache.velocity.context.AbstractContext;
+
+/**
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2006/12/20 18:56:33 $
+ *
+ */
+public class BuilderContext extends AbstractContext {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2717339663835966811L;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.velocity.context.AbstractContext#internalGet(java.lang.String)
+ */
+ public Object internalGet(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.velocity.context.AbstractContext#internalPut(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object internalPut(String arg0, Object arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.velocity.context.AbstractContext#internalContainsKey(java.lang.Object)
+ */
+ public boolean internalContainsKey(Object arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.velocity.context.AbstractContext#internalGetKeys()
+ */
+ public Object[] internalGetKeys() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.velocity.context.AbstractContext#internalRemove(java.lang.Object)
+ */
+ public Object internalRemove(Object arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: branches/refactor1/cdk/generator/src/main/java/readme.txt
===================================================================
--- branches/refactor1/cdk/generator/src/main/java/readme.txt (rev
0)
+++ branches/refactor1/cdk/generator/src/main/java/readme.txt 2007-06-28 20:26:00 UTC (rev
1390)
@@ -0,0 +1 @@
+Component development kit
\ No newline at end of file
Added: branches/refactor1/cdk/generator/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- branches/refactor1/cdk/generator/src/main/resources/META-INF/plexus/components.xml
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/plexus/components.xml 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,18 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.ajax4jsf.templatecompiler.elements.ElementsFactory</role>
+ <role-hint>a4j</role-hint>
+ <implementation>
+ org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory
+ </implementation>
+ </component>
+ <component>
+ <role>org.ajax4jsf.templatecompiler.elements.ElementsFactory</role>
+ <role-hint>jstl</role-hint>
+ <implementation>
+ org.ajax4jsf.templatecompiler.elements.JSTLElementsFactory
+ </implementation>
+ </component>
+ </components>
+</component-set>
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/VM_global_library.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/VM_global_library.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/VM_global_library.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,12 @@
+#macro( quietnull $a)
+
+#if($a)$a#end
+
+#end
+
+
+
+
+
+
+
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,109 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if($component.packageName)
+package $component.packageName;
+#end
+
+#if($component.imports)
+
+//
+// Imports
+//
+#foreach( $import in $component.imports )
+import $import;
+#end
+//
+//
+//
+
+#else
+import java.util.Iterator;
+import java.util.Collection;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
+import org.ajax4jsf.framework.renderer.ComponentVariables;
+#end
+
+#if($component.fullBaseclass)
+import $component.fullBaseclass;
+#else
+import org.ajax4jsf.framework.renderer.RendererBase;
+#end
+
+#if($component.baseclassName)
+#set( $baseclassname = $component.baseclassName )
+#else
+#set( $baseclassname = "RendererBase" )
+#end
+
+
+/**
+ * Renderer for component class ${component.fullClassName}
+ */
+public class $component.className extends $baseclassname {
+
+ public $component.className () {
+ super();
+ }
+
+#if( $component.declarations )
+ //
+ // Declarations
+ //
+#foreach( $declaration in $component.declarations )
+ $declaration
+#end
+ //
+ //
+ //
+#end
+
+
+ private String convertToString(Object obj ) {
+ return ( obj == null ? "" : obj.toString() );
+ }
+ private String convertToString(boolean b ) {
+ return String.valueOf(b);
+ }
+ private String convertToString(int b ) {
+ return b!=Integer.MIN_VALUE?String.valueOf(b):"";
+ }
+ private String convertToString(long b ) {
+ return b!=Long.MIN_VALUE?String.valueOf(b):"";
+ }
+
+ /**
+ * Get base component class, targetted for this renderer. Used for check arguments in
decode/encode.
+ * @return
+ */
+ protected Class getComponentClass() {
+#if($component.componentClass)
+ return ${component.componentClass}.class;
+#else
+ return UIComponent.class;
+#end
+ }
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeBegin.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeBegin.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeBegin.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,10 @@
+
+ public void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component ) throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
+ doEncodeBegin(writer, context, (${component.componentClass})component, variables );
+ }
+
+ public void doEncodeBegin(ResponseWriter writer, FacesContext context,
${component.componentClass} component, ComponentVariables variables ) throws IOException
{
+ $body
+ }
+
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeChildren.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeChildren.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeChildren.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,16 @@
+
+ public void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
+ doEncodeChildren(writer, context, (${component.componentClass})component, variables );
+ }
+
+ public void doEncodeChildren(ResponseWriter writer, FacesContext context,
${component.componentClass} component, ComponentVariables variables) throws IOException {
+ ${body}
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.render.Renderer#getRendersChildren()
+ */
+ public boolean getRendersChildren() {
+ return true;
+ }
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeEnd.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeEnd.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/EncodeEnd.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,12 @@
+
+ public void doEncodeEnd(ResponseWriter writer, FacesContext context,
${component.componentClass} component, ComponentVariables variables) throws IOException {
+ ${body}
+ }
+
+ public void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
+ doEncodeEnd(writer, context, (${component.componentClass})component, variables );
+
+ ComponentsVariableResolver.removeVariables(this, component);
+ }
+
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_1.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_1.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_1.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,3 @@
+Collection com_$index = (Collection)$items;
+for (Iterator iter = com_$index .iterator(); iter.hasNext();) {
+ variables.setVariable("$item", iter.next());
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_2.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_2.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/FORElement_2.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,5 @@
+for (
+ variables.setVariable("$item", $from);
+ Integer.getInteger(variables.getVariable("$item").toString()).intValue() <
Integer.getInteger($to).toString()).intValue();
+ variables.addValueToVariable("$item", new Integer(1) )
+ ) {
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/HTMLElement.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/HTMLElement.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/HTMLElement.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,32 @@
+writer.startElement("$htmlTag", component);
+#if($htmlAttributes)
+#foreach( $key in $htmlAttributes.keySet() )
+ #set ( $attr = $htmlAttributes.get($key) )
+ #if ( $attr.code )
+ $attr.code
+ #else
+ #if ( $attr.value )
+getUtils().writeAttribute(writer, "$attr.name", $attr.value );
+ #end
+ #end
+#end
+#end
+#if($passThruAttributes)
+//
+// pass thru attributes
+//
+#set( $passThruLength = ${passThruAttributes.size()})
+getUtils().encodeAttributesFromArray(context,component,new String[] {
+#foreach( $attribute in $passThruAttributes )
+ "$attribute" #if( $velocityCount < $passThruLength ),
+ #end
+#end
+});
+//
+//
+//
+#end
+#if($htmlText)
+writer.write( convertToString($htmlText) );
+writer.flush();
+#end
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/IFElement.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/IFElement.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/IFElement.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,2 @@
+if ( Boolean.valueOf( String.valueOf($if) ).booleanValue() ) {
+
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/headerResource.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/headerResource.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/headerResource.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,48 @@
+private final InternetResource[] ${property} = {
+ #set ($count = 0)
+ #foreach($resource in $resourceKeys)
+ #if($count > 0)
+ ,
+ #end
+ #set ($count = $count + 1)
+ ${resource}
+ #end
+};
+
+private InternetResource[] ${property}All = null;
+
+${getterModifier} InternetResource[] ${propertyGetterName}() {
+ synchronized (this) {
+ if (${property}All == null) {
+ InternetResource[] rsrcs = super.${propertyGetterName}();
+ boolean ignoreSuper = rsrcs == null || rsrcs.length == 0;
+ boolean ignoreThis = ${property} == null || ${property}.length == 0;
+
+ if (ignoreSuper) {
+ if (ignoreThis) {
+ ${property}All = new InternetResource[0];
+ } else {
+ ${property}All = ${property};
+ }
+ } else {
+ if (ignoreThis) {
+ ${property}All = rsrcs;
+ } else {
+ java.util.Set rsrcsSet = new java.util.LinkedHashSet();
+
+ for (int i = 0; i < rsrcs.length; i++ ) {
+ rsrcsSet.add(rsrcs[i]);
+ }
+
+ for (int i = 0; i < ${property}.length; i++ ) {
+ rsrcsSet.add(${property}[i]);
+ }
+
+ ${property}All = (InternetResource[]) rsrcsSet.toArray(new
InternetResource[rsrcsSet.size()]);
+ }
+ }
+ }
+ }
+
+ return ${property}All;
+}
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertCall.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertCall.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertCall.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,5 @@
+#if ($variableName)
+variables.setVariable("$variableName", $function);
+#else
+$function;
+#end
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertChildren.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertChildren.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertChildren.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,12 @@
+#if(${$ELIndex} || ${$ELVar})
+#if(${$ELIndex})
+Integer indexChildren_$indexChildren =
(Integer)ComponentUtils.evaluateExpression(facesContext, "$ELIndex");
+if (null != indexChildren_$indexChildren ) {
+ UIComponent component_$indexChildren =
(UIComponent)component.getChildren().get(indexChildren_$indexChildren .intValue());
+ renderChild(context, component_$indexChildren );
+}
+#else
+ UIComponent component_$indexChildren = (UIComponent)evaluateExpression(
"$ELVar" );
+ renderChild(context, component_$indexChildren );
+#end
+#end
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertComponent.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertComponent.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertComponent.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1 @@
+renderChild(context, (UIComponent)$value );
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertFacet.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertFacet.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertFacet.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,4 @@
+UIComponent indexChildren_$index = component.getFacet("$FacetName");
+if (null != indexChildren_$index && indexChildren_$index .isRendered()) {
+ renderChild(context, indexChildren_$index);
+}
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertResource.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertResource.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/insertResource.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1 @@
+variables.setVariable("$variable", getResource( "$resourceURI"
).getUri(context, component) );
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/set.vm
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/set.vm
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/set.vm 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1 @@
+variables.setVariable("$variable", $expression );
\ No newline at end of file
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/tags.bin
===================================================================
(Binary files differ)
Property changes on:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/tags.bin
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/velocity.properties
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/velocity.properties
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/velocity.properties 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,3 @@
+resource.loader = classpath,antfile
+classpath.resource.loader.class =
org.ajax4jsf.templatecompiler.velocity.ClasspathTemplateLoader
+antfile.resource.loader.class =
org.ajax4jsf.templatecompiler.velocity.AntFileResourceLoader
Added:
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/ant/velocity.properties
===================================================================
---
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/ant/velocity.properties
(rev 0)
+++
branches/refactor1/cdk/generator/src/main/resources/org/ajax4jsf/templatecompiler/ant/velocity.properties 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,3 @@
+resource.loader classpath,antfile
+classpath.resource.loader.class
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
+antfile.resource.loader.class
org.ajax4jsf.templatecompiler.velocity.AntFileResourceLoader
Added: branches/refactor1/cdk/generator/src/test/java/org/ajax4jsf/AppTest.java
===================================================================
--- branches/refactor1/cdk/generator/src/test/java/org/ajax4jsf/AppTest.java
(rev 0)
+++ branches/refactor1/cdk/generator/src/test/java/org/ajax4jsf/AppTest.java 2007-06-28
20:26:00 UTC (rev 1390)
@@ -0,0 +1,59 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
Added: branches/refactor1/cdk/pom.xml
===================================================================
--- branches/refactor1/cdk/pom.xml (rev 0)
+++ branches/refactor1/cdk/pom.xml 2007-06-28 20:26:00 UTC (rev 1390)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>master</artifactId>
+ <groupId>org.ajax4jsf</groupId>
+ <version>1.1.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.ajax4jsf</groupId>
+ <artifactId>cdk</artifactId>
+ <packaging>pom</packaging>
+ <name>JSF Components Development kit</name>
+ <version>1.1.2-SNAPSHOT</version>
+ <
url>http://labs.jboss.com/wiki/Ajax4jsf/cdk</url>
+ <dependencies />
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <modules>
+ <module>maven-cdk-plugin</module>
+ <module>compiler</module>
+ <module>generator</module>
+ <module>maven-archetype-jsf-component</module>
+ <module>maven-archetype-jsfwebapp</module>
+ </modules>
+</project>
\ No newline at end of file