You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by aw...@apache.org on 2007/07/03 22:51:35 UTC
svn commit: r552975 [3/41] - in /myfaces/trinidad/branches/pre-1.2.2-branch:
plugins/ plugins/maven-faces-plugin/
plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/
plugins/maven-faces-plugin/src/main/java/org/apach...
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java Tue Jul 3 13:51:23 2007
@@ -6,9 +6,9 @@
* to you 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
@@ -18,23 +18,20 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringWriter;
-
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.ComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.MyFacesComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.TagAttributeFilter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.generator.taglib.TrinidadComponentTagGenerator;
+import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.*;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.*;
+import org.codehaus.plexus.util.FileUtils;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -42,38 +39,12 @@
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.*;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
-
-import org.apache.myfaces.trinidadbuild.plugin.faces.io.PrettyWriter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ComponentBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ConverterBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.FacesConfigBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.MethodSignatureBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.ValidatorBean;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ComponentFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ConverterFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.FilteredIterator;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.Util;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.ValidatorFilter;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-
-import org.codehaus.plexus.util.FileUtils;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
+import java.io.*;
+import java.lang.reflect.Modifier;
+import java.util.*;
/**
* @version $Id$
@@ -227,10 +198,14 @@
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer identity = transFactory.newTransformer();
- identity.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
- _JSP_TAG_LIBRARY_DOCTYPE_PUBLIC);
- identity.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
- _JSP_TAG_LIBRARY_DOCTYPE_SYSTEM);
+ if (!_is12())
+ {
+ identity.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
+ _JSP_TAG_LIBRARY_DOCTYPE_PUBLIC);
+ identity.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
+ _JSP_TAG_LIBRARY_DOCTYPE_SYSTEM);
+ }
+
identity.transform(mergedSource, mergedResult);
targetFile.setReadOnly();
@@ -242,7 +217,7 @@
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter stream = outputFactory.createXMLStreamWriter(out);
- _writeStartTagLibrary(stream, "1.2", shortName, namespaceURI);
+ _writeStartTagLibrary(stream, _is12() ? "2.1" : "1.2", shortName, namespaceURI);
while (components.hasNext())
{
ComponentBean component = (ComponentBean)components.next();
@@ -302,9 +277,19 @@
{
stream.writeStartDocument("1.0");
stream.writeCharacters("\n");
- stream.writeDTD(dtd);
+ if (!_is12())
+ stream.writeDTD(dtd);
+
stream.writeCharacters("\n");
stream.writeStartElement("taglib");
+ if (_is12())
+ {
+ stream.writeNamespace("", "http://java.sun.com/xml/ns/javaee");
+ stream.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ stream.writeAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd");
+ stream.writeAttribute("version", "2.1");
+ }
+
stream.writeCharacters("\n ");
}
@@ -316,14 +301,30 @@
{
_writeStartTagLibrary(stream, _JSP_TAG_LIBRARY_DTD);
stream.writeStartElement("tlib-version");
- stream.writeCharacters(project.getVersion());
- stream.writeEndElement();
+ String tlibVersion = project.getVersion();
+ // Remove everything but dewey-decimal characters (i.e., numbers and periods)
+ tlibVersion = tlibVersion.replaceAll("[^.0-9]", "");
+ // Remove leading and/or trailing periods
+ while (tlibVersion.startsWith("."))
+ {
+ tlibVersion = tlibVersion.substring(1);
+ }
- stream.writeCharacters("\n ");
+ while (tlibVersion.endsWith("."))
+ {
+ tlibVersion = tlibVersion.substring(0, tlibVersion.length() - 1);
+ }
- stream.writeStartElement("jsp-version");
- stream.writeCharacters(version);
+ stream.writeCharacters(tlibVersion);
stream.writeEndElement();
+
+ if (!_is12())
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("jsp-version");
+ stream.writeCharacters(version);
+ stream.writeEndElement();
+ }
stream.writeCharacters("\n ");
stream.writeStartElement("short-name");
stream.writeCharacters(shortName);
@@ -353,6 +354,14 @@
stream.writeCharacters("\n ");
stream.writeStartElement("tag");
stream.writeCharacters("\n ");
+ if (component.getDescription() != null)
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("description");
+ stream.writeCData(component.getDescription());
+ stream.writeEndElement();
+ }
+
stream.writeStartElement("name");
stream.writeCharacters(component.getTagName().getLocalPart());
stream.writeEndElement();
@@ -360,15 +369,16 @@
stream.writeStartElement("tag-class");
stream.writeCharacters(component.getTagClass());
stream.writeEndElement();
- if (component.getDescription() != null)
+
+ // In JSP 2.1, body-content is not optional
+ if (_is12())
{
stream.writeCharacters("\n ");
- stream.writeStartElement("description");
- stream.writeCData(component.getDescription());
+ stream.writeStartElement("body-content");
+ stream.writeCharacters("JSP");
stream.writeEndElement();
}
-
GenerateJspTaglibsMojo.this.writeCustomComponentTagDescriptorContent(stream, component);
Iterator properties = component.properties(true);
@@ -379,7 +389,8 @@
writeTagAttribute(stream,
property.getPropertyName(),
property.getDescription(),
- property.getUnsupportedAgents());
+ property.getUnsupportedAgents(),
+ property);
}
stream.writeCharacters("\n ");
@@ -396,6 +407,14 @@
stream.writeCharacters("\n ");
stream.writeStartElement("tag");
stream.writeCharacters("\n ");
+ if (converter.getDescription() != null)
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("description");
+ stream.writeCData(converter.getDescription());
+ stream.writeEndElement();
+ }
+
stream.writeStartElement("name");
stream.writeCharacters(converter.getTagName().getLocalPart());
stream.writeEndElement();
@@ -403,16 +422,18 @@
stream.writeStartElement("tag-class");
stream.writeCharacters(converter.getTagClass());
stream.writeEndElement();
- if (converter.getDescription() != null)
+
+ // In JSP 2.1, body-content is not optional
+ if (_is12())
{
stream.writeCharacters("\n ");
- stream.writeStartElement("description");
- stream.writeCData(converter.getDescription());
+ stream.writeStartElement("body-content");
+ stream.writeCharacters("empty");
stream.writeEndElement();
}
// converters need an id attribute
- writeTagAttribute(stream, "id", "the identifier for the component", null);
+ writeTagAttribute(stream, "id", "the identifier for the converter", null, null);
Iterator properties = converter.properties();
properties = new FilteredIterator(properties, new TagAttributeFilter());
@@ -422,7 +443,8 @@
writeTagAttribute(stream,
property.getPropertyName(),
property.getDescription(),
- property.getUnsupportedAgents());
+ property.getUnsupportedAgents(),
+ property);
}
stream.writeCharacters("\n ");
@@ -433,21 +455,12 @@
XMLStreamWriter stream,
String propertyName,
String description,
- String[] unsupportedAgents) throws XMLStreamException
+ String[] unsupportedAgents,
+ PropertyBean property) throws XMLStreamException
{
stream.writeCharacters("\n ");
stream.writeStartElement("attribute");
- stream.writeCharacters("\n ");
- stream.writeStartElement("name");
- stream.writeCharacters(propertyName);
- stream.writeEndElement();
-
- stream.writeCharacters("\n ");
- stream.writeStartElement("rtexprvalue");
- stream.writeCharacters("false");
- stream.writeEndElement();
-
if (description != null ||
unsupportedAgents.length > 0)
{
@@ -473,6 +486,102 @@
stream.writeEndElement();
}
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("name");
+
+ if (property != null)
+ stream.writeCharacters(property.getJspPropertyName());
+ else
+ stream.writeCharacters(propertyName);
+
+ stream.writeEndElement();
+
+ if (!_is12())
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("rtexprvalue");
+ stream.writeCharacters("false");
+ stream.writeEndElement();
+ }
+ else
+ {
+ if (property != null)
+ {
+ if (property.isRequired())
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("required");
+ stream.writeCharacters("true");
+ stream.writeEndElement();
+ }
+
+ if (property.isMethodExpression() || property.isMethodBinding())
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("deferred-method");
+ stream.writeCharacters("\n ");
+ MethodSignatureBean sig = property.getMethodBindingSignature();
+ if (sig != null)
+ {
+ stream.writeStartElement("method-signature");
+ stream.writeCharacters(sig.getReturnType());
+ stream.writeCharacters(" myMethod(");
+ String[] params = sig.getParameterTypes();
+ for (int i = 0; i < params.length; i++)
+ {
+ if (i > 0)
+ stream.writeCharacters(", ");
+ stream.writeCharacters(params[i]);
+ }
+
+ stream.writeCharacters(")");
+ stream.writeEndElement();
+ }
+ stream.writeEndElement();
+ }
+ else if (!property.isLiteralOnly() ||
+ // "binding" is always a deferred-value
+ "binding".equals(propertyName))
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("deferred-value");
+ String propertyClass = property.getPropertyClass();
+ // Writing java.lang.String is usually a bad idea - it
+ // means that null gets coerced to the empty string.
+ if (("java.lang.String".equals(propertyClass) && coerceStrings) ||
+ _CAN_COERCE.contains(property.getPropertyClass()))
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("type");
+ // Trim out any use of generics here - since JSP coercion
+ // certainly can't do anything there
+ int genericIndex = propertyClass.indexOf('<');
+ if (genericIndex > 0)
+ propertyClass = propertyClass.substring(0, genericIndex);
+
+ stream.writeCharacters(propertyClass);
+ stream.writeEndElement();
+ stream.writeCharacters("\n ");
+ }
+
+ stream.writeEndElement();
+ }
+ else
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("rtexprvalue");
+ // As of JSF 1.2, "id" can be set via an rtexprvalue (but
+ // *not* by a ValueExpression) - it has to be evaluated
+ // in the JSP
+ if ("id".equals(propertyName) && !disableIdExpressions)
+ stream.writeCharacters("true");
+ else
+ stream.writeCharacters("false");
+ stream.writeEndElement();
+ }
+ }
+ }
+
stream.writeCharacters("\n ");
stream.writeEndElement();
}
@@ -486,6 +595,15 @@
{
stream.writeCharacters("\n ");
stream.writeStartElement("tag");
+
+ if (validator.getDescription() != null)
+ {
+ stream.writeCharacters("\n ");
+ stream.writeStartElement("description");
+ stream.writeCData(validator.getDescription());
+ stream.writeEndElement();
+ }
+
stream.writeCharacters("\n ");
stream.writeStartElement("name");
stream.writeCharacters(validator.getTagName().getLocalPart());
@@ -494,16 +612,18 @@
stream.writeStartElement("tag-class");
stream.writeCharacters(validator.getTagClass());
stream.writeEndElement();
- if (validator.getDescription() != null)
+
+ // In JSP 2.1, body-content is not optional
+ if (_is12())
{
stream.writeCharacters("\n ");
- stream.writeStartElement("description");
- stream.writeCData(validator.getDescription());
+ stream.writeStartElement("body-content");
+ stream.writeCharacters("empty");
stream.writeEndElement();
}
// validators need an id attribute
- writeTagAttribute(stream, "id", "the identifier for the component", null);
+ writeTagAttribute(stream, "id", "the identifier for the validator", null, null);
Iterator properties = validator.properties();
properties = new FilteredIterator(properties, new TagAttributeFilter());
@@ -513,7 +633,8 @@
writeTagAttribute(stream,
property.getPropertyName(),
property.getDescription(),
- property.getUnsupportedAgents());
+ property.getUnsupportedAgents(),
+ property);
}
stream.writeCharacters("\n ");
@@ -563,7 +684,7 @@
}
else
{
- ComponentTagGenerator componentGen = new ComponentTagGenerator();
+ ComponentTagHandlerGenerator componentGen = new ComponentTagHandlerGenerator();
ConverterTagGenerator converterGen = new ConverterTagGenerator();
ValidatorTagGenerator validatorGen = new ValidatorTagGenerator();
int count = 0;
@@ -623,8 +744,17 @@
out.println(" * Auto-generated tag class.");
out.println(" */");
- out.println("public class " + className +
- " extends ConverterTag");
+ if (_is12())
+ {
+ out.println("public class " + className +
+ " extends ConverterELTag");
+ }
+ else
+ {
+ out.println("public class " + className +
+ " extends ConverterTag");
+ }
+
out.println("{");
out.indent();
@@ -662,7 +792,15 @@
{
Set imports = new TreeSet();
- imports.add("javax.faces.webapp.ConverterTag");
+ if (_is12())
+ {
+ imports.add("javax.faces.webapp.ConverterELTag");
+ imports.add("javax.faces.context.FacesContext");
+ imports.add("javax.faces.application.Application");
+ }
+ else
+ imports.add("javax.faces.webapp.ConverterTag");
+
imports.add("javax.servlet.jsp.JspException");
imports.add(converter.getConverterClass());
@@ -671,7 +809,10 @@
if (properties.hasNext())
{
imports.add("javax.faces.convert.Converter");
- imports.add("javax.faces.el.ValueBinding");
+ if (_is12())
+ imports.add("javax.el.ValueExpression");
+ else
+ imports.add("javax.faces.el.ValueBinding");
imports.add("org.apache.myfaces.trinidadinternal.taglib.util.TagUtils");
}
@@ -735,7 +876,9 @@
{
String propName = property.getPropertyName();
String propVar = "_" + Util.getVariableFromName(propName);
- out.println("private String " + propVar + ";");
+ String jspPropType = _getJspPropertyType(property);
+
+ out.println("private " + jspPropType + " " + propVar + ";");
}
private void _writePropertySet(
@@ -745,9 +888,10 @@
String propName = property.getPropertyName();
String propVar = Util.getVariableFromName(propName);
String setMethod = Util.getPrefixedPropertyName("set", propName);
+ String jspPropType = _getJspPropertyType(property);
// TODO: restore coding standards, and make final
- out.println("public void " + setMethod + "(String " + propVar + ")");
+ out.println("public void " + setMethod + "(" + jspPropType + " " + propVar + ")");
out.println("{");
out.indent();
out.println("_" + propVar + " = " + propVar + ";");
@@ -759,19 +903,22 @@
PrettyWriter out,
ConverterBean converter) throws IOException
{
- String converterFullClass = converter.getConverterClass();
- String converterClass = Util.getClassFromFullClass(converterFullClass);
-
- out.println();
- // TODO: restore coding standards, and make final
- out.println("@Override");
- out.println("public int doStartTag() throws JspException");
- out.println("{");
- out.indent();
- out.println("super.setConverterId(" + converterClass + ".CONVERTER_ID);");
- out.println("return super.doStartTag();");
- out.unindent();
- out.println("}");
+ if (!_is12())
+ {
+ String converterFullClass = converter.getConverterClass();
+ String converterClass = Util.getClassFromFullClass(converterFullClass);
+
+ out.println();
+ // TODO: restore coding standards, and make final
+ out.println("@Override");
+ out.println("public int doStartTag() throws JspException");
+ out.println("{");
+ out.indent();
+ out.println("super.setConverterId(" + converterClass + ".CONVERTER_ID);");
+ out.println("return super.doStartTag();");
+ out.unindent();
+ out.println("}");
+ }
}
private void _writeCreateConverter(
@@ -791,8 +938,18 @@
out.println("protected Converter createConverter() throws JspException");
out.println("{");
out.indent();
- out.println(converterClass + " converter = " +
- "(" + converterClass + ")super.createConverter();");
+ if (_is12())
+ {
+ out.println("String converterId = " + converterClass + ".CONVERTER_ID;");
+ out.println("Application appl = FacesContext.getCurrentInstance().getApplication();");
+ out.println(converterClass + " converter = " +
+ "(" + converterClass + ")appl.createConverter(converterId);");
+ }
+ else
+ {
+ out.println(converterClass + " converter = " +
+ "(" + converterClass + ")super.createConverter();");
+ }
out.println("_setProperties(converter);");
out.println("return converter;");
out.unindent();
@@ -835,44 +992,89 @@
String propFullClass = property.getPropertyClass();
String propClass = Util.getClassFromFullClass(propFullClass);
String propVar = "_" + Util.getVariableFromName(propName);
+
out.println("if (" + propVar + " != null)");
out.println("{");
out.indent();
- out.println("if (TagUtils.isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = TagUtils.getValueBinding(" + propVar + ");");
- out.println("converter.setValueBinding(\"" + propName + "\", vb);");
- out.unindent();
- out.println("}");
- String propType = _resolveType(propFullClass);
- if (propType != null)
+
+ if (_is12())
{
- out.println("else");
+ out.println("if (!" + propVar + ".isLiteralText())");
out.println("{");
out.indent();
- if ("StringArray".equals(propType))
+ out.println("converter.setValueExpression(\"" + propName + "\", " +
+ propVar + ");");
+ out.unindent();
+ out.println("}");
+ String propType = _resolveType(propFullClass);
+ if (propType != null)
{
- out.println("try");
+ out.println("else");
out.println("{");
+ out.indent();
+ if ("StringArray".equals(propType))
+ {
+ out.println("try");
+ out.println("{");
+ }
+
+ out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ".getValue(null));");
+ String setMethod = Util.getPrefixedPropertyName("set", propName);
+ out.println("converter." + setMethod + "(value);");
+ if ("StringArray".equals(propType))
+ {
+ out.println("}");
+ out.println("catch (ParseException pe)");
+ out.println("{");
+ out.indent();
+ out.println("throw new JspException(");
+ out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ out.unindent();
+ out.println("}");
+ }
+ out.unindent();
+ out.println("}");
}
- out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ");");
- String setMethod = Util.getPrefixedPropertyName("set", propName);
- out.println("converter." + setMethod + "(value);");
- if ("StringArray".equals(propType))
+ }
+ else
+ {
+ out.println("if (TagUtils.isValueReference(" + propVar + "))");
+ out.println("{");
+ out.indent();
+ out.println("ValueBinding vb = TagUtils.getValueBinding(" + propVar + ");");
+ out.println("converter.setValueBinding(\"" + propName + "\", vb);");
+ out.unindent();
+ out.println("}");
+ String propType = _resolveType(propFullClass);
+ if (propType != null)
{
- out.println("}");
- out.println("catch (ParseException pe)");
+ out.println("else");
out.println("{");
out.indent();
- out.println("throw new JspException(");
- out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ if ("StringArray".equals(propType))
+ {
+ out.println("try");
+ out.println("{");
+ }
+ out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ");");
+ String setMethod = Util.getPrefixedPropertyName("set", propName);
+ out.println("converter." + setMethod + "(value);");
+ if ("StringArray".equals(propType))
+ {
+ out.println("}");
+ out.println("catch (ParseException pe)");
+ out.println("{");
+ out.indent();
+ out.println("throw new JspException(");
+ out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ out.unindent();
+ out.println("}");
+ }
out.unindent();
out.println("}");
}
- out.unindent();
- out.println("}");
}
+
out.unindent();
out.println("}");
}
@@ -902,6 +1104,19 @@
out.println("}");
}
}
+
+ private String _getJspPropertyType(PropertyBean property)
+ {
+ if (property.isMethodExpression())
+ return "MethodExpression";
+
+ if (_is12() && property.isMethodBinding())
+ return "MethodExpression";
+
+ if (_is12() && !property.isLiteralOnly())
+ return "ValueExpression";
+ return "String";
+ }
}
class ValidatorTagGenerator
@@ -939,8 +1154,17 @@
out.println(" * Auto-generated tag class.");
out.println(" */");
- out.println("public class " + className +
- " extends ValidatorTag");
+ if (_is12())
+ {
+ out.println("public class " + className +
+ " extends ValidatorELTag");
+ }
+ else
+ {
+ out.println("public class " + className +
+ " extends ValidatorTag");
+ }
+
out.println("{");
out.indent();
@@ -978,7 +1202,15 @@
{
Set imports = new TreeSet();
- imports.add("javax.faces.webapp.ValidatorTag");
+ if (_is12())
+ {
+ imports.add("javax.faces.webapp.ValidatorELTag");
+ imports.add("javax.faces.context.FacesContext");
+ imports.add("javax.faces.application.Application");
+ }
+ else
+ imports.add("javax.faces.webapp.ValidatorTag");
+
imports.add("javax.servlet.jsp.JspException");
imports.add(validator.getValidatorClass());
@@ -987,7 +1219,10 @@
if (properties.hasNext())
{
imports.add("javax.faces.validator.Validator");
- imports.add("javax.faces.el.ValueBinding");
+ if (_is12())
+ imports.add("javax.el.ValueExpression");
+ else
+ imports.add("javax.faces.el.ValueBinding");
imports.add("org.apache.myfaces.trinidadinternal.taglib.util.TagUtils");
}
@@ -1051,7 +1286,9 @@
{
String propName = property.getPropertyName();
String propVar = "_" + Util.getVariableFromName(propName);
- out.println("private String " + propVar + ";");
+ String jspPropType = _getJspPropertyType(property);
+
+ out.println("private " + jspPropType + " " + propVar + ";");
}
private void _writePropertySet(
@@ -1061,9 +1298,10 @@
String propName = property.getPropertyName();
String propVar = Util.getVariableFromName(propName);
String setMethod = Util.getPrefixedPropertyName("set", propName);
+ String jspPropType = _getJspPropertyType(property);
// TODO: restore coding standards, and make final
- out.println("public void " + setMethod + "(String " + propVar + ")");
+ out.println("public void " + setMethod + "(" + jspPropType + " " + propVar + ")");
out.println("{");
out.indent();
out.println("_" + propVar + " = " + propVar + ";");
@@ -1075,19 +1313,22 @@
PrettyWriter out,
ValidatorBean validator) throws IOException
{
- String validatorFullClass = validator.getValidatorClass();
- String validatorClass = Util.getClassFromFullClass(validatorFullClass);
-
out.println();
- // TODO: restore coding standards, and make final
- out.println("@Override");
- out.println("public int doStartTag() throws JspException");
- out.println("{");
- out.indent();
- out.println("super.setValidatorId(" + validatorClass + ".VALIDATOR_ID);");
- out.println("return super.doStartTag();");
- out.unindent();
- out.println("}");
+ if (!_is12())
+ {
+ String validatorFullClass = validator.getValidatorClass();
+ String validatorClass = Util.getClassFromFullClass(validatorFullClass);
+
+ // TODO: restore coding standards, and make final
+ out.println("@Override");
+ out.println("public int doStartTag() throws JspException");
+ out.println("{");
+ out.indent();
+ out.println("super.setValidatorId(" + validatorClass + ".VALIDATOR_ID);");
+ out.println("return super.doStartTag();");
+ out.unindent();
+ out.println("}");
+ }
}
private void _writeCreateValidator(
@@ -1107,8 +1348,18 @@
out.println("protected Validator createValidator() throws JspException");
out.println("{");
out.indent();
- out.println(validatorClass + " validator = " +
- "(" + validatorClass + ")super.createValidator();");
+ if (_is12())
+ {
+ out.println("String validatorId = " + validatorClass + ".VALIDATOR_ID;");
+ out.println("Application appl = FacesContext.getCurrentInstance().getApplication();");
+ out.println(validatorClass + " validator = " +
+ "(" + validatorClass + ")appl.createValidator(validatorId);");
+ }
+ else
+ {
+ out.println(validatorClass + " validator = " +
+ "(" + validatorClass + ")super.createValidator();");
+ }
out.println("_setProperties(validator);");
out.println("return validator;");
out.unindent();
@@ -1154,41 +1405,84 @@
out.println("if (" + propVar + " != null)");
out.println("{");
out.indent();
- out.println("if (TagUtils.isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = TagUtils.getValueBinding(" + propVar + ");");
- out.println("validator.setValueBinding(\"" + propName + "\", vb);");
- out.unindent();
- out.println("}");
- String propType = _resolveType(propFullClass);
- if (propType != null)
+ if (_is12())
{
- out.println("else");
+ out.println("if (!" + propVar + ".isLiteralText())");
out.println("{");
out.indent();
- if ("StringArray".equals(propType))
+ out.println("validator.setValueExpression(\"" + propName + "\", " +
+ propVar + ");");
+ out.unindent();
+ out.println("}");
+ String propType = _resolveType(propFullClass);
+ if (propType != null)
{
- out.println("try");
+ out.println("else");
out.println("{");
+ out.indent();
+ if ("StringArray".equals(propType))
+ {
+ out.println("try");
+ out.println("{");
+ }
+
+ out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ".getValue(null));");
+ String setMethod = Util.getPrefixedPropertyName("set", propName);
+ out.println("validator." + setMethod + "(value);");
+ if ("StringArray".equals(propType))
+ {
+ out.println("}");
+ out.println("catch (ParseException pe)");
+ out.println("{");
+ out.indent();
+ out.println("throw new JspException(");
+ out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ out.unindent();
+ out.println("}");
+ }
+ out.unindent();
+ out.println("}");
}
- out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ");");
- String setMethod = Util.getPrefixedPropertyName("set", propName);
- out.println("validator." + setMethod + "(value);");
- if ("StringArray".equals(propType))
+ }
+ else
+ {
+ out.println("if (TagUtils.isValueReference(" + propVar + "))");
+ out.println("{");
+ out.indent();
+ out.println("ValueBinding vb = TagUtils.getValueBinding(" + propVar + ");");
+ out.println("validator.setValueBinding(\"" + propName + "\", vb);");
+ out.unindent();
+ out.println("}");
+ String propType = _resolveType(propFullClass);
+ if (propType != null)
{
- out.println("}");
- out.println("catch (ParseException pe)");
+ out.println("else");
out.println("{");
out.indent();
- out.println("throw new JspException(");
- out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ if ("StringArray".equals(propType))
+ {
+ out.println("try");
+ out.println("{");
+ }
+ out.println(propClass + " value = TagUtils.get" + propType + "(" + propVar + ");");
+ String setMethod = Util.getPrefixedPropertyName("set", propName);
+ out.println("validator." + setMethod + "(value);");
+ if ("StringArray".equals(propType))
+ {
+ out.println("}");
+ out.println("catch (ParseException pe)");
+ out.println("{");
+ out.indent();
+ out.println("throw new JspException(");
+ out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
+ out.unindent();
+ out.println("}");
+ }
out.unindent();
out.println("}");
}
- out.unindent();
- out.println("}");
}
+
out.unindent();
out.println("}");
}
@@ -1218,84 +1512,120 @@
out.println("}");
}
}
+
+ private String _getJspPropertyType(PropertyBean property)
+ {
+ if (property.isMethodExpression())
+ return "MethodExpression";
+
+ if (_is12() && property.isMethodBinding())
+ return "MethodExpression";
+
+ if (_is12() && !property.isLiteralOnly())
+ return "ValueExpression";
+ return "String";
+ }
}
- class ComponentTagGenerator
+ class ComponentTagHandlerGenerator
{
- public void generateTagHandler(
- ComponentBean component)
+
+ private Set initComponentList(ComponentBean component,
+ String fullSuperclassName)
{
- String fullClassName = component.getTagClass();
+ Set componentList = new HashSet();
+ componentList.add(component);
- try
+ ComponentBean lBean = component;
+ while ((lBean = lBean.resolveSupertype()) != null &&
+ !fullSuperclassName.equals(lBean.getTagClass()))
{
- getLog().debug("Generating " + fullClassName);
+ getLog().debug(component.getComponentType()+
+ ": Add additional Tags from: " + lBean.getComponentType());
+ componentList.add(lBean);
+ }
+
+ return componentList;
+ }
+ public void generateTagHandler(ComponentBean component)
+ {
+ ComponentTagGenerator generator;
+ Set componentList;
+
+ String fullSuperclassName = component.findJspTagSuperclass();
+ if (fullSuperclassName == null)
+ {
+ getLog().warn("Missing JSP Tag superclass for component: " + component.getComponentClass()
+ + ", generation of this Tag is skipped");
+ return;
+ }
+
+ componentList = initComponentList(component, fullSuperclassName);
+
+ String fullClassName = component.getTagClass();
+ try
+ {
+ getLog().debug("Generating " + fullClassName);
+
String sourcePath = Util.convertClassToSourcePath(fullClassName, ".java");
File targetFile = new File(generatedSourceDirectory, sourcePath);
-
+
targetFile.getParentFile().mkdirs();
StringWriter sw = new StringWriter();
PrettyWriter out = new PrettyWriter(sw);
-
+
+ if (component.isTrinidadComponent())
+ {
+ generator = new TrinidadComponentTagGenerator(_is12());
+ }
+ else
+ {
+ generator = new MyFacesComponentTagGenerator(_is12());
+ }
+
String className = Util.getClassFromFullClass(fullClassName);
String packageName = Util.getPackageFromFullClass(fullClassName);
- String fullSuperclassName = component.findJspTagSuperclass();
- if (fullSuperclassName == null)
- throw new IllegalArgumentException("Missing JSP Tag superclass");
+
+ // header/copyright
+ writePreamble(out);
+
+ // package
+ out.println("package " + packageName + ";");
+
+ out.println();
+
String superclassName = Util.getClassFromFullClass(fullSuperclassName);
if (superclassName.equals(className))
+ {
superclassName = fullSuperclassName;
+ }
String componentFullClass = component.getComponentClass();
String componentClass = Util.getClassFromFullClass(componentFullClass);
-
- // header/copyright
- writePreamble(out);
-
- // package
- out.println("package " + packageName + ";");
-
- // TODO: eliminate <mfp:tag-class-modifier> metadata
+
+ generator.writeImports(out, null, packageName, fullSuperclassName, superclassName, componentList);
+
+ generator.writeClassBegin(out, className, superclassName, component, null);
+
int modifiers = component.getTagClassModifiers();
- String classStart = Modifier.toString(modifiers);
-
- out.println();
- _writeImports(out, fullSuperclassName, superclassName,
- componentFullClass, component);
-
- out.println("/**");
- // TODO: remove this blank line.
- out.println();
- out.println(" * Auto-generated tag class.");
- out.println(" */");
-
- // TODO: use canonical ordering
- classStart = classStart.replaceAll("public abstract", "abstract public");
- out.println(classStart + " class " + className +
- " extends " + superclassName);
- out.println("{");
- out.indent();
-
- _writeConstructor(out, component);
-
+ generator.writeConstructor(out, component, modifiers);
+
+
if (!Modifier.isAbstract(modifiers))
{
- _writeGetComponentType(out, component);
- _writeGetRendererType(out, component);
+ generator.writeGetComponentType(out, component);
+ generator.writeGetRendererType(out, component);
}
-
GenerateJspTaglibsMojo.this.writeCustomComponentTagHandlerContent(out, component);
-
- _writePropertyMethods(out, component);
- _writeSetProperties(out, componentClass, component);
- _writeRelease(out, component);
-
- out.unindent();
- out.println("}");
+ generator.writePropertyMembers(out, componentList);
+ generator.writeSetPropertiesMethod(out, componentClass, componentList);
+ generator.writeReleaseMethod(out, componentList);
+
+ generator.writeClassEnd(out);
out.close();
-
+
// delay write in case of error
// timestamp should not be updated when an error occurs
// delete target file first, because it is readonly
@@ -1311,666 +1641,16 @@
getLog().error("Error generating " + fullClassName, e);
}
}
+ }
- private void _writeImports(
- PrettyWriter out,
- String fullSuperclassName,
- String superclassName,
- String componentFullClass,
- ComponentBean component)
- {
- Set imports = new TreeSet();
-
- Iterator properties = component.properties();
- properties = new FilteredIterator(properties, new TagAttributeFilter());
- if (properties.hasNext())
- {
- imports.add(componentFullClass);
- }
-
- imports.add("org.apache.myfaces.trinidad.bean.FacesBean");
-
- // TODO: remove these imports
- // FIXME: Actually last 2 can be kept when not abstract
- //imports.add("javax.faces.component.UIComponent");
-
- // superclassName is fully qualified if it collides
- // with the generated class name and should not be
- // imported when such a collision would occur
- if (!superclassName.equals(fullSuperclassName))
- imports.add(fullSuperclassName);
-
- while (properties.hasNext())
- {
- PropertyBean property = (PropertyBean)properties.next();
-
- String propertyClass = property.getPropertyClass();
- String[] propertyClassParams = property.getPropertyClassParameters();
-
- if (propertyClass != null && property.isLiteralOnly())
- {
- // Import the property class only if only litterals are supported
- // otherwise the class will be a String inside the tag to support
- // ValueBinding
- imports.add(propertyClass);
- }
-
- if (_isKeyStroke(propertyClass))
- {
- imports.add("javax.faces.el.ValueBinding");
- imports.add("javax.swing.KeyStroke");
- }
- else if (_isAWTKeyStroke(propertyClass))
- {
- imports.add("javax.faces.el.ValueBinding");
- imports.add("java.awt.AWTKeyStroke");
- }
- else if (_isConverter(propertyClass))
- {
- imports.add("javax.faces.el.ValueBinding");
- imports.add("javax.faces.convert.Converter");
- }
- else if (property.isVirtual())
- {
- imports.add("javax.faces.el.ValueBinding");
- imports.add("org.apache.myfaces.trinidadinternal.taglib.util.VirtualAttributeUtils");
- }
- else if (_isColorList(propertyClass, propertyClassParams))
- {
- imports.add("javax.faces.el.ValueBinding");
- imports.add("java.text.ParseException");
- imports.add("org.apache.myfaces.trinidadinternal.taglib.util.TagUtils");
- }
- else if (property.isMethodBinding())
- {
- imports.add("javax.faces.el.MethodBinding");
- }
-
- // TODO: restore import and make reference to
- // ConstantMethodBinding relative rather
- // than absolute
- //if (property.isMethodBinding() &&
- // isStringMethodBindingReturnType(property))
- //{
- // imports.add("org.apache.myfaces.trinidadinternal.taglib.ConstantMethodBinding");
- //}
- }
-
-
- GenerateJspTaglibsMojo.this.addCustomComponentTagHandlerImports(imports, component);
-
- // do not import implicit!
- imports.removeAll(Util.PRIMITIVE_TYPES);
-
-
- String tagClass = component.getTagClass();
- String packageName = Util.getPackageFromFullClass(tagClass);
- writeImports(out, packageName, imports);
- }
-
- private void _writeConstructor(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- String fullClassName = component.getTagClass();
- String className = Util.getClassFromFullClass(fullClassName);
- out.println();
- out.println("/**");
- // TODO: restore this correctly phrased comment (tense vs. command)
- //out.println(" * Constructs an instance of " + className + ".");
- out.println(" * Construct an instance of the " + className + ".");
- out.println(" */");
- out.println("public " + className + "()");
- out.println("{");
- out.println("}");
- }
-
- private void _writeGetComponentType(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- String componentType = component.getComponentType();
- out.println();
- out.println("@Override");
- out.println("public String getComponentType()");
- out.println("{");
- out.indent();
- out.println("return \"" + componentType + "\";");
- out.unindent();
- out.println("}");
- }
-
- private void _writeGetRendererType(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- String rendererType = component.getRendererType();
- out.println();
- out.println("@Override");
- out.println("public String getRendererType()");
- out.println("{");
- out.indent();
- out.println("return " + convertStringToLiteral(rendererType) + ";");
- out.unindent();
- out.println("}");
- }
-
- private void _writeRelease(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- Iterator properties = component.properties();
- properties = new FilteredIterator(properties, new TagAttributeFilter());
- // TODO: remove special case for UIXFormTag
- if (properties.hasNext() ||
- "org.apache.myfaces.trinidadinternal.taglib.UIXFormTag".equals(component.getTagClass()))
- {
- out.println();
- out.println("@Override");
- out.println("public void release()");
- out.println("{");
- out.indent();
- out.println("super.release();");
- while (properties.hasNext())
- {
- PropertyBean property = (PropertyBean)properties.next();
- String propName = property.getPropertyName();
- String propVar = "_" + Util.getVariableFromName(propName);
- out.println(propVar + " = null;");
- }
- out.unindent();
- out.println("}");
- }
- }
-
- private void _writePropertyMethods(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- Iterator properties = component.properties();
- properties = new FilteredIterator(properties, new TagAttributeFilter());
- while (properties.hasNext())
- {
- PropertyBean property = (PropertyBean)properties.next();
- out.println();
- _writePropertyMember(out, property);
- _writePropertySet(out, property);
- }
- }
-
- private void _writePropertyMembers(
- PrettyWriter out,
- ComponentBean component) throws IOException
- {
- Iterator properties = component.properties();
- properties = new FilteredIterator(properties, new TagAttributeFilter());
- if (properties.hasNext())
- {
- out.println();
- while (properties.hasNext())
- {
- PropertyBean property = (PropertyBean)properties.next();
- _writePropertyMember(out, property);
- }
- }
- }
-
- private void _writePropertyMember(
- PrettyWriter out,
- PropertyBean property) throws IOException
- {
- String propName = property.getPropertyName();
- String propVar = "_" + Util.getVariableFromName(propName);
- out.println("private String " + propVar + ";");
- }
-
- private void _writePropertySet(
- PrettyWriter out,
- PropertyBean property) throws IOException
- {
- String propName = property.getPropertyName();
- String propVar = Util.getVariableFromName(propName);
- String setMethod = Util.getPrefixedPropertyName("set", propName);
-
- // TODO: restore coding standards, and make final
- out.println("public void " + setMethod + "(String " + propVar + ")");
- out.println("{");
- out.indent();
- out.println("_" + propVar + " = " + propVar + ";");
- out.unindent();
- out.println("}");
- }
-
- private void _writeSetProperties(
- PrettyWriter out,
- String componentClass,
- ComponentBean component) throws IOException
- {
- Iterator properties = component.properties();
- properties = new FilteredIterator(properties, new TagAttributeFilter());
- // TODO: only write out setProperties when properties exist
- // if (properties.hasNext())
- // {
- out.println();
- out.println("@Override");
- out.println("protected void setProperties(");
- out.indent();
- out.println("FacesBean bean)");
- out.unindent();
- out.println("{");
- out.indent();
- out.println("super.setProperties(bean);");
-
- while (properties.hasNext())
- {
- PropertyBean property = (PropertyBean)properties.next();
- _writeSetPropertiesCase(out, componentClass, property);
- }
- out.unindent();
- out.println("}");
- // }
- }
-
- private void _writeSetPropertiesCase(
- PrettyWriter out,
- String componentClass,
- PropertyBean property) throws IOException
- {
- String propName = property.getPropertyName();
- String propClass = property.getPropertyClass();
- String propVar = "_" + Util.getVariableFromName(propName);
-
- if (property.isVirtual())
- {
- _writeVirtualSetMethod(out, componentClass, propName);
- }
- else if (property.isMethodBinding())
- {
- _writeSetMethodBinding(out, componentClass, property);
- }
- else if (_isKeyStroke(propClass))
- {
- _writeSetKeyStroke(out, componentClass, propName);
- }
- else if (_isAWTKeyStroke(propClass))
- {
- _writeSetAWTKeyStroke(out, componentClass, propName);
- }
- else if (_isColorList(propClass, property.getPropertyClassParameters()))
- {
- _writeSetColorList(out, componentClass, propName);
- }
- else if (_isConverter(propClass))
- {
- _writeSetConverter(out, componentClass, propName);
- }
- else if (property.isLiteralOnly())
- {
- _writeSetLiteral(out, componentClass, propName, propClass, propVar);
- }
- else //if (_hasPropertySetter(property))
- {
- _writeSetProperty(out, componentClass, propName, propClass, propVar);
- }
- // else
- // {
- // _writeSetValueBinding(out, componentClass, propName, propVar);
- // }
- }
-
- /**
- * Returns true if this property is a complex Object.
- *
- * @return true if this property is a complex Object,
- * otherwise false
- */
- private boolean _hasPropertySetter(
- PropertyBean property)
- {
- String propertyClass = property.getPropertyClass();
- return (Util.PRIMITIVE_TYPES.contains(propertyClass) ||
- "java.lang.Object".equals(propertyClass) ||
- "java.lang.String".equals(propertyClass) ||
- "java.lang.String[]".equals(propertyClass));
- }
-
- private boolean _isConverter(
- String propClass)
- {
- return ("javax.faces.convert.Converter".equals(propClass));
- }
-
- private String[] _getAccessKeyPropertyKeys(
- String componentClass,
- String propName)
- {
- String[] propKeys = new String[2];
-
- int offset = propName.indexOf("AndAccessKey");
- if (offset != -1)
- {
- String mainProp = propName.substring(0, offset);
- propKeys[0] = componentClass + "." +
- Util.getConstantNameFromProperty(mainProp, "_KEY");
- propKeys[1] = componentClass + "." +
- Util.getConstantNameFromProperty("accessKey", "_KEY");
- }
-
- return propKeys;
- }
-
- private boolean _isKeyStroke(
- String propClass)
- {
- return ("javax.swing.KeyStroke".equals(propClass));
- }
-
- private boolean _isAWTKeyStroke(
- String propClass)
- {
- return ("java.awt.AWTKeyStroke".equals(propClass));
- }
-
- private boolean _isColorList(
- String propClass,
- String[] propClassParams)
- {
- return ("java.util.List".equals(propClass) &&
- propClassParams.length == 1 &&
- "java.awt.Color".equals(propClassParams[0]));
- }
-
- private void _writeSetLiteral(
- PrettyWriter out,
- String componentClass,
- String propName,
- String propClass,
- String propVar)
- {
- // TODO: reject value binding expressions for literal-only
- _writeSetProperty(out, componentClass, propName, propClass, propVar);
- }
-
- private void _writeSetProperty(
- PrettyWriter out,
- String componentClass,
- String propName,
- String propFullClass,
- String propVar)
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propClass = Util.getClassFromFullClass(propFullClass);
- String boxedClass = Util.getBoxedClass(propClass);
- String setProperty = "setProperty";
- if (!boxedClass.equals(propClass) ||
- "java.lang.Number".equals(propFullClass) ||
- "java.util.Date".equals(propFullClass) ||
- (boxedClass.indexOf("[]") != -1))
- {
- String propType = boxedClass.replaceAll("\\[\\]", "Array");
- setProperty = Util.getPrefixedPropertyName("set", propType + "Property");
- }
- out.println(setProperty + "(bean, " +
- componentClass + "." + propKey + ", " +
- propVar + ");" );
- }
-
- private void _writeSetValueBinding(
- PrettyWriter out,
- String componentClass,
- String propName,
- String propVar)
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", " +
- "createValueBinding(" + propVar + "));" );
- }
-
- private void _writeVirtualSetMethod(
- PrettyWriter out,
- String componentClass,
- String propName) throws IOException
- {
- String[] propKeys = _getAccessKeyPropertyKeys(componentClass, propName);
-
- String propVar = "_" + propName;
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
- out.println("if (isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
- out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
- out.indent();
- out.println("bean,");
- out.println("vb,");
- out.println(propKeys[0] + ",");
- out.println(propKeys[1] + ");");
- out.unindent();
- out.unindent();
- out.println("}");
- out.println("else");
- out.println("{");
- out.indent();
- out.println("VirtualAttributeUtils.setAccessKeyAttribute(");
- out.indent();
- out.println("bean,");
- out.println(propVar + ",");
- out.println(propKeys[0] + ",");
- out.println(propKeys[1] + ");");
- out.unindent();
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- }
-
- private void _writeSetMethodBinding(
- PrettyWriter out,
- String componentClass,
- PropertyBean property) throws IOException
- {
- String propName = property.getPropertyName();
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propVar = "_" + propName;
-
- MethodSignatureBean signature = property.getMethodBindingSignature();
- String[] paramTypes = (signature != null) ? signature.getParameterTypes() : null;
-
- String classArray;
-
- if (paramTypes == null || paramTypes.length == 0)
- {
- classArray = "new Class[0]";
- }
- else
- {
- StringBuffer sb = new StringBuffer();
- sb.append("new Class[]{");
- for (int i=0; i < paramTypes.length; i++)
- {
- if (i > 0)
- sb.append(',');
- sb.append(paramTypes[i]);
- sb.append(".class");
- }
-
- // TODO: remove trailing comma
- sb.append(',');
-
- sb.append('}');
- classArray = sb.toString();
- }
-
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
-
- if (isStringMethodBindingReturnType(signature))
- {
- out.println("MethodBinding mb;");
- out.println("if (isValueReference(" + propVar + "))");
- out.indent();
- out.println("mb = createMethodBinding(" + propVar + ", " + classArray + ");");
- out.unindent();
- out.println("else");
- out.indent();
- out.println("mb = new org.apache.myfaces.trinidadinternal.taglib.ConstantMethodBinding(" + propVar + ");");
- out.unindent();
- }
- else
- {
- // never a literal, no need for ConstantMethodBinding
- out.println("MethodBinding mb = createMethodBinding(" + propVar + ", " +
- classArray + ");");
- }
-
- out.println("bean.setProperty(" + componentClass + "." + propKey + ", mb);");
- out.unindent();
- out.println("}");
- }
-
- private void _writeSetKeyStroke(
- PrettyWriter out,
- String componentClass,
- String propName) throws IOException
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propVar = "_" + propName;
-
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
- out.println("if (isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
- out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
- out.unindent();
- out.println("}");
- out.println("else");
- out.println("{");
- out.indent();
- out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
- out.println("\tKeyStroke.getKeyStroke(" + propVar + "));");
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- }
-
-
- private void _writeSetAWTKeyStroke(
- PrettyWriter out,
- String componentClass,
- String propName) throws IOException
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propVar = "_" + propName;
-
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
- out.println("if (isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
- out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
- out.unindent();
- out.println("}");
- out.println("else");
- out.println("{");
- out.indent();
- out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
- out.println("\tAWTKeyStroke.getAWTKeyStroke(" + propVar + "));");
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- }
-
-
-
- private void _writeSetColorList(
- PrettyWriter out,
- String componentClass,
- String propName) throws IOException
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propVar = "_" + propName;
-
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
- out.println("if (isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
- out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
- out.unindent();
- out.println("}");
- out.println("else");
- out.println("{");
- out.indent();
- out.println("try");
- out.println("{");
- out.indent();
- out.println("bean.setProperty(" + componentClass + "." + propKey + ",");
- out.println(" TagUtils.getColorList(" + propVar + "));");
- out.unindent();
- out.println("}");
- out.println("catch (ParseException pe)");
- out.println("{");
- out.indent();
- out.println("setValidationError(");
- out.println(" pe.getMessage() + \": \" + \"Position \" + pe.getErrorOffset());");
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- }
-
-
- private void _writeSetConverter(
- PrettyWriter out,
- String componentClass,
- String propName) throws IOException
- {
- String propKey = Util.getConstantNameFromProperty(propName, "_KEY");
- String propVar = "_" + propName;
-
- out.println("if (" + propVar + " != null)");
- out.println("{");
- out.indent();
- out.println("if (isValueReference(" + propVar + "))");
- out.println("{");
- out.indent();
- out.println("ValueBinding vb = createValueBinding(" + propVar + ");");
- out.println("bean.setValueBinding(" + componentClass + "." + propKey + ", vb);");
- out.unindent();
- out.println("}");
- out.println("else");
- out.println("{");
- out.indent();
- out.println("Converter converter = getFacesContext().getApplication().");
- out.indent();
- out.println("createConverter(" + propVar + ");");
- out.unindent();
- out.println("bean.setProperty(" + componentClass + "." + propKey + ", converter);");
- out.unindent();
- out.println("}");
- out.unindent();
- out.println("}");
- }
+ protected boolean is12()
+ {
+ return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
}
- private boolean isStringMethodBindingReturnType(
- MethodSignatureBean sig)
+ private boolean _is12()
{
- return (sig != null && "java.lang.String".equals(sig.getReturnType()));
+ return is12();
}
private class IfComponentModifiedFilter extends ComponentFilter
@@ -2070,21 +1750,40 @@
/**
* @parameter
- * @required
*/
- protected String packageContains;
+ protected String packageContains = "";
/**
* @parameter
*/
protected boolean force;
+
+ /**
+ * @parameter
+ */
+ protected boolean disableIdExpressions;
+
+ /**
+ * @parameter
+ */
+ protected boolean coerceStrings;
+
+
+ /**
+ * @parameter
+ */
+ private String jsfVersion;
+
static private String _resolveType(
String className)
{
return (String)_RESOLVABLE_TYPES.get(className);
}
+ // TODO: for everything but Locale, String[], Date, and TimeZone,
+ // in JSF 1.2 we should already be going through coercion, and
+ // not need any of the "TagUtils" functions
static private Map _createResolvableTypes()
{
Map resolvableTypes = new HashMap();
@@ -2127,4 +1826,43 @@
" href CDATA #IMPLIED\n" +
" xpointer CDATA #IMPLIED>\n" +
"]>\n";
+
+ static final private Set _CAN_COERCE = new HashSet();
+ static
+ {
+ // What? Can't coerce Strings? How could that be? Well, take a look at:
+ // http://issues.apache.org/jira/browse/ADFFACES-377
+ // The silly coercion rules in JSP convert null to the
+ // empty string. So it's not that we can't coerce to
+ // String, we just really, really don't want to.
+ // _CAN_COERCE.add("java.lang.String");
+ // TODO: consider getting rid of coercion rules for
+ // all non-primitives
+ _CAN_COERCE.add("java.lang.Integer");
+ _CAN_COERCE.add("java.lang.Long");
+ _CAN_COERCE.add("java.lang.Boolean");
+ _CAN_COERCE.add("java.lang.Double");
+ _CAN_COERCE.add("java.lang.Float");
+ _CAN_COERCE.add("java.lang.Short");
+ _CAN_COERCE.add("java.lang.Character");
+ _CAN_COERCE.add("java.lang.Byte");
+ _CAN_COERCE.add("int");
+ _CAN_COERCE.add("long");
+ _CAN_COERCE.add("boolean");
+ _CAN_COERCE.add("double");
+ _CAN_COERCE.add("float");
+ _CAN_COERCE.add("short");
+ _CAN_COERCE.add("char");
+ _CAN_COERCE.add("byte");
+
+ // See http://issues.apache.org/jira/browse/ADFFACES-477: for
+ // "binding" and "converter" properties, we want the deferred-types
+ // there. Hardcoding these here is very ugly, but putting in
+ // all coercion rules would break how Trinidad handles Dates,
+ // and Lists of Colors, etc. - for those, we want to support
+ // raw Strings (which the JSP engine doesn't know how to coerce)
+ // and coerce them ourselves in the tag.
+ _CAN_COERCE.add("javax.faces.component.UIComponent");
+ _CAN_COERCE.add("javax.faces.convert.Converter");
+ }
}
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ComponentBean.java Tue Jul 3 13:51:23 2007
@@ -18,17 +18,15 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces.parse;
-import java.lang.reflect.Modifier;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.CompoundIterator;
+import javax.xml.namespace.QName;
+import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;
-import javax.xml.namespace.QName;
-
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.CompoundIterator;
-
/**
* ComponentBean is a Java representation of the faces-config component
* XML element.
@@ -228,6 +226,27 @@
return _tagClass;
}
+ /**
+ * Sets the JSP tag handler superclass for this component.
+ *
+ * @param tagSuperclass the JSP tag handler superclass
+ */
+ public void setTagSuperclass(
+ String tagSuperclass)
+ {
+ _tagSuperclass = tagSuperclass;
+ }
+
+ /**
+ * Returns the JSP tag handler superclass for this component.
+ *
+ * @return the JSP tag handler superclass
+ */
+ public String getTagSuperclass()
+ {
+ return _tagSuperclass;
+ }
+
/**
* Returns the JSP tag name for this component.
*
@@ -334,27 +353,6 @@
}
/**
- * Sets the peer type for this component.
- *
- * @param peerType the peer type
- */
- public void setPeerType(
- String peerType)
- {
- _peerType = peerType;
- }
-
- /**
- * Returns the peer type for this component.
- *
- * @return the peer type
- */
- public String getPeerType()
- {
- return _peerType;
- }
-
- /**
* Returns the default renderer type for this component.
*
* @return the default renderer type
@@ -365,17 +363,17 @@
return (parent != null) ? parent.findRendererType() : null;
}
- /**
- * Returns the default peer type for this component.
- *
- * @return the default peer type
- */
- public String getDefaultPeerType()
+ public String getImplementationType()
{
- ComponentBean parent = resolveSupertype();
- return (parent != null) ? parent.findPeerType() : null;
+ return _implementationType;
+ }
+
+ public void setImplementationType(String implementationType)
+ {
+ _implementationType = implementationType;
}
+
/**
* Adds a property to this component.
*
@@ -484,6 +482,15 @@
return properties;
}
+ /**
+ * Number of properties for this component
+ * @return num of properties
+ */
+ public int propertiesSize()
+ {
+ return _properties.size();
+ }
+
/**
* Adds a facet to this component.
*
@@ -858,20 +865,6 @@
return (parent != null) ? parent.findRendererType() : null;
}
- /**
- * Finds the peer type in the component inheritance
- * hierarchy.
- *
- * @return the peer type
- */
- public String findPeerType()
- {
- if (_peerType != null)
- return _peerType;
-
- ComponentBean parent = resolveSupertype();
- return (parent != null) ? parent.findPeerType() : null;
- }
/**
* Finds the component superclass in the component inheritance
@@ -920,6 +913,31 @@
}
/**
+ * Checks if any of the component superclasses is UIXComponentBase
+ */
+ public boolean isTrinidadComponent()
+ {
+ String implementationType = getImplementationType();
+ if (implementationType != null)
+ return "trinidad".equals(implementationType);
+
+ ComponentBean componentSupertype = resolveSupertype();
+ if (componentSupertype != null)
+ {
+ if (_TRINIDAD_COMPONENT_BASE.equals(componentSupertype.getComponentClass()))
+ {
+ return true;
+ }
+ else
+ {
+ return componentSupertype.isTrinidadComponent();
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Finds the component class in the component inheritance
* hierarchy.
*
@@ -974,7 +992,7 @@
private String _componentSupertype;
private String _componentSuperclass;
private String _rendererType;
- private String _peerType;
+ private String _implementationType;
private QName _tagName;
private String _tagClass;
private String _tagSuperclass;
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ConverterBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ConverterBean.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ConverterBean.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/ConverterBean.java Tue Jul 3 13:51:23 2007
@@ -18,14 +18,13 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces.parse;
+import javax.xml.namespace.QName;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;
-import javax.xml.namespace.QName;
-
/**
* ConverterBean is a Java representation of the faces-config converter
* XML element.
@@ -169,7 +168,7 @@
/**
* Sets the JSP tag name for this component.
*
- * @param tagClass the JSP tag name
+ * @param tagName the JSP tag name
*/
public void setTagName(
QName tagName)
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/FacesConfigParser.java Tue Jul 3 13:51:23 2007
@@ -18,26 +18,20 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces.parse;
-import java.io.IOException;
-import java.io.InputStream;
-
-import java.net.URL;
-import java.net.URLConnection;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.commons.digester.Digester;
import org.apache.commons.digester.AbstractObjectCreationFactory;
-
+import org.apache.commons.digester.Digester;
import org.apache.maven.plugin.MojoExecutionException;
-
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.rules.BeanPropertySetterRule;
+import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
-
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.rules.BeanPropertySetterRule;
-import org.apache.myfaces.trinidadbuild.plugin.faces.util.XIncludeFilter;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
public class FacesConfigParser
{
@@ -147,14 +141,16 @@
"componentSuperclass");
digester.addBeanPropertySetter("faces-config/component/component-extension/renderer-type",
"rendererType");
- digester.addBeanPropertySetter("faces-config/component/component-extension/peer-type",
- "peerType");
digester.addBeanPropertySetter("faces-config/component/component-extension/naming-container",
"namingContainer");
digester.addBeanPropertySetter("faces-config/component/component-extension/accepts-child-components",
"children");
digester.addBeanPropertySetter("faces-config/component/component-extension/tag-class",
"tagClass");
+ digester.addBeanPropertySetter("faces-config/component/component-extension/tag-superclass",
+ "tagSuperclass");
+ digester.addBeanPropertySetter("faces-config/component/component-extension/implementation-type",
+ "implementationType");
digester.addCallMethod("faces-config/component/component-extension/tag-class-modifier",
"parseTagClassModifier", 1);
digester.addCallParam("faces-config/component/component-extension/tag-class-modifier", 0);
@@ -182,6 +178,8 @@
// faces-config/component/property/property-extension
digester.addBeanPropertySetter("faces-config/component/property/property-extension/state-holder",
"stateHolder");
+ digester.addBeanPropertySetter("faces-config/component/property/property-extension/jsp-property-name",
+ "jspPropertyName");
// faces-config/component/property/property-extension
digester.addBeanPropertySetter("faces-config/component/property/property-extension/list",
"list");
@@ -192,6 +190,8 @@
digester.addBeanPropertySetter("faces-config/component/property/property-extension/transient");
digester.addBeanPropertySetter("faces-config/component/property/property-extension/literal-only",
"literalOnly");
+ digester.addBeanPropertySetter("faces-config/component/property/property-extension/enum",
+ "enum");
digester.addBeanPropertySetter("faces-config/component/property/property-extension/alternate-class",
"alternateClass");
digester.addBeanPropertySetter("faces-config/component/property/property-extension/tag-attribute-excluded",
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/parse/PropertyBean.java Tue Jul 3 13:51:23 2007
@@ -273,6 +273,22 @@
}
/**
+ * Returns true if the property is an enumerated Java type.
+ */
+ public boolean isEnum()
+ {
+ return _enum;
+ }
+
+ /**
+ * Returns true if the property is an enumerated Java type.
+ */
+ public void setEnum(boolean isEnum)
+ {
+ _enum = isEnum;
+ }
+
+ /**
* Returns true if this property is a method binding.
*
* @return true if this property is a method binding,
@@ -283,6 +299,18 @@
return ("javax.faces.el.MethodBinding".equals(getPropertyClass()));
}
+
+ /**
+ * Returns true if this property is a method binding.
+ *
+ * @return true if this property is a method binding,
+ * otherwise false
+ */
+ public boolean isMethodExpression()
+ {
+ return ("javax.el.MethodExpression".equals(getPropertyClass()));
+ }
+
/**
* Parses the possible values for this property into a String array
* using space as the separator between values.
@@ -307,14 +335,64 @@
setUnsupportedAgents(unsupportedAgents.split(" "));
}
+ /**
+ * Sets the JSP name of this property.
+ *
+ * @param jspPropertyName the JSP property name
+ */
+ public void setJspPropertyName(
+ String jspPropertyName)
+ {
+ _jspPropertyName = jspPropertyName;
+ }
+
+ /**
+ * Returns the JSP name of this property.
+ *
+ * @return the JSP property name
+ */
+ public String getJspPropertyName()
+ {
+ if (_jspPropertyName == null)
+ return getPropertyName();
+
+ return _jspPropertyName;
+ }
+
+ /**
+ * Sets the field name of this property, when not generating Trinidad components
+ *
+ * @param fieldPropertyName the field property name
+ */
+ public void setFieldPropertyName(
+ String fieldPropertyName)
+ {
+ _fieldPropertyName = fieldPropertyName;
+ }
+
+ /**
+ * Returns the field name of this property, when not generating Trinidad components
+ *
+ * @return the field property name
+ */
+ public String getFieldPropertyName()
+ {
+ if (_fieldPropertyName == null)
+ return "_"+getPropertyName();
+
+ return _fieldPropertyName;
+ }
private String _aliasOf;
+ private String _jspPropertyName;
+ private String _fieldPropertyName;
private boolean _required;
private boolean _literalOnly;
private boolean _stateHolder;
private boolean _transient;
private boolean _list;
private boolean _tagAttributeExcluded;
+ private boolean _enum;
private String[] _propertyValues;
private String[] _unsupportedAgents = _EMPTY_ARRAY;
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/SourceTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/SourceTemplate.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/SourceTemplate.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/SourceTemplate.java Tue Jul 3 13:51:23 2007
@@ -18,19 +18,8 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces.util;
-import java.io.BufferedReader;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Writer;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.io.*;
+import java.util.*;
public class SourceTemplate
{
@@ -104,8 +93,15 @@
if (line == null)
throw new EOFException("File " + _file + " ended prematurely");
- if (line.startsWith(_IGNORE_PREFIX))
- continue;
+ if (line.trim().startsWith(_IGNORE_PREFIX)){
+ if (line.trim().startsWith(_IGNORE_PREFIX2)){
+ String method = line.trim().substring(_IGNORE_PREFIX2.length()).trim();
+ if (method.length() > 0 ){
+ _ignoreMethods.add(method);
+ }
+ }
+ continue;
+ }
if (line.equals("}"))
break;
@@ -150,13 +146,19 @@
return buffer.toString();
}
- private File _file;
+ public Collection getIgnoreMethods() {
+ return _ignoreMethods;
+ }
+
+ private File _file;
private BufferedReader _reader;
private Set _imports = new HashSet();
private Map _fqcnMap = new HashMap();
private Set _implements = new HashSet();
private Map _substitutions = new HashMap();
+ private Set _ignoreMethods = new HashSet();
// Magic syntax indicating "please ignore this line"
static private final String _IGNORE_PREFIX = "/**/";
+ static private final String _IGNORE_PREFIX2 = "/**///";
}
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/util/Util.java Tue Jul 3 13:51:23 2007
@@ -18,6 +18,8 @@
*/
package org.apache.myfaces.trinidadbuild.plugin.faces.util;
+import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
+
import java.io.File;
import java.util.Collections;
import java.util.Set;
@@ -25,8 +27,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.myfaces.trinidadbuild.plugin.faces.parse.PropertyBean;
-
public class Util
{
static public String convertClassToSourcePath(
@@ -42,6 +42,17 @@
return (className != null && className.indexOf('.') != -1);
}
+ public static String getGenericsFromProperty(PropertyBean property){
+ String gen = "";
+ for (int i = 0; i < property.getAttributeClassParameters().length; i++) {
+ if (i>0){
+ gen += ",";
+ }
+ gen += getClassFromFullClass(property.getAttributeClassParameters()[i]);
+ }
+ return (gen.length() > 0?"<"+gen+">":gen);
+ }
+
static public String getClassFromFullClass(
String fullClass)
{
@@ -49,7 +60,6 @@
return null;
int lastSep = fullClass.lastIndexOf('.');
-
// Note: this code also works for the empty package
return (fullClass.substring(lastSep + 1));
}
@@ -206,6 +216,28 @@
return className;
}
+ static public String primitiveDefaultValue(String className)
+ {
+ if ("boolean".equals(className))
+ return "false";
+ else if ("byte".equals(className))
+ return "0";
+ else if ("char".equals(className))
+ return "''";
+ else if ("double".equals(className))
+ return "0.0d";
+ else if ("float".equals(className))
+ return "0.0f";
+ else if ("int".equals(className))
+ return "0";
+ else if ("long".equals(className))
+ return "0L";
+ else if ("short".equals(className))
+ return "0";
+ else
+ return className;
+ }
+
static public String fill(
String base,
int length)
@@ -257,7 +289,46 @@
return name;
}
- static private void _buildPropertyClass(StringBuffer buffer, String type)
+ static public String convertStringToLiteral(String value)
+ {
+ return convertStringToLiteral("String", value);
+ }
+
+ static public String convertStringToLiteral(String className, String value)
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ else if ("String".equals(className))
+ {
+ return "\"" + value.replaceAll("\'", "\\'") + "\"";
+ }
+ else
+ {
+ return value;
+ }
+ }
+
+ static public String getDefaultValue(PropertyBean property){
+ String propertyFullClass = property.getPropertyClass();
+ String def = property.getDefaultValue();
+ if (def == null || def.length() == 0){
+ return null;
+ }
+ if (isPrimitiveClass(propertyFullClass)){
+ return def;
+ } else if ("java.lang.String".equals(propertyFullClass)){
+ if (def.startsWith("\"") && def.endsWith("\"")){
+ return def;
+ } else {
+ return "\""+def+"\"";
+ }
+ }
+ return null;
+ }
+
+ static private void _buildPropertyClass(StringBuffer buffer, String type)
{
Matcher matcher = _GENERIC_TYPE.matcher(type);
if(matcher.matches())
Modified: myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-i18n-plugin/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-i18n-plugin/pom.xml?view=diff&rev=552975&r1=552974&r2=552975
==============================================================================
--- myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-i18n-plugin/pom.xml (original)
+++ myfaces/trinidad/branches/pre-1.2.2-branch/plugins/maven-i18n-plugin/pom.xml Tue Jul 3 13:51:23 2007
@@ -23,12 +23,12 @@
<parent>
<groupId>org.apache.myfaces.trinidadbuild</groupId>
<artifactId>maven-plugin-parent</artifactId>
- <version>1.0.2-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
</parent>
<groupId>org.apache.myfaces.trinidadbuild</groupId>
<artifactId>maven-i18n-plugin</artifactId>
- <version>1.0.2-SNAPSHOT</version>
+ <version>1.2.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Apache Trinidad Maven i18n Plugin</name>