Changeset 2970
- Timestamp:
- 06/01/13 11:24:46 (11 years ago)
- Location:
- vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/VloWebApplication.java
r2965 r2970 5 5 import eu.clarin.cmdi.vlo.dao.SearchResultsDao; 6 6 import eu.clarin.cmdi.vlo.pages.BasePage; 7 import eu.clarin.cmdi.vlo.pages.FacetBoxPanel; 8 import eu.clarin.cmdi.vlo.pages.FacetHeaderPanel; 9 import eu.clarin.cmdi.vlo.pages.FacetLinkPanel; 7 import eu.clarin.cmdi.vlo.pages.BasePanel; 10 8 import eu.clarin.cmdi.vlo.pages.FacetedSearchPage; 11 import eu.clarin.cmdi.vlo.pages.ShowResultPage;12 9 import java.util.Map; 13 10 import javax.servlet.ServletContext; … … 22 19 23 20 /** 24 * 25 * {@literal V}irtual {@literal L}anguage {@literal O}bservatory web 26 * application<br><br> 21 * Virtual Language Observatory web application<br><br> 27 22 * 28 23 * <describe VLO> … … 32 27 */ 33 28 public class VloWebApplication extends WebApplication { 34 35 /** 36 * Remember the theme to be used<br><br> 37 * 38 * The theme parameter is one in a map of parameters that is associated 39 * with a session rather than with some page or pages. 40 */ 41 private String theme = "defaultTheme"; 42 43 /** 44 * Get the name of the theme applied currently<br><br> 45 * 46 * @return the theme 47 */ 48 public String getThemeName (){ 49 // maybe this method will not be needed anymore; query 50 // the session parameters instead 51 return theme; 52 } 53 54 /** 55 * Set the name of the theme applied or to be applied 56 */ 57 public void setThemeName (String theme){ 58 // store the name as a session parameter 59 this.theme = theme; 60 } 61 62 /** 63 * Install a theme 64 * 65 * @param name the name of the theme to be installed 66 */ 67 public void setTheme (String name){ 68 // at some point invoke setThemeName (name) 69 // at some point add the theme to the list of session parameters 70 } 71 72 /** 73 * Remember a map of session level parameters<br><br> 74 */ 75 PageParameters sessionParameters = new PageParameters ("theme", "defaultTheme"); 76 77 public PageParameters getSessionParameters (){ 78 79 return sessionParameters; 80 } 81 82 /** 83 * Add the parameters persisting with the application object to an a list 84 * of parameters existing outside the object.<br><br> 85 * 86 * Invoke this method from a component, after generating a list of 87 * parameters. 88 * 89 * @param parameters the existing list of parameters 90 * @return the concatenation of the existing list and the parameters 91 * persisting with the application object. 92 */ 93 public PageParameters addSessionParameters(PageParameters parameters) { 94 95 // get the theme parameter from the application 96 97 parameters.add("theme", getThemeName()); 29 30 /** 31 * Remember the parameters that should persist in URLs to VLO pages <br><br> 32 */ 33 public PageParameters persistentParameters = new PageParameters(); 34 35 /** 36 * Reflect the persistent parameters in the page parameter map<br><br> 37 * 38 * @param parameters a page parameter map 39 * @return the page parameter map including the current persistent parameters 40 */ 41 public PageParameters reflectPersistentParameters(PageParameters parameters) { 42 43 parameters.putAll(persistentParameters); 44 45 // parameters.add("theme", "defaultTheme"); 98 46 return parameters; 99 47 } … … 128 76 // check if there is a theme parameter 129 77 String[] object = map.get("theme"); 130 78 131 79 if (object == null) { 132 // no theme in the URL, do not change the value of the parameter80 // no theme choosen, keep the current one 133 81 } else { 134 // try to replace the reference via the indexs135 if ( theme.equals(object[0])){136 // keep the theme that was installed on a previous request82 // check if the users requests a different theme 83 if (object[0].matches(currentTheme.name)) { 84 // current theme requested, nothing to do 137 85 } else { 138 // theme not installed yet, first: remember it 139 VloWebApplication.this.setThemeName(object[0]); 140 // after that: determine the intended css and "install" it 141 // determine the intended picture and install it 86 // different theme requested, compose it 87 currentTheme = new Theme (object[0]); 142 88 } 143 89 } … … 164 110 return cycle; 165 111 } 166 167 private SearchResultsDao searchResults; 168 112 113 /** 114 * Theme currently applied in the VLO web application 115 */ 116 public Theme currentTheme = new Theme ("defaultTheme"); 117 118 /** 119 * A theme is defined by a CSS file, and two image files 120 */ 121 public class Theme { 122 123 public String name, topLeftImage, topRightImage, cssFile; 124 125 /** 126 * Compose a theme<br><br> 127 * 128 * @param name the name of the theme to be composed 129 */ 130 public Theme(String themeName) { 131 132 if (themeName.matches("Clarin-d")) { 133 // select the Clarin-d theme's components 134 135 topLeftImage = "Images/topleftvlo.gif"; 136 topRightImage = "Images/toprightvlo.gif"; 137 cssFile = "css/main.css"; 138 name = "Clarin-d"; 139 } else { 140 // select the default theme elements 141 142 topLeftImage = "Images/topleftvlo.gif"; 143 topRightImage = "Images/toprightvlo.gif"; 144 cssFile = "css/main.css"; 145 name = "defaultTheme"; 146 } 147 // remember the theme as a persistent parameter 148 persistentParameters.put("theme", name); 149 } 150 } 151 169 152 /** 170 153 * Flag indicating whether or not the application object lives in a web … … 187 170 * method, uniform approach might be the most prefarable one. 188 171 */ 189 ShowResultPage.setWebApp(this); 190 FacetBoxPanel.setWebApp(this); 191 FacetHeaderPanel.setWebApp(this); 192 FacetLinkPanel.setWebApp(this); 193 FacetedSearchPage.setWebApp(this); 172 BasePage.setWebApp(this); 173 BasePanel.setWebApp(this); 194 174 195 175 // install theme -> compose theme … … 209 189 } 210 190 211 // start the application 212 191 // creata an object referring to the search results 213 192 searchResults = new SearchResultsDao(); 214 } 215 193 194 // hand over control to the application 195 } 196 197 // remember the search results 198 private SearchResultsDao searchResults; 199 216 200 /** 217 201 * Web application constructor<br><br> … … 245 229 * will create an object that will not look for an external configuration 246 230 * file; it will exclusively rely on the packaged configuration. Typically, 247 * the application's tests will send false to the application constructor.<br><br> 231 * the application's tests will send false to the application constructor. 232 * <br><br> 248 233 * 249 234 * @param inContext If and only if this parameter equals true. later on, the -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/BasePage.java
r2965 r2970 11 11 import org.apache.wicket.resource.ContextRelativeResource; 12 12 13 /** 14 * Properties common to all VLO web application's page objects 15 * 16 * @author keeloo 17 */ 13 18 public class BasePage extends WebPage implements IHeaderContributor{ 14 19 20 // reference to the web application object 21 static VloWebApplication webApp; 22 23 /** 24 * Make sure every web application object sends this message 25 * 26 * @param vloWebApplication reference to the web application object 27 */ 28 public static void setWebApp(VloWebApplication vloWebApplication) { 29 webApp = vloWebApplication; 30 } 31 32 /** 33 * Install a VLO theme<br><br> 34 * 35 * A VLO theme is determined by a CSS file and a banner split in a left and 36 * right image. 37 * 38 * The left part of the banner serves as a link to the faceted search page, 39 * the 'local' home page. Next to this page there is the page the web 40 * application is launched from. This home page is defined in the VloConfig 41 * file. 42 * 43 * @param parameters 44 */ 15 45 public BasePage(PageParameters parameters) { 46 16 47 super(parameters); 17 48 18 // delete all parameters from the map, except theme 19 String theme; 20 theme = parameters.getKey("theme"); 21 if (theme == null){ 22 theme = ""; 23 } 24 parameters = new PageParameters (); 25 parameters.add("theme", theme); 49 // set the applications local home page link to the faceted search page 50 PageParameters homeLinkParameters = new PageParameters (); 26 51 27 // set the applications (local) homelink to the faceted search page 52 webApp.reflectPersistentParameters(homeLinkParameters); 53 28 54 BookmarkablePageLink link = new BookmarkablePageLink("homeLink", 29 FacetedSearchPage.class, parameters);55 FacetedSearchPage.class, homeLinkParameters); 30 56 add(link); 31 57 32 58 // refer to the the left part of the vlo banner as a resource 33 59 Resource leftImageRes; 34 leftImageRes = new ContextRelativeResource( "Images/topleftvlo.gif");60 leftImageRes = new ContextRelativeResource(webApp.currentTheme.topLeftImage); 35 61 36 62 // create the image … … 43 69 // refer to the right part of the vlo banner as a resource 44 70 Resource rightImageRes; 45 rightImageRes = new ContextRelativeResource( "Images/toprightvlo.gif");71 rightImageRes = new ContextRelativeResource(webApp.currentTheme.topRightImage); 46 72 47 73 // create the image … … 53 79 } 54 80 81 /** 82 * Include the theme's CSS file in the HTML page<br><br> 83 * 84 * This method is invoked when Wicket renders a VLO page. 85 * 86 * @param response 87 */ 55 88 @Override 56 89 public void renderHead(IHeaderResponse response) { 57 90 58 response.renderCSSReference( "css/main.css");91 response.renderCSSReference(webApp.currentTheme.cssFile); 59 92 } 60 93 -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetBoxPanel.java
r2965 r2970 6 6 import java.util.List; 7 7 import java.util.Set; 8 9 8 import org.apache.solr.client.solrj.response.FacetField; 10 9 import org.apache.solr.client.solrj.response.FacetField.Count; … … 15 14 import org.apache.wicket.markup.html.list.ListItem; 16 15 import org.apache.wicket.markup.html.list.ListView; 17 import org.apache.wicket.markup.html.panel.Panel;18 16 import org.apache.wicket.model.IModel; 19 17 import org.apache.wicket.model.Model; 20 18 21 public class FacetBoxPanel extends Panel {19 public class FacetBoxPanel extends BasePanel { 22 20 private static final Set<String> IGNORABLE_VALUES = new HashSet<String>(); 23 21 static { … … 31 29 private FacetModel facetModel; 32 30 private int maxNrOfFacetValues; 33 34 // reference to the web application object35 static VloWebApplication webApp;36 37 /**38 * Make sure every web application object sends this message39 *40 * @param vloWebApplication reference to the web application object41 */42 public static void setWebApp (VloWebApplication vloWebApplication){43 webApp = vloWebApplication;44 }45 31 46 32 public FacetBoxPanel(String id, IModel<FacetField> model) { … … 81 67 pageParameters.add(ShowAllFacetValuesPage.FACET_MIN_OCCURS, "1"); 82 68 83 pageParameters = webApp. addSessionParameters(pageParameters);69 pageParameters = webApp.reflectPersistentParameters(pageParameters); 84 70 85 71 add(new BookmarkablePageLink("showMore", ShowAllFacetValuesPage.class, pageParameters) { -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetHeaderPanel.java
r2965 r2970 5 5 import org.apache.wicket.markup.html.basic.Label; 6 6 import org.apache.wicket.markup.html.link.BookmarkablePageLink; 7 import org.apache.wicket.markup.html.panel.Panel;8 7 import org.apache.wicket.model.IModel; 9 8 10 public class FacetHeaderPanel extends Panel {9 public class FacetHeaderPanel extends BasePanel { 11 10 12 11 private static final long serialVersionUID = 1L; 13 14 // reference to the web application object15 static VloWebApplication webApp;16 17 /**18 * Make sure every web application object sends this message19 *20 * @param vloWebApplication reference to the web application object21 */22 public static void setWebApp (VloWebApplication vloWebApplication){23 webApp = vloWebApplication;24 }25 12 26 13 public FacetHeaderPanel(String id, IModel<FacetModel> model, final SearchPageQuery query) { … … 30 17 PageParameters pageParameters = copy.getPageParameters(); 31 18 32 pageParameters = webApp. addSessionParameters(pageParameters);19 pageParameters = webApp.reflectPersistentParameters(pageParameters); 33 20 34 21 add(new BookmarkablePageLink("allLink", FacetedSearchPage.class, pageParameters)); -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetLinkPanel.java
r2965 r2970 1 1 package eu.clarin.cmdi.vlo.pages; 2 2 3 import eu.clarin.cmdi.vlo.VloWebApplication;4 3 import org.apache.solr.client.solrj.response.FacetField.Count; 5 4 import org.apache.wicket.PageParameters; 6 import org.apache.wicket.Session;7 5 import org.apache.wicket.markup.html.basic.Label; 8 6 import org.apache.wicket.markup.html.link.BookmarkablePageLink; 9 7 import org.apache.wicket.markup.html.link.Link; 10 import org.apache.wicket.markup.html.panel.Panel;11 8 import org.apache.wicket.model.IModel; 12 9 13 public class FacetLinkPanel extends Panel {10 public class FacetLinkPanel extends BasePanel { 14 11 15 12 private static final long serialVersionUID = 1L; 16 17 // reference to the web application object18 static VloWebApplication webApp;19 20 /**21 * Make sure every web application object sends this message22 *23 * @param vloWebApplication reference to the web application object24 */25 public static void setWebApp (VloWebApplication vloWebApplication){26 webApp = vloWebApplication;27 }28 13 29 14 public FacetLinkPanel(String id, IModel<Count> model, final SearchPageQuery query) { … … 35 20 PageParameters params = q.getPageParameters(); 36 21 37 params = webApp. addSessionParameters(params);22 params = webApp.reflectPersistentParameters(params); 38 23 39 24 Link<Count> facetLink = new BookmarkablePageLink("facetLink", FacetedSearchPage.class, params); -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetedSearchPage.java
r2969 r2970 38 38 private final static AutoCompleteDao autoCompleteDao = new AutoCompleteDao(); 39 39 40 // reference to the web application object41 static VloWebApplication webApp;42 43 /**44 * Make sure every web application object sends this message45 *46 * @param vloWebApplication reference to the web application object47 */48 public static void setWebApp (VloWebApplication vloWebApplication){49 webApp = vloWebApplication;50 }51 52 40 /** 53 41 * @param parameters Page parameters … … 86 74 PageParameters pageParameters = query.getPageParameters(); 87 75 88 pageParameters = webApp. addSessionParameters(pageParameters);76 pageParameters = webApp.reflectPersistentParameters(pageParameters); 89 77 90 78 setResponsePage(FacetedSearchPage.class, pageParameters); -
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java
r2969 r2970 86 86 newParam.putAll(query.getPageParameters()); 87 87 // add the persistent parameters to this map 88 newParam = webApp. addSessionParameters(newParam);88 newParam = webApp.reflectPersistentParameters(newParam); 89 89 90 90 BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam); … … 406 406 add(link); 407 407 } 408 409 // reference to the web application object410 static VloWebApplication webApp;411 412 /**413 * Make sure every web application object sends this message414 *415 * @param vloWebApplication reference to the web application object416 */417 public static void setWebApp (VloWebApplication vloWebApplication){418 webApp = vloWebApplication;419 }420 408 421 409 public static BookmarkablePageLink<ShowResultPage> createBookMarkableLink(String linkId, SearchPageQuery query, String docId) { … … 423 411 pageParameters.put(ShowResultPage.PARAM_DOC_ID, WicketURLEncoder.QUERY_INSTANCE.encode(docId)); 424 412 425 webApp. addSessionParameters(pageParameters);413 webApp.reflectPersistentParameters(pageParameters); 426 414 427 415 BookmarkablePageLink<ShowResultPage> docLink = new BookmarkablePageLink<ShowResultPage>(linkId, ShowResultPage.class,
Note: See TracChangeset
for help on using the changeset viewer.