1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.document.service.attributes;
35
36 import fr.paris.lutece.plugins.document.business.Document;
37 import fr.paris.lutece.plugins.document.business.attributes.DocumentAttribute;
38 import fr.paris.lutece.util.xml.XmlUtil;
39
40 import org.apache.commons.lang3.StringUtils;
41
42
43
44
45
46 public class FileManager extends DefaultManager
47 {
48 private static final String TAG_FILE_RESOURCE = "file-resource";
49 private static final String TAG_DOCUMENT_ID = "resource-document-id";
50 private static final String TAG_ATTRIBUTE_ID = "resource-attribute-id";
51 private static final String TAG_CONTENT_TYPE = "resource-content-type";
52 private static final String TAG_FILE_SIZE = "file-size";
53 private static final String TEMPLATE_CREATE_ATTRIBUTE = "admin/plugins/document/attributes/create_file.html";
54 private static final String TEMPLATE_MODIFY_ATTRIBUTE = "admin/plugins/document/attributes/modify_file.html";
55 private static final String TEMPLATE_CREATE_PARAMETERS_ATTRIBUTE = "admin/plugins/document/attributes/create_parameters_file.html";
56 private static final String TEMPLATE_MODIFY_PARAMETERS_ATTRIBUTE = "admin/plugins/document/attributes/modify_parameters_file.html";
57
58
59
60
61
62 protected String getCreateTemplate( )
63 {
64 return TEMPLATE_CREATE_ATTRIBUTE;
65 }
66
67
68
69
70
71 protected String getModifyTemplate( )
72 {
73 return TEMPLATE_MODIFY_ATTRIBUTE;
74 }
75
76
77
78
79
80 protected String getCreateParametersTemplate( )
81 {
82 return TEMPLATE_CREATE_PARAMETERS_ATTRIBUTE;
83 }
84
85
86
87
88
89 protected String getModifyParametersTemplate( )
90 {
91 return TEMPLATE_MODIFY_PARAMETERS_ATTRIBUTE;
92 }
93
94
95
96
97
98
99
100
101 public String getAttributeXmlValue( Document document, DocumentAttribute attribute )
102 {
103 StringBuffer sbXml = new StringBuffer( );
104
105 if ( ( attribute.getBinaryValue( ) != null ) && ( attribute.getBinaryValue( ).length != 0 ) )
106 {
107 XmlUtil.beginElement( sbXml, TAG_FILE_RESOURCE );
108 XmlUtil.addElement( sbXml, TAG_DOCUMENT_ID, document.getId( ) );
109 XmlUtil.addElement( sbXml, TAG_ATTRIBUTE_ID, attribute.getId( ) );
110 XmlUtil.addElement( sbXml, TAG_CONTENT_TYPE, attribute.getValueContentType( ) );
111 XmlUtil.endElement( sbXml, TAG_FILE_RESOURCE );
112
113 XmlUtil.addElement( sbXml, TAG_FILE_SIZE, attribute.getBinaryValue( ).length );
114
115 return sbXml.toString( );
116 }
117
118 return StringUtils.EMPTY;
119 }
120 }