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