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.content;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import olr.rdf.Attribute;
24  import olr.rdf.Definitions;
25  import olr.rdf.Resource;
26  import olr.rdf.Tools;
27  import olr.rdf.util.SortedStringList;
28  import olr.statementpool.OlrStatementPool;
29  import olr.toolbar.ToolbarSession;
30  
31  /*** 
32   * @version $Id: ContentModel.java,v 1.11 2004/08/04 12:11:19 roku Exp $
33   */
34  public final class ContentModel {
35      private final OlrStatementPool statementPool;
36  
37      private final ToolbarSession toolbarSession;
38  
39      protected String aboutURI;
40  
41      protected List attributes;
42  
43      private SortedStringList availableProperties;
44  
45      /*** 
46       * Initializes an instance of this class.
47       * @param aboutURI
48       * @param statementPool
49       * @param toolbarSession
50       */
51      public ContentModel(String aboutURI, OlrStatementPool statementPool,
52              ToolbarSession toolbarSession) {
53          this.statementPool = statementPool;
54          this.toolbarSession = toolbarSession;
55          attributes = new SortedContentAttributeList();
56          availableProperties = new SortedStringList();
57          aboutURI = Tools.correctURI(aboutURI);
58          this.aboutURI = aboutURI;
59          List attribs = getStatementPool().getAttributesAbout(aboutURI);
60          for (Iterator it = attribs.iterator(); it.hasNext(); attributes.add(new ContentAttribute(
61                  (Attribute) it.next(), statementPool, toolbarSession)))
62              ;
63          availableProperties.addAll(getStatementPool().getAvailableProperties4Resource(aboutURI));
64          availableProperties.remove(Definitions.RDF_TYPE);
65      }
66  
67      public String getAboutURI() {
68          return aboutURI;
69      }
70  
71      public String getTitle() {
72          Resource resource = getStatementPool().getResource(aboutURI);
73          if (resource != null)
74              return resource.getTitle();
75          else
76              return "<untitled>";
77      }
78  
79      public String getType() {
80          Resource resource = getStatementPool().getResource(aboutURI);
81          if (resource != null)
82              return resource.getType();
83          else
84              return "";
85      }
86  
87      public List getAvailableProperties() {
88          return availableProperties;
89      }
90  
91      public final List getContentAttributes() {
92          return attributes;
93      }
94  
95      public void addProperty(String property) {
96          Attribute attribute = new Attribute(property, "");
97          attributes.add(new ContentAttribute(attribute, getStatementPool(), getToolbarSession()));
98          getStatementPool().addAttributeAbout(getAboutURI(), attribute);
99      }
100 
101     public void removeAttribute(int index) {
102         if (index >= 0 && index < attributes.size()) {
103             getStatementPool().removeAttributeAbout(getAboutURI(),
104                     ((ContentAttribute) attributes.get(index)).getAttribute());
105             attributes.remove(index);
106         }
107     }
108 
109     private OlrStatementPool getStatementPool() {
110         return this.statementPool;
111     }
112 
113     /***
114      * @return Returns the toolbarSession.
115      */
116     private ToolbarSession getToolbarSession() {
117         return toolbarSession;
118     }
119 }