View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package olr.presentation;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import olr.rdf.Attribute;
22  import olr.rdf.OLR3Definitions;
23  import olr.rdf.Resource;
24  import olr.rdf.Tools;
25  
26  import org.w3c.dom.html.HTMLAnchorElement;
27  import org.w3c.dom.html.HTMLElement;
28  import org.w3c.dom.html.HTMLTableElement;
29  import org.w3c.dom.html.HTMLTableRowElement;
30  
31  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
32  import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
33  
34  /*** 
35   * @version $Id: Index.java,v 1.1 2004/08/03 08:33:53 roku Exp $
36   */
37  public class Index extends SecureHttpPresentation {
38      /*** 
39       * Initializes an instance of this class.
40       */
41      public Index() {
42      }
43  
44      public String handleDefault() throws HttpPresentationException {
45          return showPage(null);
46      }
47  
48      public String handleCreate() throws HttpPresentationException {
49          HttpPresentationRequest request = getComms().request;
50          String resource = Tools.IDtoURI(request.getParameter("resource"));
51          String predicate = Tools.IDtoURI(request.getParameter("predicate"));
52          Resource res = getSessionData().getStatementPool().getResource(resource);
53          List objects = res.getObjects(predicate);
54          return showPage(objects);
55  
56      }
57  
58      public String showPage(List objects) {
59          IndexHTML page = new IndexHTML();
60          HTMLTableElement table = page.getElementGenerate();
61          HTMLTableRowElement titleRow = page.getElementTitleRow();
62          HTMLTableRowElement commentRow = page.getElementCommentRow();
63          HTMLTableRowElement urlRow = page.getElementUrlRow();
64          HTMLElement title = page.getElementTitle();
65          HTMLAnchorElement link = page.getElementLink();
66          if (objects != null)
67              try {
68                  for (int i = 0; i < objects.size(); i++) {
69                      Resource object = getSessionData().getStatementPool().getResource(
70                              objects.get(i).toString());
71                      List comments = object.getComment();
72                      String hrefShow = String.valueOf(String.valueOf((new StringBuffer(
73                              "Content.po?aboutURI=")).append(Tools.URItoID(object.getURI()))));
74                      link.setAttribute("href", hrefShow);
75                      page.setTextTitle(object.getTitle());
76                      List attributes = getSessionData().getStatementPool()
77                              .getSpecificAttributesAbout(object.getURI(),
78                                      OLR3Definitions.OLR3_SHOWLINK);
79                      String s = "";
80                      String doc = "link";
81                      if (attributes.size() > 0) {
82                          for (Iterator it = attributes.iterator(); it.hasNext();) {
83                              Attribute attribute = (Attribute) it.next();
84                              s = attribute.getObject();
85                              doc = Tools.IDtoURI(s.substring(s.lastIndexOf(".") + 1));
86  
87                          }
88                      }
89                      if (doc.equalsIgnoreCase("ppt")) {
90                          doc = "(Power-Point-Präsentation)";
91                      } else if (doc.equalsIgnoreCase("pdf")) {
92                          doc = "(PDF-Dokument)";
93                      } else
94                          doc = "(HTML-Dokument)";
95                      page.setTextLink(doc);
96                      table.appendChild(titleRow.cloneNode(true));
97                      page.setTextUrls(s);
98                      table.appendChild(urlRow.cloneNode(true));
99                      page.setTextComment(comments.get(0).toString());
100                     table.appendChild(commentRow.cloneNode(true));
101                 }
102             } catch (Exception e) {
103                 e.printStackTrace();
104             }
105         titleRow.getParentNode().removeChild(titleRow);
106         urlRow.getParentNode().removeChild(urlRow);
107         commentRow.getParentNode().removeChild(commentRow);
108         return page.toDocument();
109     }
110 }