001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Wojciech Sulejman
016 *     Vladimir Pasquier <vpasquier@nuxeo.com>
017 */
018
019package org.nuxeo.ecm.platform.signature.core.sign;
020
021import org.nuxeo.common.xmap.annotation.XNode;
022import org.nuxeo.common.xmap.annotation.XObject;
023import org.nuxeo.ecm.platform.signature.api.sign.SignatureAppearanceFactory;
024
025/**
026 * Provides default values for signing services.
027 *
028 * @author <a href="mailto:ws@nuxeo.com">Wojciech Sulejman</a>
029 */
030@XObject("configuration")
031public class SignatureDescriptor {
032
033    @XNode("@id")
034    protected String id;
035
036    @XNode("reason")
037    protected String reason;
038
039    @XNode("layout")
040    protected SignatureLayout signatureLayout;
041
042    @XNode("appearanceFactory")
043    protected SignatureAppearance signatureAppearance = null;
044
045    @XObject("appearanceFactory")
046    public static class SignatureAppearance {
047        @XNode("@class")
048        protected Class<? extends SignatureAppearanceFactory> appearanceClass;
049
050        public Class<? extends SignatureAppearanceFactory> getAppearanceClass() {
051            return appearanceClass;
052        }
053    }
054    
055    /**
056     * @since 5.8 Definition of the layout applied on signatures.
057     */
058    @XObject("layout")
059    public static class SignatureLayout implements org.nuxeo.ecm.platform.signature.api.sign.SignatureLayout {
060
061        @XNode("@lines")
062        protected Integer lines = 5;
063
064        @XNode("@columns")
065        protected Integer columns = 3;
066
067        @XNode("@startLine")
068        protected Integer startLine = 1;
069
070        @XNode("@startColumn")
071        protected Integer startColumn = 1;
072
073        @XNode("@textSize")
074        protected Integer textSize = 9;
075
076        @Override
077        public Integer getLines() {
078            return lines;
079        }
080
081        @Override
082        public Integer getColumns() {
083            return columns;
084        }
085
086        @Override
087        public Integer getStartLine() {
088            return startLine;
089        }
090
091        @Override
092        public Integer getStartColumn() {
093            return startColumn;
094        }
095
096        @Override
097        public Integer getTextSize() {
098            return textSize;
099        }
100    }
101
102    public SignatureLayout getSignatureLayout() {
103        return signatureLayout;
104    }
105
106    public String getReason() {
107        return reason;
108    }
109
110    public void setReason(String reason) {
111        this.reason = reason;
112    }
113
114    public SignatureAppearanceFactory getAppearanceFatory() throws InstantiationException, IllegalAccessException {
115        Class<? extends SignatureAppearanceFactory> appearanceClass = null;
116        if (signatureAppearance != null) {
117            appearanceClass = signatureAppearance.getAppearanceClass();
118        }
119        if (appearanceClass == null) {
120            return new DefaultSignatureAppearanceFactory();
121        }
122        return appearanceClass.newInstance();
123    }
124
125    public String getId() {
126        return id;
127    }
128
129    private boolean remove;
130
131    @XNode("removeExtension")
132    protected void setRemoveExtension(boolean remove) {
133        this.remove = remove;
134    }
135
136    public boolean getRemoveExtension() {
137        return remove;
138    }
139
140}