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.web.page.v1;
009:
010: //base classes
011: import java.util.HashMap;
012:
013: //project specific classes
014: import org.jfolder.common.ImmutableByteArray;
015: import org.jfolder.common.StandardDataTypes;
016: import org.jfolder.common.function.BaseWebPageTag;
017: import org.jfolder.common.function.WebPageTagInstanceViewContext;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
019: import org.jfolder.common.function.WebPageTagInstanceViewContextSubHtmlInfo;
020: import org.jfolder.common.tagging.AppraiseConceptTagContext;
021: import org.jfolder.common.tagging.ConceptTagCharacteristic;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
028: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
029: import org.jfolder.common.tagging.InitializeConceptTagContext;
030: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
031: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
032: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
033: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
034: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
035: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
036: import org.jfolder.common.utils.xml.XMLHelper;
037: import org.jfolder.web.page.BinaryOutputFromWebPageTag;
038:
039: //other classes
040:
041: public class ResponseRenderBinaryOutputWebPageTag extends
042: BaseWebPageTag implements BinaryOutputFromWebPageTag {
043:
044: //characteristics
045: private ConceptTagCharacteristic mimeTypeCtchar = null;
046: private ConceptTagCharacteristic actionCtchar = null;
047: private ConceptTagCharacteristic outputCtchar = null;
048:
049: //mime-type details
050: public final static String MIME_TYPE_CTCON = "mime-type";
051: private final static String MIME_TYPE_TITLE = "Mime Type";
052: private final static String MIME_TYPE_SHORT_DESCRIPTION = "Mime Type";
053:
054: //action details
055: public final static String ACTION_CTCON = "action";
056: private final static String ACTION_TITLE = "Action";
057: private final static String ACTION_SHORT_DESCRIPTION = "Action";
058:
059: //output details
060: public final static String OUTPUT_CTCON = "output";
061: private final static String OUTPUT_TITLE = "Output";
062: private final static String OUTPUT_SHORT_DESCRIPTION = "Output";
063:
064: public void initialize(InitializeConceptTagContext inIctc) {
065:
066: //
067: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
068: .newInstance(inIctc);
069:
070: //
071: //constrain "mime-type"
072: ConceptTagConstraint mimeTypeCtcon = ConceptTagConstraint
073: .newInstance(MIME_TYPE_CTCON, rootCtconh);
074: mimeTypeCtcon.setTitle(MIME_TYPE_TITLE);
075: mimeTypeCtcon.setShortDescription(MIME_TYPE_SHORT_DESCRIPTION);
076: mimeTypeCtcon.setMinimumLength(1);
077: mimeTypeCtcon.setMaximumLength(1);
078: //
079: //
080: StaticConceptTagConstraintContext mimeTypeSctcc = StaticConceptTagConstraintContext
081: .newInstance(mimeTypeCtcon);
082: mimeTypeSctcc.registerEntry("PNG Image", "image/png");
083: //
084: //
085: //constrain "action"
086: ConceptTagConstraint actionCtcon = ConceptTagConstraint
087: .newInstance(ACTION_CTCON, rootCtconh);
088: actionCtcon.setTitle(ACTION_TITLE);
089: actionCtcon.setShortDescription(ACTION_SHORT_DESCRIPTION);
090: //
091: DynamicConceptTagConstraintContext actionDctcc = DynamicConceptTagConstraintContext
092: .newInstance(actionCtcon);
093: //contentDctcc.getValidator().filterDirectChildOfRoot();
094: //
095: //
096: //constrain "output"
097: ConceptTagConstraint outputCtcon = ConceptTagConstraint
098: .newInstance(OUTPUT_CTCON, rootCtconh);
099: outputCtcon.setTitle(OUTPUT_TITLE);
100: outputCtcon.setShortDescription(OUTPUT_SHORT_DESCRIPTION);
101: //
102: DynamicConceptTagConstraintContext outputDctcc = DynamicConceptTagConstraintContext
103: .newInstance(outputCtcon);
104: outputDctcc.getValidator().allowReturnOfOnlyBinary();
105:
106: inIctc.initialize();
107:
108: //
109: this .mimeTypeCtchar = mimeTypeCtcon.getCharacteristic();
110: this .actionCtchar = actionCtcon.getCharacteristic();
111: this .outputCtchar = outputCtcon.getCharacteristic();
112: }
113:
114: public void appraise(AppraiseConceptTagContext inActc) {
115:
116: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
117:
118: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
119:
120: sctiic.setInstanceTitle("Render Binary Output");
121: sctiic.setInstanceDescription("Render Binary Output");
122: //
123: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
124:
125: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
126:
127: scttic.setTypeTitle("Render Binary Output");
128: scttic.setTypeDescription("Render Binary Output");
129: } else if (inActc instanceof WebPageTagInstanceViewContext) {
130:
131: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
132:
133: //
134: WebPageTagInstanceViewContextInfo info = wptivc
135: .getInfoAsHtml();
136:
137: //
138: HashMap attrs = new HashMap();
139: //
140: attrs.put("width", "100%");
141: //attrs.put("border", "1");
142: //attrs.put("cellspacing", "0");
143: //attrs.put("cellpadding", "0");
144: //
145: info.declareMouseOutBorderAsBlack();
146: info.declareMouseOutBorderAsTwoPixel();
147: info.declareMouseOutBorderAsSolid();
148: //
149: WebPageTagInstanceViewContextInfo
150: .getMousePointerActions(attrs);
151: //
152: //
153: //
154: info
155: .setHtmlContent(WebPageTagInstanceViewContextSubHtmlInfo
156: .newInstance("table", attrs));
157: WebPageTagInstanceViewContextInfo subMacroGroupInfo = info
158: .createHtmlInfo();
159: subMacroGroupInfo.setHtmlContent(
160: "<tr><td colspan=\"4\" align=\"center\""
161: + " style=\"border: 1px dotted gray\">",
162: "Binary Output</td></tr>", true);
163: //
164: //WebPageTagInstanceViewContextInfo nextRowInfo =
165: // info.createHtmlInfo();
166: //nextRowInfo.setHtmlContent("<tr><td>", "</td></tr>", true);
167: //
168: TaglibDeclareMacroWebPageTag.addSingleLine("Mime Type",
169: MIME_TYPE_CTCON, this .mimeTypeCtchar, info, wptivc);
170: //
171: TaglibDeclareMacroWebPageTag.addSingleLine("Actions",
172: ACTION_CTCON, this .actionCtchar, info, wptivc);
173: //
174: TaglibDeclareMacroWebPageTag.addSingleLine("Output",
175: OUTPUT_CTCON, this .outputCtchar, info, wptivc);
176: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
177:
178: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
179:
180: scfrct.canReturnNothing();
181: scfrct.declareFormatAsPlain();
182: //ConceptTagFlagsHelper.setConceptTagAsUndeployable(scfrct);
183: ConceptTagFlagsHelper.assertCanBeDirectChildOfRoot(scfrct);
184: //ConceptTagFlagsHelper.registerAsHtmlConceptTag(scfrct);
185: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
186:
187: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
188: }
189: }
190:
191: public void determineValueAndClass(
192: DetermineValueAndClassConceptTagContext inDvacctc) {
193:
194: //throw UnexpectedSystemException.unknownState();
195: try {
196:
197: //
198: throw new DetermineValueAndClassConceptTagException(
199: "This function should not be called in this class");
200: } catch (DetermineValueAndClassConceptTagException dvaccte) {
201: inDvacctc.setDetermineException(dvaccte);
202: }
203: }
204:
205: public void determineClass(DetermineClassConceptTagContext inDcctc) {
206:
207: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
208: }
209:
210: //
211: //
212: //
213: public String getMimeType() {
214:
215: String outValue = null;
216:
217: outValue = this .mimeTypeCtchar.getValueAsString(0, null);
218:
219: return outValue;
220: }
221:
222: //
223: public byte[] determineBinaryOutput(
224: DetermineValueAndClassConceptTagContext inDvacctc)
225: throws DetermineValueAndClassConceptTagException {
226: //
227: byte outValue[] = null;
228:
229: //
230: this .actionCtchar.processIterativeStructure(inDvacctc, false);
231: //
232: ValueAndClassForConceptTag vacfct = this .outputCtchar
233: .getDetermineValueAndClass(0, inDvacctc);
234: //
235: ImmutableByteArray iba = StandardDataTypes
236: .getBinaryAsBinary(vacfct.getValue());
237:
238: outValue = iba.copyByteArray();
239:
240: return outValue;
241: }
242: }
|