1 | package eu.clarin.cmdi.vlo; |
---|
2 | |
---|
3 | import eu.clarin.cmdi.vlo.config.VloConfig; |
---|
4 | import eu.clarin.cmdi.vlo.service.XmlTransformationService; |
---|
5 | import eu.clarin.cmdi.vlo.service.solr.SolrDocumentService; |
---|
6 | import eu.clarin.cmdi.vlo.wicket.pages.AboutPage; |
---|
7 | import eu.clarin.cmdi.vlo.wicket.pages.AllFacetValuesPage; |
---|
8 | import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage; |
---|
9 | import eu.clarin.cmdi.vlo.wicket.pages.RecordPage; |
---|
10 | import eu.clarin.cmdi.vlo.wicket.pages.SimpleSearchPage; |
---|
11 | import eu.clarin.cmdi.vlo.wicket.pages.VloBasePage; |
---|
12 | import javax.inject.Inject; |
---|
13 | import org.apache.wicket.Application; |
---|
14 | import org.apache.wicket.markup.html.WebPage; |
---|
15 | import org.apache.wicket.protocol.http.WebApplication; |
---|
16 | import org.apache.wicket.resource.loader.BundleStringResourceLoader; |
---|
17 | import org.apache.wicket.spring.injection.annot.SpringComponentInjector; |
---|
18 | import org.apache.wicket.util.lang.Bytes; |
---|
19 | import org.slf4j.Logger; |
---|
20 | import org.slf4j.LoggerFactory; |
---|
21 | import org.springframework.beans.BeansException; |
---|
22 | import org.springframework.context.ApplicationContext; |
---|
23 | import org.springframework.context.ApplicationContextAware; |
---|
24 | |
---|
25 | /** |
---|
26 | * Application object for your web application. If you want to run this |
---|
27 | * application without deploying, run the Start class. |
---|
28 | * |
---|
29 | * @see eu.clarin.cmdi.Start#main(String[]) |
---|
30 | */ |
---|
31 | public class VloWicketApplication extends WebApplication implements ApplicationContextAware { |
---|
32 | |
---|
33 | private final static Logger logger = LoggerFactory.getLogger(VloWicketApplication.class); |
---|
34 | |
---|
35 | @Inject |
---|
36 | private SolrDocumentService documentService; |
---|
37 | @Inject |
---|
38 | private XmlTransformationService cmdiTransformationService; |
---|
39 | @Inject |
---|
40 | private VloConfig vloConfig; |
---|
41 | |
---|
42 | private ApplicationContext applicationContext; |
---|
43 | |
---|
44 | /** |
---|
45 | * @return the home page of this application |
---|
46 | * @see org.apache.wicket.Application#getHomePage() |
---|
47 | */ |
---|
48 | @Override |
---|
49 | public Class<? extends WebPage> getHomePage() { |
---|
50 | return SimpleSearchPage.class; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * @see org.apache.wicket.Application#init() |
---|
55 | */ |
---|
56 | @Override |
---|
57 | public void init() { |
---|
58 | super.init(); |
---|
59 | |
---|
60 | // register global resource bundles (from .properties files) |
---|
61 | registerResourceBundles(); |
---|
62 | |
---|
63 | // mount pages on URL paths |
---|
64 | mountPages(); |
---|
65 | |
---|
66 | // configure Wicket cache according to parameters set in VloConfig |
---|
67 | setupCache(); |
---|
68 | } |
---|
69 | |
---|
70 | private void registerResourceBundles() { |
---|
71 | // this listener will inject any spring beans that need to be autowired |
---|
72 | getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext)); |
---|
73 | // register the resource of field names (used by eu.clarin.cmdi.vlo.wicket.componentsSolrFieldNameLabel) |
---|
74 | getResourceSettings().getStringResourceLoaders().add(new BundleStringResourceLoader("fieldNames")); |
---|
75 | // register the resource of resource type names and class properties |
---|
76 | getResourceSettings().getStringResourceLoaders().add(new BundleStringResourceLoader("resourceTypes")); |
---|
77 | // register the resource of application properties (version information filtered at build time) |
---|
78 | getResourceSettings().getStringResourceLoaders().add(new BundleStringResourceLoader("application")); |
---|
79 | // register JavaScript bundle (combines JavaScript source in a single resource to decrease number of client requests) |
---|
80 | getResourceBundles().addJavaScriptBundle(VloBasePage.class, "vlo-js", |
---|
81 | JavaScriptResources.getVloFrontJS(), |
---|
82 | JavaScriptResources.getVloHeaderJS(), |
---|
83 | JavaScriptResources.getJQueryWatermarkJS() |
---|
84 | ); |
---|
85 | } |
---|
86 | |
---|
87 | private void mountPages() { |
---|
88 | // Faceted search page (simple search is on root) |
---|
89 | mountPage("/search", FacetedSearchPage.class); |
---|
90 | // Record (query result) page. E.g. /vlo/record?docId=abc123 |
---|
91 | // (cannot encode docId in path because it contains a slash) |
---|
92 | mountPage("/record", RecordPage.class); |
---|
93 | // All facet values page (kept for compatibility with old bookmarks) |
---|
94 | // E.g. /vlo/values/genre?facetMinOccurs=1 (min occurs not in path |
---|
95 | // because it's a filter on the facet list) |
---|
96 | mountPage("/values/${" + AllFacetValuesPage.SELECTED_FACET_PARAM + "}", AllFacetValuesPage.class); |
---|
97 | // About page |
---|
98 | mountPage("/about", AboutPage.class); |
---|
99 | } |
---|
100 | |
---|
101 | private void setupCache() { |
---|
102 | // configure cache by applying the vlo configuration settings to it |
---|
103 | final int pagesInApplicationCache = vloConfig.getPagesInApplicationCache(); |
---|
104 | logger.info("Setting Wicket in-memory cache size to {}", pagesInApplicationCache); |
---|
105 | this.getStoreSettings().setInmemoryCacheSize(pagesInApplicationCache); |
---|
106 | |
---|
107 | final Bytes sessionCacheSize = Bytes.kilobytes((long) vloConfig.getSessionCacheSize()); |
---|
108 | logger.info("Setting Wicket max size per session to {}", sessionCacheSize); |
---|
109 | this.getStoreSettings().setMaxSizePerSession(sessionCacheSize); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * |
---|
114 | * @return the active VLO wicket application |
---|
115 | */ |
---|
116 | public static VloWicketApplication get() { |
---|
117 | return (VloWicketApplication) Application.get(); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * Method needed for dynamic injection of application context (as happens in |
---|
122 | * unit tests) |
---|
123 | * |
---|
124 | * @param applicationContext |
---|
125 | * @throws BeansException |
---|
126 | */ |
---|
127 | @Override |
---|
128 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
---|
129 | this.applicationContext = applicationContext; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * |
---|
134 | * @return a service that retrieves SolrDocuments from the attached index |
---|
135 | */ |
---|
136 | public SolrDocumentService getDocumentService() { |
---|
137 | return documentService; |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * |
---|
142 | * @return a service that transforms CMDI documents to HTML representations |
---|
143 | */ |
---|
144 | public XmlTransformationService getCmdiTransformationService() { |
---|
145 | return cmdiTransformationService; |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|