001: /*
002: * JBoss, a division of Red Hat
003: * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022:
023: package org.jboss.portal.core.admin.ui;
024:
025: import org.jboss.portal.core.model.portal.PortalObject;
026: import org.jboss.portal.core.model.portal.control.ControlConstants;
027:
028: import javax.faces.model.SelectItem;
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: /**
033: * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
034: * @version $Revision: 8785 $
035: */
036: public class ControlPropertiesBean extends PropertyBeanContainer {
037:
038: /** . */
039: private List portalSelectItems;
040:
041: /** . */
042: private List pageSelectItems;
043:
044: /** . */
045: final PortalObjectManagerBean pomgr;
046: private static final String DISPLAY_THE_DEFAULT_ERROR_MESSAGE = "Display the default error message";
047: private static final String REDIRECT_TO_THE_SPECIFIED_RESOURCE = "Redirect to the specified resource";
048: private static final String REMOVE_THE_RESOURCE_FROM_PAGE = "Remove the resource from page";
049:
050: public ControlPropertiesBean(PortalObjectManagerBean pomgr) {
051: this .pomgr = pomgr;
052:
053: }
054:
055: public List getPortalSelectItems() {
056: if (portalSelectItems == null) {
057: portalSelectItems = new ArrayList();
058: portalSelectItems.add(new SelectItem(
059: ControlConstants.IGNORE_CONTROL_VALUE,
060: DISPLAY_THE_DEFAULT_ERROR_MESSAGE));
061: portalSelectItems.add(new SelectItem(
062: ControlConstants.JSP_CONTROL_VALUE,
063: REDIRECT_TO_THE_SPECIFIED_RESOURCE));
064: }
065: return portalSelectItems;
066: }
067:
068: public List getPageSelectItems() {
069: if (pageSelectItems == null) {
070: pageSelectItems = new ArrayList();
071: pageSelectItems.add(new SelectItem(
072: ControlConstants.IGNORE_CONTROL_VALUE,
073: DISPLAY_THE_DEFAULT_ERROR_MESSAGE));
074: pageSelectItems.add(new SelectItem(
075: ControlConstants.HIDE_CONTROL_VALUE,
076: REMOVE_THE_RESOURCE_FROM_PAGE));
077: pageSelectItems.add(new SelectItem(
078: ControlConstants.JSP_CONTROL_VALUE,
079: REDIRECT_TO_THE_SPECIFIED_RESOURCE));
080: }
081: return pageSelectItems;
082: }
083:
084: private ControlPropertyBean grabProperty(String name) {
085: if (name == null) {
086: throw new IllegalArgumentException("name cannot be null");
087: }
088:
089: if (!PropertiesInfo.isControlProperty(name)) {
090: throw new IllegalStateException(
091: "trying to process non control property: " + name);
092: }
093:
094: PortalObject object = pomgr.getSelectedObject();
095:
096: object = pomgr.getPortalObjectContainer().getObject(
097: object.getId());
098:
099: PropertiesInfo info = new PropertiesInfo(object);
100:
101: boolean inheritable = object.getType() != PortalObject.TYPE_CONTEXT;
102: boolean inherited = !object.getDeclaredProperties()
103: .containsKey(name);
104: String value = object.getProperty(name);
105: return new ControlPropertyBean(this ,
106: info.getPropertyInfo(name), inherited, inheritable,
107: value);
108: }
109:
110: public ControlPropertyBean getPageControlAccessDenied() {
111: return grabProperty(ControlConstants.PAGE_ACCESS_DENIED_CONTROL_KEY);
112: }
113:
114: public ControlPropertyBean getPageControlUnavailable() {
115: return grabProperty(ControlConstants.PAGE_UNAVAILABLE_CONTROL_KEY);
116: }
117:
118: public ControlPropertyBean getPageControlError() {
119: return grabProperty(ControlConstants.PAGE_ERROR_CONTROL_KEY);
120: }
121:
122: public ControlPropertyBean getPageControlInternalError() {
123: return grabProperty(ControlConstants.PAGE_INTERNAL_ERROR_CONTROL_KEY);
124: }
125:
126: public ControlPropertyBean getPageControlNotFound() {
127: return grabProperty(ControlConstants.PAGE_NOT_FOUND_CONTROL_KEY);
128: }
129:
130: public ControlPropertyBean getPageControlResourceURI() {
131: return grabProperty(ControlConstants.PAGE_RESOURCE_URI_CONTROL_KEY);
132: }
133:
134: public ControlPropertyBean getPortalControlAccessDenied() {
135: return grabProperty(ControlConstants.PORTAL_ACCESS_DENIED_CONTROL_KEY);
136: }
137:
138: public ControlPropertyBean getPortalControlUnavailable() {
139: return grabProperty(ControlConstants.PORTAL_UNAVAILABLE_CONTROL_KEY);
140: }
141:
142: public ControlPropertyBean getPortalControlError() {
143: return grabProperty(ControlConstants.PORTAL_ERROR_CONTROL_KEY);
144: }
145:
146: public ControlPropertyBean getPortalControlInternalError() {
147: return grabProperty(ControlConstants.PORTAL_INTERNAL_ERROR_CONTROL_KEY);
148: }
149:
150: public ControlPropertyBean getPortalControlNotFound() {
151: return grabProperty(ControlConstants.PORTAL_NOT_FOUND_CONTROL_KEY);
152: }
153:
154: public ControlPropertyBean getPortalControlResourceURI() {
155: return grabProperty(ControlConstants.PORTAL_RESOURCE_URI_CONTROL_KEY);
156: }
157:
158: public PortalObject getRelatedObject() {
159: return pomgr.getSelectedObject();
160: }
161: }
|