001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.impl.render.dynamic;
023:
024: import java.util.Map;
025:
026: /**
027: * Encapsulate dyna render options.
028: *
029: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
030: * @version $Revision: 8784 $
031: */
032: public class DynaRenderOptions {
033:
034: /** Drag and drop. */
035: public static final String DND_ENABLED = "theme.dyna.dnd_enabled";
036:
037: /** Partial refresh. */
038: public static final String PARTIAL_REFRESH_ENABLED = "theme.dyna.partial_refresh_enabled";
039:
040: /** Blocking HTTP GET (to do). */
041: public static final String BLOCKING_HTTP_GET_ENABLED = "theme.dyna.blocking_http_get_enabled";
042:
043: /** Flyweight pattern. */
044: private static final DynaRenderOptions[] FLYWEIGHTS = {
045: new DynaRenderOptions(null, null),
046: new DynaRenderOptions(Boolean.TRUE, null),
047: new DynaRenderOptions(Boolean.FALSE, null), null,
048: new DynaRenderOptions(null, Boolean.TRUE),
049: new DynaRenderOptions(Boolean.TRUE, Boolean.TRUE),
050: new DynaRenderOptions(Boolean.FALSE, Boolean.TRUE), null,
051: new DynaRenderOptions(null, Boolean.FALSE),
052: new DynaRenderOptions(Boolean.TRUE, Boolean.FALSE),
053: new DynaRenderOptions(Boolean.FALSE, Boolean.FALSE), };
054:
055: public static DynaRenderOptions getOptions(boolean dnd,
056: boolean partialRefresh) {
057: return getOptions(Boolean.valueOf(dnd), Boolean
058: .valueOf(partialRefresh));
059: }
060:
061: public static DynaRenderOptions getOptions(Boolean dnd,
062: Boolean partialRefresh) {
063: int index = dnd == null ? 0 : dnd.booleanValue() ? 1 : 2;
064: index += partialRefresh == null ? 0 : partialRefresh
065: .booleanValue() ? 4 : 8;
066: return FLYWEIGHTS[index];
067: }
068:
069: public static DynaRenderOptions getOptions(String dndValue,
070: String partialRefreshValue) {
071: Boolean dnd = dndValue == null ? null : Boolean
072: .valueOf(dndValue);
073: Boolean partialRefresh = partialRefreshValue == null ? null
074: : Boolean.valueOf(partialRefreshValue);
075: return getOptions(dnd, partialRefresh);
076: }
077:
078: public static DynaRenderOptions getOptions(Map propertyMap) {
079: String dndValue = (String) propertyMap.get(DND_ENABLED);
080: String partialRefreshValue = (String) propertyMap
081: .get(PARTIAL_REFRESH_ENABLED);
082: return getOptions(dndValue, partialRefreshValue);
083: }
084:
085: /** . */
086: public static final DynaRenderOptions NO_AJAX = DynaRenderOptions
087: .getOptions(Boolean.FALSE, Boolean.FALSE);
088:
089: /** . */
090: public static final DynaRenderOptions AJAX = DynaRenderOptions
091: .getOptions(Boolean.TRUE, Boolean.TRUE);
092:
093: /**
094: * Set the options on the specifed property map.
095: *
096: * @param propertyMap the map to alter
097: */
098: public void setOptions(Map propertyMap) {
099: if (dnd != null) {
100: propertyMap.put(DND_ENABLED, dnd.toString());
101: } else {
102: propertyMap.remove(DND_ENABLED);
103: }
104: if (partialRefresh != null) {
105: propertyMap.put(PARTIAL_REFRESH_ENABLED, partialRefresh
106: .toString());
107: } else {
108: propertyMap.remove(PARTIAL_REFRESH_ENABLED);
109: }
110: }
111:
112: /** . */
113: private final Boolean dnd;
114:
115: /** . */
116: private final Boolean partialRefresh;
117:
118: private DynaRenderOptions(Boolean dnd, Boolean partialRefresh) {
119: this .dnd = dnd;
120: this .partialRefresh = partialRefresh;
121: }
122:
123: public Boolean getDnD() {
124: return dnd;
125: }
126:
127: public boolean isDnDEnabled() {
128: return dnd != null && dnd.booleanValue();
129: }
130:
131: public Boolean getPartialRefresh() {
132: return partialRefresh;
133: }
134:
135: public boolean isPartialRefreshEnabled() {
136: return partialRefresh != null && partialRefresh.booleanValue();
137: }
138: }
|