001: /*
002: * Milin Radivoj
003: * rmilin@gmail.com
004: */
005:
006: package org.enhydra.snapperAdmin.business;
007:
008: import java.io.File;
009: import java.sql.Timestamp;
010: import java.util.ArrayList;
011: import java.util.Hashtable;
012: import java.util.Iterator;
013: import java.util.List;
014: import java.util.Vector;
015:
016: import org.apache.xmlbeans.XmlOptions;
017: import org.enhydra.snapperAdmin.SnapperAdmin;
018: import org.enhydra.snapperAdmin.business.DocumentGroupImpl;
019: import org.enhydra.snapperAdmin.business.PathImpl;
020: import org.enhydra.snapperAdmin.business.SiteImpl;
021: import org.enhydra.snapperAdmin.spec.DocumentGroup;
022: import org.enhydra.snapperAdmin.spec.FileType;
023: import org.enhydra.snapperAdmin.spec.Path;
024: import org.enhydra.snapperAdmin.spec.Site;
025: import org.enhydra.snapperAdmin.spec.SiteList;
026: import org.enhydra.snapper.xml.configuration.DOCUMENTGROUPLISTDocument;
027: import org.enhydra.snapper.xml.configuration.PATHDocument;
028: import org.enhydra.snapper.xml.configuration.SITELISTDocument;
029: import org.enhydra.snapper.xml.configuration.DOCUMENTGROUPDocument.DOCUMENTGROUP;
030: import org.enhydra.snapper.xml.configuration.DOCUMENTGROUPLISTDocument.DOCUMENTGROUPLIST;
031: import org.enhydra.snapper.xml.configuration.FILETYPEDocument.FILETYPE;
032: import org.enhydra.snapper.xml.configuration.FILTERDBDocument.FILTERDB;
033: import org.enhydra.snapper.xml.configuration.INCLUDEDBDocument.INCLUDEDB;
034: import org.enhydra.snapper.xml.configuration.METADBDocument.METADB;
035: import org.enhydra.snapper.xml.configuration.PATHDocument.PATH;
036: import org.enhydra.snapper.xml.configuration.PATHLISTDocument.PATHLIST;
037: import org.enhydra.snapper.xml.configuration.SITEDocument.SITE;
038: import org.enhydra.snapper.xml.configuration.SITELISTDocument.SITELIST;
039:
040: import com.lutris.logging.Logger;
041:
042: /**
043: * @author Milin Radivoj
044: */
045:
046: public class SiteListImpl implements SiteList {
047:
048: private static Site[] listOFSites = null;
049:
050: private static String confFilePath;
051:
052: private static String documentGroupConfFilePath;
053:
054: private static int forAllMAXSIZE = 99999;
055:
056: private static int forAllMAXAGE = 99999;
057:
058: private static String forAllLANGUAGE = "DE";
059:
060: private static boolean forAllSEARCH = true;
061:
062: private static boolean forDOWNLOAD = true;
063:
064: private static boolean forAllINDEXCONTENT = true;
065:
066: private static boolean forAllINDEXDIRECTORY = false;
067:
068: private static boolean forAllINDEXUNKNOWNFILETYPES = false;
069:
070: public static DocumentGroup forAllDocumentGroup = null;
071:
072: private static boolean fromFile = false;
073:
074: public Site[] getList() {
075: return listOFSites;
076: }
077:
078: public Site findSiteByName(String name) {
079:
080: if (name != null && listOFSites != null) {
081: for (int i = 0; i < listOFSites.length; i++) {
082: if (name != null
083: && name.equalsIgnoreCase(listOFSites[i]
084: .getNAME()))
085: return listOFSites[i];
086: }
087: }
088: return null;
089: }
090:
091: public void deleteSite(String siteName) {
092: if (siteName == null) {
093: SnapperAdmin.log.write(Logger.ERROR, " Site : " + siteName
094: + " not exist, will not be deleted!");
095: return;
096: }
097:
098: try {
099: Vector newList = new Vector();
100:
101: for (int k = 0; k < listOFSites.length; k++) {
102: if (!siteName.equals(listOFSites[k].getNAME())) {
103: newList.add(listOFSites[k]);
104: }
105: }
106:
107: Site[] newSiteList = new Site[newList.size()];
108:
109: for (int k = 0; k < newList.size(); k++) {
110: newSiteList[k] = (Site) newList.get(k);
111: }
112:
113: listOFSites = newSiteList;
114: write();
115:
116: } catch (Exception e) {
117: SnapperAdmin.log.write(Logger.ERROR, " Site : " + siteName
118: + " not deleted : " + e.getMessage());
119: e.printStackTrace();
120: }
121:
122: }
123:
124: public void addSite(Site site) {
125:
126: if (site == null) {
127: return;
128: }
129:
130: if (listOFSites != null) {
131: for (int i = 0; i < listOFSites.length; i++) {
132: String name = listOFSites[i].getNAME();
133:
134: if (name.equalsIgnoreCase(site.getNAME())) {
135: SnapperAdmin.log.write(Logger.ERROR,
136: " Site with name : " + name
137: + " already exists !");
138: return;
139: }
140: }
141: }
142:
143: try {
144: Site[] newSiteList;
145: if (listOFSites != null) {
146: newSiteList = new Site[listOFSites.length + 1];
147: for (int k = 0; k < listOFSites.length; k++) {
148:
149: newSiteList[k] = listOFSites[k];
150: }
151:
152: newSiteList[listOFSites.length] = site;
153: } else {
154: newSiteList = new Site[1];
155: newSiteList[0] = site;
156: }
157:
158: listOFSites = newSiteList;
159: write();
160:
161: } catch (Exception e) {
162: SnapperAdmin.log
163: .write(Logger.ERROR, " Site : " + site.getNAME()
164: + " not added : " + e.getMessage());
165: e.printStackTrace();
166: }
167: }
168:
169: public void updateSite(Site site) {
170: if (site == null) {
171: return;
172: }
173:
174: if (listOFSites != null) {
175: for (int i = 0; i < listOFSites.length; i++) {
176: String name = listOFSites[i].getNAME();
177:
178: if (name.equalsIgnoreCase(site.getNAME())) {
179: listOFSites[i] = site;
180: write();
181: }
182: }
183: } else {
184: return;
185: }
186: }
187:
188: public DocumentGroup getDefaultDocumentGroup() {
189: return forAllDocumentGroup;
190: }
191:
192: public void init(String confFilePath,
193: String documentGroupConfFilePath) {
194:
195: if (confFilePath == null) {
196: SnapperAdmin.log
197: .write(Logger.ERROR,
198: " Missing path to configuration file, Aborting with configuration process !!!");
199: return;
200: }
201:
202: this .confFilePath = confFilePath;
203: this .documentGroupConfFilePath = documentGroupConfFilePath;
204:
205: SITELISTDocument listFromFile = null;
206:
207: try {
208:
209: XmlOptions m_validationOptions;
210: ArrayList validationErrors = new ArrayList();
211: m_validationOptions = new XmlOptions();
212: m_validationOptions.setErrorListener(validationErrors);
213: listFromFile = SITELISTDocument.Factory.parse(new File(
214: confFilePath));
215:
216: boolean isValid = listFromFile
217: .validate(m_validationOptions);
218:
219: if (!isValid) {
220:
221: Iterator iter = validationErrors.iterator();
222: while (iter.hasNext()) {
223: SnapperAdmin.log.write(Logger.ERROR, ""
224: + iter.next());
225:
226: }
227: SnapperAdmin.log
228: .write(Logger.ERROR,
229: " Validation of document faild , aborting with configuration process !!!");
230:
231: forAllDocumentGroup = new DocumentGroupImpl();
232:
233: forAllDocumentGroup.setIsDefaultDocGroup(true);
234: try {
235: if (documentGroupConfFilePath != null) {
236: ((DocumentGroupImpl) forAllDocumentGroup)
237: .init(DOCUMENTGROUPLISTDocument.Factory
238: .parse(
239: new File(
240: documentGroupConfFilePath))
241: .getDOCUMENTGROUPLIST());
242: } else
243: forAllDocumentGroup = null;
244: } catch (Exception e) {
245: SnapperAdmin.log
246: .write(
247: Logger.ERROR,
248: " Problem ocured while reading conf file : "
249: + documentGroupConfFilePath
250: + " with message : "
251: + e.getMessage()
252: + " , aborting with configuration process !!!");
253: }
254:
255: return;
256: }
257: } catch (Exception e) {
258: SnapperAdmin.log
259: .write(
260: Logger.ERROR,
261: " Problem ocured while reading conf file : "
262: + confFilePath
263: + " with message : "
264: + e.getMessage()
265: + " , aborting with configuration process !!!");
266:
267: forAllDocumentGroup = new DocumentGroupImpl();
268:
269: forAllDocumentGroup.setIsDefaultDocGroup(true);
270: try {
271: if (documentGroupConfFilePath != null) {
272: ((DocumentGroupImpl) forAllDocumentGroup)
273: .init(DOCUMENTGROUPLISTDocument.Factory
274: .parse(
275: new File(
276: documentGroupConfFilePath))
277: .getDOCUMENTGROUPLIST());
278: } else
279: forAllDocumentGroup = null;
280: } catch (Exception exx) {
281: SnapperAdmin.log
282: .write(
283: Logger.ERROR,
284: " Problem ocured while reading conf file : "
285: + documentGroupConfFilePath
286: + " with message : "
287: + e.getMessage()
288: + " , aborting with configuration process !!!");
289: }
290:
291: return;
292: }
293:
294: int size = listFromFile.getSITELIST().sizeOfSITEArray();
295:
296: if (size < 1) {
297: SnapperAdmin.log.write(Logger.INFO, "None Site is defined");
298: }
299:
300: listOFSites = new SiteImpl[size];
301:
302: // initialize root Document group
303: forAllDocumentGroup = new DocumentGroupImpl();
304: forAllDocumentGroup.setIsDefaultDocGroup(true);
305:
306: if (!listFromFile.getSITELIST().isSetDOCUMENTGROUPLIST()) {
307: fromFile = true;
308: SnapperAdmin.log.write(Logger.INFO,
309: " DOCUMENTGROUPLIST for all sites is not defined, using default list : "
310: + documentGroupConfFilePath);
311: try {
312: if (documentGroupConfFilePath != null) {
313: ((DocumentGroupImpl) forAllDocumentGroup)
314: .init(DOCUMENTGROUPLISTDocument.Factory
315: .parse(
316: new File(
317: documentGroupConfFilePath))
318: .getDOCUMENTGROUPLIST());
319: } else
320: forAllDocumentGroup = null;
321: } catch (Exception e) {
322: SnapperAdmin.log
323: .write(
324: Logger.ERROR,
325: " Problem ocured while reading conf file : "
326: + documentGroupConfFilePath
327: + " with message : "
328: + e.getMessage()
329: + " , aborting with configuration process !!!");
330: }
331:
332: } else {
333: ((DocumentGroupImpl) forAllDocumentGroup).init(listFromFile
334: .getSITELIST().getDOCUMENTGROUPLIST());
335: }
336: // collect top default values from xml file
337: forAllMAXSIZE = listFromFile.getSITELIST().getMAXSIZE();
338: forAllMAXAGE = listFromFile.getSITELIST().getMAXAGE();
339: String temp = listFromFile.getSITELIST().getLANGUAGE()
340: .toString();
341: if (temp != null) {
342: forAllLANGUAGE = temp;
343: }
344: forAllSEARCH = listFromFile.getSITELIST().getSEARCH();
345: forDOWNLOAD = listFromFile.getSITELIST().getDOWNLOAD();
346: forAllINDEXCONTENT = listFromFile.getSITELIST()
347: .getINDEXCONTENT();
348: forAllINDEXDIRECTORY = listFromFile.getSITELIST()
349: .getINDEXDIRECTORY();
350: forAllINDEXUNKNOWNFILETYPES = listFromFile.getSITELIST()
351: .getINDEXUNKNOWNFILETYPES();
352:
353: for (int i = 0; i < size; i++) {
354:
355: SITE confFileSite = (SITE) listFromFile.getSITELIST()
356: .getSITEArray(i);
357: SiteImpl curentSite = new SiteImpl();
358: // initialize default values
359: curentSite.setMAXSIZE(forAllMAXSIZE);
360: curentSite.setMAXAGE(forAllMAXAGE);
361: curentSite.setLANGUAGE(forAllLANGUAGE);
362: curentSite.setSEARCH(forAllSEARCH);
363: curentSite.setDOWNLOAD(forDOWNLOAD);
364: curentSite.setINDEXCONTENT(forAllINDEXCONTENT);
365: curentSite.setINDEXDIRECTORY(forAllINDEXDIRECTORY);
366: curentSite
367: .setINDEXUNKNOWNFILETYPES(forAllINDEXUNKNOWNFILETYPES);
368:
369: if (confFileSite.getNAME() != null) {
370: boolean detected = false;
371: for (int k = 0; k < listOFSites.length; k++) {
372:
373: if (null != listOFSites[k]) {
374: String existingNameOfSite = listOFSites[k]
375: .getNAME();
376:
377: if (existingNameOfSite.equals(confFileSite
378: .getNAME())) {
379: SnapperAdmin.log
380: .write(
381: Logger.WARNING,
382: "Site 'NAME' parameter :"
383: + existingNameOfSite
384: + " already exists, this Site definition will be ignored");
385: detected = true;
386: break;
387: }
388: }
389:
390: }
391: if (!detected)
392: curentSite.setNAME(confFileSite.getNAME());
393: else
394: continue;
395: } else {
396: SnapperAdmin.log
397: .write(
398: Logger.WARNING,
399: "Site 'NAME' parameter was not properly initialized , this Site definition will be ignored");
400: continue;
401: }
402:
403: if (confFileSite.isSetMAXSIZE()) {
404: curentSite.setMAXSIZE(confFileSite.getMAXSIZE());
405: }
406:
407: if (confFileSite.isSetMAXAGE()) {
408: curentSite.setMAXAGE(confFileSite.getMAXAGE());
409: }
410:
411: if (confFileSite.isSetLANGUAGE()) {
412: curentSite.setLANGUAGE(confFileSite.getLANGUAGE()
413: .toString());
414: }
415:
416: if (confFileSite.isSetSEARCH()) {
417: curentSite.setSEARCH(confFileSite.getSEARCH());
418: }
419:
420: if (confFileSite.isSetDOWNLOAD()) {
421: curentSite.setDOWNLOAD(confFileSite.getDOWNLOAD());
422: }
423:
424: if (confFileSite.isSetINDEXCONTENT()) {
425: curentSite.setINDEXCONTENT(confFileSite
426: .getINDEXCONTENT());
427: }
428:
429: if (confFileSite.isSetINDEXDIRECTORY()) {
430: curentSite.setINDEXDIRECTORY(confFileSite
431: .getINDEXDIRECTORY());
432: }
433:
434: if (confFileSite.isSetINDEXUNKNOWNFILETYPES()) {
435: curentSite.setINDEXUNKNOWNFILETYPES(confFileSite
436: .getINDEXUNKNOWNFILETYPES());
437: }
438:
439: if (confFileSite.isSetINDEXDIR()) {
440: String path = confFileSite.getINDEXDIR();
441:
442: if (path != null)
443: curentSite.setINDEXDIR(path);
444: else {
445: String dir = SnapperAdmin.getIndexDir();
446:
447: if (dir.endsWith("\\") || dir.endsWith("/"))
448: dir = dir + confFileSite.getNAME();
449: else
450: dir = dir + File.separator
451: + confFileSite.getNAME();
452:
453: curentSite.setINDEXDIR(dir);
454: SnapperAdmin.log
455: .write(
456: Logger.INFO,
457: " For Site :"
458: + curentSite.getNAME()
459: + " 'INDEXDIR' parameter was not properly initialized, value '"
460: + dir + "' will be used");
461:
462: }
463:
464: } else {
465: String dir = SnapperAdmin.getIndexDir();
466:
467: if (dir.endsWith("\\") || dir.endsWith("/"))
468: dir = dir + confFileSite.getNAME();
469: else
470: dir = dir + File.separator + confFileSite.getNAME();
471:
472: SnapperAdmin.log
473: .write(
474: Logger.INFO,
475: " For Site :"
476: + curentSite.getNAME()
477: + " 'INDEXDIR' parameter is not defined, value '"
478: + dir + "' will be used");
479: curentSite.setINDEXDIR(dir);
480: }
481:
482: if (confFileSite.isSetFILTERDB()) {
483: curentSite.setFILTERDB(confFileSite.getFILTERDB()
484: .getNAME());
485: curentSite.setFILTERTABLE(confFileSite.getFILTERDB()
486: .getFILTERTABLE());
487: curentSite.setFILTERCOLUMN(confFileSite.getFILTERDB()
488: .getFILTERCOLUMN());
489: }
490:
491: if (confFileSite.isSetINCLUDEDB()) {
492: curentSite.setINCLUDEDB(confFileSite.getINCLUDEDB()
493: .getNAME());
494: curentSite.setINCLUDETABLE(confFileSite.getINCLUDEDB()
495: .getINCLUDETABLE());
496: curentSite.setINCLUDECOLUMN(confFileSite.getINCLUDEDB()
497: .getINCLUDECOLUMN());
498: curentSite.setINCLUDECOLUMNMODIFIED(confFileSite
499: .getINCLUDEDB().getINCLUDECOLUMNMODIFIED());
500: }
501:
502: if (confFileSite.isSetMETADB()) {
503: curentSite
504: .setMETADB(confFileSite.getMETADB().getNAME());
505: curentSite.setMETATABLE(confFileSite.getMETADB()
506: .getMETATABLE());
507: curentSite.setMETAFILE(confFileSite.getMETADB()
508: .getMETAFILECOLUMN());
509: curentSite.setMETAKEY(confFileSite.getMETADB()
510: .getMETAKEYCOLUMN());
511: curentSite.setMETAVALUE(confFileSite.getMETADB()
512: .getMETAVALUECOLUMN());
513: }
514:
515: int pathListSize = 0;
516:
517: try {
518: pathListSize = confFileSite.getPATHLIST()
519: .sizeOfPATHArray();
520: } catch (Exception e) {
521: pathListSize = 0;
522: }
523:
524: PathImpl[] pathList = null;
525:
526: if (pathListSize > 0) {
527: pathList = new PathImpl[pathListSize];
528:
529: for (int j = 0; j < pathListSize; j++) {
530: PATH zeusPath = (PATH) confFileSite.getPATHLIST()
531: .getPATHArray(j);
532: PathImpl pathImpl = new PathImpl();
533:
534: pathImpl.setType(zeusPath.getPATHTYPE().toString());
535: pathImpl.setRoot(zeusPath.getROOT());
536:
537: if (zeusPath.isSetHOST())
538: pathImpl.setHost(zeusPath.getHOST());
539: else
540: pathImpl.setHost("");
541:
542: /* if (zeusPath.isSetPORT())
543: pathImpl.setPort(zeusPath.getPORT());
544: else
545: pathImpl.setPort("");
546: */
547: if (zeusPath.isSetLOGINNAME())
548: pathImpl.setUser(zeusPath.getLOGINNAME());
549: else
550: pathImpl.setUser("");
551:
552: if (zeusPath.isSetPASSWORD())
553: pathImpl.setPass(zeusPath.getPASSWORD());
554: else
555: pathImpl.setPass("");
556:
557: if (zeusPath.isSetMAPPINGROOT())
558: pathImpl.setMappingRoot(zeusPath
559: .getMAPPINGROOT());
560: else
561: pathImpl.setMappingRoot("");
562:
563: pathList[j] = pathImpl;
564:
565: }
566:
567: }
568:
569: if (pathList != null) {
570: curentSite.setPathList(pathList);
571: }
572:
573: DOCUMENTGROUPLIST siteDGL = confFileSite
574: .getDOCUMENTGROUPLIST();
575:
576: if (siteDGL == null) {
577: curentSite.setDocumentGroup(forAllDocumentGroup);
578:
579: } else {
580: DocumentGroupImpl current = new DocumentGroupImpl();
581: ((DocumentGroupImpl) current).init(siteDGL);
582: curentSite.setDocumentGroup(current);
583: }
584:
585: listOFSites[i] = curentSite;
586: }
587:
588: if (listOFSites != null) {
589: int sciped = 0;
590: Site[] listOFSitesFinall = listOFSites;
591:
592: for (int k = 0; k < listOFSites.length; k++) {
593: if (null == listOFSites[k])
594: sciped++;
595: }
596:
597: if (sciped > 0) {
598: listOFSitesFinall = new Site[listOFSites.length
599: - sciped];
600: int z = 0;
601: for (int k = 0; k < listOFSites.length; k++) {
602: if (null != listOFSites[k]) {
603: listOFSitesFinall[z] = listOFSites[k];
604: z++;
605: }
606: }
607:
608: }
609:
610: listOFSites = listOFSitesFinall;
611: }
612: }
613:
614: public synchronized void write() {
615:
616: SITELISTDocument listFromFile = SITELISTDocument.Factory
617: .newInstance();
618: SITELIST sl = listFromFile.addNewSITELIST();
619:
620: if (forAllDocumentGroup != null) {
621: if (fromFile) {
622: writeToFileDefaultDocumentGroup();
623: } else {
624: DOCUMENTGROUPLIST dgl = sl.addNewDOCUMENTGROUPLIST();
625:
626: try {
627: List lista = forAllDocumentGroup
628: .getListOfDocumentGroup();
629:
630: if (lista != null) {
631: for (int i = 0; i < lista.size(); i++) {
632: String groupName = (String) lista.get(i);
633:
634: if (!groupName
635: .equalsIgnoreCase("All supported")) {
636: FileType[] ft = forAllDocumentGroup
637: .getListOfFILETYPES(groupName);
638:
639: DOCUMENTGROUP newDG = dgl
640: .addNewDOCUMENTGROUP();
641: newDG.setNAME(groupName);
642:
643: for (int j = 0; j < ft.length; j++) {
644: FILETYPE newFT = newDG
645: .addNewFILETYPE();
646: newFT.setEXTENSION(ft[j]
647: .getEXTENSION());
648: newFT.setNAME(ft[j].getNAME());
649: newFT.setPARSEAS(ft[j].getPARSER());
650: }
651:
652: }
653: }
654: }
655:
656: } catch (Exception e) {
657: e.printStackTrace();
658: }
659:
660: }
661:
662: }
663: if (listOFSites != null) {
664:
665: for (int i = 0; i < listOFSites.length; i++) {
666:
667: SITE xmlSite = sl.addNewSITE();
668: Site currentSite = listOFSites[i];
669:
670: Path[] pathList = currentSite.getPathList();
671:
672: if (pathList != null) {
673: PATHLIST pL = xmlSite.addNewPATHLIST();
674:
675: for (int j = 0; j < pathList.length; j++) {
676: PATH p = pL.addNewPATH();
677:
678: Path currentPath = pathList[j];
679:
680: String root = currentPath.getRoot();
681: String type = currentPath.getType();
682: String host = currentPath.getHost();
683: String mr = currentPath.getMappingRoot();
684: String pass = currentPath.getPass();
685: String user = currentPath.getUser();
686:
687: p.setROOT(root);
688:
689: if (type.equals(PATH.PATHTYPE.FILE_SYSTEM
690: .toString()))
691: p.setPATHTYPE(PATH.PATHTYPE.FILE_SYSTEM);
692:
693: if (type.equals(PATH.PATHTYPE.FTP.toString()))
694: p.setPATHTYPE(PATH.PATHTYPE.FTP);
695:
696: if (type.equals(PATH.PATHTYPE.UNC.toString()))
697: p.setPATHTYPE(PATH.PATHTYPE.UNC);
698:
699: if (type.equals(PATH.PATHTYPE.WEB_DAV
700: .toString()))
701: p.setPATHTYPE(PATH.PATHTYPE.WEB_DAV);
702:
703: if (host != null && !host.equals(""))
704: p.setHOST(host);
705: if (user != null && !user.equals(""))
706: p.setLOGINNAME(user);
707: if (mr != null && !mr.equals(""))
708: p.setMAPPINGROOT(mr);
709: if (pass != null && !pass.equals(""))
710: p.setPASSWORD(pass);
711: /* if(port!=null)
712: p.setPORT(port);
713: */
714:
715: }
716: }
717:
718: DocumentGroup docGroups = currentSite
719: .getDocumentGroup();
720:
721: if (docGroups != null && !docGroups.isDefaultDocGroup()) {
722: try {
723: DOCUMENTGROUPLIST dgl = xmlSite
724: .addNewDOCUMENTGROUPLIST();
725: List lista = docGroups.getListOfDocumentGroup();
726:
727: for (int j = 0; j < lista.size(); j++) {
728: String groupName = (String) lista.get(j);
729:
730: if (groupName != null
731: && !groupName
732: .equals("All supported")) {
733: DOCUMENTGROUP dg = dgl
734: .addNewDOCUMENTGROUP();
735: dg.setNAME(groupName);
736:
737: FileType[] ft = docGroups
738: .getListOfFILETYPES(groupName);
739:
740: for (int k = 0; k < ft.length; k++) {
741: FileType currentFT = ft[k];
742: String ex = currentFT
743: .getEXTENSION();
744: String name = currentFT.getNAME();
745: String parser = currentFT
746: .getPARSER();
747:
748: FILETYPE fff = dg.addNewFILETYPE();
749: fff.setEXTENSION(ex);
750: fff.setNAME(name);
751: fff.setPARSEAS(parser);
752: }
753: }
754:
755: }
756:
757: } catch (Exception e) {
758: e.printStackTrace();
759: }
760:
761: }
762:
763: boolean download = currentSite.getDOWNLOAD();
764: if (!download)
765: xmlSite.setDOWNLOAD(download);
766:
767: String fC = currentSite.getFILTERCOLUMN();
768: String fDB = currentSite.getFILTERDB();
769: String fT = currentSite.getFILTERTABLE();
770:
771: if (fC != null && fDB != null && fT != null) {
772: FILTERDB fdb = xmlSite.addNewFILTERDB();
773:
774: fdb.setFILTERCOLUMN(fC);
775: fdb.setFILTERTABLE(fT);
776: fdb.setNAME(fDB);
777: }
778:
779: String ic = currentSite.getINCLUDECOLUMN();
780: String icm = currentSite.getINCLUDECOLUMNMODIFIED();
781: String idb = currentSite.getINCLUDEDB();
782: String it = currentSite.getINCLUDETABLE();
783:
784: if (ic != null && icm != null && idb != null
785: && it != null) {
786: INCLUDEDB ii = xmlSite.addNewINCLUDEDB();
787:
788: ii.setINCLUDECOLUMN(ic);
789: ii.setINCLUDECOLUMNMODIFIED(icm);
790: ii.setINCLUDETABLE(it);
791: ii.setNAME(idb);
792: }
793:
794: String mdb = currentSite.getMETADB();
795: String mf = currentSite.getMETAFILE();
796: String mk = currentSite.getMETAKEY();
797: String mt = currentSite.getMETATABLE();
798: String mv = currentSite.getMETAVALUE();
799:
800: if (mdb != null && mf != null && mk != null
801: && mt != null && mv != null) {
802: METADB mm = xmlSite.addNewMETADB();
803:
804: mm.setMETAFILECOLUMN(mf);
805: mm.setMETAKEYCOLUMN(mk);
806: mm.setMETATABLE(mt);
807: mm.setMETAVALUECOLUMN(mv);
808: mm.setNAME(mdb);
809: }
810:
811: boolean indexContent = currentSite.getINDEXCONTENT();
812:
813: if (!indexContent)
814: xmlSite.setINDEXCONTENT(indexContent);
815:
816: String indexDir = currentSite.getINDEXDIR();
817:
818: if (indexDir != null) {
819: xmlSite.setINDEXDIR(indexDir);
820: }
821:
822: boolean indexDirecotry = currentSite
823: .getINDEXDIRECTORY();
824:
825: if (indexDirecotry)
826: xmlSite.setINDEXDIRECTORY(indexDirecotry);
827:
828: boolean indexUkn = currentSite
829: .getINDEXUNKNOWNFILETYPES();
830:
831: if (indexUkn)
832: xmlSite.setINDEXUNKNOWNFILETYPES(indexUkn);
833:
834: String leng = currentSite.getLANGUAGE();
835:
836: if (leng != null) {
837:
838: if (leng.equals(SITE.LANGUAGE.EN.toString()))
839: xmlSite.setLANGUAGE(SITE.LANGUAGE.EN);
840: else
841: xmlSite.setLANGUAGE(SITE.LANGUAGE.DE);
842: }
843:
844: int maxAge = currentSite.getMAXAGE();
845:
846: if (maxAge != 99999)
847: xmlSite.setMAXAGE(maxAge);
848:
849: int maxSize = currentSite.getMAXSIZE();
850:
851: if (maxSize != 99999)
852: xmlSite.setMAXSIZE(maxSize);
853:
854: xmlSite.setNAME(currentSite.getNAME());
855:
856: boolean search = currentSite.getSEARCH();
857:
858: if (!search)
859: xmlSite.setSEARCH(search);
860:
861: }
862: }
863:
864: boolean ok = listFromFile.validate();
865:
866: if (!ok)
867: SnapperAdmin.log.write(Logger.INFO,
868: "nije proshla validacija ");
869: else {
870: File confFile = new File(confFilePath);
871: try {
872: XmlOptions opt = new XmlOptions();
873: opt.setSavePrettyPrint();
874: listFromFile.save(confFile, opt);
875: } catch (Exception e) {
876: e.printStackTrace();
877: }
878: }
879:
880: }
881:
882: public synchronized void setDefaultDocumentGroup(DocumentGroup dg) {
883: forAllDocumentGroup = dg;
884: }
885:
886: private void writeToFileDefaultDocumentGroup() {
887:
888: if (documentGroupConfFilePath == null) {
889: SnapperAdmin.log.write(Logger.INFO,
890: "nije proshla validacija ");
891: return;
892: }
893:
894: if (forAllDocumentGroup != null) {
895: DOCUMENTGROUPLISTDocument base = DOCUMENTGROUPLISTDocument.Factory
896: .newInstance();
897: DOCUMENTGROUPLIST dgl = base.addNewDOCUMENTGROUPLIST();
898:
899: try {
900: List lista = forAllDocumentGroup
901: .getListOfDocumentGroup();
902:
903: if (lista != null) {
904: for (int i = 0; i < lista.size(); i++) {
905: String groupName = (String) lista.get(i);
906:
907: if (!groupName
908: .equalsIgnoreCase("All supported")) {
909: FileType[] ft = forAllDocumentGroup
910: .getListOfFILETYPES(groupName);
911:
912: DOCUMENTGROUP newDG = dgl
913: .addNewDOCUMENTGROUP();
914: newDG.setNAME(groupName);
915:
916: for (int j = 0; j < ft.length; j++) {
917: FILETYPE newFT = newDG.addNewFILETYPE();
918: newFT
919: .setEXTENSION(ft[j]
920: .getEXTENSION());
921: newFT.setNAME(ft[j].getNAME());
922: newFT.setPARSEAS(ft[j].getPARSER());
923: }
924:
925: }
926: }
927: }
928:
929: } catch (Exception e) {
930: e.printStackTrace();
931: }
932:
933: XmlOptions m_validationOptions;
934: ArrayList validationErrors = new ArrayList();
935: m_validationOptions = new XmlOptions();
936: m_validationOptions.setErrorListener(validationErrors);
937:
938: boolean ok = base.validate(m_validationOptions);
939:
940: if (!ok) {
941: Iterator iter = validationErrors.iterator();
942: while (iter.hasNext()) {
943: SnapperAdmin.log.write(Logger.ERROR, ""
944: + iter.next());
945: }
946: } else {
947: File confFile = new File(documentGroupConfFilePath);
948: try {
949: XmlOptions opt = new XmlOptions();
950: opt.setSavePrettyPrint();
951: base.save(confFile, opt);
952:
953: } catch (Exception e) {
954: e.printStackTrace();
955: }
956:
957: }
958: }
959: }
960:
961: }
|