001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.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.dynamicdatamapping.model.DDMStructure;
023    
024    import java.io.InputStream;
025    
026    /**
027     * @author Juan Fern??ndez
028     */
029    public class DDMStructureResourceImpl extends BaseResourceImpl {
030    
031            public DDMStructureResourceImpl(
032                    DDMStructure structure, String parentPath, String name) {
033    
034                    super(
035                            parentPath, name,
036                            structure.getName(structure.getDefaultLanguageId()),
037                            structure.getCreateDate(), structure.getModifiedDate(),
038                            structure.getXsd().length());
039    
040                    setModel(structure);
041                    setClassName(DDMStructure.class.getName());
042                    setPrimaryKey(structure.getPrimaryKey());
043    
044                    _structure = structure;
045            }
046    
047            @Override
048            public InputStream getContentAsStream() throws WebDAVException {
049                    try {
050                            return new UnsyncByteArrayInputStream(
051                                    _structure.getXsd().getBytes(StringPool.UTF8));
052                    }
053                    catch (Exception e) {
054                            throw new WebDAVException(e);
055                    }
056            }
057    
058            @Override
059            public String getContentType() {
060                    return ContentTypes.TEXT_XML;
061            }
062    
063            @Override
064            public boolean isCollection() {
065                    return false;
066            }
067    
068            private DDMStructure _structure;
069    
070    }