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.modules.metadatadublincore.business;
35
36 import fr.paris.lutece.portal.service.util.AppLogService;
37 import fr.paris.lutece.portal.service.util.AppPropertiesService;
38 import fr.paris.lutece.util.xml.XmlUtil;
39
40 import org.apache.commons.digester.Digester;
41 import org.apache.commons.digester.xmlrules.DigesterLoader;
42
43 import org.xml.sax.SAXException;
44
45 import java.io.FileNotFoundException;
46 import java.io.IOException;
47 import java.io.StringReader;
48
49 import java.net.URL;
50
51
52
53
54
55 public class DublinCoreMetadata
56 {
57 private static final String PROPERTY_DEFAULT_TITLE = "document-metadatadublincore.default.title";
58 private static final String PROPERTY_DEFAULT_CREATOR = "document-metadatadublincore.default.creator";
59 private static final String PROPERTY_DEFAULT_SUBJECT = "document-metadatadublincore.default.subject";
60 private static final String PROPERTY_DEFAULT_DESCRIPTION = "document-metadatadublincore.default.description";
61 private static final String PROPERTY_DEFAULT_PUBLISHER = "document-metadatadublincore.default.publisher";
62 private static final String PROPERTY_DEFAULT_CONTRIBUTOR = "document-metadatadublincore.default.contributor";
63 private static final String PROPERTY_DEFAULT_DATE = "document-metadatadublincore.default.date";
64 private static final String PROPERTY_DEFAULT_TYPE = "document-metadatadublincore.default.type";
65 private static final String PROPERTY_DEFAULT_FORMAT = "document-metadatadublincore.default.format";
66 private static final String PROPERTY_DEFAULT_IDENTIFIER = "document-metadatadublincore.default.identifier";
67 private static final String PROPERTY_DEFAULT_SOURCE = "document-metadatadublincore.default.source";
68 private static final String PROPERTY_DEFAULT_LANGUAGE = "document-metadatadublincore.default.language";
69 private static final String PROPERTY_DEFAULT_RELATION = "document-metadatadublincore.default.relation";
70 private static final String PROPERTY_DEFAULT_COVERAGE = "document-metadatadublincore.default.coverage";
71 private static final String PROPERTY_DEFAULT_RIGTHS = "document-metadatadublincore.default.rigths";
72 private static final String FILE_RULES = "/fr/paris/lutece/plugins/document/modules/metadatadublincore/business/dublincore-digester-rules.xml";
73
74
75 private String _strTitle;
76 private String _strCreator;
77 private String _strSubject;
78 private String _strDescription;
79 private String _strPublisher;
80 private String _strContributor;
81 private String _strDate;
82 private String _strType;
83 private String _strFormat;
84 private String _strIdentifier;
85 private String _strSource;
86 private String _strLanguage;
87 private String _strRelation;
88 private String _strCoverage;
89 private String _strRights;
90
91
92
93
94 public DublinCoreMetadata( )
95 {
96 _strTitle = AppPropertiesService.getProperty( PROPERTY_DEFAULT_TITLE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_TITLE ) : "";
97 _strCreator = AppPropertiesService.getProperty( PROPERTY_DEFAULT_CREATOR ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_CREATOR ) : "";
98 _strSubject = AppPropertiesService.getProperty( PROPERTY_DEFAULT_SUBJECT ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_SUBJECT ) : "";
99 _strDescription = AppPropertiesService.getProperty( PROPERTY_DEFAULT_DESCRIPTION ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_DESCRIPTION ) : "";
100 _strPublisher = AppPropertiesService.getProperty( PROPERTY_DEFAULT_PUBLISHER ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_PUBLISHER ) : "";
101 _strContributor = AppPropertiesService.getProperty( PROPERTY_DEFAULT_CONTRIBUTOR ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_CONTRIBUTOR ) : "";
102 _strDate = AppPropertiesService.getProperty( PROPERTY_DEFAULT_DATE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_DATE ) : "";
103 _strType = AppPropertiesService.getProperty( PROPERTY_DEFAULT_TYPE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_TYPE ) : "";
104 _strFormat = AppPropertiesService.getProperty( PROPERTY_DEFAULT_FORMAT ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_FORMAT ) : "";
105 _strIdentifier = AppPropertiesService.getProperty( PROPERTY_DEFAULT_IDENTIFIER ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_IDENTIFIER ) : "";
106 _strSource = AppPropertiesService.getProperty( PROPERTY_DEFAULT_SOURCE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_SOURCE ) : "";
107 _strLanguage = AppPropertiesService.getProperty( PROPERTY_DEFAULT_LANGUAGE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_LANGUAGE ) : "";
108 _strRelation = AppPropertiesService.getProperty( PROPERTY_DEFAULT_RELATION ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_RELATION ) : "";
109 _strCoverage = AppPropertiesService.getProperty( PROPERTY_DEFAULT_COVERAGE ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_COVERAGE ) : "";
110 _strRights = AppPropertiesService.getProperty( PROPERTY_DEFAULT_RIGTHS ) != null ? AppPropertiesService.getProperty( PROPERTY_DEFAULT_RIGTHS ) : "";
111 }
112
113
114
115
116
117 public String getTitle( )
118 {
119 return _strTitle;
120 }
121
122
123
124
125
126 public void setTitle( String strTitle )
127 {
128 _strTitle = strTitle;
129 }
130
131
132
133
134
135 public String getCreator( )
136 {
137 return _strCreator;
138 }
139
140
141
142
143
144 public void setCreator( String strCreator )
145 {
146 _strCreator = strCreator;
147 }
148
149
150
151
152
153 public String getSubject( )
154 {
155 return _strSubject;
156 }
157
158
159
160
161
162 public void setSubject( String strSubject )
163 {
164 _strSubject = strSubject;
165 }
166
167
168
169
170
171 public String getDescription( )
172 {
173 return _strDescription;
174 }
175
176
177
178
179
180 public void setDescription( String strDescription )
181 {
182 _strDescription = strDescription;
183 }
184
185
186
187
188
189 public String getPublisher( )
190 {
191 return _strPublisher;
192 }
193
194
195
196
197
198 public void setPublisher( String strPublisher )
199 {
200 _strPublisher = strPublisher;
201 }
202
203
204
205
206
207 public String getContributor( )
208 {
209 return _strContributor;
210 }
211
212
213
214
215
216 public void setContributor( String strContributor )
217 {
218 _strContributor = strContributor;
219 }
220
221
222
223
224
225 public String getDate( )
226 {
227 return _strDate;
228 }
229
230
231
232
233
234 public void setDate( String strDate )
235 {
236 _strDate = strDate;
237 }
238
239
240
241
242
243 public String getType( )
244 {
245 return _strType;
246 }
247
248
249
250
251
252 public void setType( String strType )
253 {
254 _strType = strType;
255 }
256
257
258
259
260
261 public String getFormat( )
262 {
263 return _strFormat;
264 }
265
266
267
268
269
270 public void setFormat( String strFormat )
271 {
272 _strFormat = strFormat;
273 }
274
275
276
277
278
279 public String getIdentifier( )
280 {
281 return _strIdentifier;
282 }
283
284
285
286
287
288 public void setIdentifier( String strIdentifier )
289 {
290 _strIdentifier = strIdentifier;
291 }
292
293
294
295
296
297 public String getSource( )
298 {
299 return _strSource;
300 }
301
302
303
304
305
306 public void setSource( String strSource )
307 {
308 _strSource = strSource;
309 }
310
311
312
313
314
315 public String getLanguage( )
316 {
317 return _strLanguage;
318 }
319
320
321
322
323
324 public void setLanguage( String strLanguage )
325 {
326 _strLanguage = strLanguage;
327 }
328
329
330
331
332
333 public String getRelation( )
334 {
335 return _strRelation;
336 }
337
338
339
340
341
342 public void setRelation( String strRelation )
343 {
344 _strRelation = strRelation;
345 }
346
347
348
349
350
351 public String getCoverage( )
352 {
353 return _strCoverage;
354 }
355
356
357
358
359
360 public void setCoverage( String strCoverage )
361 {
362 _strCoverage = strCoverage;
363 }
364
365
366
367
368
369 public String getRights( )
370 {
371 return _strRights;
372 }
373
374
375
376
377
378 public void setRights( String strRights )
379 {
380 _strRights = strRights;
381 }
382
383
384
385
386
387 public String getXml( )
388 {
389 StringBuffer sbXml = new StringBuffer( );
390 XmlUtil.beginElement( sbXml, "metadata" );
391
392 if ( ( _strTitle != null ) && ( !_strTitle.equals( "" ) ) )
393 {
394 XmlUtil.addElement( sbXml, "title", _strTitle );
395 }
396
397 if ( ( _strCreator != null ) && ( !_strCreator.equals( "" ) ) )
398 {
399 XmlUtil.addElement( sbXml, "creator", _strCreator );
400 }
401
402 if ( ( _strSubject != null ) && ( !_strSubject.equals( "" ) ) )
403 {
404 XmlUtil.addElement( sbXml, "subject", _strSubject );
405 }
406
407 if ( ( _strDescription != null ) && ( !_strDescription.equals( "" ) ) )
408 {
409 XmlUtil.addElement( sbXml, "description", _strDescription );
410 }
411
412 if ( ( _strPublisher != null ) && ( !_strPublisher.equals( "" ) ) )
413 {
414 XmlUtil.addElement( sbXml, "publisher", _strPublisher );
415 }
416
417 if ( ( _strContributor != null ) && ( !_strContributor.equals( "" ) ) )
418 {
419 XmlUtil.addElement( sbXml, "contributor", _strContributor );
420 }
421
422 if ( ( _strDate != null ) && ( !_strDate.equals( "" ) ) )
423 {
424 XmlUtil.addElement( sbXml, "date", _strDate );
425 }
426
427 if ( ( _strType != null ) && ( !_strType.equals( "" ) ) )
428 {
429 XmlUtil.addElement( sbXml, "type", _strType );
430 }
431
432 if ( ( _strFormat != null ) && ( !_strFormat.equals( "" ) ) )
433 {
434 XmlUtil.addElement( sbXml, "format", _strFormat );
435 }
436
437 if ( ( _strIdentifier != null ) && ( !_strIdentifier.equals( "" ) ) )
438 {
439 XmlUtil.addElement( sbXml, "identifier", _strIdentifier );
440 }
441
442 if ( ( _strSource != null ) && ( !_strSource.equals( "" ) ) )
443 {
444 XmlUtil.addElement( sbXml, "source", _strSource );
445 }
446
447 if ( ( _strLanguage != null ) && ( !_strLanguage.equals( "" ) ) )
448 {
449 XmlUtil.addElement( sbXml, "language", _strLanguage );
450 }
451
452 if ( ( _strRelation != null ) && ( !_strRelation.equals( "" ) ) )
453 {
454 XmlUtil.addElement( sbXml, "relation", _strRelation );
455 }
456
457 if ( ( _strContributor != null ) && ( !_strContributor.equals( "" ) ) )
458 {
459 XmlUtil.addElement( sbXml, "coverage", _strCoverage );
460 }
461
462 if ( ( _strRights != null ) && ( !_strRights.equals( "" ) ) )
463 {
464 XmlUtil.addElement( sbXml, "rights", _strRights );
465 }
466
467 XmlUtil.endElement( sbXml, "metadata" );
468
469 return sbXml.toString( );
470 }
471
472
473
474
475
476 public void load( String strXmlData )
477 {
478
479 URL rules = getClass( ).getResource( FILE_RULES );
480 Digester digester = DigesterLoader.createDigester( rules );
481
482
483 digester.push( this );
484
485 try
486 {
487 if ( strXmlData != null )
488 {
489 StringReader sr = new StringReader( strXmlData );
490 digester.parse( sr );
491 }
492 }
493 catch ( FileNotFoundException e )
494 {
495 AppLogService.error( e.getMessage( ), e );
496 }
497 catch ( SAXException e )
498 {
499 AppLogService.error( e.getMessage( ), e );
500 }
501 catch ( IOException e )
502 {
503 AppLogService.error( e.getMessage( ), e );
504 }
505 }
506 }