001/*
002 * (C) Copyright 2006-2016 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 *     Vladimir Pasquier <vpasquier@nuxeo.com>
018 *     Antoine Taillefer <ataillefer@nuxeo.com>
019 *
020 */
021
022package org.nuxeo.ecm.platform.groups.audit.service;
023
024import java.io.File;
025import java.io.IOException;
026import java.io.Serializable;
027import java.net.URL;
028
029import org.apache.commons.io.FileUtils;
030
031import org.nuxeo.common.xmap.annotation.XNode;
032import org.nuxeo.common.xmap.annotation.XObject;
033import org.nuxeo.ecm.core.api.NuxeoException;
034import org.nuxeo.runtime.api.Framework;
035
036/**
037 * XMap descriptor for contributed export service factory (and template).
038 *
039 * @since 5.7
040 */
041@XObject("ExcelExport")
042public class ExcelExportServiceDescriptor implements Serializable {
043
044    private static final long serialVersionUID = 1L;
045
046    @XNode("@name")
047    protected String name;
048
049    @XNode("@factoryClass")
050    private Class<? extends ExcelExportFactory> factoryClass;
051
052    private File template;
053
054    public String getName() {
055        return name;
056    }
057
058    public File getTemplate() {
059        return template;
060    }
061
062    @XNode("@template")
063    public void setTemplate(String templatePath) {
064        URL templateUrl = ExcelExportServiceDescriptor.class.getResource("/" + templatePath);
065        try {
066            template = Framework.createTempFile("ExcelTemplate", ".xls");
067            template.createNewFile();
068            FileUtils.copyURLToFile(templateUrl, template);
069        } catch (IOException e) {
070        }
071    }
072
073    public ExcelExportFactory getFactory() {
074        if (factoryClass != null) {
075            try {
076                return factoryClass.newInstance();
077            } catch (ReflectiveOperationException e) {
078                throw new NuxeoException(e);
079            }
080        }
081        return null;
082    }
083
084}