1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package olr.presentation;
16
17 import java.util.List;
18
19 import olr.rdf.Attribute;
20 import olr.rdf.OLR3Definitions;
21 import olr.rdf.Resource;
22 import olr.rdf.Tools;
23 import olr.viewer.CourseViewer;
24 import olr.viewer.ModelViewerRow;
25
26 import org.apache.log4j.Logger;
27 import org.w3c.dom.html.HTMLTableElement;
28 import org.w3c.dom.html.HTMLTableRowElement;
29
30 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
31 import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
32
33 /***
34 * @version $Id: ImageStructure.java,v 1.8 2004/08/03 09:47:36 roku Exp $
35 */
36 public class ImageStructure extends SecureHttpPresentation {
37 /***
38 * Initializes an instance of this class.
39 */
40 public ImageStructure() {
41 }
42
43 public String handleDefault() throws HttpPresentationException {
44 return showPage();
45 }
46
47 public String handleExpand() throws HttpPresentationException {
48 HttpPresentationRequest request = getComms().request;
49 try {
50 CourseViewer courseViewer = getSessionData().getCourseViewers().getActiveViewer();
51 int rowNr = Integer.parseInt(request.getParameter("row"));
52 courseViewer.expandResource(rowNr);
53 } catch (Exception e) {
54 e.printStackTrace();
55 }
56 return showPage();
57 }
58
59 public String showPage() {
60 final ImageStructureHTML page = new ImageStructureHTML();
61 try {
62 final HTMLTableElement table = page.getElementGenerate();
63 final HTMLTableRowElement root = page.getElementRoot();
64 final HTMLTableRowElement imageInstance = page.getElementImageInstance();
65 final HTMLTableRowElement other = page.getElementOther();
66 final CourseViewer courseViewer = getSessionData().getCourseViewers().getActiveViewer();
67 if (courseViewer != null) {
68 final List rows = courseViewer.getModelRows();
69
70 for (int rowNr = 0; rowNr < rows.size(); rowNr++) {
71
72 final ModelViewerRow row = (ModelViewerRow) rows.get(rowNr);
73 courseViewer.checkSub(rowNr);
74
75 if (row.isPredicate())
76 continue;
77 final Resource resource = getSessionData().getStatementPool().getResource(
78 row.getResource());
79 if (resource == null)
80 continue;
81 final String type = resource.getType();
82 final String title = resource.getTitle();
83 final String indent = "".concat(String.valueOf(String.valueOf(row.getIndent() * 4)));
84 final String hrefExpand = String.valueOf(String.valueOf((new StringBuffer(
85 "ImageStructure.po?event=expand&row=")).append(rowNr)));
86 final String hrefShow = String.valueOf(String.valueOf((new StringBuffer(
87 "Content.po?aboutURI=")).append(Tools.URItoID(resource.getURI()))));
88 if (row.getIndent() == 0) {
89 page.getElementSpace0().setWidth(indent);
90 page.getElementShow0().setHref(hrefShow);
91 page.setTextShow0(title);
92 table.appendChild(root.cloneNode(true));
93 continue;
94 }
95 final List engineImages = getSessionData().getStatementPool()
96 .getSpecificAttributesAbout(type, OLR3Definitions.OLR3_ENGINEIMAGE);
97 if (engineImages.size() > 0) {
98 page.getElementSpace1().setWidth(indent);
99 page.getElementImage()
100 .setSrc(((Attribute) engineImages.get(0)).getObject());
101 page.getElementExpand1().setHref(hrefExpand);
102 page.getElementShow1().setHref(hrefShow);
103 page.setTextShow1(title);
104 table.appendChild(imageInstance.cloneNode(true));
105 } else {
106 page.getElementSpace2().setWidth(indent);
107 page.getElementExpand2().setHref(hrefExpand);
108 page.getElementShow2().setHref(hrefShow);
109 page.setTextExpand2(row.isExpandable() ? row.isExpanded() ? "-" : "+" : "");
110 page.setTextShow2(title);
111 table.appendChild(other.cloneNode(true));
112 }
113 }
114 }
115 table.removeChild(root);
116 table.removeChild(imageInstance);
117 table.removeChild(other);
118 } catch (Exception e) {
119 Logger.getLogger(getClass()).error(e);
120 }
121 return page.toDocument();
122 }
123
124 private final String THIS_HTML = "ImageStructure.po";
125
126 private final String CONTENT_HTML = "Content.po";
127 }