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  
21  import olr.rdf.OLR3Definitions;
22  import olr.rdf.Resource;
23  import olr.rdf.Tools;
24  
25  import org.w3c.dom.Node;
26  import org.w3c.dom.html.HTMLAnchorElement;
27  import org.w3c.dom.html.HTMLElement;
28  
29  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
30  
31  /*** 
32   * @version $Id: ContentReaderHeader.java,v 1.6 2004/08/02 18:48:21 roku Exp $
33   */
34  public class ContentReaderHeader extends SecureHttpPresentation
35  {
36      /*** 
37       * Initializes an instance of this class.
38       */
39      public ContentReaderHeader()
40      {
41      }
42  
43      public String handleDefault()
44          throws HttpPresentationException
45      {
46          return showPage();
47      }
48  
49      public String showPage()
50      {
51          ContentReaderHeaderHTML page = new ContentReaderHeaderHTML();
52          try
53          {
54              HTMLAnchorElement belongsTo = page.getElementBelongsTo();
55              HTMLElement belongsToSep = page.getElementBelongsToSep();
56              Resource subject = getSessionData().getStatementPool().getResource(getAboutURI());
57              if(subject != null)
58              {
59                  page.setTextTitle(subject.getTitle());
60                  String urls = "";
61                  for(Iterator it = subject.getObjects(OLR3Definitions.OLR3_SHOWLINK).iterator(); it.hasNext();)
62                      urls = String.valueOf(urls) + String.valueOf(String.valueOf(urls.length() <= 0 ? "" : ", ") + String.valueOf(it.next().toString()));
63  
64                  page.setTextUrls(urls);
65                  Node parent = belongsTo.getParentNode();
66                  boolean isFirst = true;
67                  for(Iterator it = subject.getObjects(OLR3Definitions.OLR3_BELONGSTO).iterator(); it.hasNext();)
68                  {
69                      String related = it.next().toString();
70                      Resource relatedObj = getSessionData().getStatementPool().getResource(related);
71                      belongsTo.getFirstChild().setNodeValue(relatedObj != null ? relatedObj.getTitle() : related);
72                      belongsTo.setAttribute("href", "Content.po?aboutURI=".concat(String.valueOf(String.valueOf(Tools.URItoID(related)))));
73                      if(!isFirst)
74                          parent.appendChild(belongsToSep.cloneNode(true));
75                      parent.appendChild(belongsTo.cloneNode(true));
76                      isFirst = false;
77                  }
78  
79                  parent.removeChild(belongsTo);
80                  parent.removeChild(belongsToSep);
81              }
82          }
83          catch(Exception e)
84          {
85              e.printStackTrace();
86          }
87          return page.toDocument();
88      }
89  
90      private String getAboutURI()
91      {
92          try
93          {
94              String aboutURI = getComms().request.getParameter("aboutURI");
95              if(aboutURI != null)
96              {
97                  String s = Tools.IDtoURI(aboutURI);
98                  return s;
99              }
100         }
101         catch(Exception e)
102         {
103             e.printStackTrace();
104         }
105         return null;
106     }
107 }