1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journal.webdav;
21  
22  import com.liferay.portal.kernel.util.ContentTypes;
23  import com.liferay.portal.kernel.util.StringPool;
24  import com.liferay.portal.webdav.BaseResourceImpl;
25  import com.liferay.portal.webdav.WebDAVException;
26  import com.liferay.portlet.journal.model.JournalTemplate;
27  
28  import java.io.ByteArrayInputStream;
29  import java.io.InputStream;
30  
31  /**
32   * <a href="JournalTemplateResourceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class JournalTemplateResourceImpl extends BaseResourceImpl {
38  
39      public JournalTemplateResourceImpl(
40          JournalTemplate template, String parentPath, String name) {
41  
42          super(
43              parentPath, name, template.getTemplateId(),
44              template.getCreateDate(), template.getModifiedDate(),
45              template.getXsl().length());
46  
47          setModel(template);
48          setClassName(JournalTemplate.class.getName());
49          setPrimaryKey(template.getPrimaryKey());
50  
51          _template = template;
52      }
53  
54      public boolean isCollection() {
55          return false;
56      }
57  
58      public String getContentType() {
59          return ContentTypes.TEXT_XML;
60      }
61  
62      public InputStream getContentAsStream() throws WebDAVException {
63          try {
64              return new ByteArrayInputStream(
65                  _template.getXsl().getBytes(StringPool.UTF8));
66          }
67          catch (Exception e) {
68              throw new WebDAVException(e);
69          }
70      }
71  
72      private JournalTemplate _template;
73  
74  }