001: /*
002: * snapper
003: *
004: * Enhydra super-servlet presentation object
005: *
006: */
007:
008: package org.enhydra.snapperAdmin.presentation;
009:
010: // Enhydra SuperServlet specification imports
011:
012: import java.util.Hashtable;
013: import java.util.List;
014: import java.util.Vector;
015:
016: import org.enhydra.snapper.SnapperManager;
017: import org.enhydra.xml.xmlc.XMLObject;
018: import org.w3c.dom.Node;
019: import org.w3c.dom.html.HTMLOptionElement;
020: import org.w3c.dom.html.HTMLTableRowElement;
021: import org.enhydra.snapperAdmin.presentation.BasePO;
022: import org.enhydra.snapperAdmin.Log;
023: import org.enhydra.snapperAdmin.presentation.html.*;
024: import org.enhydra.snapperAdmin.spec.DocumentGroup;
025: import org.enhydra.snapperAdmin.spec.DocumentGroupFactory;
026: import org.enhydra.snapperAdmin.spec.FileType;
027: import org.enhydra.snapperAdmin.spec.Site;
028: import org.enhydra.snapperAdmin.spec.SiteFactory;
029: import org.enhydra.snapperAdmin.spec.SiteList;
030: import org.enhydra.snapperAdmin.spec.SiteListFactory;
031:
032: import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
033:
034: public class UpdateSitePresentation extends BasePO {
035:
036: /**
037: * Constants representing HTTP parameters passed in from
038: * the form submission
039: */
040: // private static String SITE_NAME = "site_nameInput";
041: // private static String LANGUAGE = "site_languageInput";
042: private static String MAX_SIZE = "site_MaxSizeInput";
043: private static String MAX_AGE = "site_MaxAgeInput";
044:
045: private static String SEARCH = "site_SearchInput";
046: private static String DL = "site_DownloadableInput";
047: private static String INDEXCONTENT = "site_IndexContentInput";
048: private static String INDEXDIRECTORY = "site_IndexDirectoryInput";
049:
050: private static String INDEXDIR = "site_IndexDirInput";
051:
052: // private static String DB = "site_FilterDBInput";
053:
054: // private static String TABLE = "site_FilterTableInput";
055: // private static String COLUMN = "site_FilterColumnInput";
056:
057: protected XMLObject getDOM() throws Exception {
058:
059: UpdateSiteHTML updateSite;
060: updateSite = (UpdateSiteHTML) comms.xmlcFactory
061: .create(UpdateSiteHTML.class);
062: String action = comms.request.getParameter("action");
063: if (action != null && action.equals("update")) {
064: // String name = comms.request.getParameter(SITE_NAME);
065: // String language = comms.request.getParameter(LANGUAGE);
066: String size = comms.request.getParameter(MAX_SIZE);
067: String age = comms.request.getParameter(MAX_AGE);
068:
069: String search = comms.request.getParameter(SEARCH);
070: String dl = comms.request.getParameter(DL);
071: String ic = comms.request.getParameter(INDEXCONTENT);
072: String idir = comms.request.getParameter(INDEXDIRECTORY);
073: String iuft = comms.request
074: .getParameter("site_IndexUnknownFileTypesInput");
075: String id = comms.request.getParameter(INDEXDIR);
076: // String db = comms.request.getParameter(DB);
077: // String table = comms.request.getParameter(TABLE);
078: // String column = comms.request.getParameter(COLUMN);
079:
080: SiteList sl = SiteListFactory
081: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
082:
083: Site oldSite = sl.findSiteByName(comms.request
084: .getParameter("site_oidInput"));
085:
086: Site site = SiteFactory
087: .getSite("org.enhydra.snapperAdmin.business.SiteImpl");
088:
089: try {
090:
091: if (oldSite != null) {
092: site.setPathList(oldSite.getPathList());
093: }
094:
095: site.setNAME(comms.request
096: .getParameter("site_oidInput"));
097:
098: int sizeI = 99999;
099: try {
100: sizeI = (new Integer(size)).intValue();
101: } catch (Exception e) {
102:
103: }
104:
105: site.setMAXSIZE(sizeI);
106:
107: int ageI = 99999;
108: try {
109: ageI = (new Integer(age)).intValue();
110: } catch (Exception e) {
111:
112: }
113: site.setMAXAGE(ageI);
114:
115: if (search == null)
116: site.setSEARCH(false);
117: else
118: site.setSEARCH(true);
119:
120: if (dl == null)
121: site.setDOWNLOAD(false);
122: else
123: site.setDOWNLOAD(true);
124:
125: if (ic == null)
126: site.setINDEXCONTENT(false);
127: else
128: site.setINDEXCONTENT(true);
129:
130: if (iuft == null)
131: site.setINDEXUNKNOWNFILETYPES(false);
132: else
133: site.setINDEXUNKNOWNFILETYPES(true);
134:
135: if (idir == null)
136: site.setINDEXDIRECTORY(false);
137: else
138: site.setINDEXDIRECTORY(true);
139:
140: if (SnapperManager.getInstance()
141: .getFileSeparatorConvention() != null
142: && SnapperManager.getInstance()
143: .getFileSeparatorConvention()
144: .equalsIgnoreCase("unix"))
145: id = id.replaceAll("\\\\", "/");
146:
147: if (id != null && !id.equals(""))
148: site.setINDEXDIR(id);
149:
150: String option = comms.request.getParameter("R1");
151: if (option.equals("VF")) {
152: if (comms.request
153: .getParameter("site_FilterDBInput") != null
154: && !comms.request.getParameter(
155: "site_FilterDBInput").equals("")
156: && comms.request
157: .getParameter("site_FilterTableInput") != null
158: && !comms.request.getParameter(
159: "site_FilterTableInput").equals("")
160: && comms.request
161: .getParameter("site_FilterColumnInput") != null
162: && !comms.request.getParameter(
163: "site_FilterColumnInput")
164: .equals("")) {
165: site.setFILTERDB(comms.request
166: .getParameter("site_FilterDBInput"));
167: site.setFILTERTABLE(comms.request
168: .getParameter("site_FilterTableInput"));
169: site
170: .setFILTERCOLUMN(comms.request
171: .getParameter("site_FilterColumnInput"));
172: }
173: } else {
174: if (comms.request.getParameter("site_IncludeDB") != null
175: && !comms.request.getParameter(
176: "site_IncludeDB").equals("")
177: && comms.request
178: .getParameter("site_IncludeTable") != null
179: && !comms.request.getParameter(
180: "site_IncludeTable").equals("")
181: && comms.request
182: .getParameter("site_IncludeColumn") != null
183: && !comms.request.getParameter(
184: "site_IncludeColumn").equals("")
185: && comms.request
186: .getParameter("site_IncludeColumnModified") != null
187: && !comms.request.getParameter(
188: "site_IncludeColumnModified")
189: .equals("")) {
190: site.setINCLUDEDB(comms.request
191: .getParameter("site_IncludeDB"));
192: site.setINCLUDETABLE(comms.request
193: .getParameter("site_IncludeTable"));
194: site.setINCLUDECOLUMN(comms.request
195: .getParameter("site_IncludeColumn"));
196: site
197: .setINCLUDECOLUMNMODIFIED(comms.request
198: .getParameter("site_IncludeColumnModified"));
199: }
200: }
201:
202: if (comms.request.getParameter("site_MetadataDB") != null
203: && !comms.request.getParameter(
204: "site_MetadataDB").equals("")
205: && comms.request
206: .getParameter("site_MetadataTable") != null
207: && !comms.request.getParameter(
208: "site_MetadataTable").equals("")
209: && comms.request
210: .getParameter("site_MetadataColumnFile") != null
211: && !comms.request.getParameter(
212: "site_MetadataColumnFile").equals("")
213: && comms.request
214: .getParameter("site_MetadataColumnKey") != null
215: && !comms.request.getParameter(
216: "site_MetadataColumnKey").equals("")
217: && comms.request
218: .getParameter("site_MetadataColumnValue") != null
219: && !comms.request.getParameter(
220: "site_MetadataColumnValue").equals("")) {
221: site.setMETADB(comms.request
222: .getParameter("site_MetadataDB"));
223: site.setMETATABLE(comms.request
224: .getParameter("site_MetadataTable"));
225: site.setMETAFILE(comms.request
226: .getParameter("site_MetadataColumnFile"));
227: site.setMETAKEY(comms.request
228: .getParameter("site_MetadataColumnKey"));
229: site.setMETAVALUE(comms.request
230: .getParameter("site_MetadataColumnValue"));
231: }
232:
233: boolean needToRemember = false;
234: DocumentGroup defDocGrop = sl.getDefaultDocumentGroup();
235: FileType[] ftypes = null;
236:
237: if (defDocGrop != null) {
238:
239: ftypes = defDocGrop.getListOfAllFILETYPES();
240: if (ftypes != null)
241: for (int i = 0; i < ftypes.length; i++) {
242:
243: String param = comms.request
244: .getParameter("filetype"
245: + ftypes[i].getEXTENSION());
246:
247: if (param != null) {
248: if (param.equals("ON")) {
249:
250: } else {
251: needToRemember = true;
252: break;
253: }
254:
255: } else {
256: needToRemember = true;
257: break;
258: }
259: }
260: }
261:
262: if (needToRemember) {
263: //ajmo ponovo al sad upisujemo!!!
264: Vector colectionOExtensionToRemember = new Vector();
265:
266: DocumentGroup finall = DocumentGroupFactory
267: .getDocumentGroup("org.enhydra.snapperAdmin.business.DocumentGroupImpl");
268:
269: for (int i = 0; i < ftypes.length; i++) {
270:
271: String param = comms.request
272: .getParameter("filetype"
273: + ftypes[i].getEXTENSION());
274:
275: if (param != null) {
276: if (param.equals("ON")) {
277: //pamtimo ekstenziju
278: colectionOExtensionToRemember
279: .add(ftypes[i].getEXTENSION());
280: }
281: }
282: }
283:
284: List grupe = defDocGrop.getListOfDocumentGroup();
285:
286: if (grupe != null) {
287: for (int h = 0; h < grupe.size(); h++) {
288: String groupname = (String) grupe.get(h);
289:
290: if (!groupname.equals("All supported")) {
291: Vector www = new Vector();
292:
293: FileType[] tipovi = defDocGrop
294: .getListOfFILETYPES(groupname);
295:
296: if (tipovi != null) {
297: for (int y = 0; y < tipovi.length; y++) {
298:
299: if (colectionOExtensionToRemember
300: .contains(tipovi[y]
301: .getEXTENSION()))
302: www.add(tipovi[y]);
303: }
304: }
305:
306: FileType[] upisujuse = new FileType[www
307: .size()];
308:
309: for (int y = 0; y < www.size(); y++) {
310:
311: upisujuse[y] = (FileType) www
312: .get(y);
313: }
314: //result.put(groupname, upisujuse);
315: finall.addDocumentGroup(groupname,
316: upisujuse);
317: }
318:
319: }
320: }
321: //finall.setDocumentGroup(result);
322: site.setDocumentGroup(finall);
323: } else {
324: site.setDocumentGroup(sl.getDefaultDocumentGroup());
325: }
326:
327: sl.updateSite(site);
328:
329: } catch (Exception ex) {
330: System.out.println(ex.toString());
331: }
332:
333: throw new ClientPageRedirectException(comms.request
334: .getAppFileURIPath("SiteListPresentation.po"));
335: }
336: try {
337: Site site = null;
338: SiteList sl = SiteListFactory
339: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
340:
341: site = sl.findSiteByName(comms.request
342: .getParameter("site_oidInput"));
343:
344: String lang = site.getLANGUAGE();
345:
346: HTMLOptionElement templateOption0 = updateSite
347: .getElementTemplateLanguage();
348: Node languageSelect = templateOption0.getParentNode();
349: templateOption0.removeAttribute("id");
350: templateOption0
351: .removeChild(templateOption0.getFirstChild());
352:
353: HTMLOptionElement clonedOption2 = (HTMLOptionElement) templateOption0
354: .cloneNode(true);
355: clonedOption2.setValue("DE");
356: Node optionTextNode2 = clonedOption2.getOwnerDocument()
357: .createTextNode("DE");
358: if (lang == null || (lang != null && !lang.equals("EN")))
359: clonedOption2.setAttribute("selected", "selected");
360: else
361: clonedOption2.removeAttribute("selected");
362: clonedOption2.appendChild(optionTextNode2);
363: languageSelect.appendChild(clonedOption2);
364:
365: HTMLOptionElement clonedOption1 = (HTMLOptionElement) templateOption0
366: .cloneNode(true);
367: clonedOption1.setValue("EN");
368: Node optionTextNode1 = clonedOption1.getOwnerDocument()
369: .createTextNode("EN");
370: if (lang == null || (lang != null && !lang.equals("EN")))
371: clonedOption1.removeAttribute("selected");
372: else
373: clonedOption1.setAttribute("selected", "selected");
374: clonedOption1.appendChild(optionTextNode1);
375:
376: languageSelect.appendChild(clonedOption1);
377: templateOption0.getParentNode()
378: .removeChild(templateOption0);
379: //updateSite.getElementTemplateLanguage().setValue(lang);
380:
381: updateSite.getElementMaxAgeInput().setValue(
382: String.valueOf(site.getMAXAGE()));
383: updateSite.getElementMaxSizeInput().setValue(
384: String.valueOf(site.getMAXSIZE()));
385: updateSite.getElementSite_SearchInput().setChecked(
386: site.getSEARCH());
387: updateSite.getElementSite_DownloadableInput().setChecked(
388: site.getDOWNLOAD());
389: updateSite.getElementSite_IndexContentInput().setChecked(
390: site.getINDEXCONTENT());
391: updateSite.getElementSite_IndexDirectoryInput().setChecked(
392: site.getINDEXDIRECTORY());
393: updateSite.getElementSite_IndexUnknownFileTypesInput()
394: .setChecked(site.getINDEXUNKNOWNFILETYPES());
395: updateSite.getElementSite_IndexDirInput().setValue(
396: site.getINDEXDIR());
397: updateSite.getElementSite_FilterDBInput().setValue(
398: site.getFILTERDB());
399: updateSite.getElementSite_FilterColumnInput().setValue(
400: site.getFILTERCOLUMN());
401: updateSite.getElementSite_FilterTableInput().setValue(
402: site.getFILTERTABLE());
403: updateSite.getElementSite_oidInput().setValue(
404: site.getNAME());
405: updateSite.setTextLabelSite(comms.request
406: .getParameter("site_oidInput"));
407: updateSite.getElementSite_FilterDBInput().setValue(
408: site.getFILTERDB());
409: updateSite.getElementSite_FilterTableInput().setValue(
410: site.getFILTERTABLE());
411: updateSite.getElementSite_FilterColumnInput().setValue(
412: site.getFILTERCOLUMN());
413: updateSite.getElementSite_IncludeDB().setValue(
414: site.getINCLUDEDB());
415: updateSite.getElementSite_IncludeTable().setValue(
416: site.getINCLUDETABLE());
417: updateSite.getElementSite_IncludeColumn().setValue(
418: site.getINCLUDECOLUMN());
419: updateSite.getElementSite_IncludeColumnModified().setValue(
420: site.getINCLUDECOLUMNMODIFIED());
421: updateSite.getElementSite_MetadataDB().setValue(
422: site.getMETADB());
423: updateSite.getElementSite_MetadataTable().setValue(
424: site.getMETATABLE());
425: updateSite.getElementSite_MetadataColumnFile().setValue(
426: site.getMETAFILE());
427: updateSite.getElementSite_MetadataColumnKey().setValue(
428: site.getMETAKEY());
429: updateSite.getElementSite_MetadataColumnValue().setValue(
430: site.getMETAVALUE());
431:
432: if (!SiteListPresentation.haveUpdater) {
433: updateSite.getElementMaxAgeInput().setDisabled(true);
434: updateSite.getElementMaxSizeInput().setDisabled(true);
435: updateSite.getElementSite_SearchInput().setDisabled(
436: true);
437: updateSite.getElementSite_DownloadableInput()
438: .setDisabled(true);
439: updateSite.getElementSite_IndexContentInput()
440: .setDisabled(true);
441: updateSite.getElementSite_IndexDirectoryInput()
442: .setDisabled(true);
443: updateSite.getElementSite_IndexUnknownFileTypesInput()
444: .setDisabled(true);
445: updateSite.getElementSite_IndexDirInput().setDisabled(
446: true);
447: updateSite.getElementSite_FilterDBInput().setDisabled(
448: true);
449: updateSite.getElementSite_FilterColumnInput()
450: .setDisabled(true);
451: updateSite.getElementSite_FilterTableInput()
452: .setDisabled(true);
453: updateSite.getElementSite_FilterDBInput().setDisabled(
454: true);
455: updateSite.getElementSite_FilterTableInput()
456: .setDisabled(true);
457: updateSite.getElementSite_FilterColumnInput()
458: .setDisabled(true);
459: updateSite.getElementSite_IncludeDB().setDisabled(true);
460: updateSite.getElementSite_IncludeTable().setDisabled(
461: true);
462: updateSite.getElementSite_IncludeColumn().setDisabled(
463: true);
464: updateSite.getElementSite_IncludeColumnModified()
465: .setDisabled(true);
466: updateSite.getElementSite_MetadataDB()
467: .setDisabled(true);
468: updateSite.getElementSite_MetadataTable().setDisabled(
469: true);
470: updateSite.getElementSite_MetadataColumnFile()
471: .setDisabled(true);
472: updateSite.getElementSite_MetadataColumnKey()
473: .setDisabled(true);
474: updateSite.getElementSite_MetadataColumnValue()
475: .setDisabled(true);
476: updateSite.getElementSelectAll().setDisabled(true);
477: }
478:
479: String documentGroupID = comms.request
480: .getParameter("site_documentGroupInput");
481:
482: DocumentGroup group = site.getDocumentGroup();
483: DocumentGroup defaultDocG = sl.getDefaultDocumentGroup();
484: Vector listGrops = new Vector();
485:
486: if (defaultDocG != null)
487: listGrops = (Vector) defaultDocG
488: .getListOfDocumentGroup();
489:
490: HTMLOptionElement groupOption = updateSite
491: .getElementDocumentGroup();
492: Node groupSelect = groupOption.getParentNode();
493: groupOption.removeAttribute("id");
494: groupOption.removeChild(groupOption.getFirstChild());
495: boolean hasSelected = false;
496:
497: for (int numGroups = 0; numGroups < listGrops.size(); numGroups++) {
498:
499: HTMLOptionElement clonedOption = (HTMLOptionElement) groupOption
500: .cloneNode(true);
501: clonedOption.setValue((String) listGrops
502: .elementAt(numGroups));
503: Node optionTextNode = clonedOption
504: .getOwnerDocument()
505: .createTextNode(
506: (String) listGrops.elementAt(numGroups));
507: clonedOption.appendChild(optionTextNode);
508:
509: if (((String) listGrops.elementAt(numGroups))
510: .equals(documentGroupID)) {
511: clonedOption.setAttribute("selected", "selected");
512: hasSelected = true;
513: } else
514: clonedOption.removeAttribute("selected");
515: // Do only a shallow copy of the option as we don't want the text child
516: // of the node option
517: groupSelect.appendChild(clonedOption);
518: }
519:
520: groupOption.setValue("-1");
521: Node optionTextNode = groupOption.getOwnerDocument()
522: .createTextNode("");
523: if (!hasSelected)
524: groupOption.setAttribute("selected", "selected");
525: else
526: groupOption.removeAttribute("selected");
527: groupOption.appendChild(optionTextNode);
528:
529: HTMLTableRowElement ftrow = updateSite
530: .getElementFiletyperow();
531: Node table = ftrow.getParentNode();
532:
533: if (!listGrops.contains(documentGroupID)) {
534: //listamo sve i chekiramo koji se parsiraju
535: FileType[] filetypes = group.getListOfAllFILETYPES();
536: FileType[] ft = defaultDocG.getListOfAllFILETYPES();
537: if (ft != null) {
538: for (int i = 0; i < ft.length; i++) {
539:
540: updateSite
541: .setTextFiletypelabel(ft[i].getNAME()
542: + (" (*."
543: + ft[i].getEXTENSION() + ")"));
544: updateSite.getElementFiletypecheck()
545: .setChecked(false);
546: updateSite.getElementFiletypecheck().setName(
547: "filetype" + ft[i].getEXTENSION());
548: if (!SiteListPresentation.haveUpdater) {
549: updateSite.getElementFiletypecheck()
550: .setDisabled(true);
551: }
552: if (filetypes != null) {
553: for (int k = 0; k < filetypes.length; k++) {
554:
555: String curent = filetypes[k]
556: .getEXTENSION();
557: if (ft[i].getEXTENSION().equals(curent)) {
558: updateSite
559: .getElementFiletypecheck()
560: .setChecked(true);
561: break;
562: }
563: }
564: }
565:
566: table.appendChild(ftrow.cloneNode(true));
567:
568: }
569: }
570: } else {
571: FileType[] filetypes = defaultDocG
572: .getListOfAllFILETYPES();
573: if (filetypes != null)
574: for (int i = 0; i < filetypes.length; i++) {
575: updateSite
576: .setTextFiletypelabel(filetypes[i]
577: .getNAME()
578: + (" (*."
579: + filetypes[i]
580: .getEXTENSION() + ")"));
581: updateSite.getElementFiletypecheck()
582: .setChecked(false);
583: updateSite.getElementFiletypecheck().setName(
584: "filetype"
585: + filetypes[i].getEXTENSION());
586: if (!SiteListPresentation.haveUpdater) {
587: updateSite.getElementFiletypecheck()
588: .setDisabled(true);
589: }
590: if (documentGroupID != null) {
591:
592: FileType[] specFiletypes = defaultDocG
593: .getListOfFILETYPES(documentGroupID);
594:
595: for (int x = 0; x < specFiletypes.length; x++) {
596:
597: String extension = specFiletypes[x]
598: .getEXTENSION();
599:
600: if (extension.equals(filetypes[i]
601: .getEXTENSION()))
602: updateSite
603: .getElementFiletypecheck()
604: .setChecked(true);
605: }
606:
607: }
608:
609: table.appendChild(ftrow.cloneNode(true));
610: }
611: }
612: table.removeChild(ftrow);
613:
614: updateSite.getElementAction().setValue("update");
615:
616: if (!SiteListPresentation.haveUpdater) {
617: updateSite.getElementUpdateButton().getParentNode()
618: .removeChild(
619: updateSite.getElementUpdateButton());
620: }
621:
622: } catch (Exception ex) {
623: ex.printStackTrace();
624: Log.logException(ex);
625: }
626: return updateSite;
627:
628: }
629: }
|