1 /*
2 * Copyright (C) 2017-2019 Centre National d'Etudes Spatiales (CNES).
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 package fr.cnes.doi.resource.citation;
20
21 import fr.cnes.doi.application.DoiCrossCiteApplication;
22 import fr.cnes.doi.resource.AbstractResource;
23 import org.apache.logging.log4j.Logger;
24 import org.restlet.data.MediaType;
25 import org.restlet.ext.wadl.DocumentationInfo;
26 import org.restlet.ext.wadl.RepresentationInfo;
27 import org.restlet.resource.ResourceException;
28
29 /**
30 * Base resource for CrossCite application.
31 *
32 * @author Jean-Christophe Malapert (jean-christophe.malapert@cnes.fr)
33 */
34 public class BaseCitationResource extends AbstractResource {
35
36 /**
37 * Parameter providing the digital object identifier
38 * {@value #DOI_PARAMETER}.
39 */
40 public static final String DOI_PARAMETER = "doi";
41
42 /**
43 * Language parameter to format the citation {@value #LANG_PARAMETER}.
44 */
45 public static final String LANG_PARAMETER = "lang";
46
47 /**
48 * Style parameter to format the citation {@value #STYLE_PARAMETER}.
49 */
50 public static final String STYLE_PARAMETER = "style";
51
52 /**
53 * Logger.
54 */
55 protected volatile Logger LOG;
56
57 /**
58 * Cross cite application.
59 */
60 private volatile DoiCrossCiteApplication app;
61
62 /**
63 * Init.
64 *
65 * @throws ResourceException - if a problem happens
66 */
67 @Override
68 protected void doInit() throws ResourceException {
69 super.doInit();
70 this.app = (DoiCrossCiteApplication) getApplication();
71 this.LOG = this.app.getLog();
72 }
73
74 /**
75 * List representation.
76 *
77 * @param title Title of the representation
78 * @param media Media type of the response
79 * @param content Explanation of the representation
80 * @return the Wadl representation of this representation
81 */
82 protected RepresentationInfo listRepresentation(final String title,
83 final MediaType media,
84 final String content) {
85 final RepresentationInfo repInfo = new RepresentationInfo();
86 repInfo.setMediaType(media);
87 final DocumentationInfo docInfo = new DocumentationInfo();
88 docInfo.setTitle(title);
89 docInfo.setTextContent(content);
90 repInfo.setDocumentation(docInfo);
91 return repInfo;
92 }
93
94 /**
95 * Returns CrossCiteApplication.
96 *
97 * @return the app
98 */
99 public DoiCrossCiteApplication getApp() {
100 return app;
101 }
102 }