KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > ajax > ListAttributeCategoriesAction


1 package com.sslexplorer.ajax;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10
11 import org.ajaxtags.helpers.AjaxXmlBuilder;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionMapping;
14 import org.apache.struts.util.MessageResources;
15
16 import com.sslexplorer.boot.PropertyClass;
17 import com.sslexplorer.boot.PropertyClassManager;
18 import com.sslexplorer.boot.PropertyDefinition;
19 import com.sslexplorer.boot.Util;
20 import com.sslexplorer.core.CoreUtil;
21 import com.sslexplorer.properties.attributes.AttributeDefinition;
22 import com.sslexplorer.properties.attributes.AttributesPropertyClass;
23 import com.sslexplorer.security.SessionInfo;
24
25 /**
26  * Implementation of {@link com.sslexplorer.ajax.AbstractAjaxXMLAction} that
27  * returns an XML document containing all currently configured <i>Attribute
28  * Definition</i> categories.
29  * <p>
30  * A single request parameter is supported, <i>category</i> that will narrow
31  * the results returned to those that begin with the supplied value.
32  *
33  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
34  */

35 public class ListAttributeCategoriesAction extends AbstractAjaxXMLAction {
36
37     /*
38      * (non-Javadoc)
39      *
40      * @see com.sslexplorer.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping,
41      * org.apache.struts.action.ActionForm,
42      * javax.servlet.http.HttpServletRequest,
43      * javax.servlet.http.HttpServletResponse)
44      */

45     protected void onAjaxRequest(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response,
46                                  AjaxXmlBuilder builder) throws Exception JavaDoc {
47         List JavaDoc<String JavaDoc> c = new ArrayList JavaDoc<String JavaDoc>();
48         for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) {
49             if (propertyClass instanceof AttributesPropertyClass) {
50                 Collection JavaDoc<PropertyDefinition> l = propertyClass.getDefinitions();
51                 String JavaDoc category = request.getParameter("category");
52                 for (PropertyDefinition d : l) {
53                     AttributeDefinition def = (AttributeDefinition)d;
54                     String JavaDoc categoryLabel = def.getCategoryLabel();
55                     MessageResources mr = CoreUtil.getMessageResources(request.getSession(), def.getMessageResourcesKey());
56                     String JavaDoc s = mr == null ? null : mr.getMessage("userAttributeCategory." + def.getCategory() + ".title");
57                     if (s != null && !s.equals("")) {
58                         categoryLabel = Util.urlDecode(s);
59                     } else {
60                         categoryLabel = categoryLabel == null || categoryLabel.equals("") ? "Attributes" : categoryLabel;
61                     }
62                     if ((category == null || category.equals("") || categoryLabel.toLowerCase().startsWith(category.toLowerCase()))
63                                     && !c.contains(categoryLabel)) {
64                         c.add(categoryLabel);
65                     }
66                 }
67
68             }
69         }
70         for (Iterator JavaDoc i = c.iterator(); i.hasNext();) {
71             String JavaDoc n = Util.encodeHTML((String JavaDoc) i.next());
72             builder.addItem(n, n);
73         }
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
80      * org.apache.struts.action.ActionForm,
81      * javax.servlet.http.HttpServletRequest,
82      * javax.servlet.http.HttpServletResponse)
83      */

84     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
85         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
86     }
87
88 }
89
Popular Tags