source: vlo/branches/vlo-2.13-param/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/config/WebAppConfig.java @ 2570

Last change on this file since 2570 was 2570, checked in by keeloo, 11 years ago

created branch for parameterized vlo

File size: 18.3 KB
Line 
1
2package eu.clarin.cmdi.vlo.config;
3
4import java.io.UnsupportedEncodingException;
5import java.net.URLEncoder;
6import org.simpleframework.xml.Element;
7import org.simpleframework.xml.ElementArray;
8import org.simpleframework.xml.Root;
9import org.slf4j.LoggerFactory;
10
11/**
12 * Web application configuration<br><br>
13 *
14 * The parameter members which are part of the web application configuration
15 * come in two categories. One type of parameters play a role only in the
16 * application, others are determined by the context of the application.<br><br>
17 *
18 * The first type of parameter is defined in the web application parameter file.
19 * These parameters are referred to as application parameters. The second type
20 * of parameter is determined by the context of the application. These
21 * parameters are called context parameters.<br><br>
22 *
23 * Because the application is indifferent to the origin of a parameter, the
24 * WebAppConfig class is the place to switch from one type of parameter to the
25 * other. In other words: you do not have to change the application if you
26 * replace an application parameter by a context parameter. The change is
27 * reflected here, and not in the application. In a sense, this relieves the
28 * need to use get and read methods. Such methods still have an advantage
29 * though, because you can change a parameter without changing the rest of the
30 * application.<br><br>
31 *
32 * An application parameter is defined an XML file in the resources directory of
33 * the package. For every application parameter, the WebApplication class
34 * contains a member that is annotated according to the Simple framework
35 * specification. So<br><br>
36 *
37 * {@literal <parameterMember>}"the value of the
38 * parameter"{@literal </parameterMember>}<br><br>
39 *
40 * in the XML file is accompanied by<br><br>
41 *
42 * {@literal
43 *
44 * @element}<br> {@literal parameterMember}<br><br>
45 *
46 * in the WebAppConfig class. When the application invokes Simple by<br><br>
47 *
48 * WebAppConfig.get();<br><br>
49 *
50 * the parameter itself is accessed by<br><br>
51 *
52 * WebAppConfig.get().getParameterMember();<br><br>
53 *
54 * If you want to add a type of member that is not included in the class yet,
55 * refer to the Simple framework's specification.<br><br>
56 *
57 * A context parameter also resides in an XML file. For more information on the
58 * location and the format of this file, please refer to the Apache Tomcat
59 * configuration reference.<br><br>
60 *
61 * Note on the explanation of the meaning of the parameters. Because the meaning
62 * of a parameter is not local to this class, or even not local to the
63 * configuration package, they are described in the general VLO
64 * documentation.<br><br>
65 *
66 * @author keeloo
67 */
68@Root
69public class WebAppConfig extends ConfigFileParam {
70
71    // create a reference to the application logging
72    private final static org.slf4j.Logger LOG =
73            LoggerFactory.getLogger(WebAppConfig.class);
74   
75    // connect to the logging framework
76    private class WebAppConfigLogger implements ConfigFilePersister.Logger {
77
78        @Override
79        public void log(Object data) {
80
81            LOG.error(data.toString());
82        }
83    }
84   
85    private static WebAppConfigLogger logger;
86
87    /**
88     * Constructor method
89     */
90    public WebAppConfig() {
91        // let the superclass know about the logger defined here
92        // ConfigFileParam.logger = webAppConfigLogger;
93       
94        logger = new WebAppConfigLogger();
95       
96        ConfigFilePersister.setLogger(WebAppConfig.logger);
97    }
98
99    /**
100     * Application parameter XML file.
101     */
102    public static final String CONFIG_FILE = WebAppConfig.class.getResource("/WebAppConfig.xml").getFile();
103
104    /**
105     * Application parameter XML file. Represent the filename by a method
106     * primarily for making it available to the superclass. In other words: this
107     * method overrides a method in the superclass.
108     *
109     * @return the name of the application parameter XML file
110     */
111    @Override
112    public String getFileName() {
113        /**
114         * Check the name of the web application parameter file. May be turn it
115         * into a {@literal maven} parameter.
116         */
117        return CONFIG_FILE;
118    }
119   
120    /**
121     * Make the configuration accessible<br><br>
122     *
123     * Both the Simple framework and the methods in the web application need to
124     * access the configuration. Access is granted by defining a member holding
125     * the configuration, that is, by defining a member of type WebAppConfig.
126     */
127    private static WebAppConfig config = null;
128
129    /**
130     * Make the configuration statically accessible<br><br>
131     *
132     * Access for the Simple framework is achieved by passing the member to the
133     * read method defined in the superclass.<br><br>
134     *
135     * Access for the web application is achieved by invoking one of the get or
136     * read methods. Because these methods return a non-static value, while
137     * WebAppConfig on the other hand denotes a static context,<br><br>
138     *
139     * WebAppConfig.getParameterMember()<br><br>
140     *
141     * for example, would not be valid. On encountering get() however, a new
142     * context is opened, and from that, getParameterMember() can be
143     * invoked:<br><br>
144     *
145     * WebAppConfig.get().getParameterMember()<br><br>
146     *
147     * @return the web application configuration in a new context
148     */
149    public static WebAppConfig get() {
150        if (config == null) {
151            // the configuration is not there yet; create it now
152            config = new WebAppConfig();
153        }
154
155        // get the xml file configuration by invoking the superclass method
156        config = (WebAppConfig) read(config);
157
158        /* Contrary to Simple, the web context parameters are not retrieved
159         * by annotation. Get them by invoking a local method.
160         */
161        // config = addFromContext(config);
162
163        return config;
164    }
165   
166    /**
167     * Web application parameter members<br><br>
168     *
169     * Initialize a member corresponding to application parameters with an empty
170     * string at least, for this will allow them to be linearized to
171     * corresponding elements in the XML file. Note that for the moment only
172     * de-linearization is supported by the WebAppConfig class.
173     *
174     * Refer to the general VLO documentation for a description of the member
175     * parameters.
176     */
177
178    @Element // annotation directive as defined by Simple
179    private String vloHomeLink = "";
180
181    // In the XML file, the value of the parameter is expanded by Maven.
182    @Element
183    private String profileSchemaUrl = "";
184
185    @Element
186    private String componentRegistryRESTURL = "";
187   
188    @Element
189    private String handleServerUrl = "";
190
191    // In the XML file, the value of the parameter is expanded by Maven.
192    @Element
193    private String solrUrl = "";
194   
195    @Element
196    private String imdiBrowserUrl = "";
197   
198    /**
199     * Note. The national project mapping itself is not part of the web
200     * application configuration.
201     */
202    @Element
203    private String nationalProjectMapping = "";
204   
205    /**
206     * An array of facetFields<br><br>
207     *
208     * In case of an array of elements, the number of elements in the array
209     * needs to be communicated to Simple. The following would be a correct
210     * description of an array of three facet fields<br><br>
211     *
212     * {@literal <facetFields length="3">}<br>
213     * {@literal    <facetField>}<br>
214     * {@literal       fieldOne}<br>
215     * {@literal    </facetField>}<br>
216     * {@literal    <facetField>}<br>
217     * {@literal       fieldTwo}<br>
218     * {@literal    </facetField>}<br>
219     * {@literal    <facetField>}<br>
220     * {@literal       fieldThree}<br>
221     * {@literal    </facetField>}<br>
222     * {@literal </facetFields>}<br><br>
223     *
224     * To let Spring now it has to interpret the facetFields element as an
225     * array, use the ElementArray directive. Use the directive to let Spring
226     * know that the elements inside 'facetFields' are named 'facetField'.
227     */
228
229    @ElementArray(entry="facetField")
230    private String[] facetFields = {"", "", ""};
231   
232    @Element
233    private String countryComponentUrl = "";
234   
235    @Element
236    private String language2LetterCodeComponentUrl ="";
237   
238    @Element
239    private String language3LetterCodeComponentUrl = "";
240   
241    @Element
242    private String silToISO639CodesUrl = "";
243   
244    @Element
245    private String FederatedContentSearchUrl = " ";
246   
247    /**
248     * Get and read methods for web application parameter members<br><br>
249     *
250     * By using a get or read method, you can apply an operation to a parameter
251     * here, in the WebAppConfig class, without the need to make changes in
252     * different parts of the application.
253     */
254   
255    /**
256     * Get the VloHomeLink parameter<br><br>
257     *
258     * For a description of the parameter, refer to the general VLO
259     * documentation.
260     *
261     * @return the parameter
262     */
263    public String getVloHomeLink() {
264        return vloHomeLink;
265    }
266
267    /**
268     * Set the VloHomeLink parameter<br><br>
269     *
270     * For a description of the parameter, refer to the general VLO
271     * documentation.
272     *
273     * @param vloHomeLink the parameter
274     */
275    public void setVloHomeLink(String vloHomeLink) {
276        this.vloHomeLink = vloHomeLink;
277    }
278
279    /**
280     * Get the ProfileSchemaUrl by profileId parameter<br><br>
281     *
282     * For a description of the schema, refer to the general VLO documentation.
283     * Note: the profileId needs to be expanded.
284     *
285     * @return the parameter
286     */
287    public String getComponentRegistryProfileSchema(String profileId) {
288        return profileSchemaUrl.replace("${PROFILE_ID}", profileId);
289    }
290
291    /**
292     * Set the ProfileSchemaUrl parameter<br><br>
293     *
294     * For a description of the schema, refer to the general VLO documentation.
295     * Note: the profileId needs to be expanded.
296     *
297     * @param profileId the parameter
298     */
299    public void setProfileSchemaUrl(String profileSchemaUrl) {
300        this.profileSchemaUrl = profileSchemaUrl;
301    }
302
303    /**
304     * Get the ComponentRegisteryRESTURL parameter<br><br>
305     *
306     * For a description of the parameter, refer to the general VLO
307     * documentation.
308     *
309     * @return the parameter
310     */
311    public String getComponentRegistryRESTURL() {
312        return componentRegistryRESTURL;
313    }
314
315    /**
316     * Set the ComponentRegisteryRESTURL parameter<br><br>
317     *
318     * For a description of the parameter, refer to the general VLO
319     * documentation.
320     *
321     * @param componentRegistryRESTURL the parameter
322     */
323    public void setComponentRegistryRESTURL(String componentRegistryRESTURL) {
324        this.componentRegistryRESTURL = componentRegistryRESTURL;
325    }
326
327    /**
328     * Get the HandleServerUrl parameter<br><br>
329     *
330     * For a description of the parameter, refer to the general VLO
331     * documentation.
332     *
333     * @return the parameter
334     */
335    public String getHandleServerUrl() {
336        return handleServerUrl;
337    }
338
339    /**
340     * Set the HandleServerUrl parameter<br><br>
341     *
342     * For a description of the parameter, refer to the general VLO
343     * documentation.
344     *
345     * @param handleServerUrl the parameter
346     */
347    public void setHandleServerUrl(String handleServerUrl) {
348        this.handleServerUrl = handleServerUrl;
349    }
350
351    /**
352     * Get the SolrUrl parameter<br><br>
353     *
354     * For a description of the parameter, refer to the general VLO
355     * documentation.
356     *
357     * @return the parameter
358     */
359    public void setSolrUrl(String solrUrl) {
360        this.solrUrl = solrUrl;
361    }
362
363    /**
364     * Set the SolrUrl parameter<br><br>
365     *
366     * For a description of the parameter, refer to the general VLO
367     * documentation.
368     *
369     * @param solrUrl the parameter
370     */
371    public String getSolrUrl() {
372        return solrUrl;
373    }
374
375    /**
376     * Set the IMDIBrowserUrl parameter<br><br>
377     *
378     * For a description of the parameter, refer to the general VLO
379     * documentation.
380     *
381     * @param imdiBrowserUrl the parameter
382     */
383    public void setIMDIBrowserUrl(String imdiBrowserUrl) {
384        this.imdiBrowserUrl = imdiBrowserUrl;
385    }
386
387    /**
388     * Get ProfileSchemaUrl parameter combined with a handle<br><br>
389     *
390     * For a description of the schema, refer to the general VLO documentation.
391     *
392     * @param handle the handle to be combined with the parameter
393     */
394    public String getIMDIBrowserUrl(String handle) {
395        String result;
396        try {
397            result = imdiBrowserUrl + URLEncoder.encode(handle, "UTF-8");
398        } catch (UnsupportedEncodingException e) {
399            result = imdiBrowserUrl + handle;
400        }
401        return result;
402    }
403   
404
405    /**
406     * Get the FederatedContentSearchUrl parameter<br><br>
407     *
408     * For a description of the parameter, refer to the general VLO
409     * documentation.
410     *
411     * @return the parameter
412     */
413    public void setFederatedContentSearchUrl(String solrUrl) {
414        this.FederatedContentSearchUrl = FederatedContentSearchUrl;
415    }
416
417    /**
418     * Set the FederatedContentSearchUrl parameter<br><br>
419     *
420     * For a description of the parameter, refer to the general VLO
421     * documentation.
422     *
423     * @param FederatedContentSearchUrl the parameter
424     */
425    public String getFederatedContentSearchUrl() {
426        return FederatedContentSearchUrl;
427    }
428
429    /**
430     * Set the NationalProjectMapping parameter<br><br>
431     *
432     * For a description of the parameter, refer to the general VLO
433     * documentation.
434     *
435     * @param nationalProjectMapping the parameter
436     */
437    public void setNationalProjectMapping(String nationalProjectMapping) {
438        this.nationalProjectMapping = nationalProjectMapping;
439    }
440
441    /**
442     * Get the NationalProjectMapping parameter<br><br>
443     *
444     * For a description of the parameter, refer to the general VLO
445     * documentation.
446     *
447     * @return the parameter
448     */
449    public String getNationalProjectMapping() {
450        return nationalProjectMapping;
451    }
452
453    /**
454     * Get the FacetFields parameter<br><br>
455     *
456     * For a description of the parameter, refer to the general VLO
457     * documentation.
458     *
459     * @return the parameter
460     */
461    public String[] getFacetFields() {
462        return facetFields;
463    }
464
465    /**
466     * Set the FacetFields parameter<br><br>
467     *
468     * For a description of the parameter, refer to the general VLO
469     * documentation.
470     *
471     * @param facetFields the parameter, a list of facet fields
472     */
473    public void setFacetFields(String[] facetFields) {
474        this.facetFields = facetFields;
475    }
476
477    /**
478     * Get the CountryComponentUrl parameter<br><br>
479     *
480     * For a description of the parameter, refer to the general VLO
481     * documentation.
482     *
483     * @return the parameter
484     */
485    public String getCountryComponentUrl() {
486        return countryComponentUrl;
487    }
488
489    /**
490     * Set the CountryComponentUrl parameter<br><br>
491     *
492     * For a description of the parameter, refer to the general VLO
493     * documentation.
494     *
495     * @param countryComponentUrl the parameter
496     */
497    public void setCountryComponentUrl(String countryComponentUrl) {
498        this.countryComponentUrl = countryComponentUrl;
499    }
500
501    /**
502     * Get the Language2LetterCodeComponentUrl parameter<br><br>
503     *
504     * For a description of the parameter, refer to the general VLO
505     * documentation.
506     *
507     * @return the parameter
508     */
509    public String getLanguage2LetterCodeComponentUrl() {
510        return language2LetterCodeComponentUrl;
511    }
512
513    /**
514     * Set the Language2LetterCodeComponentUrl parameter<br><br>
515     *
516     * For a description of the parameter, refer to the general VLO
517     * documentation.
518     *
519     * @param language2LetterCodeComponentUrl the parameter
520     */
521    public void setLanguage2LetterCodeComponentUrl(String language2LetterCodeComponentUrl) {
522        this.language2LetterCodeComponentUrl = language2LetterCodeComponentUrl;
523    }
524
525    /**
526     * Get the Language3LetterCodeComponentUrl parameter<br><br> For a
527     * description of the parameter, refer to the general VLO documentation.
528     *
529     * @return the parameter
530     */
531    public String getLanguage3LetterCodeComponentUrl() {
532        return language3LetterCodeComponentUrl;
533    }
534
535    /**
536     * Set the Language3LetterCodeComponentUrl parameter<br><br> For a
537     * description of the parameter, refer to the general VLO documentation.
538     *
539     * @param language3LetterCodeComponentUrl the parameter
540     */
541    public void setLanguage3LetterCodeComponentUrl(String language3LetterCodeComponentUrl) {
542        this.language3LetterCodeComponentUrl = language3LetterCodeComponentUrl;
543    }
544
545    /**
546     * Get the SilToISO639CodesUrl parameter<br><br>
547     *
548     * For a description of the parameter, refer to the general VLO
549     * documentation.
550     *
551     * @return the parameter
552     */
553    public String getSilToISO639CodesUrl() {
554        return silToISO639CodesUrl;
555    }
556
557    /**
558     * Set the SilToISO639CodesUrl parameter<br><br>
559     *
560     * For a description of the parameter, refer to the general VLO
561     * documentation.
562     *
563     * @param silToISO639CodesUrl the parameter
564     */
565    public void setSilToISO639CodesUrl(String silToISO639CodesUrl) {
566        this.silToISO639CodesUrl = silToISO639CodesUrl;
567    }
568   
569    /**
570     * Retrieve the context parameters<br><br>
571     *
572     * Note that in terms of the configuration, properties of the context are
573     * treated as parameters also.
574     *
575     * @param config the static WebAppConfig member
576     *
577     * @return the static WebAppConfig member
578     */
579    static WebAppConfig addFromContext(WebAppConfig config) {
580       
581        // retrieve parameters from the context of the web application
582       
583        docBase = WebAppParam.getContextParam ("docBase");
584       
585        return config;
586    }
587   
588    /**
589     * Web application context members<br><br>
590     *
591     * The following defines the members corresponding to context.
592     */
593   
594    /**
595     * Context members
596     */
597    static String docBase = "";
598   
599    /**
600     * Get and read methods for the context members
601     */
602   
603    /**
604     *
605     * @return
606     */
607    public String getDocbaBase() {
608        return docBase;
609    }
610   
611    /**
612     *
613     * @return
614     */
615    public String setDocBase(String param) {
616        // potentially, modify the parameter in the configuration
617        docBase = param; 
618        return docBase;
619    }
620}
Note: See TracBrowser for help on using the repository browser.