001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags;
020:
021: import org.apache.beehive.netui.tags.tree.InheritableState;
022: import org.apache.beehive.netui.util.config.ConfigUtil;
023: import org.apache.beehive.netui.util.config.bean.JspTagConfig;
024: import org.apache.beehive.netui.util.config.bean.IdJavascript;
025:
026: /**
027: * This class implements a series of static method that will return configuration information. The
028: * information is buffered, and config properties values defined here. The document type configuration
029: * is not found in this class. It is found TagRenderBase {@link org.apache.beehive.netui.tags.rendering.TagRenderingBase}
030: * and the HTML tag {@link org.apache.beehive.netui.tags.html.Html}.
031: */
032: final public class TagConfig {
033: // This is the value of the javascript support for the webapp. This should
034: // be one of the enum values defined above.
035: private static int javascriptMode = -1;
036:
037: private static String defaultTreeImageLocation = null;
038: private static String defaultTreeRendererClassName = null;
039:
040: /**
041: * Return true if the legacy JavaScript support should be written to the output stream.
042: * @return boolean
043: */
044: public static boolean isLegacyJavaScript() {
045: if (javascriptMode == -1) {
046: setLegacyJavaScriptMode();
047: }
048: assert (javascriptMode != -1);
049: return (javascriptMode == IdJavascript.INT_LEGACY || javascriptMode == IdJavascript.INT_LEGACY_ONLY);
050: }
051:
052: /**
053: * Return true if the default JavaScript support should be written to the output stream.
054: * @return boolean
055: */
056: public static boolean isDefaultJavaScript() {
057: if (javascriptMode == -1) {
058: setLegacyJavaScriptMode();
059: }
060: assert (javascriptMode != -1);
061: return (javascriptMode == IdJavascript.INT_DEFAULT || javascriptMode == IdJavascript.INT_LEGACY);
062: }
063:
064: /**
065: * This method returns the default location for the tree images. This may be configured by setting
066: * the <tree-image-location> element in the netui.config file to the location of the images.
067: * This location should not include the context path of the webapp or the leading '/', but should be an absolute
068: * path within the webapp.
069: * <p><tree-image-location>resources/images</tree-image-location>
070: * </p>
071: * @return the default location of the tree images.
072: */
073: public static String getTreeImageLocation() {
074: if (defaultTreeImageLocation == null) {
075: JspTagConfig tagConfig = ConfigUtil.getConfig()
076: .getJspTagConfig();
077: if (tagConfig != null) {
078: String s = tagConfig.getTreeImageLocation();
079: defaultTreeImageLocation = (s != null) ? s
080: : InheritableState.DEFAULT_IMAGES;
081: } else
082: defaultTreeImageLocation = InheritableState.DEFAULT_IMAGES;
083: }
084: assert (defaultTreeImageLocation != null);
085: return defaultTreeImageLocation;
086: }
087:
088: /**
089: * This method returns the class name of the renderer to use for NetUI
090: * trees in the Web application. The class name returned will usually
091: * be the predefined default NetUI implementation,
092: * {@link org.apache.beehive.netui.tags.tree.TreeRenderer}, unless
093: * NetUI is configured to use a different implementation.
094: * This may be configured by setting the <tree-renderer-class>
095: * element in the beehive-netui-config file to the name of a class that
096: * extends {@link org.apache.beehive.netui.tags.tree.TreeRenderer}.
097: * <p><tree-renderer-class>com.xyz.tree.CustomTreeRenderer</tree-renderer-class>
098: * </p>
099: * <p>Note that the NetUI {@link org.apache.beehive.netui.tags.tree.Tree}
100: * tag has an attribute for setting the name of the TreeRenderer class to
101: * use on a tree by tree bases.
102: * </p>
103: * @return the name of the class to use to renderer the trees in the application.
104: */
105: public static String getTreeRendererClassName() {
106: if (defaultTreeRendererClassName == null) {
107: JspTagConfig tagConfig = ConfigUtil.getConfig()
108: .getJspTagConfig();
109: if (tagConfig != null) {
110: // the schema config includes a default value so we shouldn't
111: // get a null value from the config object.
112: defaultTreeRendererClassName = tagConfig
113: .getTreeRendererClass();
114: }
115: }
116: return defaultTreeRendererClassName;
117: }
118:
119: /**
120: * This will set the JavaScript support level for the id and name attributes.
121: */
122: private static void setLegacyJavaScriptMode() {
123: JspTagConfig tagConfig = ConfigUtil.getConfig()
124: .getJspTagConfig();
125: if (tagConfig != null) {
126: javascriptMode = tagConfig.getIdJavascript().getValue();
127: } else {
128: javascriptMode = IdJavascript.INT_DEFAULT;
129: }
130: }
131: }
|