From d18b02782e95bef002814e3dba0b5223ac2c4bb6 Mon Sep 17 00:00:00 2001 From: ryounes Date: Tue, 24 May 2011 19:00:30 +0000 Subject: [PATCH] Changes to QR code generation to support swapping in a different model in IndividualController: fixed NPEs, and change getQrCode() to doQrCode() so it's invoked only when the template asks for it. --- .../templates/freemarker/body/aboutQrCodes.ftl | 4 ++-- .../freemarker/body/foaf-person--exportQrCode.ftl | 2 +- .../individual/individual-qrCodeFoafPerson.ftl | 2 +- .../individual/individual-qrCodeGenerator.ftl | 6 +++--- .../individual/IndividualTemplateModel.java | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/productMods/templates/freemarker/body/aboutQrCodes.ftl b/productMods/templates/freemarker/body/aboutQrCodes.ftl index aeb7c1ff..41ec0c81 100644 --- a/productMods/templates/freemarker/body/aboutQrCodes.ftl +++ b/productMods/templates/freemarker/body/aboutQrCodes.ftl @@ -6,13 +6,13 @@

What is QR?

-

QR stands for Quick Response is a standard for two-dimensional barcodes that can be read by mobile devices equipped with cameras (such as a smartphone).

+

QR, which stands for Quick Response, is a standard for two-dimensional barcodes that can be read by mobile devices equipped with cameras (such as a smartphone).

What kind of data is in a QR code?

QR codes can encode many different types of data. The QR code on the profile page of a person in VIVO encodes information about that person in vCard format. This is a sort of digital business card, containing information about the person's name, address, telephone number, email address, and more.

-

If you click on a person's QR code in VIVO, you will be taken to the QR Export page for that person. On this page contains the vCard QR code seen on the front page, as well as a QR code containing a simple hyperlink to the user's VIVO profile. It also contains an HTML tag for each code, that can be embedded in a web page to display that code on other sites.

+

If you click on a person's QR code in VIVO, you will be taken to the QR Export page for that person. This page contains the vCard QR code seen on the front page, as well as a QR code containing a simple hyperlink to the user's VIVO profile. It also contains an HTML tag for each code, that can be embedded in a web page to display that code on other sites.

<#-- todo: make VIVO API? Currently pasting Google API code into export area, this will be static and not change if VIVO data is updated. -->

How do I read a QR code?

diff --git a/productMods/templates/freemarker/body/foaf-person--exportQrCode.ftl b/productMods/templates/freemarker/body/foaf-person--exportQrCode.ftl index dbab2238..d6c00c1a 100644 --- a/productMods/templates/freemarker/body/foaf-person--exportQrCode.ftl +++ b/productMods/templates/freemarker/body/foaf-person--exportQrCode.ftl @@ -6,7 +6,7 @@ <#assign qrCodeWidth = "150"> -

Export QR Code (What is this?)

+

Export QR Code (What is this?)

<#assign thumbUrl = individual.thumbUrl! "${urls.images}/placeholders/person.thumbnail.jpg" > diff --git a/productMods/templates/freemarker/body/partials/individual/individual-qrCodeFoafPerson.ftl b/productMods/templates/freemarker/body/partials/individual/individual-qrCodeFoafPerson.ftl index 467c52d4..7a0bc83c 100644 --- a/productMods/templates/freemarker/body/partials/individual/individual-qrCodeFoafPerson.ftl +++ b/productMods/templates/freemarker/body/partials/individual/individual-qrCodeFoafPerson.ftl @@ -3,5 +3,5 @@ <#include "individual-qrCodeGenerator.ftl"> <#if hasValidVCard()> -
  • qr icon
  • +
  • qr icon
  • \ No newline at end of file diff --git a/productMods/templates/freemarker/body/partials/individual/individual-qrCodeGenerator.ftl b/productMods/templates/freemarker/body/partials/individual/individual-qrCodeGenerator.ftl index 21e72246..094830b9 100644 --- a/productMods/templates/freemarker/body/partials/individual/individual-qrCodeGenerator.ftl +++ b/productMods/templates/freemarker/body/partials/individual/individual-qrCodeGenerator.ftl @@ -24,7 +24,7 @@ <#function getQrCodeUrlForVCard qrCodeWidth> - <#local qrData = individual.qrData > + <#local qrData = individual.doQrData() > <#local core = "http://vivoweb.org/ontology/core#"> <#local foaf = "http://xmlns.com/foaf/0.1/"> @@ -69,7 +69,7 @@ <#function getQrCodeUrlForLink qrCodeWidth> - <#local qrData = individual.qrData > + <#local qrData = individual.doQrData() > <#local url = qrData.externalUrl! > @@ -105,7 +105,7 @@ <#function hasValidVCard> - <#local qrData = individual.qrData > + <#local qrData = individual.doQrData() > <#local firstName = qrData.firstName! > <#local lastName = qrData.lastName! > diff --git a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java index 4b02eb18..2888a60b 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java @@ -102,7 +102,7 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel { return id; } - public Map getQrData() { + public Map doQrData() { if(qrData == null) qrData = generateQrData(); return qrData; @@ -120,15 +120,15 @@ public class IndividualTemplateModel extends BaseIndividualTemplateModel { Collection phoneNumbers = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, core + "phoneNumber"); Collection emails = wdf.getDataPropertyStatementDao().getDataPropertyStatementsForIndividualByDataPropertyURI(individual, core + "email"); - if(firstNames.size() > 0) + if(firstNames != null && ! firstNames.isEmpty()) qrData.put("firstName", firstNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); - if(lastNames.size() > 0) + if(lastNames != null && ! lastNames.isEmpty()) qrData.put("lastName", lastNames.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); - if(preferredTitles.size() > 0) + if(preferredTitles != null && ! preferredTitles.isEmpty()) qrData.put("preferredTitle", preferredTitles.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); - if(phoneNumbers.size() > 0) + if(phoneNumbers != null && ! phoneNumbers.isEmpty()) qrData.put("phoneNumber", phoneNumbers.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); - if(emails.size() > 0) + if(emails != null && ! emails.isEmpty()) qrData.put("email", emails.toArray(new DataPropertyStatement[firstNames.size()])[0].getData()); String tempUrl = vreq.getRequestURL().toString();