1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package olr.presentation;
18
19 import java.util.Iterator;
20
21 import olr.rdf.Attribute;
22 import olr.rdf.OLR3Definitions;
23 import olr.rdf.Resource;
24 import olr.rdf.Tools;
25 import olr.statementpool.DBStatement;
26 import olr.statementpool.ExtStatement;
27
28 import org.apache.log4j.Logger;
29 import org.w3c.dom.Node;
30 import org.w3c.dom.html.HTMLAnchorElement;
31 import org.w3c.dom.html.HTMLElement;
32 import org.w3c.dom.html.HTMLInputElement;
33 import org.w3c.dom.html.HTMLTableRowElement;
34
35 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
36
37 /***
38 * @version $Id: Activities.java,v 1.12 2004/08/02 18:46:20 roku Exp $
39 */
40 public class Activities extends SecureHttpPresentation {
41 public String handleDefault() {
42 return showPage();
43 }
44
45 public String handleAddKeywordMode() {
46 return showPage(1);
47 }
48
49 public String handleAddDescriptionMode() {
50 return showPage(2);
51 }
52
53 public String handleAddBookmarkMode() {
54 return showPage(3);
55 }
56
57 public String handleAddKeyword() throws HttpPresentationException {
58 return addItem(OLR3Definitions.OLR3_KEYWORD);
59 }
60
61 public String handleAddDescription() throws HttpPresentationException {
62 return addItem(OLR3Definitions.OLR3_DESCRIPTION);
63 }
64
65 public String handleAddBookmark() throws HttpPresentationException {
66 return addItem(OLR3Definitions.OLR3_BOOKMARK);
67 }
68
69 private String addItem(String predicate) throws HttpPresentationException {
70 try {
71 String subject = getAboutURI();
72 String object = getComms().request.getParameter("newItem");
73 String typ = getComms().request.getParameter("typ");
74 if (subject != null && object != null && typ != null && object.length() > 0) {
75 ExtStatement statement = new ExtStatement(subject, predicate, object);
76 statement.setPublic(typ.equals("public"));
77 DBStatement dbStatement = getSessionData().getStatementPool().saveStatementToDB(
78 statement);
79 getSessionData()
80 .getStatementPool()
81 .addStatement(
82 ((olr.rdf.Statement) (dbStatement != null ? ((olr.rdf.Statement) (dbStatement))
83 : ((olr.rdf.Statement) (statement)))));
84 }
85 } catch (Exception e) {
86 e.printStackTrace();
87 }
88 return showPage();
89 }
90
91 public String handleRemoveKeyword() throws HttpPresentationException {
92 return removeItem(OLR3Definitions.OLR3_KEYWORD);
93 }
94
95 public String handleRemoveDescription() throws HttpPresentationException {
96 return removeItem(OLR3Definitions.OLR3_DESCRIPTION);
97 }
98
99 public String handleRemoveBookmark() throws HttpPresentationException {
100 return removeItem(OLR3Definitions.OLR3_BOOKMARK);
101 }
102
103 private String removeItem(String predicate) throws HttpPresentationException {
104 try {
105 String subject = getAboutURI();
106 String nr = getComms().request.getParameter("nr");
107 if (subject != null && nr != null) {
108 Attribute attribute = (Attribute) getSessionData().getStatementPool()
109 .getSpecificAttributesAbout(subject, predicate).get(Integer.parseInt(nr));
110 boolean canDelete = false;
111 if (attribute instanceof DBStatement)
112 canDelete = getSessionData().getStatementPool().removeStatementOfUserFromDB(
113 (DBStatement) attribute);
114 else
115 canDelete = true;
116 if (canDelete)
117 getSessionData().getStatementPool().removeAttributeAbout(subject, attribute);
118 }
119 } catch (Exception e) {
120 Logger.getLogger(this.getClass()).error(e);
121 throw new HttpPresentationException(e);
122 }
123 return showPage();
124 }
125
126 public String showPage() {
127 return showPage(0);
128 }
129
130 public String showPage(int mode) {
131 ActivitiesHTML page = new ActivitiesHTML();
132 HTMLTableRowElement keywordRow = page.getElementKeywordRow();
133 HTMLElement keyword = page.getElementKeyword();
134 HTMLAnchorElement keywordRemove = page.getElementRemoveKeywordLink();
135 HTMLAnchorElement keywordAdd = page.getElementAddKeywordLink();
136 HTMLAnchorElement related = page.getElementRelatedLink();
137 HTMLTableRowElement relatedRow = page.getElementRelatedRow();
138 HTMLTableRowElement descriptionRow = page.getElementDescriptionRow();
139 HTMLElement description = page.getElementDescription();
140 HTMLAnchorElement descriptionRemove = page.getElementRemoveDescriptionLink();
141 HTMLAnchorElement descriptionAdd = page.getElementAddDescriptionLink();
142 HTMLTableRowElement bookmarkRow = page.getElementBookmarkRow();
143 HTMLAnchorElement bookmark = page.getElementBookmark();
144 HTMLAnchorElement bookmarkRemove = page.getElementRemoveBookmarkLink();
145 HTMLAnchorElement bookmarkAdd = page.getElementAddBookmarkLink();
146 HTMLTableRowElement addKeywordRow = page.getElementAddKeywordRow();
147 HTMLTableRowElement addDescriptionRow = page.getElementAddDescriptionRow();
148 HTMLTableRowElement addBookmarkRow = page.getElementAddBookmarkRow();
149 HTMLInputElement aboutURIItem = page.getElementAboutURI();
150 String aboutURI = getAboutURI();
151 Resource subject = null;
152 if (aboutURI != null)
153 subject = getSessionData().getStatementPool().getResource(aboutURI);
154 if (subject != null)
155 try {
156 aboutURIItem.setValue(Tools.URItoID(aboutURI));
157 keywordAdd.setHref("Activities.po?event=addKeywordMode&aboutURI=".concat(String
158 .valueOf(String.valueOf(Tools.URItoID(aboutURI)))));
159 descriptionAdd.setHref("Activities.po?event=addDescriptionMode&aboutURI="
160 .concat(String.valueOf(String.valueOf(Tools.URItoID(aboutURI)))));
161 bookmarkAdd.setHref("Activities.po?event=addBookmarkMode&aboutURI=".concat(String
162 .valueOf(String.valueOf(Tools.URItoID(aboutURI)))));
163 if (mode != 1)
164 addKeywordRow.getParentNode().removeChild(addKeywordRow);
165 if (mode != 2)
166 addDescriptionRow.getParentNode().removeChild(addDescriptionRow);
167 if (mode != 3)
168 addBookmarkRow.getParentNode().removeChild(addBookmarkRow);
169 Node parent = keywordRow.getParentNode();
170 int n = 0;
171 Iterator it;
172 for (it = subject.getAttributes(OLR3Definitions.OLR3_KEYWORD).iterator(); it
173 .hasNext(); parent.insertBefore(keywordRow.cloneNode(true), keywordRow)) {
174 Attribute attribute = (Attribute) it.next();
175 page.setTextKeyword(attribute.getObject());
176 keywordRemove.setHref(String.valueOf(String.valueOf((new StringBuffer(
177 "Activities.po?event=removeKeyword&aboutURI=")).append(
178 Tools.URItoID(aboutURI)).append("&nr=").append(n++))));
179 }
180
181 parent.removeChild(keywordRow);
182 parent = relatedRow.getParentNode();
183 it = getSessionData().getStatementPool().getResourcesHavingKeyword(
184 subject.getObjects(OLR3Definitions.OLR3_KEYWORD)).iterator();
185 do {
186 if (!it.hasNext())
187 break;
188 String uri = it.next().toString();
189 Resource relatedObj = getSessionData().getStatementPool().getResource(uri);
190 if (relatedObj != null && !uri.equals(aboutURI)) {
191 page.setTextRelatedLink(relatedObj.getTitle());
192 related.setHref("Content.po?aboutURI=".concat(String.valueOf(String
193 .valueOf(Tools.URItoID(relatedObj.getURI())))));
194 parent.insertBefore(relatedRow.cloneNode(true), relatedRow);
195 }
196 } while (true);
197 parent.removeChild(relatedRow);
198 parent = descriptionRow.getParentNode();
199 n = 0;
200 for (it = subject.getAttributes(OLR3Definitions.OLR3_DESCRIPTION).iterator(); it
201 .hasNext(); parent.insertBefore(descriptionRow.cloneNode(true),
202 descriptionRow)) {
203 Attribute attribute = (Attribute) it.next();
204 page.setTextDescription(attribute.getObject());
205 descriptionRemove.setHref(String.valueOf(String.valueOf((new StringBuffer(
206 "Activities.po?event=removeDescription&aboutURI=")).append(
207 Tools.URItoID(aboutURI)).append("&nr=").append(n++))));
208 }
209
210 parent.removeChild(descriptionRow);
211 parent = bookmarkRow.getParentNode();
212 n = 0;
213 for (it = subject.getAttributes(OLR3Definitions.OLR3_BOOKMARK).iterator(); it
214 .hasNext(); parent.insertBefore(bookmarkRow.cloneNode(true), bookmarkRow)) {
215 Attribute attribute = (Attribute) it.next();
216 String uri = attribute.getObject();
217 Resource bookmarkObj = getSessionData().getStatementPool().getResource(uri);
218 if (bookmarkObj != null) {
219 page.setTextBookmark(bookmarkObj.getTitle());
220 bookmark.setHref("Content.po?aboutURI=".concat(String.valueOf(String
221 .valueOf(Tools.URItoID(uri)))));
222 } else {
223 page.setTextBookmark(uri);
224 bookmark.setHref(uri);
225 }
226 bookmarkRemove.setHref(String.valueOf(String.valueOf((new StringBuffer(
227 "Activities.po?event=removeBookmark&aboutURI=")).append(
228 Tools.URItoID(aboutURI)).append("&nr=").append(n++))));
229 }
230
231 parent.removeChild(bookmarkRow);
232 } catch (Exception e) {
233 e.printStackTrace();
234 }
235 return page.toDocument();
236 }
237
238 private String getAboutURI() {
239 try {
240 String aboutURI = getComms().request.getParameter("aboutURI");
241 if (aboutURI != null) {
242 String s = Tools.IDtoURI(aboutURI);
243 return s;
244 }
245 } catch (Exception e) {
246 e.printStackTrace();
247 }
248 return null;
249 }
250
251 private final String THIS_HTML = "Activities.po";
252
253 private final int DEFAULT_MODE = 0;
254
255 private final int ADD_KEYWORD_MODE = 1;
256
257 private final int ADD_DESCRIPTION_MODE = 2;
258
259 private final int ADD_BOOKMARK_MODE = 3;
260 }