001: package org.enhydra.snapperPreviewer.presentation;
002:
003: /**
004: * @author Milin Radivoj
005: * @author Milic Djordje
006: */
007:
008: import java.io.File;
009: import java.io.FileWriter;
010: import java.util.Properties;
011:
012: import org.enhydra.snapperPreviewer.presentation.ErrorHTML;
013: import org.enhydra.snapperPreviewer.presentation.PreviewHTML;
014: import org.enhydra.snapperPreviewer.Previewer;
015: import org.enhydra.snapperPreviewer.spec.PreviewBuilder;
016: import org.enhydra.snapperPreviewer.spec.PreviewBuilderFactory;
017: import org.enhydra.snapperPreviewer.spec.TransformManager;
018: import org.enhydra.snapperPreviewer.spec.TransformManagerFactory;
019: import org.enhydra.xml.xmlc.XMLObject;
020: import org.w3c.dom.CDATASection;
021:
022: import com.lutris.appserver.server.httpPresentation.HttpPresentationOutputStream;
023:
024: public class Preview extends BasePO {
025:
026: Properties pictureConversionRequestParm = new Properties();
027:
028: Properties parserLimitProperties = new Properties();
029:
030: protected XMLObject getDOM() throws Exception {
031:
032: comms.request.getHttpServletRequest().setCharacterEncoding(
033: "UTF-8");
034: String fullFilePath = comms.request
035: .getParameter("fullFilePath");
036: String parseOnFly = comms.request.getParameter("parseOnFly");
037:
038: String siteName = comms.request.getParameter("siteName");
039: String id = comms.request.getParameter("id");
040: String query = comms.request.getParameter("query");
041:
042: String xslSheme = comms.request.getParameter("xsl");
043: String xslDir = Previewer.getXslDirectory();
044:
045: int previewNumLimit = Previewer.getContainerFilesPreviewLimit();
046:
047: String toNavigate = comms.request.getParameter("toNavigate");
048:
049: String inside = comms.request.getParameter("inside");
050:
051: managePictureRequestParameters();
052: parserLimitProperties();
053:
054: String showContainerData = comms.request
055: .getParameter("toPreviewContainerFiles");
056: boolean show = Previewer.getPreviewFilesInContainer();
057:
058: try {
059: if (showContainerData != null)
060: show = (new Boolean(showContainerData)).booleanValue();
061: } catch (Exception e) {
062: show = Previewer.getPreviewFilesInContainer();
063: }
064:
065: pictureConversionRequestParm.setProperty(
066: "toPreviewContainerFiles", (new Boolean(show))
067: .toString());
068:
069: pictureConversionRequestParm.setProperty(
070: "ContainerPreviewNumberLimit", (new Integer(
071: previewNumLimit).toString()));
072:
073: if (toNavigate != null)
074: pictureConversionRequestParm.setProperty("toNavigate",
075: toNavigate);
076:
077: if (inside != null)
078: pictureConversionRequestParm.setProperty("inside", inside);
079:
080: String showContainerFileNum = comms.request
081: .getParameter("numberOfFilesInContainer");
082: int num = Previewer.getFilesInContainerNumber();
083:
084: try {
085: if (showContainerFileNum != null)
086: num = (new Integer(showContainerFileNum)).intValue();
087: } catch (Exception e) {
088: num = Previewer.getFilesInContainerNumber();
089: }
090:
091: String langpair = comms.request.getParameter("langpair");
092:
093: if (langpair == null || langpair.equals("")) {
094: langpair = "none";
095: }
096:
097: if ((fullFilePath == null || fullFilePath.equals(""))
098: && (id == null || id.equals(""))) {
099: WelcomeHTML html = (WelcomeHTML) comms.xmlcFactory
100: .create(WelcomeHTML.class);
101:
102: return html;
103: }
104:
105: if (xslSheme == null || xslSheme.equals("")) {
106: xslSheme = "preview";
107: }
108:
109: PreviewBuilder builder = PreviewBuilderFactory
110: .getPreviewBuilder("org.enhydra.snapperPreviewer.business.PreviewBuilder");
111:
112: String resultXML = "";
113: if (fullFilePath != null && !fullFilePath.equals(""))
114: if (parseOnFly != null && !parseOnFly.equals("")) {
115: resultXML = builder.getDocument(fullFilePath, null,
116: langpair, show, num,
117: pictureConversionRequestParm,
118: parserLimitProperties);
119: } else {
120: resultXML = builder.getDocument(fullFilePath, query,
121: null, langpair, show, num,
122: pictureConversionRequestParm,
123: parserLimitProperties);
124: }
125: else if (id != null && !id.equals("")) {
126: resultXML = builder.getDocument(siteName, id, query, null,
127: langpair, show, num, pictureConversionRequestParm,
128: parserLimitProperties);
129:
130: }
131:
132: if (resultXML == null || resultXML.equals("")) {
133: ErrorHTML html = (ErrorHTML) comms.xmlcFactory
134: .create(ErrorHTML.class);
135:
136: return html;
137: }
138:
139: String finall;
140:
141: if (!xslSheme.equals("none")) {
142: TransformManager manager = TransformManagerFactory
143: .getTransformManager("org.enhydra.snapperPreviewer.business.TransformManager");
144: finall = manager.transform(resultXML, xslDir + "/"
145: + xslSheme + ".xsl");
146: } else {
147: comms.response.setContentType("text/xml");
148: HttpPresentationOutputStream os = comms.response
149: .getOutputStream();
150: builder.writeResult(resultXML, os);
151: comms.response.flush();
152: return null;
153: }
154:
155: PreviewHTML page;
156: page = (PreviewHTML) comms.xmlcFactory
157: .create(PreviewHTML.class);
158:
159: CDATASection cdata = page.createCDATASection(finall);
160: page.getElementResult().appendChild(cdata);
161: return page;
162: }
163:
164: private void managePictureRequestParameters() throws Exception {
165:
166: String pixelNum = comms.request.getParameter("maxPixelNumber");
167: String reduceColor = comms.request.getParameter("reduceColor");
168: String forceOut = comms.request
169: .getParameter("forceOutputFileFormat");
170: String useGrayFilter = comms.request
171: .getParameter("useGrayFilter");
172: String zoomed = comms.request.getParameter("zoomed");
173: String toShowTranslateBar = Previewer.toShowTranslateBar();
174:
175: if (pixelNum != null && !pixelNum.equals("")) {
176: int num = (new Integer(pixelNum)).intValue();
177: if (num < 1)
178: num = 1;
179: String numS = (new Integer(num)).toString();
180: pictureConversionRequestParm.setProperty("maxPixelNumber",
181: numS);
182: } else {
183: String num = (new Integer(Previewer.getPicturePixel()))
184: .toString();
185: pictureConversionRequestParm.setProperty("maxPixelNumber",
186: num);
187: }
188:
189: if (reduceColor != null && !reduceColor.equals(""))
190: pictureConversionRequestParm.setProperty("reduceColor",
191: reduceColor);
192:
193: if (forceOut != null && !forceOut.equals(""))
194: pictureConversionRequestParm.setProperty(
195: "forceOutputFileFormat", forceOut);
196:
197: if (useGrayFilter != null && !useGrayFilter.equals(""))
198: pictureConversionRequestParm.setProperty("useGrayFilter",
199: useGrayFilter);
200:
201: if (zoomed != null && !zoomed.equals(""))
202: pictureConversionRequestParm.setProperty("zoomed", zoomed);
203:
204: if (toShowTranslateBar != null
205: && !toShowTranslateBar.equals(""))
206: pictureConversionRequestParm.setProperty(
207: "showTranslateBar", toShowTranslateBar);
208: }
209:
210: private void parserLimitProperties() throws Exception {
211: String parserPageLimit = comms.request
212: .getParameter("parserPageLimit");
213: String parserCharacterLimit = comms.request
214: .getParameter("parserCharacterLimit");
215:
216: if (parserPageLimit != null && !parserPageLimit.equals("")) {
217: parserLimitProperties.setProperty("pdf", parserPageLimit);
218: parserLimitProperties.setProperty("ppt", parserPageLimit);
219: parserLimitProperties.setProperty("docx", parserPageLimit);
220: parserLimitProperties.setProperty("xlsx", parserPageLimit);
221: parserLimitProperties.setProperty("pptx", parserPageLimit);
222: }
223:
224: if (parserCharacterLimit != null
225: && !parserCharacterLimit.equals("")) {
226: parserLimitProperties.setProperty("doc",
227: parserCharacterLimit);
228: parserLimitProperties.setProperty("xls",
229: parserCharacterLimit);
230: parserLimitProperties.setProperty("oo",
231: parserCharacterLimit);
232: parserLimitProperties.setProperty("rtf",
233: parserCharacterLimit);
234: parserLimitProperties.setProperty("txt",
235: parserCharacterLimit);
236: }
237: }
238:
239: }
|