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.JournalStructure;
23  
24  import java.io.InputStream;
25  
26  /**
27   * <a href="JournalStructureResourceImpl.java.html"><b><i>View Source</i></b>
28   * </a>
29   *
30   * @author Alexander Chow
31   */
32  public class JournalStructureResourceImpl extends BaseResourceImpl {
33  
34      public JournalStructureResourceImpl(
35          JournalStructure structure, String parentPath, String name) {
36  
37          super(
38              parentPath, name, structure.getStructureId(),
39              structure.getCreateDate(), structure.getModifiedDate(),
40              structure.getXsd().length());
41  
42          setModel(structure);
43          setClassName(JournalStructure.class.getName());
44          setPrimaryKey(structure.getPrimaryKey());
45  
46          _structure = structure;
47      }
48  
49      public boolean isCollection() {
50          return false;
51      }
52  
53      public String getContentType() {
54          return ContentTypes.TEXT_XML;
55      }
56  
57      public InputStream getContentAsStream() throws WebDAVException {
58          try {
59              return new UnsyncByteArrayInputStream(
60                  _structure.getXsd().getBytes(StringPool.UTF8));
61          }
62          catch (Exception e) {
63              throw new WebDAVException(e);
64          }
65      }
66  
67      private JournalStructure _structure;
68  
69  }