Update of
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-struts/src/main/java/org/xdoclet/plugin/struts
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3949/plugin-struts/src/main/java/org/xdoclet/plugin/struts
Modified Files:
StrutsValidationXMLPlugin.java
Added Files:
StrutsMessagePlugin.java StrutsMessagePlugin.vm
StrutsTilesPlugin.java StrutsTilesPlugin.jelly
tiles-config_1_1.dtd
Log Message:
fix for XDP-73 and some improvements of build process
--- NEW FILE: tiles-config_1_1.dtd ---
<!--
DTD for the Tile Definition File, Version 1.1
To support validation of your configuration file, include the following
DOCTYPE element at the beginning (after the "xml" declaration):
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://struts.apache.org/dtds/tiles-config_1_1.dtd">
$Id: tiles-config_1_1.dtd,v 1.1 2005/07/02 13:16:29 ko5tik Exp $
-->
<!-- ========== Defined Types ============================================= -->
<!-- A "Boolean" is the string representation of a boolean (true or false)
variable.
-->
<!ENTITY % Boolean "(true|false)">
<!-- A "ContentType" is the content type of an attribute passed to a tile
component.
-->
<!ENTITY % ContentType "(string|page|template|definition)">
<!-- A "ClassName" is the fully qualified name of a Java class that is
instantiated to provide the functionality of the enclosing element.
-->
<!ENTITY % ClassName "CDATA">
<!-- A "RequestPath" is an module-relative URI path, beginning with a
slash, that identifies a mapped resource (such as a JSP page or a servlet)
within this web application.
-->
<!ENTITY % RequestPath "CDATA">
<!-- A "DefinitionName" is the unique identifier of a definition. This
identifier
is a logical name used to reference the definition.
-->
<!ENTITY % DefinitionName "CDATA">
<!-- A "BeanName" is the identifier of a JavaBean, such as a form bean,
and also serves as the name of the corresponding scripting variable
and the name of the JSP attribute under which the bean is accessed.
Therefore, it must conform to the rules for a Java identifier.
-->
<!ENTITY % BeanName "CDATA">
<!-- A "PropName" is the name of a JavaBeans property, and must begin with
a lower case letter and contain only characters that are legal in a
Java identifier.
-->
<!ENTITY % PropName "CDATA">
<!-- A "Location" is a relative path, delimited by "/" characters, that
defines the location of a resource relative to the location of the
configuration file itself.
-->
<!ENTITY % Location "#PCDATA">
<!-- ========== Top Level Elements ======================================== -->
<!-- deprecated: use tiles-definitions instead.-->
<!ELEMENT component-definitions (definition+)>
<!-- The "tiles-definitions" element is the root of the configuration file
hierarchy, and contains nested elements for all of the other
configuration settings.
-->
<!ELEMENT tiles-definitions (definition+)>
<!-- The "definition" element describes a definition that can be inserted in a
jsp
page. This definition is identified by its logical name. A definition
allows
to define all the attributes that can be set in <insert> tag from a jsp
page.
controllerClass The fully qualified Java class name of the controller
subclass to call immediately before the tiles is inserted.
Only one of controllerClass or controllerUrl should be
specified.
controllerUrl The context-relative path to the resource used as
controller
called immediately before the tiles is inserted.
Only one of controllerClass or controllerUrl should be
specified.
extends Name of a definition that is used as ancestor of this
definition.
All attributes from the ancestor are available to the new
definition. Any attribute inherited from the ancestor can
be overloaded by providing a new value.
name The unique identifier for this definition.
page Same as path.
path The context-relative path to the resource used as tiles to
insert. This tiles will be inserted and a tiles context
containing appropriate attributes will be available.
role Security role name that is allowed access to this
definition
object. The definition is inserted only if the role name is
allowed.
template Same as path. For compatibility with the template tag
library.
-->
<!ELEMENT definition (icon?, display-name?, description?, put*, putList*)>
<!ATTLIST definition id ID #IMPLIED>
<!ATTLIST definition controllerClass %ClassName; #IMPLIED>
<!ATTLIST definition controllerUrl %RequestPath; #IMPLIED>
<!ATTLIST definition extends %DefinitionName; #IMPLIED>
<!ATTLIST definition name %DefinitionName; #REQUIRED>
<!ATTLIST definition page %RequestPath; #IMPLIED>
<!ATTLIST definition path %RequestPath; #IMPLIED>
<!ATTLIST definition role CDATA #IMPLIED>
<!ATTLIST definition template %RequestPath; #IMPLIED>
<!-- The "put" element describes an attribute of a definition. It allows to
specify the tiles attribute name and its value. The tiles value can be
specified as an xml attribute, or in the body of the <put> tag.
content Same as value. For compatibility with the template tag
library.
direct Same as type="string". For compatibility with the template
tag library.
name The unique identifier for this put.
type The type of the value. Can be: string, page, template or
definition.
By default, no type is associated to a value. If a type is
associated, it will be used as a hint to process the value
when the attribute will be used in the inserted tiles.
value The value associated to this tiles attribute. The value
should
be specified with this tag attribute, or in the body of
the tag.
-->
<!ELEMENT put (#PCDATA)>
<!ATTLIST put id ID #IMPLIED>
<!ATTLIST put content CDATA #IMPLIED>
<!ATTLIST put direct %Boolean; #IMPLIED>
<!ATTLIST put name CDATA #REQUIRED>
<!ATTLIST put type %ContentType; #IMPLIED>
<!ATTLIST put value CDATA #IMPLIED>
<!-- The "putList" element describes a list attribute of a definition. It
allows to
specify an attribute that is a java List containing any kind of values. In
the config file, the list elements are specified by nested <add>, <item> or
<putList>.
name The unique identifier for this put list.
-->
<!ELEMENT putList ( (add* | item* | bean* | putList*)+) >
<!ATTLIST putList id ID #IMPLIED>
<!ATTLIST putList name CDATA #REQUIRED>
<!-- ========== Subordinate Elements ====================================== -->
<!-- The "add" element describes an element of a list. It is similar to the
<put> element.
content Same as value. For compatibility with the template tag
library.
direct Same as type="string". For compatibility with the template
tag library.
type The type of the value. Can be: string, page, template or
definition.
By default, no type is associated to a value. If a type is
associated, it will be used as a hint to process the value
when the attribute will be used in the inserted tiles.
value The value associated to this tiles attribute. The value
should
be specified with this tag attribute, or in the body of
the tag.
-->
<!ELEMENT add (#PCDATA)>
<!ATTLIST add id ID #IMPLIED>
<!ATTLIST add content CDATA #IMPLIED>
<!ATTLIST add direct %Boolean; #IMPLIED>
<!ATTLIST add type %ContentType; #IMPLIED>
<!ATTLIST add value CDATA #IMPLIED>
<!-- The "bean" element describes an element of a list. It create a bean of the
specified java classtype. This bean is initialized with appropriate nested
<set-property>.
classtype The fully qualified classname for this bean.
-->
<!ELEMENT bean (set-property*)>
<!ATTLIST bean id ID #IMPLIED>
<!ATTLIST bean classtype %ClassName; #REQUIRED>
<!-- The "set-property" element specifies the method name and initial value of
a bean property. When the object representing
the surrounding element is instantiated, the accessor for the indicated
property is called and passed the indicated value.
property Name of the JavaBeans property whose setter method
will be called.
value String representation of the value to which this
property will be set, after suitable type conversion
-->
<!ELEMENT set-property EMPTY>
<!ATTLIST set-property id ID #IMPLIED>
<!ATTLIST set-property property %PropName; #REQUIRED>
<!ATTLIST set-property value CDATA #REQUIRED>
<!-- The "item" element describes an element of a list. It create a bean added
as
element to the list. Each bean can contain different properties: value,
link,
icon, tooltip. These properties are to be interpreted by the jsp page using
them.
By default the bean is of type
"org.apache.struts.tiles.beans.SimpleMenuItem". This bean is useful to
create a list of beans used as menu items.
classtype The fully qualified classtype for this bean.
If specified, the classtype must be a subclass of the
interface
"org.apache.struts.tiles.beans.MenuItem".
icon The bean 'icon' property.
link The bean 'link' property.
tooltip The bean 'tooltip' property.
value The bean 'value' property.
-->
<!ELEMENT item (#PCDATA)>
<!ATTLIST item id ID #IMPLIED>
<!ATTLIST item classtype %ClassName; #IMPLIED>
<!ATTLIST item icon CDATA #IMPLIED>
<!ATTLIST item link CDATA #REQUIRED>
<!ATTLIST item tooltip CDATA #IMPLIED>
<!ATTLIST item value CDATA #REQUIRED>
<!-- ========== Info Elements ====================================== -->
<!-- The "description" element contains descriptive (paragraph length) text
about the surrounding element, suitable for use in GUI tools.
-->
<!ELEMENT description (#PCDATA)>
<!ATTLIST description id ID #IMPLIED>
<!-- The "display-name" element contains a short (one line) description of
the surrounding element, suitable for use in GUI tools.
-->
<!ELEMENT display-name (#PCDATA)>
<!ATTLIST display-name id ID #IMPLIED>
<!-- The "icon" element contains a small-icon and large-icon element which
specify the location, relative to the Struts configuration file, for small
and large images used to represent the surrounding element in GUI tools.
-->
<!ELEMENT icon (small-icon?, large-icon?)>
<!ATTLIST icon id ID #IMPLIED>
<!-- The "large-icon" element specifies the location, relative to the Struts
configuration file, of a resource containing a large (32x32 pixel)
icon image.
-->
<!ELEMENT large-icon (%Location;)>
<!ATTLIST large-icon id ID #IMPLIED>
<!-- The "small-icon" element specifies the location, relative to the Struts
configuration file, of a resource containing a small (16x16 pixel)
icon image.
-->
<!ELEMENT small-icon (%Location;)>
<!ATTLIST small-icon id ID #IMPLIED>
Index: StrutsValidationXMLPlugin.java
===================================================================
RCS file:
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-struts/src/main/java/org/xdoclet/plugin/struts/StrutsValidationXMLPlugin.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** StrutsValidationXMLPlugin.java 31 May 2005 11:26:15 -0000 1.4
--- StrutsValidationXMLPlugin.java 2 Jul 2005 13:16:29 -0000 1.5
***************
*** 32,36 ****
private static final String VALIDATOR_FORM_CLASSNAME =
"org.apache.struts.validator.ValidatorForm";
! private final static List PROPERTY_TAGS = new ArrayList();
private Collection validatorFormClasses;
--- 32,36 ----
private static final String VALIDATOR_FORM_CLASSNAME =
"org.apache.struts.validator.ValidatorForm";
! //private final static List PROPERTY_TAGS = new ArrayList();
private Collection validatorFormClasses;
--- NEW FILE: StrutsMessagePlugin.java ---
/*
* Copyright (c) 2003
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.struts;
import org.xdoclet.plugin.struts.qtags.StrutsMsgTagImpl;
import org.xdoclet.plugin.struts.qtags.TagLibrary;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import org.generama.QDoxCapableMetadataProvider;
import org.generama.VelocityTemplateEngine;
import org.generama.WriterMapper;
import org.generama.defaults.QDoxPlugin;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaMethod;
/**
* Generate resource bundle messages for struts
*
* @author Eduardo Franceschi
*/
public class StrutsMessagePlugin extends QDoxPlugin {
private static final String DEFAULT_FILENAME = "ApplicationResources";
private static final String DEFAULT_FILENAME_EXT = ".properties";
private Map strutsMessages;
private String fileName;
private String lang;
private String country;
private String variant;
private String mergefile;
public StrutsMessagePlugin(VelocityTemplateEngine templateEngine,
QDoxCapableMetadataProvider metadataProvider,
WriterMapper writerMapper) {
super(templateEngine, metadataProvider, writerMapper);
setMultioutput(false);
new TagLibrary(metadataProvider);
}
public String getFileName() {
if (fileName == null) {
String bundleKey = getBundleKey();
if (!bundleKey.equals("")) {
bundleKey = "_" + bundleKey;
}
return DEFAULT_FILENAME + bundleKey + DEFAULT_FILENAME_EXT;
}
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getLang() {
return lang;
}
public String getCountry() {
return country;
}
public String getVariant() {
return variant;
}
public void setLang(String lang) {
this.lang = lang;
}
public void setCountry(String country) {
this.country = country;
}
public void setVariant(String variant) {
this.variant = variant;
}
public String getMergefile() {
return mergefile;
}
public void setMergefile(String mergefile) {
this.mergefile = mergefile;
}
public String getBundleKey() {
StringBuffer sb = new StringBuffer();
if (getLang() != null) {
sb.append(getLang());
} else {
return "";
}
if (getCountry() != null) {
sb.append("_");
sb.append(getCountry());
} else {
return sb.toString();
}
if (getVariant() != null) {
sb.append("_");
sb.append(getVariant());
}
return sb.toString();
}
public boolean messageApplicable(StrutsMsgTagImpl tag) {
if (getLang() == null) {
return tag.getLang() == null;
} else if (getLang().equals(tag.getLang())) {
if (getCountry() == null) {
return tag.getCountry() == null;
} else if (getCountry().equals(tag.getCountry())) {
if (getVariant() == null) {
return tag.getVariant() == null;
} else {
return getVariant().equals(tag.getVariant());
}
}
}
return false;
}
public Map getStrutsMessages() {
if (strutsMessages == null) {
strutsMessages = new TreeMap();
Collection metadata = metadataProvider.getMetadata();
Iterator it = metadata.iterator();
while (it.hasNext()) {
JavaClass clazz = (JavaClass) it.next();
System.out.println(" * Processing file " +
clazz.getFullyQualifiedName());
DocletTag classTags[] =
clazz.getTagsByName(StrutsMsgTagImpl.NAME);
for (int i = 0; i < classTags.length; i++) {
addTags((StrutsMsgTagImpl) classTags[i]);
}
JavaMethod methods[] = clazz.getMethods();
for (int j=0; j<methods.length; j++) {
DocletTag methodTags[] =
methods[j].getTagsByName(StrutsMsgTagImpl.NAME);
for (int i = 0; i < methodTags.length; i++) {
addTags((StrutsMsgTagImpl) methodTags[i]);
}
}
JavaField fields[] = clazz.getFields();
for (int j=0; j<fields.length; j++) {
DocletTag fieldTags[] =
fields[j].getTagsByName(StrutsMsgTagImpl.NAME);
for (int i = 0; i < fieldTags.length; i++) {
addTags((StrutsMsgTagImpl) fieldTags[i]);
}
}
}
}
return strutsMessages;
}
public String getMergefileContent() throws IOException {
// Velocity does not include files outside their context
// So, load the file into a StringBuffer to return a string
// Anybody have a better idea ?
StringBuffer strbuf = new StringBuffer();
File merge = new File(mergefile);
if (merge.exists()) {
BufferedReader r = new BufferedReader(new FileReader(merge));
int c;
while ((c = r.read()) != -1) {
strbuf.append((char) c);
}
}
return strbuf.toString();
}
private void addTags(StrutsMsgTagImpl tag) {
if (messageApplicable(tag)) {
String key = tag.getKey();
strutsMessages.put(key, tag);
}
}
public void start() {
this.setFilereplace(this.getFileName());
super.start();
System.out.println(" * Generating file " + getFileName());
}
}
--- NEW FILE: StrutsTilesPlugin.jelly ---
<?xml version="1.0" encoding="UTF-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:jsl="jelly:jsl">
<x:doctype name="tiles-definitions" publicId="-//Apache Software
Foundation//DTD Tiles Configuration//EN"
systemId="http://jakarta.apache.org/struts/dtds/tiles-config.dtd" trim="true" />
<tiles-definitions>
<!-- tiles merge contents... -->
<j:if test="${plugin.getMergeFile('tiles.xml').exists()}">
<x:parse var="tilesDefs"
xml="${plugin.getMergeFile('tiles.xml')}"/>
</j:if>
<jsl:stylesheet select="$tilesDefs">
<jsl:template match="*" trim="false">
<jsl:copy>
<jsl:applyTemplates/>
</jsl:copy>
</jsl:template>
<jsl:template match="/" trim="false">
<jsl:applyTemplates select="child::*/child::*"
/>
</jsl:template>
</jsl:stylesheet>
<j:forEach var="def" items="${plugin.getAllDefs()}">
<j:set var="value" value="${def.value}" />
<definition name="${def.key}" extends="${value.extends}"
path="${value.path}">
<j:forEach var="prop" items="${value.props}">
<put name="${prop.key}" value="${prop.value}" />
</j:forEach>
</definition>
</j:forEach>
</tiles-definitions>
</j:jelly>
--- NEW FILE: StrutsMessagePlugin.vm ---
# $dontedit
# Struts Application Resources for locale#if($plugin.bundleKey=="") default
#else $plugin.bundleKey #end
#foreach ($entry in $plugin.strutsMessages)
$entry.key=$entry.getNamedParameter("msg")
#end
#if($plugin.mergefile)
## included properties from merge file $plugin.mergefile
$plugin.getMergefileContent()
#end
--- NEW FILE: StrutsTilesPlugin.java ---
/*
* Copyright (c) 2003
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.struts;
import org.xdoclet.plugin.struts.qtags.StrutsTilesPutTagImpl;
import org.xdoclet.plugin.struts.qtags.StrutsTilesTagImpl;
import org.xdoclet.plugin.struts.qtags.TagLibrary;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import org.generama.JellyTemplateEngine;
import org.generama.QDoxCapableMetadataProvider;
import org.generama.WriterMapper;
import org.generama.defaults.QDoxPlugin;
import org.generama.defaults.XMLOutputValidator;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
/**
* Generate tiles definition xml for struts
*
* @author Eduardo Franceschi
*/
public class StrutsTilesPlugin extends QDoxPlugin {
private String fileName = "tiles-defs.xml";
private File mergedir;
private Map defs;
public StrutsTilesPlugin(JellyTemplateEngine templateEngine,
QDoxCapableMetadataProvider metadataProvider,
WriterMapper writerMapper) {
super(templateEngine, metadataProvider, writerMapper);
setMultioutput(false);
Map dtds =
Collections.singletonMap("http://jakarta.apache.org/struts/dtds/tiles-config.dtd",
getClass().getResource("tiles-config_1_1.dtd"));
setOutputValidator(new XMLOutputValidator(dtds));
new TagLibrary(metadataProvider);
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public File getMergedir() {
return mergedir;
}
public void setMergedir(File mergefile) {
this.mergedir = mergefile;
}
public File getMergeFile(String fileName) {
if (fileName != null && getMergedir() != null) {
if (getMergedir().isDirectory()) {
File[] files = getMergedir().listFiles();
for (int i = 0; i < files.length; i++) {
if (fileName.trim().equals(files[i].getName())) {
return files[i];
}
}
}
}
return null;
}
public void start() {
this.setFilereplace(this.getFileName());
super.start();
System.out.println(" * Generating file " + getFileName());
}
public Map getAllDefs() {
if (defs == null) {
defs = new TreeMap();
Collection metadata = metadataProvider.getMetadata();
Iterator it = metadata.iterator();
while (it.hasNext()) {
JavaClass clazz = (JavaClass) it.next();
System.out.println(" * Processing file " +
clazz.getFullyQualifiedName());
DocletTag[] tags1 =
clazz.getTagsByName(StrutsTilesTagImpl.NAME);
Definition def = null;
for (int i = 0; i < tags1.length; i++) {
StrutsTilesTagImpl tag = (StrutsTilesTagImpl) tags1[i];
def = new Definition(tag);
defs.put(tag.getName_(), def);
}
if (def != null) {
DocletTag[] tags2 =
clazz.getTagsByName(StrutsTilesPutTagImpl.NAME);
for (int i = 0; i < tags2.length; i++) {
StrutsTilesPutTagImpl tag = (StrutsTilesPutTagImpl)
tags2[i];
String parent = tag.getParent();
if (parent == null) {
parent = def.getName(); // Default Parent
}
def = (Definition) defs.get(parent);
if (def != null) {
def.props.put(tag.getName_(), tag.getValue_());
}
}
}
}
}
return defs;
}
public class Definition {
private String name;
private String path;
private String eztends;
private Map props = new TreeMap();
public Definition(StrutsTilesTagImpl tag) {
name = tag.getName_();
eztends = tag.getExtends();
path = tag.getPath();
}
public String getExtends() {
return eztends;
}
public void setExtends(String eztends) {
this.eztends = eztends;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Map getProps() {
return props;
}
public void setProps(Map props) {
this.props = props;
}
}
}
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
xdoclet-plugins-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-plugins-commits