View Javadoc

1   /**
2    * This file Copyright (c) 2009-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.templatingkit.dam;
35  
36  import info.magnolia.dam.DamNodeTypes;
37  import info.magnolia.dam.asset.AbstractDamAsset;
38  import info.magnolia.dam.asset.Asset;
39  import info.magnolia.dam.asset.DamAsset;
40  import info.magnolia.dam.asset.DamException;
41  import info.magnolia.dam.asset.variation.NoSuchVariationException;
42  import info.magnolia.jcr.util.PropertyUtil;
43  
44  import java.io.InputStream;
45  import java.util.Calendar;
46  
47  import javax.jcr.Node;
48  import javax.jcr.Property;
49  
50  /**
51   * Asset wrapper used by STK.<br>
52   * <pre>
53   * This wrapper override some Asset properties if they are defined on the Content node.<br>
54   * If the property is not present in the content node, return the-one defined on the Asset. <br>
55   * Overrided properties:
56   *  - caption
57   *  - title
58   *  - description
59   *  - copyright
60   * </pre>
61   */
62  public class STKAssetWrapper extends AbstractDamAsset {
63  
64      private DamAsset asset;
65      private Node contentNode;
66  
67      public STKAssetWrapper(DamAsset asset, Node contentNode) {
68          this.asset = asset;
69          this.contentNode = contentNode;
70      }
71  
72      @Override
73      public String getCaption() {
74          return PropertyUtil.getString(contentNode, DamNodeTypes.Asset.CAPTION, asset.getCaption());
75      }
76  
77      @Override
78      public String getTitle() {
79          return PropertyUtil.getString(contentNode, DamNodeTypes.Asset.TITLE, asset.getTitle());
80      }
81  
82      @Override
83      public String getDescription() {
84          return PropertyUtil.getString(contentNode, DamNodeTypes.Asset.DESCRIPTION, asset.getDescription());
85      }
86  
87      @Override
88      public String getCopyright() {
89          return PropertyUtil.getString(contentNode, DamNodeTypes.Asset.COPYRIGHT, asset.getCopyright());
90      }
91  
92      @Override
93      public Asset getVariation(String variationName) throws NoSuchVariationException {
94          return asset.getVariation(variationName);
95      }
96  
97      @Override
98      public String getName() {
99          return asset.getName();
100     }
101 
102     @Override
103     public String getLink() throws DamException {
104         return asset.getLink();
105     }
106 
107     @Override
108     public int getHeight() {
109         return asset.getHeight();
110     }
111 
112     @Override
113     public int getWidth() {
114         return asset.getWidth();
115     }
116 
117     @Override
118     public long getFileSize() {
119         return asset.getFileSize();
120     }
121 
122     @Override
123     public String getFileExtension() {
124         return asset.getFileExtension();
125     }
126 
127     @Override
128     public String getFileName() {
129         return asset.getFileName();
130     }
131 
132     @Override
133     public String getMimeType() {
134         return asset.getMimeType();
135     }
136 
137     @Override
138     public Calendar getLastModified() {
139         return asset.getLastModified();
140     }
141 
142     @Override
143     public Property getBinaryData() {
144         return asset.getBinaryData();
145     }
146 
147     @Override
148     public InputStream getContentStream() {
149         return asset.getContentStream();
150     }
151 }