001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.console.web.dictionary;
009:
010: //base classes
011: import java.io.IOException;
012: import java.net.URLEncoder;
013: import java.util.ArrayList;
014: import java.util.Collections;
015: import java.util.HashMap;
016: import javax.servlet.http.HttpServletRequest;
017:
018: //project specific classes
019: import org.jfolder.common.UnexpectedSystemException;
020: import org.jfolder.common.tagging.ConceptTagPreferences;
021: import org.jfolder.common.tagging.ConceptTagPreferencesHelper;
022: import org.jfolder.common.tagging.ConceptTagSetHolder;
023: import org.jfolder.common.utils.misc.MiscHelper;
024: import org.jfolder.common.utils.web.ParameterHelper;
025: import org.jfolder.common.utils.web.ParameterSet;
026: import org.jfolder.common.utils.xml.LinearXPath;
027: import org.jfolder.common.utils.xml.XMLHelper;
028: import org.jfolder.common.web.template.ConsoleTemplateContext;
029: import org.jfolder.common.web.template.ConsoleTemplateParameters;
030: import org.jfolder.common.web.template.SubmitActionContext;
031: import org.jfolder.common.web.template.SubmitActionParameters;
032: import org.jfolder.config.instance.ConfigInstance;
033: import org.jfolder.config.instance.ConfigInstanceConfig;
034: import org.jfolder.console.base.ConsolePageParameters;
035: import org.jfolder.security.lifecycle.SecurityLifecycleHelper;
036: import org.jfolder.security.model.UserHolder;
037: import org.jfolder.services.config.ConfigService;
038: import org.jfolder.services.config.ConfigServiceCaller;
039: import org.jfolder.services.config.ConfigServiceCallerFactory;
040:
041: //other classes
042:
043: public class ConceptTagDictionaryIndexContext extends
044: BaseConceptTagDictionaryContext {
045:
046: protected ConceptTagDictionaryIndexContext(ParameterSet inPs) {
047: //
048: super (inPs);
049: }
050:
051: public String getFromPage() {
052: return ConsolePageParameters.SERVLET_DICTIONARY_INDEX;
053: }
054:
055: public String getHandle() {
056: return NULL_HANDLE;
057: }
058:
059: public String getHandleExtension() {
060: throw new UnexpectedSystemException(
061: "This function should not be called in this class");
062: }
063:
064: protected void renderConsolePage() throws IOException {
065:
066: ParameterSet ps = getParameterSet();
067:
068: //render content
069: startCommonPage();
070:
071: //startEnclosingTableAndRowAndCell(attrs);
072: //
073: //startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
074: //
075: //
076: //startAndEndStretchTableAndRowAndCell("<hr/>");
077: //
078: if (ps.isParameterString(PARAMETER__PREF_HANDLE)) {
079: String prefHan = ps.getParameter(PARAMETER__PREF_HANDLE);
080: //srcIndex = srcIndex + "?" + PARAMETER__PREF_HANDLE + "="
081: // + URLEncoder.encode(prefHandle);
082: ConceptTagPreferences localCtp = ConceptTagPreferencesHelper
083: .getPreferencesFromHandle(prefHan);
084:
085: ConceptTagSetHolder localCtsh = localCtp.getSetHolder();
086:
087: ArrayList items = new ArrayList();
088:
089: ArrayList namespaces = localCtsh.getRegisteredNameSpaces();
090: for (int i = 0; i < namespaces.size(); i++) {
091: String nextNamespace = (String) namespaces.get(i);
092: ArrayList names = localCtsh
093: .getRegisteredNames(nextNamespace);
094: for (int j = 0; j < names.size(); j++) {
095: String nextName = (String) names.get(j);
096: //
097: String nextClass = localCtsh
098: .getConceptTagClassAsString(nextNamespace,
099: nextName);
100: //
101: String nextTitle = localCtsh
102: .getTypeTitle(nextClass);
103: //MiscHelper.println(
104: // "ConTagDicIndCon nextTitle = " + nextTitle);
105: //
106: ConceptTagDictionaryIndexItem nextCtdii = new ConceptTagDictionaryIndexItem(
107: nextTitle, prefHan, nextNamespace, nextName);
108: //
109: items.add(nextCtdii);
110: }
111: }
112:
113: Collections.sort(items);
114:
115: startTable(2);
116: startRow();
117: startAndEndCell(2, convertPrefHanToLabel(prefHan),
118: addStyle(getFontStyle(14, ARIAL, BLACK),
119: "text-decoration", "underline"));
120: endRow();
121: for (int i = 0; i < items.size(); i++) {
122: ConceptTagDictionaryIndexItem nextCtdii = (ConceptTagDictionaryIndexItem) items
123: .get(i);
124:
125: String namespaceEncoding = "";
126: if (nextCtdii.getNamespace() != null) {
127: namespaceEncoding = "&"
128: + PARAMETER__CT_NS
129: + "="
130: + URLEncoder.encode(nextCtdii
131: .getNamespace());
132: }
133:
134: //
135: String url = ConsolePageParameters.SERVLET_DICTIONARY_DISPLAY
136: + "?"
137: + PARAMETER__PREF_HANDLE
138: + "="
139: + URLEncoder.encode(nextCtdii
140: .getPreferencesHandle())
141: + namespaceEncoding
142: + "&"
143: + PARAMETER__CT_NAME
144: + "=" + URLEncoder.encode(nextCtdii.getName());
145: String target = TARGET__DISPLAY;
146: String lab = XMLHelper.fromStringToCData(nextCtdii
147: .getTitle());
148: String hyperLink = createHyperLink(url, target, lab);
149: //
150: startRow();
151: startAndEndCell(2, hyperLink, getFontStyle(12, ARIAL,
152: BLACK));
153: endRow();
154: }
155: endTable();
156: } else {
157: startTable(1);
158: startRow();
159: startAndEndCell(1,
160: "Please choose one of the above categories.",
161: getFontStyle(11, ARIAL, BLACK));
162: endRow();
163: endTable();
164: }
165: //
166: //startAndEndStretchTableAndRowAndCell("<hr color=\"#FFFFF\"/>");
167: //
168: //
169: //endEnclosingTableAndRowAndCell();
170: //
171:
172: endCommonPage();
173: }
174: }
|