View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.document.modules.metadatadublincore;
35  
36  import fr.paris.lutece.plugins.document.modules.metadatadublincore.business.DublinCoreMetadata;
37  import fr.paris.lutece.plugins.document.service.metadata.MetadataHandler;
38  import fr.paris.lutece.portal.service.admin.AdminUserService;
39  import fr.paris.lutece.portal.service.template.AppTemplateService;
40  import fr.paris.lutece.util.html.HtmlTemplate;
41  
42  import java.util.HashMap;
43  import java.util.Locale;
44  import java.util.Map;
45  
46  import javax.servlet.http.HttpServletRequest;
47  
48  
49  /**
50   * Dublin Core Metadata Handler
51   */
52  public class DublinCoreMetadataHandler implements MetadataHandler
53  {
54      private static final String TEMPLATE_FORM = "admin/plugins/document/modules/metadatadublincore/dublin_core_form.html";
55  
56      // Parameters
57      private static final String PARAMETER_TITLE = "dc_title";
58      private static final String PARAMETER_CREATOR = "dc_creator";
59      private static final String PARAMETER_SUBJECT = "dc_subject";
60      private static final String PARAMETER_DESCRIPTION = "dc_description";
61      private static final String PARAMETER_PUBLISHER = "dc_publisher";
62      private static final String PARAMETER_CONTRIBUTOR = "dc_contributor";
63      private static final String PARAMETER_DATE = "dc_date";
64      private static final String PARAMETER_TYPE = "dc_type";
65      private static final String PARAMETER_FORMAT = "dc_format";
66      private static final String PARAMETER_IDENTIFIER = "dc_identifier";
67      private static final String PARAMETER_SOURCE = "dc_source";
68      private static final String PARAMETER_LANGUAGE = "dc_language";
69      private static final String PARAMETER_RELATION = "dc_relation";
70      private static final String PARAMETER_COVERAGE = "dc_coverage";
71      private static final String PARAMETER_RIGTHS = "dc_rights";
72      private static final String MARK_METADATA = "metadata";
73  
74      /**
75       * {@inheritDoc}
76       */
77      @Override
78      public String getCreateForm( HttpServletRequest request )
79      {
80          DublinCoreMetadatamodules/metadatadublincore/business/DublinCoreMetadata.html#DublinCoreMetadata">DublinCoreMetadata metadata = new DublinCoreMetadata(  );
81          Map<String, Object> model = new HashMap<String, Object>(  );
82          model.put( MARK_METADATA, metadata );
83  
84          Locale locale = AdminUserService.getLocale( request );
85          HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORM, locale, model );
86  
87          return template.getHtml(  );
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      public String getModifyForm( HttpServletRequest request, String strXmlData )
95      {
96          DublinCoreMetadatamodules/metadatadublincore/business/DublinCoreMetadata.html#DublinCoreMetadata">DublinCoreMetadata metadata = new DublinCoreMetadata(  );
97          metadata.load( strXmlData );
98  
99          Map<String, Object> model = new HashMap<String, Object>(  );
100         model.put( MARK_METADATA, metadata );
101 
102         Locale locale = AdminUserService.getLocale( request );
103         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORM, locale, model );
104 
105         return template.getHtml(  );
106     }
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public String getXmlMetadata( Map<String, String[]> parameters )
113     {
114         DublinCoreMetadataent/modules/metadatadublincore/business/DublinCoreMetadata.html#DublinCoreMetadata">DublinCoreMetadata meta = new DublinCoreMetadata(  );
115         meta.setTitle( parameters.get( PARAMETER_TITLE )[0] );
116         meta.setCreator( parameters.get( PARAMETER_CREATOR )[0] );
117         meta.setSubject( parameters.get( PARAMETER_SUBJECT )[0] );
118         meta.setDescription( parameters.get( PARAMETER_DESCRIPTION )[0] );
119         meta.setPublisher( parameters.get( PARAMETER_PUBLISHER )[0] );
120         meta.setContributor( parameters.get( PARAMETER_CONTRIBUTOR )[0] );
121         meta.setDate( parameters.get( PARAMETER_DATE )[0] );
122         meta.setType( parameters.get( PARAMETER_TYPE )[0] );
123         meta.setFormat( parameters.get( PARAMETER_FORMAT )[0] );
124         meta.setIdentifier( parameters.get( PARAMETER_IDENTIFIER )[0] );
125         meta.setSource( parameters.get( PARAMETER_SOURCE )[0] );
126         meta.setLanguage( parameters.get( PARAMETER_LANGUAGE )[0] );
127         meta.setRelation( parameters.get( PARAMETER_RELATION )[0] );
128         meta.setCoverage( parameters.get( PARAMETER_COVERAGE )[0] );
129         meta.setRights( parameters.get( PARAMETER_RIGTHS )[0] );
130 
131         return meta.getXml(  );
132     }
133 }