web.xml: add servlet for ExportQrCodeController
individual-exportQrCode.ftl: basic mockup for QR Export page ExportQrCodeController: created IndividualTemplateModel.java: prevent QR data from being generated twice, add URL for Export QR Code page
This commit is contained in:
parent
cb38cd87df
commit
e08a675874
4 changed files with 110 additions and 0 deletions
|
@ -1413,6 +1413,16 @@
|
||||||
<url-pattern>NONE</url-pattern>
|
<url-pattern>NONE</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ExportQrCodeController</servlet-name>
|
||||||
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.ExportQrCodeController</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ExportQrCodeController</servlet-name>
|
||||||
|
<url-pattern>/qrcode</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
|
||||||
<!-- ============================== servlet-mappings ======================== -->
|
<!-- ============================== servlet-mappings ======================== -->
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Page providing options for disseminating QR codes -->
|
||||||
|
|
||||||
|
<#include "individual-qrCodeFoafPerson.ftl">
|
||||||
|
|
||||||
|
<#assign qrCodeWidth = "150">
|
||||||
|
|
||||||
|
<h2>Export QR Code</h2>
|
||||||
|
<div>
|
||||||
|
<div style="float:left">
|
||||||
|
<#assign thumbUrl = individual.thumbUrl! "${urls.images}/placeholders/person.thumbnail.jpg" >
|
||||||
|
<img src="${thumbUrl}" />
|
||||||
|
</div>
|
||||||
|
<div style="float:left">
|
||||||
|
<h3>${individual.nameStatement.value}</h3>
|
||||||
|
</div>
|
||||||
|
<div style="clear:both" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="border:1px solid #cccccc">
|
||||||
|
<h4 style="padding-left:5px">VCard</h4>
|
||||||
|
<@qrCodeVCard qrCodeWidth="150" />
|
||||||
|
<textarea readonly="readonly" style="width:600px;height:120px">
|
||||||
|
<img src="${getQrCodeUrlForVCard(qrCodeWidth)}" /><#t>
|
||||||
|
</textarea><#t>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="border:1px solid #cccccc">
|
||||||
|
<h4 style="padding-left:5px">Hyperlink</h4>
|
||||||
|
<@qrCodeLink qrCodeWidth="150" />
|
||||||
|
<textarea readonly="readonly" style="width:600px;height:120px">
|
||||||
|
<img src="${getQrCodeUrlForLink(qrCodeWidth)}" /><#t>
|
||||||
|
</textarea><#t>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualController;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
import freemarker.ext.beans.BeansWrapper;
|
||||||
|
import freemarker.template.DefaultObjectWrapper;
|
||||||
|
|
||||||
|
public class ExportQrCodeController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Log log = LogFactory.getLog(ExportQrCodeController.class);
|
||||||
|
private static final String TEMPLATE_DEFAULT = "individual-exportQrCode.ftl";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
try {
|
||||||
|
Individual individual = IndividualController.getIndividualFromRequest(vreq);
|
||||||
|
|
||||||
|
DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
|
||||||
|
wrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE);
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
body.put("individual", wrapper.wrap(new IndividualTemplateModel(individual, vreq)));
|
||||||
|
|
||||||
|
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error(e, e);
|
||||||
|
return new ExceptionResponseValues(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTitle(String siteName, VitroRequest vreq) {
|
||||||
|
return "Export QR Code for " + IndividualController.getIndividualFromRequest(vreq).getRdfsLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IndividualTemplateModel.class);
|
private static final Log log = LogFactory.getLog(IndividualTemplateModel.class);
|
||||||
|
private Map<String, String> qrData = null;
|
||||||
|
|
||||||
public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
||||||
super(individual, vreq);
|
super(individual, vreq);
|
||||||
|
@ -75,6 +76,12 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> getQrData() {
|
public Map<String, String> getQrData() {
|
||||||
|
if(qrData == null)
|
||||||
|
qrData = generateQrData();
|
||||||
|
return qrData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> generateQrData() {
|
||||||
String core = "http://vivoweb.org/ontology/core#";
|
String core = "http://vivoweb.org/ontology/core#";
|
||||||
String foaf = "http://xmlns.com/foaf/0.1/";
|
String foaf = "http://xmlns.com/foaf/0.1/";
|
||||||
|
|
||||||
|
@ -104,6 +111,10 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel {
|
||||||
String externalUrl = tempUrl + profileUrl;
|
String externalUrl = tempUrl + profileUrl;
|
||||||
qrData.put("externalUrl", externalUrl);
|
qrData.put("externalUrl", externalUrl);
|
||||||
|
|
||||||
|
String individualUri = individual.getURI();
|
||||||
|
String contextPath = vreq.getContextPath();
|
||||||
|
qrData.put("exportQrCodeUrl", contextPath + "/qrcode?uri=" + UrlBuilder.urlEncode(individualUri));
|
||||||
|
|
||||||
return qrData;
|
return qrData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue