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.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    }