Strabon

changeset 510:9ad5fecacad6

Finally got to remove the scriplets from store.jsp and use plain, fucking JSTL and EL expressions at the cost of my disruption of piece of mind
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Jul 26 15:47:35 2012 +0300 (2012-07-26)
parents fc8d2ebc91ce
children b0437d20216c
files endpoint/WebContent/store.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java
line diff
     1.1 --- a/endpoint/WebContent/store.jsp	Wed Jul 25 18:38:08 2012 +0300
     1.2 +++ b/endpoint/WebContent/store.jsp	Thu Jul 26 15:47:35 2012 +0300
     1.3 @@ -1,6 +1,5 @@
     1.4  <jsp:directive.page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"/>
     1.5 -<jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/>
     1.6 -<jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.StoreBean"/>
     1.7 +<jsp:useBean id="commonBean" class="eu.earthobservatory.org.StrabonEndpoint.Common" scope="application"/>
     1.8  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
     1.9  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    1.10  <html>
    1.11 @@ -27,11 +26,11 @@
    1.12  <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
    1.13  
    1.14  <!-- include TELEIOS header and description -->
    1.15 -<%@ include file="teleios-header.html"%>
    1.16 +<jsp:include page="teleios-header.html"/>
    1.17  <!-- include TELEIOS header and description -->
    1.18  
    1.19  <FORM method=POST enctype="UTF-8" accept-charset="UTF-8" action="Store">
    1.20 -<INPUT type=hidden name="<%=Common.VIEW%>" value="<%=Common.VIEW_TYPE%>"/>
    1.21 +<INPUT type=hidden name="${commonBean.view}" value="${commonBean.viewType}"/>
    1.22  
    1.23  <TABLE border="0" width="100%">
    1.24  <TR> 
    1.25 @@ -64,13 +63,15 @@
    1.26  	<!--  direct input form -->
    1.27  		<td id="output">Direct Input:</td>
    1.28  		<td id="output">
    1.29 -			<textarea name="<%=StoreBean.PARAM_DATA%>" rows="15" cols="100"></textarea></td>
    1.30 +			<textarea name="${commonBean.paramData}" rows="15" cols="100"></textarea></td>
    1.31  		<td rowspan=4 id="output">
    1.32  			<CENTER>RDF Format:<br/>
    1.33  				<SELECT name="format">
    1.34 -				<% for (String format : Common.registeredFormats) {%>
    1.35 -					<OPTION value="<%=format%>"><%=format%></OPTION>
    1.36 -				<%}%>
    1.37 +				
    1.38 +				<c:forEach var="format" items="${commonBean.registeredFormats}">
    1.39 +					<OPTION value="${format}">${format}</OPTION>
    1.40 +				</c:forEach>
    1.41 +				
    1.42  				</SELECT>
    1.43  			</CENTER>
    1.44  		</td>
    1.45 @@ -78,7 +79,7 @@
    1.46  	<tr>
    1.47  		<td colspan=2 id="output"><br/>
    1.48  		<CENTER>
    1.49 -			<input type="submit" value="Store Input" name="<%=StoreBean.SUBMIT_INPUT%>" style="width: 400px"/>
    1.50 +			<input type="submit" value="Store Input" name="${commonBean.submitInput}" style="width: 400px"/>
    1.51  		</CENTER><br/>
    1.52  		</td>
    1.53  	</tr>
    1.54 @@ -86,14 +87,14 @@
    1.55  	<tr>
    1.56  		<td id="output" >URI Input:</td>
    1.57  		<td id="output">
    1.58 -			<textarea name="<%=StoreBean.PARAM_DATA_URL%>" rows="1" cols="100"></textarea>
    1.59 +			<textarea name="${commonBean.paramDataURL}" rows="1" cols="100"></textarea>
    1.60  		</td>
    1.61  	</tr>
    1.62  	
    1.63  	<tr>
    1.64  		<td colspan=2 id="output"><br/>
    1.65  			<CENTER>
    1.66 -				<INPUT type="submit" value="Store from URI" name="<%=StoreBean.SUBMIT_URL%>" style="width: 400px"/>
    1.67 +				<INPUT type="submit" value="Store from URI" name="${commonBean.submitURL}" style="width: 400px"/>
    1.68  			</CENTER><br/>
    1.69  		</td>
    1.70  	</tr>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Wed Jul 25 18:38:08 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Thu Jul 26 15:47:35 2012 +0300
     2.3 @@ -4,6 +4,7 @@
     2.4  package eu.earthobservatory.org.StrabonEndpoint;
     2.5  
     2.6  import java.util.ArrayList;
     2.7 +import java.util.List;
     2.8  
     2.9  import org.openrdf.rio.RDFFormat;
    2.10  
    2.11 @@ -15,20 +16,32 @@
    2.12  public class Common {
    2.13  
    2.14      /**
    2.15 -	 * Parameter used in the jsp file to denote the usage
    2.16 +	 * Parameter used in JSP files to denote the usage
    2.17  	 * of the HTML interface
    2.18  	 */
    2.19  	public static final String VIEW 		= "view";
    2.20  	public static final String VIEW_TYPE 	= "HTML";
    2.21 +
    2.22 +	/**
    2.23 +	 * Parameters used in the store.jsp file
    2.24 +	 */
    2.25 +	public static final String PARAM_DATA 		= "data";
    2.26 +	public static final String PARAM_FORMAT 	= "format";
    2.27 +	public static final String PARAM_DATA_URL	= "url";
    2.28 +	
    2.29 +	/**
    2.30 +	 * Submit buttons in store.jsp
    2.31 +	 */
    2.32 +	public static final String SUBMIT_INPUT		= "dsubmit";
    2.33 +	public static final String SUBMIT_URL		= "fromurl";
    2.34  	
    2.35  	/**
    2.36  	 * Keeps the registered and available RDF formats.
    2.37  	 */
    2.38 -	public static ArrayList<String> registeredFormats;
    2.39 +	public static final List<String> registeredFormats = new ArrayList<String>();
    2.40  	
    2.41  	// initialize registered and available formats
    2.42  	static {
    2.43 -		registeredFormats = new ArrayList<String>();
    2.44  		for (RDFFormat format : RDFFormat.values()) {
    2.45  			registeredFormats.add(format.getName());
    2.46  		}
    2.47 @@ -60,5 +73,37 @@
    2.48                  
    2.49          return null;
    2.50      }
    2.51 -
    2.52 +    
    2.53 +    /* The following getters exist only because we need access to this class
    2.54 +     * through JSP pages. To do so, the class need to be a Bean, thus even
    2.55 +     * though we have static fields, we need to have getters for the respective
    2.56 +     * static fields that are not static themselves. */
    2.57 +    
    2.58 +    public List<String> getRegisteredFormats() {
    2.59 +    	return Common.registeredFormats;
    2.60 +    }
    2.61 +    
    2.62 +    public String getView() {
    2.63 +    	return Common.VIEW;
    2.64 +    }
    2.65 +    
    2.66 +    public String getViewType() {
    2.67 +    	return Common.VIEW_TYPE;
    2.68 +    }
    2.69 +    
    2.70 +    public String getParamData() {
    2.71 +    	return Common.PARAM_DATA;
    2.72 +    }
    2.73 +    
    2.74 +    public String getSubmitInput() {
    2.75 +    	return Common.SUBMIT_INPUT;
    2.76 +    }
    2.77 +    
    2.78 +    public String getSubmitURL() {
    2.79 +    	return Common.SUBMIT_URL;
    2.80 +    }
    2.81 +    
    2.82 +    public String getParamDataURL() {
    2.83 +    	return Common.PARAM_DATA_URL;
    2.84 +    }
    2.85  }
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Wed Jul 25 18:38:08 2012 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Thu Jul 26 15:47:35 2012 +0300
     3.3 @@ -33,13 +33,6 @@
     3.4  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StoreBean.class);
     3.5  	
     3.6  	/**
     3.7 -	 * Parameters used in the store.jsp file
     3.8 -	 */
     3.9 -	public static final String PARAM_DATA 		= "data";
    3.10 -	public static final String PARAM_FORMAT 	= "format";
    3.11 -	public static final String PARAM_DATA_URL	= "url";
    3.12 -	
    3.13 -	/**
    3.14  	 * Error/Info parameters used in the store.jsp file
    3.15  	 */
    3.16  	public static final String ERROR 			= "error";
    3.17 @@ -51,12 +44,6 @@
    3.18  	private static final String STORE_ERROR 	= "An error occurred while storing input data!";
    3.19  	private static final String PARAM_ERROR 	= "RDF format or input data are not set or are invalid!";
    3.20  	private static final String STORE_OK		= "Data stored successfully!";
    3.21 -	
    3.22 -	/**
    3.23 -	 * Submit buttons
    3.24 -	 */
    3.25 -	public static final String SUBMIT_INPUT		= "dsubmit";
    3.26 -	public static final String SUBMIT_URL		= "fromurl";
    3.27  
    3.28  	/**
    3.29  	 * Strabon wrapper
    3.30 @@ -80,10 +67,10 @@
    3.31  	
    3.32  	private String getData(HttpServletRequest request) {
    3.33  		// check whether we read from INPUT or URL
    3.34 -		boolean input = (request.getParameter(SUBMIT_URL) != null) ? false:true;
    3.35 +		boolean input = (request.getParameter(Common.SUBMIT_URL) != null) ? false:true;
    3.36  		
    3.37  		// return "data" value accordingly
    3.38 -		return input ? request.getParameter(PARAM_DATA):request.getParameter(PARAM_DATA_URL);
    3.39 +		return input ? request.getParameter(Common.PARAM_DATA):request.getParameter(Common.PARAM_DATA_URL);
    3.40  	}
    3.41  	
    3.42  	@Override
    3.43 @@ -108,7 +95,7 @@
    3.44       */
    3.45      private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    3.46  		// check whether we read from INPUT or URL
    3.47 -		boolean input = (request.getParameter(SUBMIT_URL) != null) ? false:true;
    3.48 +		boolean input = (request.getParameter(Common.SUBMIT_URL) != null) ? false:true;
    3.49  		
    3.50      	// get the dispatcher for forwarding the rendering of the response
    3.51      	RequestDispatcher dispatcher = request.getRequestDispatcher("store.jsp");
    3.52 @@ -117,7 +104,7 @@
    3.53      	String data = getData(request);
    3.54      			
    3.55      	// the format of the data
    3.56 -    	RDFFormat format = (request.getParameter(PARAM_FORMAT) != null) ? RDFFormat.valueOf(request.getParameter(PARAM_FORMAT)):null;
    3.57 +    	RDFFormat format = (request.getParameter(Common.PARAM_FORMAT) != null) ? RDFFormat.valueOf(request.getParameter(Common.PARAM_FORMAT)):null;
    3.58      	
    3.59      	if (data == null || format == null) {
    3.60      		request.setAttribute(ERROR, PARAM_ERROR);
    3.61 @@ -148,7 +135,7 @@
    3.62       */
    3.63      private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    3.64  		// check whether we read from INPUT or URL
    3.65 -		boolean input = (request.getParameter(SUBMIT_URL) != null) ? false:true;
    3.66 +		boolean input = (request.getParameter(Common.SUBMIT_URL) != null) ? false:true;
    3.67  		
    3.68      	// RDF data to store
    3.69      	String data = getData(request);