001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.template.xdocreport.jaxrs; 020 021import org.nuxeo.template.api.adapters.TemplateSourceDocument; 022 023import fr.opensagres.xdocreport.remoting.resources.domain.Resource; 024import fr.opensagres.xdocreport.remoting.resources.domain.ResourceType; 025 026/** 027 * @author <a href="mailto:[email protected]">Tiry</a> 028 */ 029public class ResourceWrapper { 030 031 public static Resource wrap(TemplateSourceDocument srcDocument) { 032 Resource rs = new Resource(); 033 rs.setType(ResourceType.TEMPLATE); 034 035 rs.setName(srcDocument.getName()); 036 rs.setId(srcDocument.getId()); 037 038 Resource fileResource = new NonRecursiveResource(); 039 fileResource.setName(srcDocument.getFileName()); 040 fileResource.setId(srcDocument.getId()); 041 fileResource.setType(ResourceType.DOCUMENT); 042 043 Resource METAResource = new NonRecursiveResource(); 044 METAResource.setName("META-INF"); 045 METAResource.setId(srcDocument.getId() + "/META-INF"); 046 METAResource.setType(ResourceType.CATEGORY); 047 048 Resource fieldResource = new NonRecursiveResource(); 049 fieldResource.setName(srcDocument.getName() + ".fields.xml"); 050 fieldResource.setId(srcDocument.getId() + ".fields.xml"); 051 fieldResource.setType(ResourceType.DOCUMENT); 052 053 METAResource.getChildren().add(fieldResource); 054 055 rs.getChildren().add(fileResource); 056 rs.getChildren().add(METAResource); 057 058 return rs; 059 } 060}