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.view.base;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.common.function.WebPageTagInstanceViewContext;
016: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
017: import org.jfolder.common.utils.xml.XMLHelper;
018:
019: //other classes
020:
021: public class PopUpViewTitleHelper {
022:
023: //
024: private PopUpViewTitleHelper() {
025: }
026:
027: //
028: //
029: public final static String constructTitleWithEarmark(
030: WebPageTagInstanceViewContextInfo inParentWptivci,
031: String inTitle) {
032:
033: StringBuffer outValue = new StringBuffer();
034:
035: outValue.append(inTitle);
036:
037: if (inParentWptivci.isSubEarmarkPresent()) {
038: //
039: WebPageTagInstanceViewContextInfo earmarkWptivci = inParentWptivci
040: .getSubEarmark();
041: //
042: //
043: int count = earmarkWptivci.getContentLength();
044: //
045: if (count > 0) {
046: outValue.append("\n");
047: }
048: //
049: constructTitle(outValue, true, earmarkWptivci, 0, count,
050: false);
051: }
052:
053: return outValue.toString();
054: }
055:
056: //
057: //
058: public final static String constructTitle(
059: WebPageTagInstanceViewContextInfo inWptivci,
060: int inStartIndex, int inEndIndex, boolean inLimitDepth) {
061:
062: StringBuffer outValue = new StringBuffer();
063:
064: constructTitle(outValue, true, inWptivci, inStartIndex,
065: inEndIndex, inLimitDepth);
066:
067: return outValue.toString();
068: }
069:
070: //
071: public final static void constructTitle(StringBuffer inSb,
072: boolean inIndent,
073: WebPageTagInstanceViewContextInfo inWptivci,
074: int inStartIndex, int inEndIndex, boolean inLimitDepth) {
075: //
076: //StringBuffer outValue = new StringBuffer();
077:
078: boolean useBullets = (inEndIndex - inStartIndex > 1);
079:
080: ArrayList nonHtmls = new ArrayList();
081: for (int i = inStartIndex; i < inEndIndex; i++) {
082: //
083: WebPageTagInstanceViewContextInfo nextWptivci = inWptivci
084: .getContentAsInfo(i);
085: //
086: StringBuffer nextSb = new StringBuffer();
087: if (useBullets || inIndent) {
088: if (inIndent) {
089: nextSb.append(" ");
090: }
091: nextSb.append("- ");
092: }
093: generateNonHtmlViewForTitle(nextWptivci, nextSb,
094: inLimitDepth);
095: //
096: nonHtmls.add(nextSb.toString());
097: }
098: //
099: //
100: for (int i = 0; i < nonHtmls.size(); i++) {
101: if (i > 0) {
102: inSb.append("\n");
103: }
104: String nextNonHtml = ((String) nonHtmls.get(i));
105: //inSb.append(XMLHelper.fromStringToCData(nextNonHtml));
106: inSb.append(nextNonHtml);
107: }
108:
109: //return outValue.toString();
110: }
111:
112: //
113: //
114: //
115: public final static void generateNonHtmlViewForTitle(
116: WebPageTagInstanceViewContextInfo inWptivci,
117: StringBuffer inSb, boolean inLimitDepth) {
118: //
119: if (inWptivci.isMarkedAsNonHtml()) {
120: //
121: inSb.append(XMLHelper.fromStringToCData(inWptivci
122: .getNonHtmlStartContent()));
123: //
124: //
125: //
126: for (int i = 0; i < inWptivci.getContentLength(); i++) {
127: WebPageTagInstanceViewContextInfo nextWptivci = inWptivci
128: .getContentAsInfo(i);
129: if (!inLimitDepth) {
130: generateNonHtmlViewForTitle(nextWptivci, inSb,
131: inLimitDepth);
132: }
133: }
134: //
135: //
136: inSb.append(XMLHelper.fromStringToCData(inWptivci
137: .getNonHtmlEndContent()));
138: } else if (inWptivci.isMarkedAsIterativeNonHtml()) {
139: //
140: //
141: //inSb.append(
142: // WebPageTagInstanceViewContext.convertTextToHtml(
143: // inWptivci.getNonHtmlStartContent()));
144: //
145: //
146: //
147: //
148: inSb.append("//");
149: //
150: for (int i = 0; i < inWptivci.getContentLength(); i = i + 3) {
151: WebPageTagInstanceViewContextInfo nextStartWptivci = inWptivci
152: .getContentAsInfo(i);
153: if (!inLimitDepth) {
154: generateNonHtmlViewForTitle(nextStartWptivci, inSb,
155: inLimitDepth);
156: }
157: inSb.append("....");
158: WebPageTagInstanceViewContextInfo nextEndWptivci = inWptivci
159: .getContentAsInfo(i + 2);
160: if (!inLimitDepth) {
161: generateNonHtmlViewForTitle(nextEndWptivci, inSb,
162: inLimitDepth);
163: }
164: }
165: //
166: inSb.append("//");
167: //
168: //
169: //
170: //inSb.append(
171: // WebPageTagInstanceViewContext.convertTextToHtml(
172: // inWptivci.getNonHtmlEndContent()));
173: } else {
174: throw UnexpectedSystemException.unknownState();
175: }
176: //
177: }
178:
179: //
180: //
181: //
182: public final static String constructIterativeTitle(
183: PopUpViewHolder inPuvh) {
184: //
185: StringBuffer outValue = new StringBuffer();
186:
187: boolean useBullets = (inPuvh.getInfo().getContentLength() > 1);
188:
189: ArrayList nonHtmls = new ArrayList();
190: for (int i = 0; i < inPuvh.getInfo().getContentLength(); i = i + 3) {
191: //
192: WebPageTagInstanceViewContextInfo nextStartWptivci = inPuvh
193: .getInfo().getContentAsInfo(i);
194: WebPageTagInstanceViewContextInfo nextEndWptivci = inPuvh
195: .getInfo().getContentAsInfo(i + 2);
196: //
197: StringBuffer nextSb = new StringBuffer();
198: if (useBullets) {
199: nextSb.append("- ");
200: }
201: PopUpViewTitleHelper.generateNonHtmlViewForTitle(
202: nextStartWptivci, nextSb, false);
203: nextSb.append("//....//");
204: PopUpViewTitleHelper.generateNonHtmlViewForTitle(
205: nextEndWptivci, nextSb, false);
206: //
207: nonHtmls.add(nextSb.toString());
208: }
209: //
210: //
211: for (int i = 0; i < nonHtmls.size(); i++) {
212: if (i > 0) {
213: outValue.append("\n");
214: }
215: String nextNonHtml = ((String) nonHtmls.get(i));
216: outValue.append(nextNonHtml);
217: //outValue.append(XMLHelper.fromStringToCData(nextNonHtml));
218: }
219:
220: return outValue.toString();
221: }
222: }
|