1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }