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.base.context;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.HashMap;
015:
016: //project specific classes
017: import org.jfolder.common.UnexpectedSystemException;
018: import org.jfolder.common.tagging.ConceptTag;
019: import org.jfolder.common.tagging.ConceptTagCharacteristic;
020: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
021: import org.jfolder.common.tagging.ConceptTagConstraint;
022: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
023: import org.jfolder.common.tagging.ConceptTagHelper;
024: import org.jfolder.common.tagging.ConceptTagMessageHolder;
025: import org.jfolder.common.tagging.ConceptTagPreferences;
026: import org.jfolder.common.tagging.RootConceptTagHolder;
027: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
028: import org.jfolder.common.utils.misc.MiscHelper;
029: import org.jfolder.common.web.template.ConsoleParameterContext;
030: import org.jfolder.common.web.template.SubmitActionContext;
031: import org.jfolder.common.web.template.SubmitActionParameters;
032: import org.jfolder.console.base.ConsolePageContext;
033: import org.jfolder.console.base.ConsolePageMessageHolder;
034: import org.jfolder.console.base.ConsolePageSession;
035: import org.jfolder.console.base.NamesForSubCpc;
036:
037: //other classes
038:
039: public class SubMessageHolderConsolePageContext extends
040: BaseSubBoxConsolePageContext {
041:
042: //
043: private ConsolePageMessageHolder cpmh = null;
044:
045: protected SubMessageHolderConsolePageContext(String inName,
046: int inColumnWidth, int inHeight, String inSideColor,
047: ConsolePageContext inCpc, ConsolePageMessageHolder inCpmh) {
048:
049: super (inName, inColumnWidth, inHeight, inSideColor, inCpc);
050: //
051: this .cpmh = inCpmh;
052: }
053:
054: private final static SubMessageHolderConsolePageContext newInstance(
055: int inColumnWidth, int inHeight, String inSideColor,
056: ConsolePageContext inCpc, boolean inWrap, int inPadding,
057: ConsolePageMessageHolder inCpmh) throws IOException {
058:
059: SubMessageHolderConsolePageContext outValue = null;
060:
061: if (inCpc.isSubConsolePageContextPresent(NamesForSubCpc
062: .getSubMessageHolderCpcName())) {
063: //
064: Object o = inCpc.getSubConsolePageContext(NamesForSubCpc
065: .getSubMessageHolderCpcName());
066: outValue = (SubMessageHolderConsolePageContext) o;
067: //
068: outValue.setTotalColumnWidth(inCpc.getLongestRowWidth());
069: //
070: outValue.setMessageHolder(inCpmh);
071: } else {
072: outValue = new SubMessageHolderConsolePageContext(
073: NamesForSubCpc.getSubMessageHolderCpcName(),
074: inColumnWidth, inHeight, inSideColor, inCpc, inCpmh);
075: inCpc.registerSubConsolePageContext(NamesForSubCpc
076: .getSubMessageHolderCpcName(), outValue);
077: }
078: outValue.setContentWrap(inWrap);
079: outValue.setPadding(inPadding);
080:
081: outValue.copyFromParent(inCpc);
082: outValue.createConsolePage(inCpc.getWriter(), inCpc
083: .getPageSetupContext());
084:
085: return outValue;
086: }
087:
088: //
089: private void setMessageHolder(ConsolePageMessageHolder inCpmh) {
090: this .cpmh = inCpmh;
091: }
092:
093: //
094: protected HashMap getMainTableFormat() {
095: return alignCenter(null);
096: }
097:
098: //
099: public final static void renderMessagesIfPresent(
100: ConsolePageContext inCpc) throws IOException {
101: //
102: //ConsolePageMessageHolder getRootHolderMessageHolder();
103: ConsolePageMessageHolder localCpmh = inCpc
104: .getConsolePageSession().getMessageHolder();
105: ConsolePageMessageHolder rcthCpmh = getRootHolderMessageHolder(inCpc
106: .getConsolePageSession());
107: //
108: ConsolePageMessageHolder parentCpmh = null;
109: //
110: if (!localCpmh.isEmpty() && !rcthCpmh.isEmpty()) {
111: localCpmh
112: .setInformationHeader("The following messages pertain to your previous action");
113: parentCpmh = ConsolePageMessageHolder.newInstance();
114: parentCpmh.addSubMessage(localCpmh);
115: parentCpmh.addSubMessage(rcthCpmh);
116: parentCpmh
117: .setInformationHeader("The following messages pertain to your previous action"
118: + " and this file");
119: } else if (localCpmh.isEmpty() && !rcthCpmh.isEmpty()) {
120: parentCpmh = rcthCpmh;
121: } else if (!localCpmh.isEmpty() && rcthCpmh.isEmpty()) {
122: parentCpmh = ConsolePageMessageHolder.newInstance();
123: parentCpmh
124: .setInformationHeader("The following messages pertain to your previous action");
125: //parentCpmh = localCpmh;
126: parentCpmh.addSubMessage(localCpmh);
127: } else {
128: parentCpmh = ConsolePageMessageHolder.newInstance();
129: }
130: //
131: if (!parentCpmh.isEmpty()) {
132:
133: int height = 100;
134: //if (parentCpmh.getTotalMessageCount() < 3) {
135: // height = 25 * parentCpmh.getTotalMessageCount();
136: //}
137:
138: SubMessageHolderConsolePageContext.newInstance(inCpc
139: .getLongestRowWidth(), height, "666666", inCpc,
140: false, 2, parentCpmh);
141: //startAndEndStretchTableAndRowAndCell("ErrorPresent",
142: // alignCenter(getFontStyle(14, ARIAL, ERROR_COLOR)));
143: }
144: }
145:
146: protected void renderPreContent() throws IOException {
147: getParentCpc().startAndEndStretchTableAndRowAndCell("<hr/>");
148: getParentCpc().startTable(getParentCpc().getLongestRowWidth());
149: getParentCpc().startRow();
150: }
151:
152: protected void renderContent() throws IOException {
153: ConsolePageMessageHolder parentCpmh = ConsolePageMessageHolder
154: .newInstance();
155: parentCpmh.addSubMessage(this .cpmh);
156: //simpleAndPrint("Error Messages Here");
157: renderContent(parentCpmh);
158: }
159:
160: private void renderContent(ConsolePageMessageHolder inCpmh)
161: throws IOException {
162:
163: //
164: if (inCpmh.getSubMessageCount() > 0) {
165: printAndIndent("<ul>");
166: for (int i = 0; i < inCpmh.getSubMessageCount(); i++) {
167: ConsolePageMessageHolder nextCpmh = inCpmh
168: .getSubMessage(i);
169: String nextColor = "";
170: if (nextCpmh.isHeaderInformation()) {
171: nextColor = "000099";
172: } else if (nextCpmh.isHeaderWarning()) {
173: nextColor = "999900";
174: } else if (nextCpmh.isHeaderError()) {
175: nextColor = "990000";
176: } else {
177: throw UnexpectedSystemException.unknownState();
178: }
179: //
180: String nextHeader = nextCpmh.getHeaderMessage();
181: if (nextCpmh.getCtHandle() != null) {
182: SubmitActionContext sacGoTo = SubmitActionContext
183: .newInstance(this );
184: sacGoTo.addAction(
185: ConsoleParameterContext.FIRST_INPUT,
186: singleQuotes(SubmitActionParameters.MOVE));
187: sacGoTo.addParameter(
188: ConsoleParameterContext.FIRST_INPUT,
189: singleQuotes(nextCpmh.getCtHandle()));
190: //
191: nextHeader = "<a href=\"javascript:"
192: + submitActionCall(sacGoTo)
193: + "\" style=\"color: '#" + nextColor
194: + "'\">" + nextHeader + "</a>";
195: } else {
196: nextHeader = "<a style=\"color: '#" + nextColor
197: + "'\">" + nextHeader + "</a>";
198: }
199: //
200: simpleAndPrint("<li>" + nextHeader + "</li>");
201: renderContent(nextCpmh);
202: }
203: revertAndPrint("</ul>");
204: }
205: }
206:
207: protected void renderPostContent() throws IOException {
208: getParentCpc().endRow();
209: getParentCpc().endTable();
210: }
211:
212: //
213: private final static ConsolePageMessageHolder getRootHolderMessageHolder(
214: ConsolePageSession inCps) {
215:
216: ConsolePageMessageHolder outValue = ConsolePageMessageHolder
217: .newInstance();
218:
219: if (inCps.getCurrentApplicationRootHolder() != null) {
220: RootConceptTagHolder localRcth = inCps
221: .getCurrentApplicationRootHolder();
222: ConceptTagPreferences localCtp = localRcth.getPreferences();
223: ConceptTagCharacteristicHolder localCtcharh = localRcth
224: .getFirstChildCharacteristicHolder();
225: HashMap catalog = new HashMap();
226: //
227: getRootHolderMessageHolder(localRcth, localCtcharh,
228: localCtp.getRootHandle(), catalog);
229: //
230: ArrayList catalogKeys = new ArrayList(catalog.keySet());
231: Collections.sort(catalogKeys);
232: for (int i = 0; i < catalogKeys.size(); i++) {
233: String nextCatalogKey = (String) catalogKeys.get(i);
234: ArrayList nextCatalogValues = (ArrayList) catalog
235: .get(nextCatalogKey);
236: HashMap nextCatalog = new HashMap();
237: for (int j = 0; j < nextCatalogValues.size(); j++) {
238: Object o[] = (Object[]) nextCatalogValues.get(j);
239: nextCatalog.put(o[0], o);
240: }
241: ArrayList nextCatalogKeys = new ArrayList(nextCatalog
242: .keySet());
243: Collections.sort(nextCatalogKeys);
244: //
245: ConsolePageMessageHolder parentCtMessage = outValue
246: .createSubMessage();
247: parentCtMessage.setCtHandle(nextCatalogKey);
248: //
249: ConceptTagConstraintHolder parentCtconh = ConceptTagHelper
250: .getConstraintHolder(localRcth, nextCatalogKey);
251: ConceptTagCharacteristicHolder parentCtcharh = parentCtconh
252: .getCharacteristicHolder();
253: ConceptTag parentCt = parentCtcharh.getConceptTag();
254: StudioConceptTagInstanceInfoContext parentSctiic = StudioConceptTagInstanceInfoContext
255: .newInstance();
256: parentCt.appraise(parentSctiic);
257: parentCtMessage.setInformationHeader(parentSctiic
258: .getInstanceDescription());
259: //
260: if (nextCatalog.containsKey(nextCatalogKey)) {
261: //
262: Object parObj[] = (Object[]) nextCatalog
263: .get(nextCatalogKey);
264: //
265: String parentHandle = (String) parObj[0];
266: ConceptTagMessageHolder parentCtmh = (ConceptTagMessageHolder) parObj[1];
267: boolean parentCtcharPresent = ((Boolean) parObj[2])
268: .booleanValue();
269: //
270: processMessage(localRcth, parentCtMessage,
271: parentHandle, parentCtmh,
272: parentCtcharPresent);
273: }
274: for (int j = 0; j < nextCatalogKeys.size(); j++) {
275: String nextCatalogSubKey = (String) nextCatalogKeys
276: .get(j);
277: if (!nextCatalogSubKey.equals(nextCatalogKey)) {
278: //
279: ConsolePageMessageHolder subCtMessage = parentCtMessage
280: .createSubMessage();
281: subCtMessage.setCtHandle(nextCatalogSubKey);
282: //
283: Object subObj[] = (Object[]) nextCatalog
284: .get(nextCatalogSubKey);
285: //
286: String subHandle = (String) subObj[0];
287: ConceptTagMessageHolder subCtmh = (ConceptTagMessageHolder) subObj[1];
288: boolean subCtcharPresent = ((Boolean) subObj[2])
289: .booleanValue();
290: //
291: processMessage(localRcth, subCtMessage,
292: subHandle, subCtmh, subCtcharPresent);
293: }
294: }
295: }
296: //
297: if (!outValue.isEmpty()) {
298: outValue
299: .setInformationHeader("One or more messages for this file appear below,"
300: + " correct all errors if present (in red)");
301: }
302:
303: }
304:
305: return outValue;
306: }
307:
308: private final static void processMessage(
309: RootConceptTagHolder inRcth,
310: ConsolePageMessageHolder inConsoleMessage, String inHandle,
311: ConceptTagMessageHolder inCtMessage, boolean inCtcharPresent) {
312: //
313: MiscHelper.println("SubMesHolConPagCon inCtMess = ");
314: inCtMessage.pr();
315: //
316: for (int i = 0; i < inCtMessage.getHeaderMessageCount(); i++) {
317: ConsolePageMessageHolder subCpmh = inConsoleMessage
318: .createSubMessage();
319: subCpmh.setCtHandle(inHandle);
320: MiscHelper.println("SubMesHolConPagCon HEADER_MESSAGE = "
321: + inCtMessage.getHeaderMessage(i));
322: if (inCtMessage.isInformationHeaderMessage(i)) {
323: subCpmh.setInformationHeader(inCtMessage
324: .getHeaderMessage(i));
325: } else if (inCtMessage.isWarningHeaderMessage(i)) {
326: subCpmh.setWarningHeader(inCtMessage
327: .getHeaderMessage(i));
328: } else if (inCtMessage.isErrorHeaderMessage(i)) {
329: subCpmh.setErrorHeader(inCtMessage.getHeaderMessage(i));
330: } else {
331: throw UnexpectedSystemException.unknownState();
332: }
333: }
334: //
335: if (inCtcharPresent) {
336: ConceptTagConstraint ctcon = ConceptTagHelper
337: .getConstraint(inRcth, inHandle);
338: ConceptTagCharacteristic ctchar = ctcon.getCharacteristic();
339: //
340: String ctconDescription = ctcon.getShortDescription();
341: if (inCtMessage.isErrorPresent()) {
342: inConsoleMessage.setErrorHeader(ctconDescription);
343: } else {
344: inConsoleMessage.setInformationHeader(ctconDescription);
345: }
346: //
347: for (int i = 0; i < ctchar.getValueLength(); i++) {
348: int jCount = inCtMessage.getTotalIndexMessageCount(i);
349: for (int j = 0; j < jCount; j++) {
350: MiscHelper
351: .println("SubMesHolConPagCon INDEX_MESSAGE = "
352: + inCtMessage.getIndexMessage(i, j));
353: ConsolePageMessageHolder subCpmh = inConsoleMessage
354: .createSubMessage();
355: subCpmh.setCtHandle(inHandle);
356: if (inCtMessage.isInformationIndexMessage(i, j)) {
357: subCpmh.setInformationHeader(inCtMessage
358: .getIndexMessage(i, j));
359: } else if (inCtMessage.isWarningIndexMessage(i, j)) {
360: subCpmh.setWarningHeader(inCtMessage
361: .getIndexMessage(i, j));
362: } else if (inCtMessage.isErrorIndexMessage(i, j)) {
363: subCpmh.setErrorHeader(inCtMessage
364: .getIndexMessage(i, j));
365: } else {
366: throw UnexpectedSystemException.unknownState();
367: }
368: }
369: }
370:
371: } else {
372: ConceptTagConstraintHolder ctconh = ConceptTagHelper
373: .getConstraintHolder(inRcth, inHandle);
374: ConceptTagCharacteristicHolder ctcharh = ctconh
375: .getCharacteristicHolder();
376: //
377: if (ctcharh.isConceptTagPresent()) {
378: StudioConceptTagInstanceInfoContext sctiic = StudioConceptTagInstanceInfoContext
379: .newInstance();
380: //
381: ConceptTag ct = ctcharh.getConceptTag();
382: ct.appraise(sctiic);
383: //
384: String ctconhDescription = sctiic
385: .getInstanceDescription();
386: if (inCtMessage.isErrorPresent()) {
387: inConsoleMessage.setErrorHeader(ctconhDescription);
388: } else {
389: inConsoleMessage
390: .setInformationHeader(ctconhDescription);
391: }
392: } else {
393: String ctconhDescription = ctconh.getShortDescription();
394: if (inCtMessage.isErrorPresent()) {
395: inConsoleMessage.setErrorHeader(ctconhDescription);
396: } else {
397: inConsoleMessage
398: .setInformationHeader(ctconhDescription);
399: }
400:
401: }
402: //
403: ArrayList conNames = inCtMessage.getAllNames();
404: Collections.sort(conNames);
405: for (int i = 0; i < conNames.size(); i++) {
406: String nextConName = (String) conNames.get(i);
407: //
408: int jCount = inCtMessage
409: .getTotalNameMessageCount(nextConName);
410: for (int j = 0; j < jCount; j++) {
411: //
412: MiscHelper
413: .println("SubMesHolConPagCon NAME_MESSAGE = "
414: + inCtMessage.getNameMessage(
415: nextConName, j));
416: //
417: ConsolePageMessageHolder subCpmh = inConsoleMessage
418: .createSubMessage();
419: subCpmh.setCtHandle(inHandle);
420: //
421: if (inCtMessage.isInformationNameMessage(
422: nextConName, j)) {
423: subCpmh.setInformationHeader(inCtMessage
424: .getNameMessage(nextConName, j));
425: } else if (inCtMessage.isWarningNameMessage(
426: nextConName, j)) {
427: subCpmh.setWarningHeader(inCtMessage
428: .getNameMessage(nextConName, j));
429: } else if (inCtMessage.isErrorNameMessage(
430: nextConName, j)) {
431: subCpmh.setErrorHeader(inCtMessage
432: .getNameMessage(nextConName, j));
433: } else {
434: throw UnexpectedSystemException.unknownState();
435: }
436: }
437: }
438: }
439: }
440:
441: private final static void getRootHolderMessageHolder(
442: RootConceptTagHolder inRcth,
443: ConceptTagCharacteristicHolder inCtcharh, String inHandle,
444: HashMap inCatalog) {
445:
446: ConceptTagPreferences localCtp = inRcth.getPreferences();
447: String handCon = localCtp.getHandleConjunction();
448:
449: if (inCtcharh.isStylesType()) {
450: //
451: } else if (inCtcharh.isAttributesType()) {
452: //
453: } else {
454: getRootHolderMessageHolder(inRcth, inCtcharh
455: .getAttributes(), inHandle + handCon
456: + localCtp.getAttributeConstraintName(), inCatalog);
457: getRootHolderMessageHolder(inRcth, inCtcharh.getStyles(),
458: inHandle + handCon
459: + localCtp.getStyleConstraintName(),
460: inCatalog);
461: getRootHolderMessageHolder(inRcth, inCtcharh
462: .getUndefinedCharacteristic(), inHandle + handCon
463: + localCtp.getUnconstrainedSymbol(), inCatalog);
464: }
465: //
466: for (int i = 0; i < inCtcharh.getCharacteristicCount(); i++) {
467: ConceptTagCharacteristic nextCtchar = inCtcharh
468: .getCharacteristic(i);
469: getRootHolderMessageHolder(inRcth, nextCtchar, inHandle
470: + handCon + nextCtchar.getConstraintName(),
471: inCatalog);
472: }
473:
474: ConceptTagMessageHolder ctmh = inCtcharh
475: .getParentMessageHolder();
476: if (ctmh.isErrorPresent()) {
477: addErrorToCatalog(inRcth, ctmh, inHandle,
478: new Boolean(false), inCatalog);
479: }
480: //addRootHolderMessages(ctmh, inCpmh);
481: }
482:
483: private final static void getRootHolderMessageHolder(
484: RootConceptTagHolder inRcth,
485: ConceptTagCharacteristic inCtchar, String inHandle,
486: HashMap inCatalog) {
487:
488: //
489: ConceptTagPreferences localCtp = inRcth.getPreferences();
490: String handCon = localCtp.getHandleConjunction();
491:
492: for (int i = 0; i < inCtchar.getValueLength(); i++) {
493: if (inCtchar.isHolder(i, null)) {
494: ConceptTagCharacteristicHolder nextCtcharh = inCtchar
495: .getValueAsHolder(i, null);
496: getRootHolderMessageHolder(inRcth, nextCtcharh,
497: inHandle + handCon + i, inCatalog);
498: }
499: }
500:
501: ConceptTagMessageHolder ctmh = inCtchar
502: .getParentMessageHolder();
503: if (ctmh.isErrorPresent()) {
504: addErrorToCatalog(inRcth, ctmh, inHandle,
505: new Boolean(true), inCatalog);
506: }
507: //addRootHolderMessages(ctmh, inCpmh);
508: }
509:
510: //private final static void addRootHolderMessages(
511: // String inCurrentHandle, ConceptTagMessageHolder inCtmh,
512: // ConsolePageMessageHolder inCpmh) {
513: //
514: // MiscHelper.println("SubMesHolConPagCon inCtmh = " + inCtmh);
515: // //ConsolePageMessageHolder subMessage = inCpmh.createSubMessage();
516: // for (int i = 0; i < inCtmh.getHeaderMessageCount(); i++) {
517: // //
518: // ConsolePageMessageHolder subCpmh = inCpmh.createSubMessage();
519: // //
520: // String nextMessage = inCtmh.getHeaderMessage(i);
521: // if (inCtmh.isInformationHeaderMessage(i)) {
522: // subCpmh.setInformationHeader(nextMessage);
523: // }
524: // else if (inCtmh.isWarningHeaderMessage(i)) {
525: // subCpmh.setWarningHeader(nextMessage);
526: // }
527: // else if (inCtmh.isErrorHeaderMessage(i)) {
528: // subCpmh.setErrorHeader(nextMessage);
529: // }
530: // else {
531: // throw UnexpectedSystemException.unknownState();
532: // }
533: // }
534: //}
535: private final static void addErrorToCatalog(
536: RootConceptTagHolder inRcth,
537: ConceptTagMessageHolder inCtmh, String inHandle,
538: Boolean inCtcharSource, HashMap inCatalog) {
539: //
540: StringBuffer ctCode = new StringBuffer();
541: ConceptTagHelper.getNearestConceptTag(inRcth, inHandle, ctCode);
542: //
543: ArrayList ctErrors = null;
544: if (inCatalog.containsKey(ctCode.toString())) {
545: ctErrors = (ArrayList) inCatalog.get(ctCode.toString());
546: } else {
547: ctErrors = new ArrayList();
548: inCatalog.put(ctCode.toString(), ctErrors);
549: }
550: ctErrors.add(new Object[] { inHandle, inCtmh, inCtcharSource });
551: }
552: }
|