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.Iterator;
20  import java.util.List;
21  
22  import olr.rdf.Attribute;
23  import olr.rdf.OLR3Definitions;
24  import olr.rdf.Tools;
25  
26  import org.w3c.dom.html.HTMLFrameElement;
27  import org.w3c.dom.html.HTMLFrameSetElement;
28  
29  import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
30  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
31  import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
32  
33  /***
34   * @version $Id: ContentReader.java,v 1.9 2004/08/03 08:33:53 roku Exp $
35   */
36  public class ContentReader extends SecureHttpPresentation {
37  
38      public String handleDefault() throws HttpPresentationException {
39          return showPage();
40      }
41  
42      public String showPage() {
43          ContentReaderHTML page = new ContentReaderHTML();
44          try {
45              HTMLFrameSetElement frameSettings = page.getElementFrameSettings();
46              HTMLFrameElement link = page.getElementLink();
47              HTMLFrameElement header = page.getElementHeader();
48              HTMLFrameElement activities = page.getElementActivities();
49              HTMLFrameElement relations = page.getElementRelations();
50              HttpPresentationRequest request = getComms().request;
51              String aboutURI = request.getParameter("aboutURI");
52              String resource = request.getParameter("resource");
53              String predicate = request.getParameter("predicate");
54              if (aboutURI != null) {
55                  header.setSrc("ContentReaderHeader.po?aboutURI=".concat(String.valueOf(String
56                          .valueOf(aboutURI))));
57                  activities.setSrc("Activities.po?aboutURI=".concat(String.valueOf(String
58                          .valueOf(aboutURI))));
59                  relations.setSrc("Relations.po?aboutURI=".concat(String.valueOf(String
60                          .valueOf(aboutURI))));
61                  aboutURI = Tools.IDtoURI(aboutURI);
62                  if (predicate != null) {
63                      link.setSrc("Index.po?event=Create&resource=" + resource + "&predicate="
64                              + predicate);
65                      link.getParentNode().appendChild(link.cloneNode(true));
66                      frameSettings.setRows("45,*");
67                      link.getParentNode().removeChild(link);
68  
69                  } else {
70  
71                      final List attributes = getSessionData().getStatementPool()
72                              .getSpecificAttributesAbout(aboutURI, OLR3Definitions.OLR3_SHOWLINK);
73  
74                      if (attributes.size() > 0) {
75                          String rows = "45";
76                          for (Iterator it = attributes.iterator(); it.hasNext();) {
77                              Attribute attribute = (Attribute) it.next();
78  
79                              link.setSrc(attribute.getObject());
80                              link.getParentNode().appendChild(link.cloneNode(true));
81                              rows = String.valueOf(String.valueOf(rows)).concat(",*");
82                          }
83  
84                          frameSettings.setRows(rows);
85                          link.getParentNode().removeChild(link);
86                      }
87                  }
88              } else {
89                  throw new ClientPageRedirectException("ContentUndefined.html");
90              }
91          } catch (Exception e) {
92              e.printStackTrace();
93          }
94          return page.toDocument();
95      }
96  }