1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.webdav;
16  
17  import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
18  import com.liferay.portal.kernel.util.ContentTypes;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.webdav.BaseResourceImpl;
21  import com.liferay.portal.webdav.WebDAVException;
22  import com.liferay.portlet.journal.model.JournalTemplate;
23  
24  import java.io.InputStream;
25  
26  /**
27   * <a href="JournalTemplateResourceImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class JournalTemplateResourceImpl extends BaseResourceImpl {
32  
33      public JournalTemplateResourceImpl(
34          JournalTemplate template, String parentPath, String name) {
35  
36          super(
37              parentPath, name, template.getTemplateId(),
38              template.getCreateDate(), template.getModifiedDate(),
39              template.getXsl().length());
40  
41          setModel(template);
42          setClassName(JournalTemplate.class.getName());
43          setPrimaryKey(template.getPrimaryKey());
44  
45          _template = template;
46      }
47  
48      public boolean isCollection() {
49          return false;
50      }
51  
52      public String getContentType() {
53          return ContentTypes.TEXT_XML;
54      }
55  
56      public InputStream getContentAsStream() throws WebDAVException {
57          try {
58              return new UnsyncByteArrayInputStream(
59                  _template.getXsl().getBytes(StringPool.UTF8));
60          }
61          catch (Exception e) {
62              throw new WebDAVException(e);
63          }
64      }
65  
66      private JournalTemplate _template;
67  
68  }