001: /**
002: * Miroslav Popov, Oct 19, 2005
003: * miroslav.popov@gmail.com
004: */package org.enhydra.snapperAdmin.presentation;
005:
006: import java.util.Hashtable;
007: import java.util.List;
008: import java.util.Vector;
009:
010: import org.enhydra.snapperAdmin.presentation.BasePO;
011: import org.enhydra.snapperAdmin.presentation.html.DocumentGroupListHTML;
012: import org.enhydra.snapperAdmin.spec.DocumentGroup;
013: import org.enhydra.snapperAdmin.spec.FileType;
014: import org.enhydra.snapperAdmin.spec.Site;
015: import org.enhydra.snapperAdmin.spec.SiteList;
016: import org.enhydra.snapperAdmin.spec.SiteListFactory;
017: import org.enhydra.xml.xmlc.XMLObject;
018: import org.w3c.dom.Node;
019: import org.w3c.dom.html.HTMLTableRowElement;
020:
021: /**
022: * @author Miroslav Popov
023: *
024: */
025: public class ListDocumentGroups extends BasePO {
026:
027: private DocumentGroupListHTML htmlPage;
028:
029: protected XMLObject getDOM() throws Exception {
030:
031: htmlPage = (DocumentGroupListHTML) comms.xmlcFactory
032: .create(DocumentGroupListHTML.class);
033:
034: String toDelete = comms.request.getParameter("id");
035:
036: SiteList sl = SiteListFactory
037: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
038:
039: if (toDelete != null) {
040: DocumentGroup defDocGroup = sl.getDefaultDocumentGroup();
041:
042: if (defDocGroup != null) {
043: defDocGroup.removeDocumentGroup(toDelete);
044: /* Hashtable result = new Hashtable();
045: List listDG = defDocGroup.getListOfDocumentGroup();
046:
047: if(listDG!=null)
048: {
049: for(int h=0;h<listDG.size();h++)
050: {
051: String groupname = (String)listDG.get(h);
052:
053: if(groupname!=null && !groupname.equals(toDelete))
054: {
055: FileType[] tipovi = defDocGroup.getListOfFILETYPES(groupname);
056: if(tipovi!=null)
057: {
058: result.put(groupname, tipovi);
059: }
060: }
061: }
062: }*/
063: //defDocGroup.setDocumentGroup(result);
064: sl.setDefaultDocumentGroup(defDocGroup);
065: }
066:
067: //iz sajtova
068: Site[] siteList = sl.getList();
069:
070: if (siteList != null) {
071: for (int j = 0; j < siteList.length; j++) {
072: Site current = siteList[j];
073: if (current != null) {
074: DocumentGroup cDG = current.getDocumentGroup();
075: cDG.removeDocumentGroup(toDelete);
076: current.setDocumentGroup(cDG);
077: sl.updateSite(current);
078: }
079:
080: }
081: }
082:
083: sl.write();
084: }
085:
086: HTMLTableRowElement templateRow = htmlPage
087: .getElementTemplateRow();
088: Node sitesTable = templateRow.getParentNode();
089: String link;
090:
091: DocumentGroup group = sl.getDefaultDocumentGroup();
092:
093: if (group != null) {
094:
095: Vector groups = (Vector) group.getListOfDocumentGroup();
096:
097: if (groups != null) {
098: for (int i = 0; i < groups.size(); i++) {
099:
100: String groupName = (String) groups.elementAt(i);
101: if (groupName != null) {
102: htmlPage.setTextGroupName(groupName);
103:
104: String files = "";
105:
106: FileType[] ftypes = group
107: .getListOfFILETYPES(groupName);
108:
109: if (ftypes != null) {
110: for (int j = 0; j < ftypes.length; j++) {
111: files += " " + ftypes[j].getNAME()
112: + "(*."
113: + ftypes[j].getEXTENSION()
114: + "); ";
115: }
116:
117: }
118:
119: if (files.equals(""))
120: files = "none";
121:
122: htmlPage.setTextGroupFiles(files);
123:
124: link = "NewGroupInput.po?groupId="
125: + groups.get(i);
126: htmlPage.getElementEditLink().setHref(link);
127:
128: link = "ListDocumentGroups.po?id="
129: + groups.get(i);
130: htmlPage.getElementDeleteLink().setHref(link);
131:
132: if (!SiteListPresentation.haveUpdater) {
133: try {
134: htmlPage
135: .getElementEditLink()
136: .getParentNode()
137: .removeChild(
138: htmlPage
139: .getElementEditLink());
140: htmlPage
141: .getElementDeleteLink()
142: .getParentNode()
143: .removeChild(
144: htmlPage
145: .getElementDeleteLink());
146: } catch (Exception e) {
147: }
148: }
149:
150: sitesTable.appendChild(templateRow
151: .cloneNode(true));
152: }
153: }
154: }
155: }
156: sitesTable.removeChild(templateRow);
157:
158: if (!SiteListPresentation.haveUpdater) {
159: htmlPage.getElementFromNew().getParentNode().removeChild(
160: htmlPage.getElementFromNew());
161: }
162:
163: return htmlPage;
164: }
165:
166: }
|