View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.surf.types;
20  
21  import org.dom4j.Document;
22  import org.springframework.extensions.surf.ModelObject;
23  import org.springframework.extensions.surf.ModelPersisterInfo;
24  import org.springframework.extensions.surf.RequestContext;
25  
26  /**
27   * Default content association implementation
28   * 
29   * @author muzquiano
30   */
31  public class ContentAssociationImpl extends AbstractModelObject implements ContentAssociation
32  {
33      /**
34       * Instantiates a new content association for the given XML document
35       * 
36       * @param document the document
37       */
38      public ContentAssociationImpl(String id, ModelPersisterInfo key, Document document)
39      {
40          super(id, key, document);
41      }
42      
43      /* (non-Javadoc)
44       * @see org.alfresco.web.site.model.AbstractModelObject#getTypeName()
45       */
46      public String getTypeId() 
47      {
48          return TYPE_ID;
49      }
50      
51      /* (non-Javadoc)
52       * @see org.alfresco.web.framework.types.ContentAssociation#getSourceId()
53       */
54      public String getSourceId()
55      {
56          return getProperty(PROP_SOURCE_ID);
57      }
58  
59      /* (non-Javadoc)
60       * @see org.alfresco.web.framework.types.ContentAssociation#setSourceId(java.lang.String)
61       */
62      public void setSourceId(String sourceId)
63      {
64          setProperty(PROP_SOURCE_ID, sourceId);
65      }
66  
67      /* (non-Javadoc)
68       * @see org.alfresco.web.framework.types.ContentAssociation#getDestId()
69       */
70      public String getDestId()
71      {
72          return getProperty(PROP_DEST_ID);
73      }
74  
75      /* (non-Javadoc)
76       * @see org.alfresco.web.framework.types.ContentAssociation#setDestId(java.lang.String)
77       */
78      public void setDestId(String destId)
79      {
80          setProperty(PROP_DEST_ID, destId);
81      }
82  
83      /* (non-Javadoc)
84       * @see org.alfresco.web.framework.types.ContentAssociation#getAssociationType()
85       */
86      public String getAssociationType()
87      {
88          return getProperty(PROP_ASSOC_TYPE);
89      }
90  
91      /* (non-Javadoc)
92       * @see org.alfresco.web.framework.types.ContentAssociation#setSourceType(java.lang.String)
93       */
94      public void setSourceType(String sourceType)
95      {
96          setProperty(PROP_SOURCE_TYPE, sourceType);
97      }
98  
99      /* (non-Javadoc)
100      * @see org.alfresco.web.framework.types.ContentAssociation#getSourceType()
101      */
102     public String getSourceType()
103     {
104         return getProperty(PROP_SOURCE_TYPE);
105     }
106 
107     /* (non-Javadoc)
108      * @see org.alfresco.web.framework.types.ContentAssociation#setAssociationType(java.lang.String)
109      */
110     public void setAssociationType(String associationType)
111     {
112         setProperty(PROP_ASSOC_TYPE, associationType);
113     }
114 
115     /* (non-Javadoc)
116      * @see org.alfresco.web.framework.types.ContentAssociation#getFormatId()
117      */
118     public String getFormatId()
119     {
120         return getProperty(PROP_FORMAT_ID);
121     }
122 
123     /* (non-Javadoc)
124      * @see org.alfresco.web.framework.types.ContentAssociation#setFormatId(java.lang.String)
125      */
126     public void setFormatId(String formatId)
127     {
128         setProperty(PROP_FORMAT_ID, formatId);
129     }
130 
131     // Helpers
132 
133     public ModelObject getObject(RequestContext context)
134     {
135         ModelObject modelObject = null;
136         
137         if (isTemplateAssociation())
138         {
139             modelObject = context.getModel().getTemplate(getDestId());            
140         }
141         else if (isPageAssociation())
142         {
143             modelObject = context.getModel().getPage(getDestId());
144         }
145         
146         return modelObject;
147     }
148     
149     public boolean isTemplateAssociation()
150     {
151         return (getAssociationType() == null || "template".equalsIgnoreCase(getAssociationType()));
152     }
153     
154     /**
155      * Checks if is page association.
156      * 
157      * @return true, if is page association
158      */
159     public boolean isPageAssociation()
160     {
161         return ("page".equalsIgnoreCase(getAssociationType()));
162     }
163     
164 }