1. Refactored part of the code to give a better structure.

2. Moved image url provider to the generic utilities package.
3. Made change to co authorship jsp page to dynamically load images, which in turn uses utilities api to get the imageThumb url for a person. In case of no image, we dont append anything & hence no "placeholders" or "broken image" icons will be seen in some browsers like IE.
This commit is contained in:
cdtank 2010-06-29 16:54:59 +00:00
parent cf4ac521c4
commit e58927661e
5 changed files with 140 additions and 138 deletions

View file

@ -1,9 +1,7 @@
package edu.cornell.mannlib.vitro.webapp.visualization.coauthorship;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
@ -19,10 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryHandler;
public class VisualizationRequestHandler {
@ -58,116 +53,7 @@ public class VisualizationRequestHandler {
System.out.println(VisualizationFrameworkConstants.VIS_MODE_URL_HANDLE);
System.out.println(vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_URL_HANDLE));
System.out.println(VisualizationFrameworkConstants.IMAGE_VIS_MODE_URL_VALUE);
/*
* If the data being requested is about a standalone image, which is used when we want
* to render an image & other info for a co-author OR ego for that matter.
* */
if (VisualizationFrameworkConstants.DATA_RENDER_MODE_URL_VALUE.equalsIgnoreCase(renderMode)
&& VisualizationFrameworkConstants.IMAGE_VIS_MODE_URL_VALUE.equalsIgnoreCase(visMode) ) {
String filterRule = "?predicate = vitro:imageThumb";
GenericQueryHandler imageQueryHandler = new GenericQueryHandler(egoURIParam,
filterRule,
resultFormatParam,
rdfResultFormatParam,
dataSource,
log);
try {
GenericQueryMap imagePropertyToValues = imageQueryHandler.getJavaValueObjects();
String imagePath = "";
/*
* If there is no imageThumb property we want to give the link to "No Image" snap.
* */
if (imagePropertyToValues.size() > 0) {
String vitroSparqlNamespace = QueryConstants.PREFIX_TO_NAMESPACE.get("vitro");
String imageThumbProperty = vitroSparqlNamespace + "imageThumb";
Set<String> personImageThumbPaths = imagePropertyToValues.get(imageThumbProperty);
/*
* Although we know that there can be only one imagePath we are restricted by Java's
* expression power.
* */
for (String providedImagePath : personImageThumbPaths) {
imagePath = "/images/" + providedImagePath;
}
String imageServerPath = visualizationController.getServletContext().getRealPath(imagePath);
File imageFile = new File(imageServerPath) ;
if (!imageFile.exists()) {
Portal portal = vitroRequest.getPortal();
String themeDir = portal != null ? portal.getThemeDir() : Portal.DEFAULT_THEME_DIR_FROM_CONTEXT;
System.out.println("bfore cxtpth " + themeDir);
themeDir = vitroRequest.getContextPath() + '/' + themeDir;
System.out.println("bfore cxtpth " + themeDir);
imagePath = themeDir + "site_icons/visualization/coauthorship/no_image.png";
System.out.println(imagePath);
} else {
System.out.println("ABSOLUTE PATH : " + imageFile.getAbsolutePath());
try {
System.out.println("ABSOLUTE PATH : " + imageFile.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("ABSOLUTE PATH : " + imageFile.getName());
}
} else {
Portal portal = vitroRequest.getPortal();
String themeDir = portal != null ? portal.getThemeDir() : Portal.DEFAULT_THEME_DIR_FROM_CONTEXT;
System.out.println("bfore cxtpth " + themeDir);
themeDir = vitroRequest.getContextPath() + '/' + themeDir;
System.out.println("bfore cxtpth " + themeDir);
imagePath = themeDir + "site_icons/visualization/coauthorship/no_image.png";
System.out.println(imagePath);
}
prepareVisualizationQueryImageResponse(imagePath);
return;
} catch (MalformedQueryParametersException e) {
try {
handleMalformedParameters(e.getMessage());
} catch (ServletException e1) {
log.error(e1.getStackTrace());
} catch (IOException e1) {
log.error(e1.getStackTrace());
}
return;
}
}
QueryHandler queryManager =
new QueryHandler(egoURIParam,
resultFormatParam,
@ -281,23 +167,6 @@ public class VisualizationRequestHandler {
}
}
private void prepareVisualizationQueryImageResponse(String imageURL) {
response.setContentType("text/plain");
try {
PrintWriter responseWriter = response.getWriter();
responseWriter.append(imageURL);
responseWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void prepareVisualizationQueryStandaloneResponse(String egoURIParam,
HttpServletRequest request,
HttpServletResponse response,

View file

@ -1,4 +1,4 @@
package edu.cornell.mannlib.vitro.webapp.visualization;
package edu.cornell.mannlib.vitro.webapp.visualization.personpubcount;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@ -16,7 +16,6 @@ import org.apache.commons.logging.Log;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.personpubcount.VisualizationRequestHandler;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.BiboDocument;

View file

@ -29,7 +29,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.PDFDocument;
import edu.cornell.mannlib.vitro.webapp.visualization.VisualizationCodeGenerator;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VisConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;

View file

@ -1,10 +1,14 @@
package edu.cornell.mannlib.vitro.webapp.visualization.utilities;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Set;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -12,9 +16,15 @@ import org.apache.commons.logging.Log;
import com.hp.hpl.jena.query.DataSource;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationController;
import edu.cornell.mannlib.vitro.webapp.controller.visualization.VisualizationFrameworkConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants;
import edu.cornell.mannlib.vitro.webapp.visualization.exceptions.MalformedQueryParametersException;
import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.GenericQueryMap;
import edu.cornell.mannlib.vitro.webapp.visualization.visutils.GenericQueryHandler;
public class VisualizationRequestHandler {
@ -42,18 +52,79 @@ public class VisualizationRequestHandler {
String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_URL_HANDLE);
String profileVisMode = "PROFILE_URL";
String coAuthorVisMode = "COAUTHORSHIP_URL";
String imageVisMode = "IMAGE_URL";
String resultFormatParam = "RS_TEXT";
String rdfResultFormatParam = "RDF/XML-ABBREV";
String preparedURL = "";
try {
/*
* If the url being requested is about a standalone image, which is used when we want
* to render an image & other info for a co-author OR ego for that matter.
* */
if (imageVisMode.equalsIgnoreCase(visMode)) {
String filterRule = "?predicate = vitro:imageThumb";
GenericQueryHandler imageQueryHandler = new GenericQueryHandler(individualURIParam,
filterRule,
resultFormatParam,
rdfResultFormatParam,
dataSource,
log);
try {
GenericQueryMap imagePropertyToValues = imageQueryHandler.getJavaValueObjects();
String imagePath = "";
/*
* If there is no imageThumb property we want to give the link to "No Image" snap.
* */
if (imagePropertyToValues.size() > 0) {
String vitroSparqlNamespace = QueryConstants.PREFIX_TO_NAMESPACE.get("vitro");
String imageThumbProperty = vitroSparqlNamespace + "imageThumb";
Set<String> personImageThumbPaths = imagePropertyToValues.get(imageThumbProperty);
/*
* Although we know that there can be only one imagePath we are restricted by Java's
* expression power.
* */
for (String providedImagePath : personImageThumbPaths) {
imagePath = "/images/" + providedImagePath;
}
}
prepareVisualizationQueryResponse(imagePath);
return;
} catch (MalformedQueryParametersException e) {
try {
handleMalformedParameters(e.getMessage());
} catch (ServletException e1) {
log.error(e1.getStackTrace());
} catch (IOException e1) {
log.error(e1.getStackTrace());
}
return;
}
}
/*
* By default we will be generating profile url else some specific url like coAuthorShip vis
* url for that individual.
* */
if (coAuthorVisMode.equalsIgnoreCase(visMode)) {
else if (coAuthorVisMode.equalsIgnoreCase(visMode)) {
preparedURL += request.getContextPath()
+ "/admin/visQuery"
@ -111,4 +182,25 @@ public class VisualizationRequestHandler {
}
}
private void handleMalformedParameters(String errorMessage)
throws ServletException, IOException {
Portal portal = vitroRequest.getPortal();
request.setAttribute("error", errorMessage);
RequestDispatcher requestDispatcher = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("bodyJsp", "/templates/visualization/visualization_error.jsp");
request.setAttribute("portalBean", portal);
request.setAttribute("title", "Visualization Query Error - Individual Publication Count");
try {
requestDispatcher.forward(request, response);
} catch (Exception e) {
log.error("EntityEditController could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
}