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  
17  package olr.presentation;
18  
19  import java.util.List;
20  
21  import olr.rdf.Tools;
22  import olr.viewer.CourseViewer;
23  import olr.viewer.ModelViewerRow;
24  
25  import org.apache.log4j.Logger;
26  import org.w3c.dom.html.HTMLTableElement;
27  import org.w3c.dom.html.HTMLTableRowElement;
28  
29  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
30  import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
31  
32  /***
33   * @version $Id: Structure.java,v 1.11 2004/08/03 16:03:26 roku Exp $
34   */
35  public class Structure extends SecureHttpPresentation {
36      /***
37       * Initializes an instance of this class.
38       */
39      public Structure() {
40      }
41  
42      public String handleDefault() throws HttpPresentationException {
43          return showPage();
44      }
45  
46      public String handleExpand() throws HttpPresentationException {
47          HttpPresentationRequest request = getComms().request;
48          try {
49              CourseViewer courseViewer = getSessionData().getCourseViewers().getActiveViewer();
50              int rowNr = Integer.parseInt(request.getParameter("row"));
51              courseViewer.expandResource(rowNr);
52          } catch (Exception e) {
53              e.printStackTrace();
54          }
55          return showPage();
56      }
57  
58      public String showPage() {
59          final StructureHTML page = new StructureHTML();
60          HTMLTableElement table = page.getElementGenerate();
61          HTMLTableRowElement courseRow = page.getElementCourseRow();
62          HTMLTableRowElement resourceRow = page.getElementResourceRow();
63          HTMLTableRowElement predicateRow = page.getElementPredicateRow();
64          try {
65              final CourseViewer courseViewer = getSessionData().getCourseViewers().getActiveViewer();
66              final List rows = courseViewer.getModelRows();
67              final String modifiedURI = getComms().request.getParameter("modifiedURI");
68              if (modifiedURI != null)
69                  getSessionData().getCourseViewers().getActiveViewer().updateResource(
70                          Tools.IDtoURI(modifiedURI));
71              page.setTextCourse(getSessionData().getModel().getName());
72              page.getElementCourse().setAttribute("href", "Structure.po?event=expand&row=-1");
73              table.appendChild(courseRow.cloneNode(true));
74              for (int rowNr = 0; rowNr < rows.size(); rowNr++) {
75                  ModelViewerRow row = (ModelViewerRow) rows.get(rowNr);
76                  courseViewer.checkSub(rowNr);
77                  if (!row.isPredicate()) {
78                      page.getElementSpace1().setWidth(
79                              "".concat(String.valueOf(String.valueOf(row.getIndent() * 8))));
80                      page.setTextExpand(row.isExpandable() ? row.isExpanded() ? "-" : "+" : "");
81                      page.setTextResource(row.getTitle());
82                      page.getElementExpand().setHref(
83                              String.valueOf(String.valueOf((new StringBuffer(
84                                      "Structure.po?event=expand&row=")).append(rowNr))));
85                      page.getElementResource().setHref(
86                              String.valueOf(String
87                                      .valueOf((new StringBuffer("Content.po?aboutURI="))
88                                              .append(Tools.URItoID(row.getResource())))));
89                      table.appendChild(resourceRow.cloneNode(true));
90                  } else {
91                      page.getElementSpace2().setWidth(
92                              "".concat(String.valueOf(String.valueOf(row.getIndent() * 8))));
93                      page.setTextPredicate(row.getTitle());
94                      table.appendChild(predicateRow.cloneNode(true));
95                  }
96              }
97  
98          } catch (Exception e) {
99              Logger.getLogger(getClass()).error(e);
100         }
101         courseRow.getParentNode().removeChild(courseRow);
102         resourceRow.getParentNode().removeChild(resourceRow);
103         predicateRow.getParentNode().removeChild(predicateRow);
104         return page.toDocument();
105     }
106 
107     private final String THIS_HTML = "Structure.po";
108 
109     private final String CONTENT_HTML = "Content.po";
110 }