001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.webdav;
016    
017    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
018    import com.liferay.portal.kernel.util.ContentTypes;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.webdav.BaseResourceImpl;
021    import com.liferay.portal.kernel.webdav.WebDAVException;
022    import com.liferay.portlet.journal.model.JournalStructure;
023    
024    import java.io.InputStream;
025    
026    /**
027     * @author Alexander Chow
028     */
029    public class JournalStructureResourceImpl extends BaseResourceImpl {
030    
031            public JournalStructureResourceImpl(
032                    JournalStructure structure, String parentPath, String name) {
033    
034                    super(
035                            parentPath, name, structure.getStructureId(),
036                            structure.getCreateDate(), structure.getModifiedDate(),
037                            structure.getXsd().length());
038    
039                    setModel(structure);
040                    setClassName(JournalStructure.class.getName());
041                    setPrimaryKey(structure.getPrimaryKey());
042    
043                    _structure = structure;
044            }
045    
046            public boolean isCollection() {
047                    return false;
048            }
049    
050            public String getContentType() {
051                    return ContentTypes.TEXT_XML;
052            }
053    
054            public InputStream getContentAsStream() throws WebDAVException {
055                    try {
056                            return new UnsyncByteArrayInputStream(
057                                    _structure.getXsd().getBytes(StringPool.UTF8));
058                    }
059                    catch (Exception e) {
060                            throw new WebDAVException(e);
061                    }
062            }
063    
064            private JournalStructure _structure;
065    
066    }