source: vlo/branches/vlo-2.13-param/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java @ 2661

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

Fixed the code for accessing the parameter file via a stream.

File size: 18.2 KB
Line 
1package eu.clarin.cmdi.vlo.config;
2
3import java.io.UnsupportedEncodingException;
4import java.net.URLEncoder;
5import java.util.List;
6import org.simpleframework.xml.Element;
7import org.simpleframework.xml.ElementArray;
8import org.simpleframework.xml.ElementList;
9import org.simpleframework.xml.Root;
10import org.slf4j.LoggerFactory;
11
12
13    /**
14
15     */
16
17/**
18 * VLO configuration<br><br>
19 *
20 * The annotated members in this class are the parameters by means of which
21 * you can configure a VLO application like for example the VLO importer or
22 * the VLO web application.
23 *
24 * A member is annotated by prepending {@literal @element}. When the VloConfig
25 * class is reflected into the Simple framework, the framework will assign the
26 * values it finds in the VloConfig.xml file to the members in the VloConfig
27 * class.
28 *
29 * Whenever you need to add a parameter the VLO configuration, add a member
30 * with the appropriate name and type, and prepend an at sign to the
31 * declaration, like this:
32 *
33 * {@literal @element}<br> {@literal parameterMember}<br><br>
34 *
35 * The XML should in this case contain a definition like
36 *
37 * {@literal<parameterMember>} "the value of the
38 * parameter"{@literal </parameterMember>}<br><br>
39 *
40 * If you want to add a type of member that is not included in VloConfig class
41 * yet, or if you are looking for more information on the framework, please
42 * refer to <url> <br><br>
43 *
44 * In the VloConfig class, the parameters are stored statically. This means that
45 * after
46 *
47 * {@literal VloConfig.readPackagedConfig();}<br><br>
48 *
49 * has been issued from a certain context, you can reference a parameter by
50 *
51 * {@literal WebAppConfig.getSomeParameter();}<br><br>
52 *
53 * in any scope, also the scope from which the read message was send.
54 *
55 *
56 *
57 * Move the following remarks to a general remark in the class description, a
58 * remark indicating what you could do if you do not want to use the packaged
59 * configuration.
60 *
61 *
62 * Here, modifications of the parameters inspired on the difference
63 * in context can be made.
64 *
65 * A web application can serve as a typical example of a difference in context:
66 * the application itself runs in a web server container, while the tests
67 * associated with the web application will be run outside this container. *
68 *
69 *
70 *
71 * Through the get and set methods, the application is indifferent to the origin
72 * of a parameter: you can get and set the value of a parameter without having
73 * to worry about how the parameter was defined originally.
74 *
75 * Also, the get and set methods allow for a modification of the original value
76 * of the parameter. For example, if the format of a parameter changes, this
77 * change can be handled in the get and set methods, instead of having to
78 * modify every reference to the parameter in the application.
79 *
80 * Note on the explanation of the meaning of the parameters. Because the
81 * meaning of a parameter is not local to this class, or even not local to the
82 * configuration package, they are described in the general VLO
83 * documentation.<br><br>
84 *
85 * @author keeloo
86 */
87@Root
88public class VloConfig extends ConfigFromFile {
89
90    /**
91     * Create a reference through which a VloConfig class object can send
92     * messages to the logging framework that has been associated with the
93     * application.
94     */
95    private final static org.slf4j.Logger LOG =
96            LoggerFactory.getLogger(VloConfig.class);
97
98    /**
99     * Because the VloConfig class uses the Simple framework via the
100     * ConfigFilePersister class, implement the logging interface in
101     * that class.
102     */
103    private class VloConfigLogger implements ConfigFilePersister.Logger {
104
105        @Override
106        public void log(Object data) {
107           
108            /**
109             * Send a message to the logging framework by using the
110             * LOG reference.
111             */
112            LOG.error(data.toString());
113        }
114    }
115 
116    // create a reference to the ConfigFilePersister's logging interface
117    private static VloConfigLogger logger;
118
119    /**
120     * Constructor method
121     */
122    public VloConfig() {
123        // create the ConfigFilePersister's logging interface
124        logger = new VloConfigLogger();
125
126        /**
127         * Initialize the ConfigFilePersister's reference to the interface
128         */
129        ConfigFilePersister.setLogger(VloConfig.logger);
130    }
131   
132    /**
133     * Read the configuration from the packaged XML configuration file. 
134     *
135     * @param fileName the name of the file to read the configuration from
136     */
137    public static void readPackagedConfig() {
138       
139        // set the name of the packaged configuration file
140        String fileName = "/VloConfig.xml";
141       
142        VloConfig.readConfig (fileName);
143    }
144   
145    // VLO application configuration
146    static VloConfig config = null;
147
148    /**
149     * Read the configuration from a file.
150     *
151     * Please invoke this method instead of readPackagedConfig if you want to
152     * read the configuration from a file external to the VloConfig package.
153     *
154     * @param fileName the name of the file to read the configuration from
155     */
156    public static void readConfig(String fileName) {
157
158        if (config == null) {
159            // the configuration is not there yet; create it now
160            config = new VloConfig();
161        }
162
163        // get the XML file configuration from the file
164        read(fileName, config);
165    }
166
167    /**
168     * VLO application parameter members<br><br>
169     *
170     * Initialize the annotated members in a proper way. This will allow them to
171     * be linearized to corresponding elements in an XML file.
172     *
173     * Please refer to the general VLO documentation for a description of the
174     * member parameters.
175     */
176   
177    @Element // directive for Simple
178    private static boolean deleteAllFirst = false;
179   
180    @Element
181    private static boolean printMapping = false;
182   
183    @ElementList // directive for Simple
184    private static List<DataRoot> dataRoots;
185   
186    @Element
187    private static String vloHomeLink = "";
188   
189    @Element
190    private static String solrUrl = "";
191   
192    @Element
193    private static String profileSchemaUrl = "";
194
195    @Element
196    private static String componentRegistryRESTURL = "";
197   
198    @Element
199    private static String handleServerUrl = "";
200   
201    @Element
202    private static String imdiBrowserUrl = "";
203   
204    /**
205     * Note: the national project mapping itself is not part of the web
206     * application configuration.
207     */
208    @Element
209    private static String nationalProjectMapping = "";
210   
211    /**
212     * An array of facetFields<br><br>
213     *
214     * In case of an array of elements, the number of elements in the array
215     * needs to be communicated to the Simple framework. The following would be
216     * a correct description of an array of three facet fields<br><br>
217     *
218     * {@literal <facetFields length="3">}<br>
219     * {@literal    <facetField>}<br>
220     * {@literal       fieldOne}<br>
221     * {@literal    </facetField>}<br>
222     * {@literal    <facetField>}<br>
223     * {@literal       fieldTwo}<br>
224     * {@literal    </facetField>}<br>
225     * {@literal    <facetField>}<br>
226     * {@literal       fieldThree}<br>
227     * {@literal    </facetField>}<br>
228     * {@literal </facetFields>}<br><br>
229     *
230     * To let Simple now it has to interpret the facetFields element as an
231     * array, use the ElementArray directive. Use the directive to let Simple
232     * know that the elements inside 'facetFields' are named 'facetField'.
233     */
234    @ElementArray(entry = "facetField")
235    private static String[] facetFields = {"", "", ""};
236   
237    @Element
238    private static String countryComponentUrl = "";
239   
240    @Element
241    private static String language2LetterCodeComponentUrl = "";
242   
243    @Element
244    private static String language3LetterCodeComponentUrl = "";
245   
246    @Element
247    private static String silToISO639CodesUrl = "";
248   
249    @Element
250    private static String FederatedContentSearchUrl = " ";
251
252    /**
253     * Get and set methods for web application parameter members<br><br>
254     *
255     * By using a get or set method, you can apply an operation to a parameter
256     * here without the need to make changes in different parts of the
257     * application.
258     */
259    public static List<DataRoot> getDataRoots() {
260        return dataRoots;
261    }
262   
263    /**
264     * Set the value of the dataRoots parameter<br><br>
265     *
266     * For a description of the parameter, refer to the general VLO
267     * documentation.
268     *
269     * @param dataRoots the value
270     */
271    public static void setDataRoots(List<DataRoot> param) {
272        dataRoots = param;
273    }
274
275    /**
276     * Set the value of the deleteAllFirst parameter<br><br>
277     *
278     * For a description of the parameter, refer to the general VLO
279     * documentation.
280     *
281     * @return the value
282     */
283    public static void setDeleteAllFirst(boolean param) {
284        deleteAllFirst = param;
285    }
286
287    /**
288     * Get the value of the deleteAllFirst parameter<br><br>
289     *
290     * For a description of the parameter, refer to the general VLO
291     * documentation.
292     *
293     * @return the value
294     */
295    public static boolean isDeleteAllFirst() {
296        return deleteAllFirst;
297    }
298
299    /**
300     * Set the value of the printMapping parameter<br><br>
301     *
302     * For a description of the parameter, refer to the general VLO
303     * documentation.
304     *
305     * @param printMapping the value
306     */
307    public static void setPrintMapping(boolean param) {
308        printMapping = param;
309    }
310
311    /**
312     * Get the value of the printMapping parameter<br><br>
313     *
314     * For a description of the parameter, refer to the general VLO
315     * documentation.
316     *
317     * @return the value
318     */
319    public static boolean isPrintMapping() {
320        return printMapping;
321    }
322   
323    /**
324     * Get the value of the VloHomeLink parameter<br><br>
325     *
326     * For a description of the parameter, refer to the general VLO
327     * documentation.
328     *
329     * @return the value
330     */
331    public static String getVloHomeLink() {
332        return vloHomeLink;
333    }
334
335    /**
336     * Set the value of the VloHomeLink parameter<br><br>
337     *
338     * For a description of the parameter, refer to the general VLO
339     * documentation.
340     *
341     * @param vloHomeLink the value
342     */
343    public static void setVloHomeLink(String param) {
344        vloHomeLink = param;
345    }
346
347    /**
348     * Get the value of the SolrUrl parameter<br><br>
349     *
350     * For a description of the parameter, refer to the general VLO
351     * documentation.
352     *
353     * @return the value
354     */
355    static public String getSolrUrl() {
356        return solrUrl;
357    }
358
359    /**
360     * Set the value of the SolrUrl parameter<br><br>
361     *
362     * For a description of the parameter, refer to the general VLO
363     * documentation.
364     *
365     * @param url the parameter
366     */
367    public static void setSolrUrl(String param) {
368        solrUrl = param;
369    }
370
371    /**
372     * Get the value of the ProfileSchemaUrl by profileId parameter<br><br>
373     *
374     * For a description of the schema, refer to the general VLO documentation.
375     * Note: the profileId needs to be expanded.
376     *
377     * @return the value
378     */
379    public static String getComponentRegistryProfileSchema(String id) {
380        return profileSchemaUrl.replace("{PROFILE_ID}", id);
381    }
382
383    /**
384     * Set the value of the ProfileSchemaUrl parameter<br><br>
385     *
386     * For a description of the schema, refer to the general VLO documentation.
387     * Note: the profileId needs to be expanded.
388     *
389     * @param profileId the value
390     */
391    public static void setProfileSchemaUrl(String param) {
392        profileSchemaUrl = param;
393    }
394
395    /**
396     * Get the value of the ComponentRegisteryRESTURL parameter<br><br>
397     *
398     * For a description of the parameter, refer to the general VLO
399     * documentation.
400     *
401     * @return the value
402     */
403    public static String getComponentRegistryRESTURL() {
404        return componentRegistryRESTURL;
405    }
406
407    /**
408     * Set the value of the ComponentRegisteryRESTURL parameter<br><br>
409     *
410     * For a description of the parameter, refer to the general VLO
411     * documentation.
412     *
413     * @param componentRegistryRESTURL the value
414     */
415    public static void setComponentRegistryRESTURL(String param) {
416        componentRegistryRESTURL = param;
417    }
418
419    /**
420     * Get the value of the HandleServerUrl parameter<br><br>
421     *
422     * For a description of the parameter, refer to the general VLO
423     * documentation.
424     *
425     * @return the value
426     */
427    public static String getHandleServerUrl() {
428        return handleServerUrl;
429    }
430
431    /**
432     * Set the value of the HandleServerUrl parameter<br><br>
433     *
434     * For a description of the parameter, refer to the general VLO
435     * documentation.
436     *
437     * @param handleServerUrl the value
438     */
439    public static void setHandleServerUrl(String param) {
440        handleServerUrl = param;
441    }
442
443    /**
444     * Set the value of the IMDIBrowserUrl parameter<br><br>
445     *
446     * For a description of the parameter, refer to the general VLO
447     * documentation.
448     *
449     * @param imdiBrowserUrl the value
450     */
451    public static void setIMDIBrowserUrl(String param) {
452        imdiBrowserUrl = param;
453    }
454
455    /**
456     * Get the value of the ProfileSchemaUrl parameter combined with a handle<br><br>
457     *
458     * For a description of the schema, refer to the general VLO documentation.
459     *
460     * @return the value
461     */
462    public static String getIMDIBrowserUrl(String handle) {
463        String result;
464        try {
465            result = imdiBrowserUrl + URLEncoder.encode(handle, "UTF-8");
466        } catch (UnsupportedEncodingException e) {
467            result = imdiBrowserUrl + handle;
468        }
469        return result;
470    }
471
472    /**
473     * Get the value of the FederatedContentSearchUrl parameter<br><br>
474     *
475     * For a description of the parameter, refer to the general VLO
476     * documentation.
477     *
478     * @return the value
479     */
480    public static void setFederatedContentSearchUrl(String param) {
481        FederatedContentSearchUrl = param;
482    }
483
484    /**
485     * Set the value of the FederatedContentSearchUrl parameter<br><br>
486     *
487     * For a description of the parameter, refer to the general VLO
488     * documentation.
489     *
490     * @param FederatedContentSearchUrl the value
491     */
492    public static String getFederatedContentSearchUrl() {
493        return FederatedContentSearchUrl;
494    }
495
496    /**
497     * Set the value of the NationalProjectMapping parameter<br><br>
498     *
499     * For a description of the parameter, refer to the general VLO
500     * documentation.
501     *
502     * @param nationalProjectMapping the value
503     */
504    public static void setNationalProjectMapping(String param) {
505        nationalProjectMapping = param;
506    }
507   
508
509    /**
510     * Get the value of the NationalProjectMapping parameter<br><br>
511     *
512     * For a description of the parameter, refer to the general VLO
513     * documentation.
514     *
515     * @return the value
516     */
517    public static String getNationalProjectMapping() {
518        return nationalProjectMapping;
519    }
520
521    /**
522     * Get the value of the FacetFields parameter<br><br>
523     *
524     * For a description of the parameter, refer to the general VLO
525     * documentation.
526     *
527     * @return the value
528     */
529    public static String[] getFacetFields() {
530        return facetFields;
531    }
532
533    /**
534     * Set the value of the FacetFields parameter<br><br>
535     *
536     * For a description of the parameter, refer to the general VLO
537     * documentation.
538     *
539     * @param facetFields the value, a list of facet fields
540     */
541    public static void setFacetFields(String[] param) {
542        facetFields = param;
543    }
544
545    /**
546     * Get the value of the CountryComponentUrl parameter<br><br>
547     *
548     * For a description of the parameter, refer to the general VLO
549     * documentation.
550     *
551     * @return the value
552     */
553    public static String getCountryComponentUrl() {
554        return countryComponentUrl;
555    }
556
557    /**
558     * Set the value of the CountryComponentUrl parameter<br><br>
559     *
560     * For a description of the parameter, refer to the general VLO
561     * documentation.
562     *
563     * @param countryComponentUrl the value
564     */
565    public static void setCountryComponentUrl(String param) {
566        countryComponentUrl = param;
567    }
568
569    /**
570     * Get the value of the Language2LetterCodeComponentUrl parameter<br><br>
571     *
572     * For a description of the parameter, refer to the general VLO
573     * documentation.
574     *
575     * @return the value
576     */
577    public static String getLanguage2LetterCodeComponentUrl() {
578        return language2LetterCodeComponentUrl;
579    }
580
581    /**
582     * Set the value of the Language2LetterCodeComponentUrl parameter<br><br>
583     *
584     * For a description of the parameter, refer to the general VLO
585     * documentation.
586     *
587     * @param language2LetterCodeComponentUrl the value
588     */
589    public static void setLanguage2LetterCodeComponentUrl(String param) {
590        language2LetterCodeComponentUrl = param;
591    }
592
593    /**
594     * Get the value of the Language3LetterCodeComponentUrl parameter<br><br>
595     *
596     * For a description of the parameter, refer to the general VLO
597     * documentation.
598     *
599     * @return the value
600     */
601    public static String getLanguage3LetterCodeComponentUrl() {
602        return language3LetterCodeComponentUrl;
603    }
604
605    /**
606     * Set the value of the Language3LetterCodeComponentUrl parameter<br><br>
607     *
608     * For a description of the parameter, refer to the general VLO
609     * documentation.
610     *
611     * @param language3LetterCodeComponentUrl the value
612     */
613    public static void setLanguage3LetterCodeComponentUrl(String param) {
614        language3LetterCodeComponentUrl = param;
615    }
616
617    /**
618     * Get the value of the SilToISO639CodesUrl parameter<br><br>
619     *
620     * For a description of the parameter, refer to the general VLO
621     * documentation.
622     *
623     * @return the value
624     */
625    public static String getSilToISO639CodesUrl() {
626        return silToISO639CodesUrl;
627    }
628
629    /**
630     * Set the value of the SilToISO639CodesUrl parameter<br><br>
631     *
632     * For a description of the parameter, refer to the general VLO
633     * documentation.
634     *
635     * @param silToISO639CodesUrl the value
636     */
637    public static void setSilToISO639CodesUrl(String param) {
638        silToISO639CodesUrl = param;
639    }
640}
Note: See TracBrowser for help on using the repository browser.