KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > presentation > PathListPresentation


1 /*
2  * snapper
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package org.enhydra.snapper.presentation;
9
10
11 import org.w3c.dom.html.*;
12 import org.w3c.dom.*;
13
14 // Enhydra SuperServlet specification imports
15
import org.enhydra.snapper.spec.*;
16
17 import org.enhydra.snapper.SnapperManager;
18
19 import org.enhydra.snapper.presentation.html.*;
20 import org.enhydra.xml.xmlc.XMLObject;
21
22 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
23
24
25 public class PathListPresentation extends BasePO {
26
27     protected XMLObject getDOM() throws Exception JavaDoc {
28
29         PathListHTML htmlPage;
30         Path[] pathArray = null;
31         Site[] list = null;
32
33         htmlPage = (PathListHTML)comms.xmlcFactory.create(PathListHTML.class);
34         
35         // Check actions
36

37         String JavaDoc root = comms.request.getParameter("newPathRoot");
38         String JavaDoc add = comms.request.getParameter("add");
39         String JavaDoc change = comms.request.getParameter("change");
40         
41         
42    //Add path
43

44         if (root != null && add!=null)
45         {
46             Path path = null;
47             try{
48                 path = PathFactory.getPath("org.enhydra.snapper.business.PathImpl");
49                 path.createNew(dbTransaction);
50             if(SnapperManager.getInstance().getFileSeparatorConvention()!=null &&
51                SnapperManager.getInstance().getFileSeparatorConvention().equalsIgnoreCase("unix"))
52                       root=root.replaceAll("\\\\","/");
53                 path.setRoot(root);
54                 path.setSite(comms.request.getParameter("site"));
55                 path.setType(comms.request.getParameter("newPathType"));
56                 if (comms.request.getParameter("host") == null)
57                     path.setHost("");
58                 else
59                     path.setHost(comms.request.getParameter("host"));
60                 if (comms.request.getParameter("newUser") == null)
61                     path.setUser("");
62                 else
63                     path.setUser(comms.request.getParameter("newUser"));
64                 if (comms.request.getParameter("newPassword1") == null)
65                     path.setPass("");
66                 else
67                     path.setPass(comms.request.getParameter("newPassword1"));
68                 if (comms.request.getParameter("newMappingRoot") == null)
69                     path.setMappingRoot("");
70                 else
71                     path.setMappingRoot(comms.request.getParameter("newMappingRoot"));
72                 path.setPort("");
73                 path.save();
74                 throw new ClientPageRedirectException(comms.request.getAppFileURIPath("PathListPresentation.po"));
75                 
76             }
77             catch (Exception JavaDoc e) {throw new Exception JavaDoc ("Could not create new PathType", e);}
78         }
79         
80    // Sites combo
81

82                     
83         try{
84             SiteList site = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
85             list = site.getList(dbTransaction);
86             if (list.length == 0 ){
87                 blankHTML blankPage;
88                 blankPage = (blankHTML) comms.xmlcFactory.create(blankHTML.class);
89                 blankPage.setTextNoSite("The are no sites defined!");
90                 return blankPage;
91             }
92         
93  
94             HTMLOptionElement templateOption = htmlPage.getElementTemplateSiteList();
95             HTMLSelectElement select = htmlPage.getElementSiteList();
96             Node pathSelect = templateOption.getParentNode();
97             templateOption.removeAttribute("id");
98             templateOption.removeChild(templateOption.getFirstChild());
99             if (list.length != 0)
100                 htmlPage.setTextSiteName(list[0].getName());
101             for (int num = 0; num < list.length; num++) {
102     
103                     Site currentsite = list[num];
104                     HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true);
105                     clonedOption.setValue(currentsite.getID());
106                     Node optionTextNode = clonedOption.getOwnerDocument().
107                         createTextNode(currentsite.getName());
108                     clonedOption.appendChild(optionTextNode);
109
110                     pathSelect.appendChild(clonedOption);
111                     
112                        if (comms.request.getParameter("siteList") != null) {
113                            if ((comms.request.getParameter("siteList")).equals(currentsite.getID()) )
114                            {
115                                 select.setSelectedIndex(num+1);
116                                 htmlPage.setTextSiteName(currentsite.getName());
117                             }
118                            }
119                
120                 }
121         if (list.length != 0)
122             templateOption.getParentNode().removeChild(templateOption);
123         }
124         
125                 catch(Exception JavaDoc ex) {
126                    System.out.print(ex.toString());}
127         
128         
129    // Path table
130

131         PathType pathType = null;
132         String JavaDoc siteOID = null;
133         if (list.length != 0){
134         if (comms.request.getParameter("siteList") == null)
135             
136             siteOID = list[0].getID();
137         else siteOID = comms.request.getParameter("siteList");
138         try {
139             Path pt = PathFactory.getPath("org.enhydra.snapper.business.PathImpl");
140             
141             pathArray = pt.getListForID(dbTransaction, siteOID);
142             
143             pathType = PathTypeFactory.getPathType("org.enhydra.snapper.business.PathTypeImpl");
144             
145             
146         }catch (Exception JavaDoc ex){
147             System.out.println("Exception: "+ex);
148             pathArray = null;
149         }
150         }
151         //Site Name
152
//htmlPage.setTextSiteName(list[0].getName());
153

154         HTMLTableRowElement templateRow = htmlPage.getElementTemplateRow();
155         
156         HTMLElement pathTypeNameCellTemplate = htmlPage.getElementPathTypeName();
157         HTMLElement pathTypeCellTemplate = htmlPage.getElementPathType();
158
159         templateRow.removeAttribute("id");
160         pathTypeNameCellTemplate.removeAttribute("id");
161         //pathTypeCellTemplate.removeAttribute("id");
162

163         Node pathTable = templateRow.getParentNode();
164         String JavaDoc link;
165      if (list.length != 0){
166         for (int num = 0; num < pathArray.length; num++) {
167             try{
168             Path currentPath = pathArray[num];
169             // set text of new cells to values from string array
170
htmlPage.setTextPathTypeName(currentPath.getRoot());
171             htmlPage.setTextPathType((pathType.findPathTypeByID(currentPath.getType(), dbTransaction)).getName());
172             link = "DeletePath.po?id=" + currentPath.getID();
173             htmlPage.getElementDeleteLink().setHref(link);
174
175             //siteList.setTextLikeThisDisc();
176
pathTable.appendChild(templateRow.cloneNode(true));
177             }
178    
179         catch (Exception JavaDoc ex) {ex.printStackTrace();}
180         }
181      }
182         templateRow.getParentNode().removeChild(templateRow);
183         //siteList.setTextTime(now);
184

185         if (list.length != 0){
186         ////////////////////////////////
187
try{
188             PathType pt = PathTypeFactory.getPathType("org.enhydra.snapper.business.PathTypeImpl");
189             PathType[] pathList = pt.getList(dbTransaction);
190         
191             HTMLOptionElement templateOption = htmlPage.getElementTemplateNewPathType();
192             Node pathSelect = templateOption.getParentNode();
193             templateOption.removeAttribute("id");
194             templateOption.removeChild(templateOption.getFirstChild());
195             for (int num = 0; num < pathList.length; num++) {
196     
197                     PathType currentPathType = pathList[num];
198                     HTMLOptionElement clonedOption = (HTMLOptionElement) templateOption.cloneNode(true);
199                     clonedOption.setValue(currentPathType.getID());
200                     Node optionTextNode = clonedOption.getOwnerDocument().
201                         createTextNode(currentPathType.getName());
202                     clonedOption.appendChild(optionTextNode);
203                     // Do only a shallow copy of the option as we don't want the text child
204
// of the node option
205
pathSelect.appendChild(clonedOption);
206                 }
207         
208         
209         }
210                 catch(Exception JavaDoc ex) {
211                    System.out.print(ex.toString());}
212         }
213         
214         
215         if (comms.request.getParameter("siteList") != null){
216         htmlPage.getElementSite().setValue(comms.request.getParameter("siteList"));
217         }
218         else {
219             if (list.length != 0)
220             htmlPage.getElementSite().setValue(list[0].getID());
221         }
222      
223         return htmlPage;
224     }
225     
226
227 }
228
Popular Tags