001: /*
002: * Created on 2006.4.27
003: * Milin Radivoj
004: * rmilin@gmail.com
005: */
006: package org.enhydra.snapperPreviewer.business;
007:
008: import java.util.Enumeration;
009: import java.util.Hashtable;
010: import java.util.List;
011: import java.util.Vector;
012:
013: import org.enhydra.snapperPreviewer.spec.*;
014: import org.enhydra.snapper.xml.configuration.DOCUMENTGROUPDocument.DOCUMENTGROUP;
015: import org.enhydra.snapper.xml.configuration.DOCUMENTGROUPLISTDocument.DOCUMENTGROUPLIST;
016: import org.enhydra.snapper.xml.configuration.FILETYPEDocument.FILETYPE;
017: import org.enhydra.snapperPreviewer.Previewer;
018:
019: /**
020: * @author Milin Radivoj
021: *
022: */
023: public class DocumentGroupImpl implements DocumentGroup {
024:
025: private Hashtable table = new Hashtable();
026:
027: private FileType[] listOfAll = null;
028:
029: private boolean isDefaultDocGroup = false;
030:
031: public List getListOfDocumentGroup() throws Exception {
032:
033: Vector result = new Vector();
034:
035: for (Enumeration e = table.keys(); e.hasMoreElements();) {
036:
037: result.add(e.nextElement());
038: }
039: return result;
040: }
041:
042: public FileType[] getListOfFILETYPES(String groupName)
043: throws Exception {
044:
045: return (FileType[]) table.get(groupName);
046: }
047:
048: public FileType[] getListOfAllFILETYPES() throws Exception {
049:
050: return listOfAll;
051: }
052:
053: public void init(DOCUMENTGROUPLIST list) {
054: try {
055: int size = list.getDOCUMENTGROUPArray().length;
056:
057: if (size < 1) {
058: Previewer
059: .logWarrning("None document group is defined !!!");
060: return;
061: }
062:
063: Vector extension = new Vector();
064: Vector all = new Vector();
065: for (int i = 0; i < size; i++) {
066: DOCUMENTGROUP dg = (DOCUMENTGROUP) list
067: .getDOCUMENTGROUPArray(i);
068: String name = dg.getNAME();
069:
070: /*
071: * List ftl = dg.getFILETYPEArray());
072: *
073: * int ftSize = ftl.size();
074: */
075:
076: FILETYPE[] ftl = dg.getFILETYPEArray();
077:
078: FileType[] ftList = new FileType[ftl.length];
079:
080: for (int j = 0; j < ftl.length; j++) {
081: FileType ft = new FileTypeImpl();
082: FILETYPE zeusFt = (FILETYPE) ftl[j];
083:
084: ft.setNAME(zeusFt.getNAME());
085: ft.setEXTENSION(zeusFt.getEXTENSION());
086: ft.setPARSER(zeusFt.getPARSEAS());
087:
088: ftList[j] = ft;
089: if (!extension.contains(ft.getEXTENSION()
090: .toLowerCase())) {
091: all.add(ft);
092: extension.add(ft.getEXTENSION().toLowerCase());
093: }
094: }
095: table.put(name, ftList);
096: }
097:
098: listOfAll = new FileType[all.size()];
099:
100: for (int i = 0; i < all.size(); i++) {
101: listOfAll[i] = (FileType) all.get(i);
102: }
103:
104: table.put("All supported", listOfAll);
105:
106: } catch (Exception e) {
107: Previewer
108: .logWarrning("Problem ocured while initialyzing document group list : "
109: + e.getMessage());
110: }
111:
112: }
113:
114: }
|