Author: mrdon Date: Sun Sep 2 03:49:26 2007 New Revision: 571945 URL: http://svn.apache.org/viewvc?rev=571945&view=rev Log: Added display of constants and beans WW-2153
Added: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConstantsAction.java struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showBeans.ftl struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showConstants.ftl Modified: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/config-styles.css struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/page-header.ftl struts/struts2/trunk/plugins/config-browser/src/main/resources/struts-plugin.xml Modified: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ActionNamesAction.java Sun Sep 2 03:49:26 2007 @@ -26,6 +26,8 @@ import org.apache.struts2.StrutsConstants; import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.inject.Inject; @@ -41,7 +43,14 @@ private String namespace = ""; private Set namespaces; private String extension; + + private ConfigurationHelper configHelper; + @Inject + public void setConfigurationHelper(ConfigurationHelper cfg) { + this.configHelper = cfg; + } + public Set getActionNames() { return actionNames; } @@ -60,7 +69,7 @@ } public ActionConfig getConfig(String actionName) { - return ConfigurationHelper.getActionConfig(namespace, actionName); + return configHelper.getActionConfig(namespace, actionName); } public Set getNamespaces() { @@ -75,7 +84,7 @@ } public String execute() throws Exception { - namespaces = ConfigurationHelper.getNamespaces(); + namespaces = configHelper.getNamespaces(); if (namespaces.size() == 0) { addActionError("There are no namespaces in this configuration"); return ERROR; @@ -84,7 +93,7 @@ namespace = ""; } actionNames = - new TreeSet(ConfigurationHelper.getActionNames(namespace)); + new TreeSet(configHelper.getActionNames(namespace)); return SUCCESS; } } Modified: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java Sun Sep 2 03:49:26 2007 @@ -26,25 +26,34 @@ import org.apache.struts2.dispatcher.Dispatcher; +import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.inject.Inject; /** * ConfigurationHelper */ public class ConfigurationHelper { + + private Configuration configuration; - public static Set getNamespaces() { + @Inject + public void setConfiguration(Configuration config) { + this.configuration = config; + } + + public Set getNamespaces() { Set namespaces = Collections.EMPTY_SET; - Map allActionConfigs = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getRuntimeConfiguration().getActionConfigs(); + Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); if (allActionConfigs != null) { namespaces = allActionConfigs.keySet(); } return namespaces; } - public static Set getActionNames(String namespace) { + public Set getActionNames(String namespace) { Set actionNames = Collections.EMPTY_SET; - Map allActionConfigs = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getRuntimeConfiguration().getActionConfigs(); + Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); if (allActionConfigs != null) { Map actionMappings = (Map) allActionConfigs.get(namespace); if (actionMappings != null) { @@ -54,9 +63,9 @@ return actionNames; } - public static ActionConfig getActionConfig(String namespace, String actionName) { + public ActionConfig getActionConfig(String namespace, String actionName) { ActionConfig config = null; - Map allActionConfigs = Dispatcher.getInstance().getConfigurationManager().getConfiguration().getRuntimeConfiguration().getActionConfigs(); + Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); if (allActionConfigs != null) { Map actionMappings = (Map) allActionConfigs.get(namespace); if (actionMappings != null) { Added: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java?rev=571945&view=auto ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java (added) +++ struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java Sun Sep 2 03:49:26 2007 @@ -0,0 +1,138 @@ +/* + * $Id: ActionNamesAction.java 474191 2006-11-13 08:30:40Z mrdon $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +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; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.Inject; +import com.opensymphony.xwork2.util.ObjectTypeDeterminer; +import com.opensymphony.xwork2.util.XWorkConverter; + +/** + * Shows the beans loaded by the internal Guice container. Only shows beans that are recognized by Struts as official + * plugin extension points. + */ +public class ShowBeansAction extends ActionNamesAction { + + Map<String,Set<Binding>> bindings; + + @Inject + public void setContainer(Container container) { + 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)); + bindings.put(ActionProxyFactory.class.getName(), addBindings(container, ActionProxyFactory.class, StrutsConstants.STRUTS_ACTIONPROXYFACTORY)); + bindings.put(ObjectTypeDeterminer.class.getName(), addBindings(container, ObjectTypeDeterminer.class, StrutsConstants.STRUTS_OBJECTTYPEDETERMINER)); + bindings.put(ActionMapper.class.getName(), addBindings(container, ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS)); + bindings.put(MultiPartRequest.class.getName(), addBindings(container, MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER)); + bindings.put(FreemarkerManager.class.getName(), addBindings(container, FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME)); + 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() + { + 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); + if (chosenName == null) { + chosenName = "struts"; + } + Set<String> names = container.getInstanceNames(type); + if (!names.contains(chosenName)) { + bindings.add(new Binding(getInstanceClassName(container, type, "default"), chosenName, constName, true)); + } + for (String name : names) { + if (!"default".equals(name)) { + bindings.add(new Binding(getInstanceClassName(container, type, name), name, constName, name.equals(chosenName))); + } + } + return bindings; + } + + String getInstanceClassName(Container container, Class type, String name) { + String instName = "Class unable to be loaded"; + try { + Object inst = container.getInstance(type, name); + instName = inst.getClass().getName(); + } catch (Exception ex) { + // Ignoring beans unable to be loaded + } + 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) { + ret = -1; + } else if (b2.isDefault()) { + ret = 1; + } else { + ret = alias.compareTo(b2.getAlias()); + } + return ret; + } + } +} Modified: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConfigAction.java Sun Sep 2 03:49:26 2007 @@ -30,7 +30,9 @@ import org.apache.commons.logging.LogFactory; import com.opensymphony.xwork2.ObjectFactory; +import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.inject.Inject; /** * ShowConfigAction @@ -48,6 +50,9 @@ private String detailView = "results"; private PropertyDescriptor[] properties; private static Log log = LogFactory.getLog(ShowConfigAction.class); + + private ConfigurationHelper configHelper; + private ObjectFactory objectFactory; public String getDetailView() { return detailView; @@ -64,6 +69,16 @@ public String getNamespace() { return namespace; } + + @Inject + public void setConfigurationHelper(ConfigurationHelper cfg) { + this.configHelper = cfg; + } + + @Inject + public void setObjectFactory(ObjectFactory fac) { + this.objectFactory = fac; + } public String stripPackage(Class clazz) { return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1); @@ -91,11 +106,11 @@ public String execute() throws Exception { super.execute(); - config = ConfigurationHelper.getActionConfig(namespace, actionName); + config = configHelper.getActionConfig(namespace, actionName); actionNames = - new TreeSet(ConfigurationHelper.getActionNames(namespace)); + new TreeSet(configHelper.getActionNames(namespace)); try { - Class clazz = ObjectFactory.getObjectFactory().getClassInstance(getConfig().getClassName()); + Class clazz = objectFactory.getClassInstance(getConfig().getClassName()); java.util.Collection pds = OgnlRuntime.getPropertyDescriptors(clazz).values(); properties = (PropertyDescriptor[]) pds.toArray(PDSAT); } catch (Exception e) { Added: struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConstantsAction.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConstantsAction.java?rev=571945&view=auto ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConstantsAction.java (added) +++ struts/struts2/trunk/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowConstantsAction.java Sun Sep 2 03:49:26 2007 @@ -0,0 +1,48 @@ +/* + * $Id: ActionNamesAction.java 474191 2006-11-13 08:30:40Z mrdon $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +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; + +/** + * Shows all constants as loaded by Struts + */ +public class ShowConstantsAction extends ActionNamesAction { + + Map<String,String> consts; + + @Inject + public void setContainer(Container container) { + consts = new HashMap<String,String>(); + for (String key : container.getInstanceNames(String.class)) { + consts.put(key, container.getInstance(String.class, key)); + } + } + + public Map<String,String> getConstants() + { + return consts; + } +} Modified: struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/config-styles.css URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/config-styles.css?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/config-styles.css (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/config-styles.css Sun Sep 2 03:49:26 2007 @@ -1,24 +1,3 @@ -/* - * $Id: pom.xml 559206 2007-07-24 21:01:18Z apetrelli $ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * 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 - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - <style type="text/css"> /* colors, backgrounds, borders, link indication */ body { Modified: struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/page-header.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/page-header.ftl?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/page-header.ftl (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/page-header.ftl Sun Sep 2 03:49:26 2007 @@ -46,7 +46,18 @@ <#-- Quick hack to show menu features :) --> <#-- This should be done via contribution from the actions --> <#-- themselves. E.g via a collection of MenuItems with url and name ---> <div id="projecttools" class="toolgroup"> +--> <div class="toolgroup"> + <div class="label"><strong>Configuration</strong></div> + <div class="body"> + <div><@s.url id="constantsLink" action="showConstants" includeParams="none" /> + <a href="${constantsLink}">Constants</a> + </div> + <div><@s.url id="beansLink" action="showBeans" includeParams="none" /> + <a href="${beansLink}">Beans</a> + </div> + </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> Added: struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showBeans.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showBeans.ftl?rev=571945&view=auto ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showBeans.ftl (added) +++ struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showBeans.ftl Sun Sep 2 03:49:26 2007 @@ -0,0 +1,46 @@ +<#-- +/* + * $Id: pom.xml 559206 2007-07-24 21:01:18Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +--> +<#include "tigris-macros.ftl"/> +<@startPage pageTitle="Struts Beans"/> +<h3>Struts Beans</h3> + +<table width="100%"> + <tr> + <th>Type</th> + <th>Alias</th> + <th>Implementation</th> + <th>Constant Name</th> + </tr> + <#list beans.entrySet() as entry> + <#list entry.value as b> + <tr <#if b_index==0>class="a"<#else>class="b"</#if>> + <td><#if b_index==0>${entry.key}</#if></td> + <td>${b.alias}</td> + <td>${b.impl}</td> + <td><#if b_index==0>${b.constant}</#if></td> + </tr> + </#list> + </#list> +</table> + +<@endPage /> Added: struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showConstants.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showConstants.ftl?rev=571945&view=auto ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showConstants.ftl (added) +++ struts/struts2/trunk/plugins/config-browser/src/main/resources/config-browser/showConstants.ftl Sun Sep 2 03:49:26 2007 @@ -0,0 +1,36 @@ +<#-- +/* + * $Id: pom.xml 559206 2007-07-24 21:01:18Z apetrelli $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +--> +<#include "tigris-macros.ftl"/> +<@startPage pageTitle="Struts Constants"/> +<h3>Struts Constants</h3> + +<table width="100%"> + <#list constants.entrySet() as r> + <tr <#if r_index%2 gt 0>class="b"<#else>class="a"</#if>> + <td>${r.key}</td> + <td>${r.value}</td> + </tr> + </#list> +</table> + +<@endPage /> Modified: struts/struts2/trunk/plugins/config-browser/src/main/resources/struts-plugin.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/config-browser/src/main/resources/struts-plugin.xml?rev=571945&r1=571944&r2=571945&view=diff ============================================================================== --- struts/struts2/trunk/plugins/config-browser/src/main/resources/struts-plugin.xml (original) +++ struts/struts2/trunk/plugins/config-browser/src/main/resources/struts-plugin.xml Sun Sep 2 03:49:26 2007 @@ -27,6 +27,9 @@ "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> + + <bean class="org.apache.struts2.config_browser.ConfigurationHelper" /> + <package name="config-browser" extends="struts-default" namespace="/config-browser"> <interceptors> <interceptor-stack name="config-browser-default"> @@ -50,6 +53,14 @@ <action name="showConfig" class="org.apache.struts2.config_browser.ShowConfigAction"> <result type="freemarker" name="success">/config-browser/showConfig.ftl</result> + </action> + + <action name="showConstants" class="org.apache.struts2.config_browser.ShowConstantsAction"> + <result type="freemarker" name="success">/config-browser/showConstants.ftl</result> + </action> + + <action name="showBeans" class="org.apache.struts2.config_browser.ShowBeansAction"> + <result type="freemarker" name="success">/config-browser/showBeans.ftl</result> </action> <action name="showValidators" class="org.apache.struts2.config_browser.ListValidatorsAction">