001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.communities;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017: import java.text.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.faces.application.FacesMessage;
021: import javax.faces.component.UIComponent;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.console.common.PSBaseBean;
038:
039: public class EditCommunityBean extends PSBaseBean {
040:
041: public String name = "";
042: public String description = "";
043: public String category = "";
044: public String unlisted = "";
045: public String membershipRestricted = "";
046: public String secured = "";
047:
048: public EditCommunityBean() {
049: setSessionAttribute("editcommunitycategorypopup.mode", "browse");
050: setSessionAttribute("editcommunitycategorypopup.category", null);
051:
052: HttpServletRequest hsr = (HttpServletRequest) FacesContext
053: .getCurrentInstance().getExternalContext().getRequest();
054: name = (String) hsr.getParameter("editcommunity.selected");
055: if (name == null) {
056: name = (String) getSessionAttribute("editcommunity.selected");
057: }
058: setSessionAttribute("editcommunity.selected", name);
059:
060: try {
061: LinkedList path = new LinkedList();
062: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
063: path
064: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
065: path.addFirst("CommunityManager");
066: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
067: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
068:
069: Object[] params = { name };
070: String[] signatures = { "java.lang.String" };
071: Properties p = (Properties) getMBeanServerConnection()
072: .invoke(on, "getCommunity", params, signatures);
073: if (p.containsKey("name")) {
074: name = (String) p.getProperty("name");
075: }
076: if (p.containsKey("description")) {
077: description = (String) p.getProperty("description");
078: }
079: if (p.containsKey("category")) {
080: category = (String) p.getProperty("category");
081: }
082: if (p.containsKey("unlisted")) {
083: unlisted = (String) p.getProperty("unlisted");
084: }
085: if (p.containsKey("membershiprestricted")) {
086: membershipRestricted = (String) p
087: .getProperty("membershiprestricted");
088: }
089: if (p.containsKey("secured")) {
090: secured = (String) p.getProperty("secured");
091: }
092: } catch (Exception e) {
093: log(
094: Level.SEVERE,
095: "EditCommunityBean.EditCommunityBean() : Exception ",
096: e);
097: }
098: }
099:
100: public String getPageTitle() {
101: MessageFormat mf = new MessageFormat("");
102: mf.applyPattern(getLocalizedString("communities",
103: "editcommunity.pagetitle"));
104: return mf.format(new Object[] { name });
105: }
106:
107: public boolean getShowError() {
108: String value = (String) getSessionAttribute("editcommunity.showerror");
109: if (value == null || value.equals("false")) {
110: return false;
111: } else {
112: return true;
113: }
114: }
115:
116: public String getDescription() {
117: return description;
118: }
119:
120: public void setDescription(String description) {
121: this .description = description;
122: }
123:
124: public String getCategory() {
125: return category;
126: }
127:
128: public void setCategory(String category) {
129: this .category = category;
130: }
131:
132: public Option[] getAvailableListing() {
133: Option[] options = new Option[2];
134: options[0] = new Option("false", getLocalizedString(
135: "communities", "editcommunity.unlisted.false"));
136: options[1] = new Option("true", getLocalizedString(
137: "communities", "editcommunity.unlisted.true"));
138: return options;
139: }
140:
141: public String getListing() {
142: return unlisted;
143: }
144:
145: public void setListing(String unlisted) {
146: this .unlisted = unlisted;
147: }
148:
149: public Option[] getAvailableMembership() {
150: Option[] options = new Option[2];
151: options[0] = new Option("false", getLocalizedString(
152: "communities",
153: "editcommunity.membershiprestricted.false"));
154: options[1] = new Option("true", getLocalizedString(
155: "communities",
156: "editcommunity.membershiprestricted.true"));
157: return options;
158: }
159:
160: public String getMembership() {
161: return membershipRestricted;
162: }
163:
164: public void setMembership(String membershipRestricted) {
165: this .membershipRestricted = membershipRestricted;
166: }
167:
168: public Option[] getAvailableAccess() {
169: Option[] options = new Option[2];
170: options[0] = new Option("false", getLocalizedString(
171: "communities", "editcommunity.secured.false"));
172: options[1] = new Option("true", getLocalizedString(
173: "communities", "editcommunity.secured.true"));
174: return options;
175: }
176:
177: public String getAccess() {
178: return secured;
179: }
180:
181: public void setAccess(String secured) {
182: this .secured = secured;
183: }
184:
185: public void validate(FacesContext fc, UIComponent component,
186: Object value) throws ValidatorException {
187: String id = component.getId();
188: if (id.equals("description")) {
189: String s = (String) value;
190: if (s.length() > 256) {
191: throw new ValidatorException(
192: new FacesMessage(
193: FacesMessage.SEVERITY_ERROR,
194: getLocalizedString("communities",
195: "communities.error.error"),
196: getLocalizedString("communities",
197: "communities.error.descriptiontoolong")));
198: }
199: } else if (id.equals("category")) {
200: }
201: }
202:
203: public String save() {
204: try {
205: LinkedList path = new LinkedList();
206: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
207: path
208: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
209: path.addFirst("CommunityManager");
210: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
211: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
212:
213: Properties p = new Properties();
214: p.setProperty("name", name);
215: p.setProperty("description", description);
216: p.setProperty("category", category);
217: p.setProperty("unlisted", unlisted);
218: p.setProperty("membershiprestricted", membershipRestricted);
219: p.setProperty("secured", secured);
220:
221: Object[] params = { name, p };
222: String[] signatures = { "java.lang.String",
223: "java.util.Properties" };
224: getMBeanServerConnection().invoke(on, "setCommunity",
225: params, signatures);
226: setSessionAttribute("editcommunity.showerror", "false");
227: } catch (Exception e) {
228: log(Level.SEVERE, "EditCommunityBean.save() : Exception ",
229: e);
230: setSessionAttribute("editcommunity.showerror", "true");
231: }
232: return "gotoCommunitiesHome";
233: }
234:
235: public String cancel() {
236: return "gotoCommunitiesHome";
237: }
238:
239: }
|