001package org.nuxeo.template.adapters.doc; 002 003import java.io.Serializable; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import org.nuxeo.template.XMLSerializer; 009import org.nuxeo.template.api.TemplateInput; 010 011public class TemplateBinding { 012 013 public static final String TEMPLATE_NAME_KEY = "templateName"; 014 015 public static final String TEMPLATE_DATA_KEY = "templateData"; 016 017 public static final String TEMPLATE_ID_KEY = "templateId"; 018 019 public static final String TEMPLATE_USE_BLOB_KEY = "useMainContentAsTemplate"; 020 021 private String name; 022 023 private String templateId; 024 025 private String data; 026 027 private boolean useMainContentAsTemplate; 028 029 public TemplateBinding() { 030 } 031 032 public TemplateBinding(Map<String, Serializable> map) { 033 name = (String) map.get(TEMPLATE_NAME_KEY); 034 templateId = (String) map.get(TEMPLATE_ID_KEY); 035 data = (String) map.get(TEMPLATE_DATA_KEY); 036 if (map.get(TEMPLATE_USE_BLOB_KEY) != null) { 037 useMainContentAsTemplate = (Boolean) map.get(TEMPLATE_USE_BLOB_KEY); 038 } else { 039 useMainContentAsTemplate = false; 040 } 041 } 042 043 public String getName() { 044 return name; 045 } 046 047 public void setName(String name) { 048 this.name = name; 049 } 050 051 public String getTemplateId() { 052 return templateId; 053 } 054 055 public void setTemplateId(String templateId) { 056 this.templateId = templateId; 057 } 058 059 public String getData() { 060 return data; 061 } 062 063 public void setData(String data) { 064 this.data = data; 065 } 066 067 public void setData(List<TemplateInput> params) { 068 String xml = XMLSerializer.serialize(params); 069 setData(xml); 070 } 071 072 public boolean isUseMainContentAsTemplate() { 073 return useMainContentAsTemplate; 074 } 075 076 public void setUseMainContentAsTemplate(boolean useMainContentAsTemplate) { 077 this.useMainContentAsTemplate = useMainContentAsTemplate; 078 } 079 080 public void update(TemplateBinding other) { 081 name = other.name; 082 templateId = other.templateId; 083 data = other.data; 084 useMainContentAsTemplate = other.useMainContentAsTemplate; 085 } 086 087 public Map<String, Serializable> getAsMap() { 088 Map<String, Serializable> map = new HashMap<String, Serializable>(); 089 map.put(TEMPLATE_NAME_KEY, name); 090 map.put(TEMPLATE_ID_KEY, templateId); 091 map.put(TEMPLATE_DATA_KEY, data); 092 map.put(TEMPLATE_USE_BLOB_KEY, useMainContentAsTemplate); 093 return map; 094 } 095}