001/* 002 * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Vladimir Pasquier <vpasquier@nuxeo.com> 011 * Antoine Taillefer <ataillefer@nuxeo.com> 012 * 013 */ 014 015package org.nuxeo.ecm.platform.groups.audit.service; 016 017import java.io.File; 018import java.io.IOException; 019import java.io.Serializable; 020import java.net.URL; 021 022import org.apache.commons.io.FileUtils; 023import org.nuxeo.common.xmap.annotation.XNode; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.core.api.NuxeoException; 026 027/** 028 * XMap descriptor for contributed export service factory (and template). 029 * 030 * @since 5.7 031 */ 032@XObject("ExcelExport") 033public class ExcelExportServiceDescriptor implements Serializable { 034 035 private static final long serialVersionUID = 1L; 036 037 @XNode("@name") 038 protected String name; 039 040 @XNode("@factoryClass") 041 private Class<? extends ExcelExportFactory> factoryClass; 042 043 private File template; 044 045 public String getName() { 046 return name; 047 } 048 049 public File getTemplate() { 050 return template; 051 } 052 053 @XNode("@template") 054 public void setTemplate(String templatePath) { 055 URL templateUrl = ExcelExportServiceDescriptor.class.getResource("/" + templatePath); 056 try { 057 template = File.createTempFile("ExcelTemplate", ".xls"); 058 template.createNewFile(); 059 FileUtils.copyURLToFile(templateUrl, template); 060 } catch (IOException e) { 061 } 062 } 063 064 public ExcelExportFactory getFactory() { 065 if (factoryClass != null) { 066 try { 067 return (ExcelExportFactory) factoryClass.newInstance(); 068 } catch (ReflectiveOperationException e) { 069 throw new NuxeoException(e); 070 } 071 } 072 return null; 073 } 074 075}