Improves config-browser plugin, cleanups code, adds support for Convention plugin

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1302806 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lukasz Lenart
2012-03-20 09:17:02 +00:00
parent 9831ecf543
commit b5a58f1b90
13 changed files with 111 additions and 105 deletions
@@ -31,25 +31,24 @@ import java.util.TreeSet;
/**
* ActionNamesAction
*
*/
public class ActionNamesAction extends ActionSupport {
private static final long serialVersionUID = -5389385242431387840L;
private Set actionNames;
private Set<String> actionNames;
private String namespace = "";
private Set namespaces;
private Set<String> namespaces;
private String extension;
protected ConfigurationHelper configHelper;
@Inject
public void setConfigurationHelper(ConfigurationHelper cfg) {
this.configHelper = cfg;
}
public Set getActionNames() {
public Set<String> getActionNames() {
return actionNames;
}
@@ -60,7 +59,7 @@ public class ActionNamesAction extends ActionSupport {
public void setNamespace(String namespace) {
this.namespace = namespace;
}
@Inject(StrutsConstants.STRUTS_ACTION_EXTENSION)
public void setExtension(String ext) {
this.extension = ext;
@@ -70,15 +69,15 @@ public class ActionNamesAction extends ActionSupport {
return configHelper.getActionConfig(namespace, actionName);
}
public Set getNamespaces() {
public Set<String> getNamespaces() {
return namespaces;
}
public String getExtension() {
if ( extension == null) {
if (extension == null) {
return "action";
}
if (extension.indexOf(",") > -1) {
if (extension.contains(",")) {
return extension.substring(0, extension.indexOf(","));
}
return extension;
@@ -93,8 +92,7 @@ public class ActionNamesAction extends ActionSupport {
if (namespace == null) {
namespace = "";
}
actionNames =
new TreeSet(configHelper.getActionNames(namespace));
actionNames = new TreeSet<String>(configHelper.getActionNames(namespace));
return SUCCESS;
}
}
@@ -41,7 +41,7 @@ public class ListValidatorsAction extends ActionSupport {
private String clazz;
private String context;
List<Validator> validators = Collections.EMPTY_LIST;
List<Validator> validators = Collections.emptyList();
private ActionValidatorManager actionValidatorManager;
@@ -21,18 +21,6 @@
package org.apache.struts2.config_browser;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.components.UrlRenderer;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.velocity.VelocityManager;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.TextProvider;
@@ -40,6 +28,18 @@ import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.components.UrlRenderer;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.velocity.VelocityManager;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Shows the beans loaded by the internal Guice container. Only shows beans that are recognized by Struts as official
@@ -47,11 +47,11 @@ import com.opensymphony.xwork2.inject.Inject;
*/
public class ShowBeansAction extends ActionNamesAction {
Map<String,Set<Binding>> bindings;
Map<String, Set<Binding>> bindings;
@Inject
public void setContainer(Container container) {
bindings = new TreeMap<String,Set<Binding>>();
bindings = new TreeMap<String, Set<Binding>>();
bindings.put(ObjectFactory.class.getName(), addBindings(container, ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY));
bindings.put(XWorkConverter.class.getName(), addBindings(container, XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER));
bindings.put(TextProvider.class.getName(), addBindings(container, TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER));
@@ -63,12 +63,11 @@ public class ShowBeansAction extends ActionNamesAction {
bindings.put(VelocityManager.class.getName(), addBindings(container, VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME));
bindings.put(UrlRenderer.class.getName(), addBindings(container, UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER));
}
public Map<String, Set<Binding>> getBeans()
{
public Map<String, Set<Binding>> getBeans() {
return bindings;
}
protected Set<Binding> addBindings(Container container, Class type, String constName) {
Set<Binding> bindings = new TreeSet<Binding>();
String chosenName = container.getInstance(String.class, constName);
@@ -76,6 +75,9 @@ public class ShowBeansAction extends ActionNamesAction {
chosenName = "struts";
}
Set<String> names = container.getInstanceNames(type);
if (names == null) {
names = Collections.emptySet();
}
if (!names.contains(chosenName)) {
bindings.add(new Binding(getInstanceClassName(container, type, "default"), chosenName, constName, true));
}
@@ -97,33 +99,36 @@ public class ShowBeansAction extends ActionNamesAction {
}
return instName;
}
public class Binding implements Comparable<Binding> {
private String impl;
private String alias;
private String constant;
private boolean isDefault;
public Binding(String impl, String alias, String constant, boolean def) {
this.impl = impl;
this.alias = alias;
this.constant = constant;
this.isDefault = def;
}
public String getImpl() {
return impl;
}
public String getAlias() {
return alias;
}
public String getConstant() {
return constant;
}
public boolean isDefault() {
return isDefault;
}
public int compareTo(Binding b2) {
int ret = 0;
if (isDefault) {
@@ -39,8 +39,6 @@ public class ShowConfigAction extends ActionNamesAction {
private static final long serialVersionUID = -1630527489407671652L;
private static final PropertyDescriptor[] PDSAT = new PropertyDescriptor[0];
private String namespace;
private String actionName;
private ActionConfig config;
@@ -60,7 +58,7 @@ public class ShowConfigAction extends ActionNamesAction {
this.detailView = detailView;
}
public Set getActionNames() {
public Set<String> getActionNames() {
return actionNames;
}
@@ -21,29 +21,28 @@
package org.apache.struts2.config_browser;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import java.util.HashMap;
import java.util.Map;
/**
* Shows all constants as loaded by Struts
*/
public class ShowConstantsAction extends ActionNamesAction {
Map<String,String> consts;
private Map<String, String> constants;
@Inject
public void setContainer(Container container) {
consts = new HashMap<String,String>();
constants = new HashMap<String, String>();
for (String key : container.getInstanceNames(String.class)) {
consts.put(key, container.getInstance(String.class, key));
constants.put(key, container.getInstance(String.class, key));
}
}
public Map<String,String> getConstants()
{
return consts;
public Map<String, String> getConstants() {
return constants;
}
}
@@ -21,48 +21,34 @@
package org.apache.struts2.config_browser;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
/**
* Shows all constants as loaded by Struts
*/
public class ShowJarsAction extends ActionNamesAction {
List<Properties> poms;
@Inject
public void setContainer(Container container) {
public List<Properties> getJarPoms() {
try {
poms = configHelper.getJarProperties();
}
catch (IOException ioe) {
return configHelper.getJarProperties();
} catch (IOException ioe) {
// this is the config browser, so it doesn't seem necessary to do more than just
// send up a debug message
if (LOG.isDebugEnabled()) {
LOG.debug("IOException caught while retrieving jar properties - " + ioe.getMessage());
}
poms = Collections.EMPTY_LIST; // maybe avoiding NPE later
return Collections.emptyList(); // maybe avoiding NPE later
}
}
public List<Properties> getJarPoms()
{
return poms;
}
public Iterator<URL> getPluginsLoaded()
{
public Iterator<URL> getPluginsLoaded() {
try {
return ClassLoaderUtil.getResources("struts-plugin.xml", ShowJarsAction.class, false);
} catch (IOException e) {
@@ -71,4 +57,5 @@ public class ShowJarsAction extends ActionNamesAction {
}
return null;
}
}
@@ -21,6 +21,14 @@
package org.apache.struts2.config_browser;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionException;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import com.opensymphony.xwork2.validator.Validator;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -30,14 +38,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionException;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import com.opensymphony.xwork2.validator.Validator;
/**
* ShowValidatorAction
*
@@ -47,8 +47,8 @@ public class ShowValidatorAction extends ListValidatorsAction {
private static Logger LOG = LoggerFactory.getLogger(ShowValidatorAction.class);
Set properties = Collections.EMPTY_SET;
int selected = 0;
private Set<PropertyInfo> properties = Collections.emptySet();
private int selected = 0;
ReflectionProvider reflectionProvider;
ReflectionContextFactory reflectionContextFactory;
@@ -76,16 +76,16 @@ public class ShowValidatorAction extends ListValidatorsAction {
}
public Validator getSelectedValidator() {
return (Validator) validators.get(selected);
return validators.get(selected);
}
public String execute() throws Exception {
loadValidators();
Validator validator = getSelectedValidator();
properties = new TreeSet();
properties = new TreeSet<PropertyInfo>();
try {
Map context = reflectionContextFactory.createDefaultContext(validator);
BeanInfo beanInfoFrom = null;
Map<String, Object> context = reflectionContextFactory.createDefaultContext(validator);
BeanInfo beanInfoFrom;
try {
beanInfoFrom = Introspector.getBeanInfo(validator.getClass(), Object.class);
} catch (IntrospectionException e) {
@@ -96,8 +96,7 @@ public class ShowValidatorAction extends ListValidatorsAction {
PropertyDescriptor[] pds = beanInfoFrom.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
for (PropertyDescriptor pd : pds) {
String name = pd.getName();
Object value = null;
if (pd.getReadMethod() == null) {
@@ -118,10 +117,11 @@ public class ShowValidatorAction extends ListValidatorsAction {
addActionError("Unable to retrieve properties: " + e.toString());
}
if (hasErrors())
if (hasErrors()) {
return ERROR;
else
} else {
return SUCCESS;
}
}
public static class PropertyInfo implements Comparable {
@@ -32,7 +32,7 @@
<@s.param name="namespace">${namespace}</@s.param>
<@s.param name="actionName">${name}</@s.param>
</@s.url>
<li><a href="${showConfig}">${name}</a></li>
<li><@s.a href="%{showConfig}">${name}</@s.a></li>
</#list>
</ul>
</td>
@@ -41,7 +41,7 @@
<table border="0" cellspacing="0" cellpadding="4" width="100%" id="main">
<tr valign="top">
<#if !hideNav?exists> <td id="leftcol" width="20%">
<#if !hideNav??> <td id="leftcol" width="20%">
<div id="navcolumn">
<#-- Quick hack to show menu features :)
--> <#-- This should be done via contribution from the actions
@@ -61,15 +61,34 @@
</div>
</div>
<div id="projecttools" class="toolgroup">
<#if namespaces?exists> <div class="label"><strong>Namespaces</strong></div>
<div class="body">
<#foreach namespace in namespaces> <div><@s.url id="namespaceLink" action="actionNames" includeParams="none"><@s.param name="namespace">${namespace}</@s.param></@s.url><a href="${namespaceLink}"><#if namespace == ""> default <#else> ${namespace} </#if></a></div>
</#foreach> </div>
</#if> </div>
<#if namespaces??>
<div class="label"><strong>Namespaces</strong></div>
<div class="body">
<#foreach namespace in namespaces>
<div>
<@s.url var="namespaceLink" action="actionNames" includeParams="none">
<@s.param name="namespace">${namespace}</@s.param>
</@s.url>
<@s.a href="%{namespaceLink}"><#if namespace == ""> default <#else> ${namespace} </#if></@s.a>
</div>
</#foreach>
</div>
</#if>
</div>
<div class="toolgroup">
<#if actionNames?exists> <div class="label"><strong>Actions in <#if namespace == ""> default <#else> ${namespace} </#if></strong></div>
<#foreach name in actionNames> <div><@s.url id="actionLink" action="showConfig" includeParams="none"><@s.param name="namespace">${namespace}</@s.param><@s.param name="actionName">${name}</@s.param></@s.url><a href="${actionLink}">${name}</a></div>
</#foreach> </#if> </div>
<#if actionNames??>
<div class="label"><strong>Actions in <#if namespace == ""> default <#else> ${namespace} </#if></strong></div>
<#foreach name in actionNames>
<div>
<@s.url id="actionLink" action="showConfig" includeParams="none" escapeAmp="false">
<@s.param name="namespace">${namespace}</@s.param>
<@s.param name="actionName">${name}</@s.param>
</@s.url>
<@s.a href="%{actionLink}">${name}</@s.a>
</div>
</#foreach>
</#if>
</div>
</div>
</td>
</#if> <td>
@@ -34,8 +34,8 @@
${p}
</#list></td></tr>
<tr><td>Default location:</td><td> <a href="${base}${namespace}/${actionName}.${extension}">
${base}${namespace}/${actionName}.${extension}
<tr><td>Default location:</td><td> <a href="${base}${namespace}/${actionName}<#if extension != ''>.${extension}</#if>">
${base}${namespace}/${actionName}<#if extension != "">.${extension}</#if>
</a>
</td></tr>
</table>
@@ -24,7 +24,7 @@
<table width="100%">
<tr><th>Field</th><th>Type</th><th>&nbsp;</th></tr>
<#assign row = 0>
<#if validators?exists>
<#if validators??>
<#foreach i in validators>
<tr <#if i_index%2 gt 0>class="b"<#else>class="a"</#if>>
<td>${i.fieldName!"(see expression)"}</td>
@@ -44,7 +44,7 @@
<#macro tab name, url, isSelected>
<#if isSelected == "true">
<th><a href="${url}">${name}</h></td>
<th><a href="${url}">${name}</a></th>
<#else>
<td><a href="${url}">${name}</a></td>
</#if>
@@ -34,11 +34,11 @@
<#foreach prop in properties>
<tr <#if prop_index%2 gt 0>class="b"<#else>class="a"</#if>>
<td>${prop.name}</td>
<td><#if prop.value?exists>
<td><#if prop.value??>
<#if prop.value?is_collection>(size = ${prop.value?size})<#foreach v in prop.value>${v.value}, </#foreach>
<#else>${prop.value?string}</#if>
<#else> <b>null</b> </#if></td>
<td><#if prop.value?exists && prop.value?is_collection>(collection)<#else>${prop.type.name}</#if></td>
<td><#if prop.value?? && prop.value?is_collection>(collection)<#else>${prop.type.name}</#if></td>
</tr>
</#foreach></table>
<#call endPage>