001    /**
002     * Copyright (c) 2000-2013 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.JournalTemplate;
023    
024    import java.io.InputStream;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class JournalTemplateResourceImpl extends BaseResourceImpl {
030    
031            public JournalTemplateResourceImpl(
032                    JournalTemplate template, String parentPath, String name) {
033    
034                    super(
035                            parentPath, name, template.getTemplateId(),
036                            template.getCreateDate(), template.getModifiedDate(),
037                            template.getXsl().length());
038    
039                    setModel(template);
040                    setClassName(JournalTemplate.class.getName());
041                    setPrimaryKey(template.getPrimaryKey());
042    
043                    _template = template;
044            }
045    
046            @Override
047            public InputStream getContentAsStream() throws WebDAVException {
048                    try {
049                            return new UnsyncByteArrayInputStream(
050                                    _template.getXsl().getBytes(StringPool.UTF8));
051                    }
052                    catch (Exception e) {
053                            throw new WebDAVException(e);
054                    }
055            }
056    
057            @Override
058            public String getContentType() {
059                    return ContentTypes.TEXT_XML;
060            }
061    
062            @Override
063            public boolean isCollection() {
064                    return false;
065            }
066    
067            private JournalTemplate _template;
068    
069    }