Author: dolander Date: Thu Dec 9 08:34:33 2004 New Revision: 111403 URL: http://svn.apache.org/viewcvs?view=rev&rev=111403 Log: Add support for JavaScript namespaces to lookup the "real id" and "real name" based upon the tagId. THis is currently off by default in the DRT webapp.
Added: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/TagConfig.java Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml Added: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/TagConfig.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/TagConfig.java?view=auto&rev=111403 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/TagConfig.java Thu Dec 9 08:34:33 2004 @@ -0,0 +1,83 @@ +package org.apache.beehive.netui.tags; + +import org.apache.beehive.netui.util.config.ConfigUtil; +import org.apache.beehive.netui.util.config.bean.JspTagConfig; + + +/** + * This class implements a series of static method that will return configuration information. The + * information is buffered, and config properties values defined here. The document type configuration + * is not found in this class. It is found TagRenderBase [EMAIL PROTECTED] org.apache.beehive.netui.tags.rendering.TagRenderingBase} + * and the HTML tag [EMAIL PROTECTED] org.apache.beehive.netui.tags.html.Html}. + */ +final public class TagConfig +{ + /** + * This flag will turn on Legacy JavaScript support for id and name attributes. When this is set + * the default tag JavaScript will also be output. + */ + public static final String LEGACY_JAVA_SCRIPT = "Legacy-JavaScript"; + + /** + * This flag will make Legacy JavaScript support the only type of JavaScript output for id and name + * attributes. + */ + public static final String LEGACY_JAVA_SCRIPT_ONLY = "Legacy-JavaScript-Only"; + + + private static final int JAVASCRIPT_DEFAULT = 1; + private static final int JAVASCRIPT_LEGACY_ONLY = 2; + private static final int JAVASCRIPT_INCLUDE_LEGACY = 3; + + private static int javascriptMode = -1; + + + /** + * Return true if the legacy JavaScript support should be written to the output stream. + * @return + */ + public static boolean isLegacyJavaScript() + { + if (javascriptMode == -1) { + setLegacyJavaScriptMode(); + } + assert(javascriptMode != -1); + return (javascriptMode == JAVASCRIPT_INCLUDE_LEGACY || javascriptMode == JAVASCRIPT_LEGACY_ONLY); + } + + /** + * Return true if the default JavaScript support should be written to the output stream. + * @return + */ + public static boolean isDefaultJavaScript() + { + if (javascriptMode == -1) { + setLegacyJavaScriptMode(); + } + assert(javascriptMode != -1); + return (javascriptMode == JAVASCRIPT_INCLUDE_LEGACY || javascriptMode == JAVASCRIPT_DEFAULT); + } + + /** + * This will set the JavaScript support level for the id and name attributes. + */ + private static void setLegacyJavaScriptMode() { + JspTagConfig tagConfig = ConfigUtil.getConfig().getJspTagConfig(); + if (tagConfig != null) { + String s = tagConfig.getIdJavascript(); + if (LEGACY_JAVA_SCRIPT.equals(s)) { + javascriptMode = JAVASCRIPT_INCLUDE_LEGACY; + } + else if (LEGACY_JAVA_SCRIPT_ONLY.equals(s)) { + javascriptMode = JAVASCRIPT_LEGACY_ONLY; + } + else { + javascriptMode = JAVASCRIPT_DEFAULT; + } + } + else { + javascriptMode = JAVASCRIPT_DEFAULT; + } + System.err.println("Javascript Mode:" + javascriptMode); + } +} Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java&r1=111402&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java (original) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlBaseTag.java Thu Dec 9 08:34:33 2004 @@ -499,32 +499,32 @@ // Legacy Java Script support -- This writes out a single table with both the id and names // mixed. This is legacy support to match the pre beehive behavior. String idScript = null; - if (!ctrlState) { - idScript = addTagIdMapping(id, state.id); - } - else { - AbstractHtmlControlState cState = (AbstractHtmlControlState) state; - if (cState.name != null) - idScript = addTagIdMapping(id, cState.name); - else + if (TagConfig.isLegacyJavaScript()) { + if (!ctrlState) { idScript = addTagIdMapping(id, state.id); + } + else { + AbstractHtmlControlState cState = (AbstractHtmlControlState) state; + if (cState.name != null) + idScript = addTagIdMapping(id, cState.name); + else + idScript = addTagIdMapping(id, state.id); + } } //if (idScript != null) // javaScript.setRef(idScript); //} // map the tagId to the real id - /* - if (ctrlState) { - AbstractHtmlControlState cState = (AbstractHtmlControlState) state; - idScript = addTagIdMappings(id, cState.id, cState.name); - } - else { - idScript = addTagIdMapping(id, state.id); - } - */ - - //System.out.println("Writting:" + id + " " + state.id); + if (TagConfig.isDefaultJavaScript()) { + if (ctrlState) { + AbstractHtmlControlState cState = (AbstractHtmlControlState) state; + idScript = addTagIdMappings(id, cState.id, cState.name); + } + else { + idScript = addTagIdMapping(id, state.id); + } + } //String idScript = addTagIdMapping(id, state.id); //return idScript; Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java&r1=111402&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java (original) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/HtmlDataSourceTag.java Thu Dec 9 08:34:33 2004 @@ -142,35 +142,6 @@ String idScript = renderNameAndId(state, parentForm); if (idScript != null) javaScript.setRef(idScript); - - // if there is an id, we need to create the javascript and form - // focus support for it. - /* - IHtmlIdWriter idWriter = getNearestIdWriter(); - if (idWriter != null) { - String id = getTagId(); - if (id != null) { - - // form keeps track of this so that it can add this control to it's focus map - // @todo: should this be moved outside of the idWriter? Seems like it should - Form parentForm = getNearestForm(); - if (parentForm != null) - parentForm.addTagID(state.id, state.name); - - // rewrite the id - state.id = rewriteName(id); - - // map the tagId to the real id - //String idScript = addTagIdMappings(id, state.id, state.name); - - // @todo: add this back under the compat javascript flag - // add the state mapping - String idScript = addTagIdMapping(state.id, state.name); - if (idScript != null) - javaScript.setRef(idScript); - } - } - */ } /** Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java&r1=111402&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java (original) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/JavaScriptUtils.java Thu Dec 9 08:34:33 2004 @@ -18,6 +18,7 @@ package org.apache.beehive.netui.tags.html; import org.apache.beehive.netui.tags.IScriptReporter; +import org.apache.beehive.netui.tags.TagConfig; import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; import java.io.Serializable; @@ -114,7 +115,6 @@ return; } - //StringBuilder sb = new StringBuilder(256); writeScriptBlock(results, s); return; } @@ -140,14 +140,38 @@ if (scriptReporter == null) sb = new StringBuilder(256); - String s = getString("getNetuiTagNameAdvanced", null); - if (scriptReporter != null) - scriptReporter.addScriptFunction(s); - else { - sb.append(s); - sb.append("\n"); + String s; + // if we are supporting legacy javascript then output the original javascript method + if (TagConfig.isLegacyJavaScript()) { + s = getString("getNetuiTagNameAdvanced", null); + if (scriptReporter != null) + scriptReporter.addScriptFunction(s); + else { + sb.append(s); + sb.append("\n"); + } + } + + // if we are supporting the default javascript then output the lookup methods for id and name + if (TagConfig.isDefaultJavaScript()) { + s = getString("lookupIdByTagId", null); + if (scriptReporter != null) + scriptReporter.addScriptFunction(s); + else { + sb.append(s); + sb.append("\n"); + } + + s = getString("lookupNameByTagId", null); + if (scriptReporter != null) + scriptReporter.addScriptFunction(s); + else { + sb.append(s); + sb.append("\n"); + } } + // output the scopeId lookup method. s = getString("getScopeId", null); if (scriptReporter != null) scriptReporter.addScriptFunction(s); Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java&r1=111402&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java (original) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java Thu Dec 9 08:34:33 2004 @@ -19,6 +19,7 @@ import org.apache.beehive.netui.tags.AbstractClassicTag; import org.apache.beehive.netui.tags.IScriptReporter; +import org.apache.beehive.netui.tags.TagConfig; import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; import org.apache.beehive.netui.tags.rendering.WriteRenderAppender; @@ -406,22 +407,30 @@ // @todo: need to make the writeNetuiNameFunction deal with different functions boolean writeFunctions = false; - String val = processIdMap(_idMap, "idMappingEntry"); - if (val != null) { - jsu.writeIdMap(this, "idMappingTable", val); - writeFunctions = true; - } - - val = processIdMap(_idToIdMap, "tagIdMappingEntry"); - if (val != null) { - jsu.writeIdMap(this, "tagIdMappingTable", val); - writeFunctions = true; - } - - val = processIdMap(_idToNameMap, "tagIdNameMappingEntry"); - if (val != null) { - jsu.writeIdMap(this, "tagIdNameMappingTable", val); - writeFunctions = true; + String val; + + // if we are writing out legacy JavaScript support output the idMap + if (TagConfig.isLegacyJavaScript()) { + val = processIdMap(_idMap, "idMappingEntry"); + if (val != null) { + jsu.writeIdMap(this, "idMappingTable", val); + writeFunctions = true; + } + } + + // if we are writing out default JavaScript support we create both the name and id map + if (TagConfig.isDefaultJavaScript()) { + val = processIdMap(_idToIdMap, "tagIdMappingEntry"); + if (val != null) { + jsu.writeIdMap(this, "tagIdMappingTable", val); + writeFunctions = true; + } + + val = processIdMap(_idToNameMap, "tagIdNameMappingEntry"); + if (val != null) { + jsu.writeIdMap(this, "tagIdNameMappingTable", val); + writeFunctions = true; + } } if (writeFunctions) { Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties&r1=111402&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties (original) +++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/javaScript.properties Thu Dec 9 08:34:33 2004 @@ -103,6 +103,30 @@ \ return netui_names[scopeId + "__" + id];\n\ }\n +#method to do lookup in netui_tagIdMap +lookupIdByTagId=\ +// lookup by tagId to "real id"\n\ +function lookupIdByTagId(id, tag)\n\ +{\n\ +\ var scopeId = getScopeId(tag);\n\ +\ if (scopeId == \"\")\n\ +\ return netui_tagIdMap[id];\n\ +\ else\n\ +\ return netui_tagIdMap[scopeId + "__" + id];\n\ +}\n + +#method to do lookup in netui_tagIdNameMap +lookupNameByTagId=\ +// lookup by tagId to "real name"\n\ +function lookupNameByTagId(id, tag)\n\ +{\n\ +\ var scopeId = getScopeId(tag);\n\ +\ if (scopeId == \"\")\n\ +\ return netui_tagIdNameMap[id];\n\ +\ else\n\ +\ return netui_tagIdNameMap[scopeId + "__" + id];\n\ +}\n + # method to find the scope id getScopeId=\ // This method will walk the hierarchy from the pass element looking for a scopeId.\n\ Modified: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml?view=diff&rev=111403&p1=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml&r1=111402&p2=incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml&r2=111403 ============================================================================== --- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml (original) +++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/WEB-INF/local-netui-config.xml Thu Dec 9 08:34:33 2004 @@ -49,7 +49,7 @@ <jsp-tag-config> <doctype>html4-loose</doctype> - <id-transparency>Transparent Off</id-transparency> + <id-javascript>Legacy-JavaScript-Only</id-javascript> </jsp-tag-config> <iterator-factories>
