View Javadoc

1   /*
2    *  $Id: Relations.java,v 1.5 2004/07/25 14:10:53 roku Exp $ 
3    *
4    *  Copyright 2004 University of Hannover
5    *
6    *  Licensed under the Apache License, Version 2.0 (the "License");
7    *  you may not use this file except in compliance with the License.
8    *  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package olr.presentation;
20  
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import olr.rdf.Resource;
25  import olr.rdf.Tools;
26  import olr.relations.RelationViewer;
27  
28  import org.w3c.dom.Node;
29  import org.w3c.dom.html.HTMLAnchorElement;
30  import org.w3c.dom.html.HTMLElement;
31  import org.w3c.dom.html.HTMLTableElement;
32  import org.w3c.dom.html.HTMLTableRowElement;
33  
34  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
35  
36  
37  public class Relations extends ExtendedHttpPresentation
38  {
39  
40      public Relations()
41      {
42      }
43  
44      public boolean loggedInUserRequired()
45      {
46          return true;
47      }
48  
49      public String handleDefault()
50          throws HttpPresentationException
51      {
52          return showPage();
53      }
54  
55      public String showPage()
56      {
57          RelationsHTML page = new RelationsHTML();
58          try
59          {
60              HTMLTableElement table = page.getElementGenerate();
61              HTMLTableRowElement relationTypeRow = page.getElementRelationTypeRow();
62              HTMLTableRowElement relationRow = page.getElementRelationRow();
63              HTMLAnchorElement relation = page.getElementRelation();
64              HTMLElement relationSep = page.getElementRelationSep();
65              String aboutURI = getAboutURI();
66              RelationViewer relationViewer = getSessionData().getRelationViewer();
67              if(relationViewer != null && aboutURI != null)
68              {
69                  Node parent = relation.getParentNode();
70                  Iterator relationTypes = relationViewer.getRelationTypes().iterator();
71                  do
72                  {
73                      if(!relationTypes.hasNext())
74                          break;
75                      Resource relationType = (Resource)relationTypes.next();
76                      page.setTextRelationType(relationType.getTitle());
77                      for(; parent.getChildNodes().getLength() > 0; parent.removeChild(parent.getChildNodes().item(0)));
78                      List relations = relationViewer.getSpecificRelations(aboutURI, relationType.getURI());
79                      if(relations.size() > 0)
80                      {
81                          for(int i = 0; i < relations.size(); i++)
82                          {
83                              Resource relationObj = (Resource)relations.get(i);
84                              page.setTextRelation(relationObj.getTitle());
85                              relation.setAttribute("href", "Content.po?aboutURI=".concat(String.valueOf(String.valueOf(Tools.URItoID(relationObj.getURI())))));
86                              if(i > 0)
87                                  parent.appendChild(relationSep.cloneNode(true));
88                              parent.appendChild(relation.cloneNode(true));
89                          }
90  
91                          table.appendChild(relationTypeRow.cloneNode(true));
92                          table.appendChild(relationRow.cloneNode(true));
93                      }
94                  } while(true);
95              }
96              relationRow.getParentNode().removeChild(relationRow);
97              relationTypeRow.getParentNode().removeChild(relationTypeRow);
98          }
99          catch(Exception e)
100         {
101             e.printStackTrace();
102         }
103         return page.toDocument();
104     }
105 
106     private String getAboutURI()
107     {
108         try
109         {
110             String aboutURI = getComms().request.getParameter("aboutURI");
111             if(aboutURI != null)
112             {
113                 String s = Tools.IDtoURI(aboutURI);
114                 return s;
115             }
116         }
117         catch(Exception e)
118         {
119             e.printStackTrace();
120         }
121         return null;
122     }
123 }