1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
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  }