View Javadoc
1   /**
2    * This file Copyright (c) 2014-2015 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.dam.api;
35  
36  import info.magnolia.dam.api.metadata.AssetMetadata;
37  import java.io.InputStream;
38  import java.util.Calendar;
39  
40  /**
41   * TODO : do we need this ? If so, maybe call it AssetWrapper to be consistent.
42   * I suspect it is/was only needed because of StkAssetWrapper, and that specific wrapper might actually be wrapping a Rendition rather than an asset . . .
43   */
44  public abstract class AssetDecorator implements Asset {
45  
46      public static Asset unwrap(Asset asset) {
47          while (asset instanceof AssetDecorator) {
48              asset = ((AssetDecorator) asset).getDecorated();
49          }
50          return asset;
51      }
52  
53      private final Asset decorated;
54  
55      protected AssetDecorator(Asset decorated) {
56          this.decorated = decorated;
57      }
58  
59      public Asset getDecorated() {
60          return decorated;
61      }
62  
63      @Override
64      public ItemKey getItemKey() {
65          return decorated.getItemKey();
66      }
67  
68      @Override
69      public AssetProvider getAssetProvider() {
70          return decorated.getAssetProvider();
71      }
72  
73      @Override
74      public String getLink() {
75          return decorated.getLink();
76      }
77  
78      @Override
79      public String getTitle() {
80          return decorated.getTitle();
81      }
82  
83      @Override
84      public String getSubject() {
85          return decorated.getSubject();
86      }
87  
88      @Override
89      public String getDescription() {
90          return decorated.getDescription();
91      }
92  
93      @Override
94      public String getCaption() {
95          return decorated.getCaption();
96      }
97  
98      @Override
99      public String getLanguage() {
100         return decorated.getLanguage();
101     }
102 
103     @Override
104     public String getCopyright() {
105         return decorated.getCopyright();
106     }
107 
108     @Override
109     public String getComment() {
110         return decorated.getComment();
111     }
112 
113     @Override
114     public Calendar getCreated() {
115         return decorated.getCreated();
116     }
117 
118     @Override
119     public Calendar getLastModified() {
120         return decorated.getLastModified();
121     }
122 
123     @Override
124     public <M extends AssetMetadata> M getMetadata(Class<M> metaDataType) {
125         return decorated.getMetadata(metaDataType);
126     }
127 
128     @Override
129     public String getMimeType() {
130         return decorated.getMimeType();
131     }
132 
133     @Override
134     public long getFileSize() {
135         return decorated.getFileSize();
136     }
137 
138     @Override
139     public InputStream getContentStream() {
140         return decorated.getContentStream();
141     }
142 
143     @Override
144     public String getFileName() {
145         return decorated.getFileName();
146     }
147 
148     @Override
149     public String getPath() {
150         return decorated.getPath();
151     }
152 
153     @Override
154     public String getName() {
155         return decorated.getName();
156     }
157 
158     @Override
159     public Folder getParent() {
160         return decorated.getParent();
161     }
162 
163     @Override
164     public boolean isFolder() {
165         return decorated.isFolder();
166     }
167 
168     @Override
169     public boolean isAsset() {
170         return decorated.isAsset();
171     }
172 
173     @Override
174     public <M extends AssetMetadata> boolean supports(Class<M> metaDataType) {
175         return decorated.supports(metaDataType);
176     }
177 }