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.List;
19  
20  import olr.rdf.Attribute;
21  import olr.rdf.Resource;
22  import olr.rdf.Tools;
23  import olr.viewer.CourseViewer;
24  import olr.viewer.ModelViewerRow;
25  
26  import org.w3c.dom.html.HTMLAnchorElement;
27  import org.w3c.dom.html.HTMLElement;
28  import org.w3c.dom.html.HTMLImageElement;
29  import org.w3c.dom.html.HTMLTableElement;
30  import org.w3c.dom.html.HTMLTableRowElement;
31  
32  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
33  
34  /***
35   * @version $Id: TBLStructure.java,v 1.1 2004/08/03 08:33:53 roku Exp $
36   */
37  public class TBLStructure extends SecureHttpPresentation {
38  
39      public String handleDefault() throws HttpPresentationException {
40          return showPage();
41      }
42  
43      public String showPage() {
44          TBLStructureHTML page = new TBLStructureHTML();
45          HTMLTableElement table1 = page.getElementGenerate();
46          HTMLTableElement table = page.getElementTable();
47          HTMLAnchorElement basisRow = page.getElementBasisRow();
48          HTMLAnchorElement fragenRow = page.getElementFragenRow();
49          HTMLAnchorElement weiterRow = page.getElementWeiterRow();
50          HTMLAnchorElement uebungRow = page.getElementUebungRow();
51          HTMLImageElement basis = page.getElementBasis();
52          HTMLImageElement fragen = page.getElementFragen();
53          HTMLImageElement weiter = page.getElementWeiter();
54          HTMLImageElement uebung = page.getElementUebung();
55          HTMLTableRowElement courseRow = page.getElementCourseRow();
56          HTMLTableRowElement headLineRow = page.getElementHeadLineRow();
57          HTMLElement headline = page.getElementHeadline();
58  
59          try {
60              CourseViewer courseViewer = getSessionData().getCourseViewers().getActiveViewer();
61              List rows = courseViewer.getModelRows();
62              String modifiedURI = getComms().request.getParameter("modifiedURI");
63              if (modifiedURI != null)
64                  getSessionData().getCourseViewers().getActiveViewer().updateResource(
65                          Tools.IDtoURI(modifiedURI));
66  
67              for (int rowNr = 0; rowNr < rows.size(); rowNr++) {
68  
69                  ModelViewerRow row = (ModelViewerRow) rows.get(rowNr);
70                  courseViewer.expandAllResource(rowNr);
71                  Resource resource = getSessionData().getStatementPool().getResource(
72                          row.getResource());
73                  if (row.getIndent() == 0 && !row.isPredicate()) {
74  
75                      String title = resource.getTitle();
76                      page.setTextCoursename(title);
77                      table1.appendChild(courseRow.cloneNode(true));
78                      continue;
79                  }
80  
81                  if (row.getIndent() == 4) {
82                      page.setTextHeadline(row.getTitle());
83                      String prop = "";
84                      Attribute erg = new Attribute(null, null);
85                      Resource topic = getSessionData().getStatementPool().getResource(
86                              row.getResource());
87                      Attribute a;
88                      String name;
89                      String predicate;
90                      String topicName = row.getTitle();
91                      String part;
92                      Resource question;
93                      String hrefShow;
94  
95                      List attributes = topic.getAttributes();
96                      for (int i = 0; i < attributes.size(); i++) {
97                          a = (Attribute) attributes.get(i);
98  
99                          if (getSessionData().getStatementPool().getResourceTitle(a.getPredicate())
100                                 .equalsIgnoreCase("tbl:hasBasicInformations")) {
101 
102                             erg = a;
103                             if (erg != null) {
104                                 hrefShow = String.valueOf(String.valueOf((new StringBuffer(
105                                         "ContentReader.po?aboutURI=")).append(Tools
106                                         .URItoID(getSessionData().getStatementPool().getResource(
107                                                 erg.getObject()).getURI()))));
108                                 name = Tools.URItoID(erg.getObject());
109                                 predicate = Tools
110                                         .URItoID("http://tauschasbuch.mondschafe.de/tbl#hasBasicElement");
111                                 basisRow.setAttribute("href", hrefShow + "&resource=" + name
112                                         + "&predicate=" + predicate);
113                             }
114                         }
115                         if (getSessionData().getStatementPool().getResourceTitle(a.getPredicate())
116                                 .equalsIgnoreCase("tbl:hasFurtherInformations")) {
117 
118                             erg = a;
119                             if (erg != null) {
120                                 hrefShow = String.valueOf(String.valueOf((new StringBuffer(
121                                         "ContentReader.po?aboutURI=")).append(Tools
122                                         .URItoID(getSessionData().getStatementPool().getResource(
123                                                 erg.getObject()).getURI()))));
124                                 name = Tools.URItoID(erg.getObject());
125                                 predicate = Tools
126                                         .URItoID("http://tauschasbuch.mondschafe.de/tbl#hasFurtherElement");
127                                 weiterRow.setAttribute("href", hrefShow + "&resource=" + name
128                                         + "&predicate=" + predicate);
129                             }
130                         }
131                         if (getSessionData().getStatementPool().getResourceTitle(a.getPredicate())
132                                 .equalsIgnoreCase("tbl:hasPractice")) {
133 
134                             erg = a;
135                             if (erg != null) {
136                                 hrefShow = String.valueOf(String.valueOf((new StringBuffer(
137                                         "ContentReader.po?aboutURI=")).append(Tools
138                                         .URItoID(getSessionData().getStatementPool().getResource(
139                                                 erg.getObject()).getURI()))));
140                                 name = Tools.URItoID(erg.getObject());
141                                 predicate = Tools
142                                         .URItoID("http://tauschasbuch.mondschafe.de/tbl#hasPracticeElement");
143                                 uebungRow.setAttribute("href", hrefShow + "&resource=" + name
144                                         + "&predicate=" + predicate);
145                             }
146                         }
147                         if (getSessionData().getStatementPool().getResourceTitle(a.getPredicate())
148                                 .equalsIgnoreCase("tbl:hasQuestions")) {
149                             erg = a;
150                             if (erg != null) {
151                                 question = getSessionData().getStatementPool().getResource(
152                                         a.getObject());
153                                 hrefShow = String.valueOf(String.valueOf((new StringBuffer(
154                                         "Content.po?aboutURI=")).append(Tools.URItoID(question
155                                         .getURI()))));
156                                 fragenRow.setAttribute("href", hrefShow);
157                             }
158                         }
159                     }
160 
161                     basis.setSrc("media/basisOff.gif");
162                     fragen.setSrc("media/fragenOff.gif");
163                     weiter.setSrc("media/weiterOff.gif");
164                     uebung.setSrc("media/aufgabenOff.gif");
165                     table.appendChild(headLineRow.cloneNode(true));
166 
167                 }
168             }
169 
170         } catch (Exception e) {
171             e.printStackTrace();
172         }
173         courseRow.getParentNode().removeChild(courseRow);
174         headLineRow.getParentNode().removeChild(headLineRow);
175 
176         return page.toDocument();
177     }
178 
179     private final String THIS_HTML = "Structure.po";
180 
181     private final String CONTENT_HTML = "Content.po";
182 
183 }
184