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.adapters.doc; 020 021import java.io.Serializable; 022import java.util.HashMap; 023import java.util.List; 024import java.util.Map; 025 026import org.nuxeo.template.XMLSerializer; 027import org.nuxeo.template.api.TemplateInput; 028 029public class TemplateBinding { 030 031 public static final String TEMPLATE_NAME_KEY = "templateName"; 032 033 public static final String TEMPLATE_DATA_KEY = "templateData"; 034 035 public static final String TEMPLATE_ID_KEY = "templateId"; 036 037 public static final String TEMPLATE_USE_BLOB_KEY = "useMainContentAsTemplate"; 038 039 private String name; 040 041 private String templateId; 042 043 private String data; 044 045 private boolean useMainContentAsTemplate; 046 047 public TemplateBinding() { 048 } 049 050 public TemplateBinding(Map<String, Serializable> map) { 051 name = (String) map.get(TEMPLATE_NAME_KEY); 052 templateId = (String) map.get(TEMPLATE_ID_KEY); 053 data = (String) map.get(TEMPLATE_DATA_KEY); 054 if (map.get(TEMPLATE_USE_BLOB_KEY) != null) { 055 useMainContentAsTemplate = (Boolean) map.get(TEMPLATE_USE_BLOB_KEY); 056 } else { 057 useMainContentAsTemplate = false; 058 } 059 } 060 061 public String getName() { 062 return name; 063 } 064 065 public void setName(String name) { 066 this.name = name; 067 } 068 069 public String getTemplateId() { 070 return templateId; 071 } 072 073 public void setTemplateId(String templateId) { 074 this.templateId = templateId; 075 } 076 077 public String getData() { 078 return data; 079 } 080 081 public void setData(String data) { 082 this.data = data; 083 } 084 085 public void setData(List<TemplateInput> params) { 086 String xml = XMLSerializer.serialize(params); 087 setData(xml); 088 } 089 090 public boolean isUseMainContentAsTemplate() { 091 return useMainContentAsTemplate; 092 } 093 094 public void setUseMainContentAsTemplate(boolean useMainContentAsTemplate) { 095 this.useMainContentAsTemplate = useMainContentAsTemplate; 096 } 097 098 public void update(TemplateBinding other) { 099 name = other.name; 100 templateId = other.templateId; 101 data = other.data; 102 useMainContentAsTemplate = other.useMainContentAsTemplate; 103 } 104 105 public Map<String, Serializable> getAsMap() { 106 Map<String, Serializable> map = new HashMap<String, Serializable>(); 107 map.put(TEMPLATE_NAME_KEY, name); 108 map.put(TEMPLATE_ID_KEY, templateId); 109 map.put(TEMPLATE_DATA_KEY, data); 110 map.put(TEMPLATE_USE_BLOB_KEY, useMainContentAsTemplate); 111 return map; 112 } 113}