From e956a3668aacf1a0ff1b4138c225aa1aff8bdcc0 Mon Sep 17 00:00:00 2001 From: bdc34 Date: Thu, 3 Feb 2011 20:28:36 +0000 Subject: [PATCH] Changing ViewFinder.java to not check the vclasses for custom short views. NIHVIVO-2024 --- .../mannlib/vitro/webapp/web/ViewFinder.java | 182 +++++++++--------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/ViewFinder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/ViewFinder.java index ee33622ce..435df86bd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/ViewFinder.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/ViewFinder.java @@ -80,101 +80,101 @@ public class ViewFinder { } private String findCustomTemplateByVClasses(Individual individual, VitroRequest vreq) { - - Method method = view.getMethod(); - TemplateLoader templateLoader = ((Configuration) vreq.getAttribute("freemarkerConfig")).getTemplateLoader(); - - /* RY The logic here is incorrect. The vclasses are - * returned in a random order, whereas we need to - * traverse the class hierarchy and find the most - * specific custom view applicable to the individual. - * The logic is complex because individuals can belong - * to multiple classes, and classes can subclass multiple - * classes. If there are two competing custom views at the - * same level of specificity, what should we do? Also, if we - * are displaying a list of individuals belonging to a certain - * class, we may want to use only a custom view defined for that - * class and NOT a more specific one. See NIHVIVO-568. Similarly - * when we're displaying an object property: if we are displaying - * #hasPrincipalInvestigatorRole, the object should be displayed - * as a PrincipalInvestigatorRole object rather than some other type. - * - * For now, iterate first through asserted classes, and if no custom view - * found there, iterate through inferred classes. Modeled on MiscWebUtils.getCustomShortView(). - */ - String customTemplate = null; - VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao(); - List vclasses = individual.getVClasses(true); // get directly asserted vclasses - Set superClasses = new HashSet(); - - // First try directly asserted classes. There is no useful decision - // mechanism for the case where two directly asserted classes - // define a custom template. - // RY If we're getting the custom short view with reference to an object property. - // should we use the property's getRangeVClass() method instead? - for (VClass vclass : vclasses) { - // Use this class's custom template, if there is one - customTemplate = findCustomTemplateForVClass(vclass, method, templateLoader); - if (customTemplate != null) { - return customTemplate; - } - // Otherwise, add superclass to list of vclasses to check for custom - // templates. - String vclassUri = vclass.getURI(); - superClasses.addAll(vcDao.getAllSuperClassURIs(vclassUri)); - } - - // Next try superclasses. There is no useful decision mechanism for - // the case where two superclasses have a custom template defined. - for (String superClassUri : superClasses) { - VClass vc = vcDao.getVClassByURI(superClassUri); - customTemplate = findCustomTemplateForVClass(vc, method, templateLoader); - if (customTemplate != null) { - return customTemplate; - } - } +// +// Method method = view.getMethod(); +// TemplateLoader templateLoader = ((Configuration) vreq.getAttribute("freemarkerConfig")).getTemplateLoader(); +// +// /* RY The logic here is incorrect. The vclasses are +// * returned in a random order, whereas we need to +// * traverse the class hierarchy and find the most +// * specific custom view applicable to the individual. +// * The logic is complex because individuals can belong +// * to multiple classes, and classes can subclass multiple +// * classes. If there are two competing custom views at the +// * same level of specificity, what should we do? Also, if we +// * are displaying a list of individuals belonging to a certain +// * class, we may want to use only a custom view defined for that +// * class and NOT a more specific one. See NIHVIVO-568. Similarly +// * when we're displaying an object property: if we are displaying +// * #hasPrincipalInvestigatorRole, the object should be displayed +// * as a PrincipalInvestigatorRole object rather than some other type. +// * +// * For now, iterate first through asserted classes, and if no custom view +// * found there, iterate through inferred classes. Modeled on MiscWebUtils.getCustomShortView(). +// */ +// String customTemplate = null; +// VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao(); +// List vclasses = individual.getVClasses(true); // get directly asserted vclasses +// Set superClasses = new HashSet(); +// +// // First try directly asserted classes. There is no useful decision +// // mechanism for the case where two directly asserted classes +// // define a custom template. +// // RY If we're getting the custom short view with reference to an object property. +// // should we use the property's getRangeVClass() method instead? +// for (VClass vclass : vclasses) { +// // Use this class's custom template, if there is one +// customTemplate = findCustomTemplateForVClass(vclass, method, templateLoader); +// if (customTemplate != null) { +// return customTemplate; +// } +// // Otherwise, add superclass to list of vclasses to check for custom +// // templates. +// String vclassUri = vclass.getURI(); +// superClasses.addAll(vcDao.getAllSuperClassURIs(vclassUri)); +// } +// +// // Next try superclasses. There is no useful decision mechanism for +// // the case where two superclasses have a custom template defined. +// for (String superClassUri : superClasses) { +// VClass vc = vcDao.getVClassByURI(superClassUri); +// customTemplate = findCustomTemplateForVClass(vc, method, templateLoader); +// if (customTemplate != null) { +// return customTemplate; +// } +// } return null; } - private String findCustomTemplateForVClass(VClass vclass, Method method, TemplateLoader templateLoader) { - String customTemplate = null; - String vClassCustomTemplate = null; - - try { - vClassCustomTemplate = (String) method.invoke(vclass); - } catch (IllegalArgumentException e) { - log.error("Incorrect arguments passed to method " + method.getName() + " in findCustomTemplateForVClass()."); - } catch (IllegalAccessException e) { - log.error("Method " + method.getName() + " cannot be accessed in findCustomTemplateForVClass()."); - } catch (InvocationTargetException e) { - log.error("Exception thrown by method " + method.getName() + " in findCustomTemplateForVClass()."); - } - - if (!StringUtils.isEmpty(vClassCustomTemplate)) { - log.debug("Custom template " + vClassCustomTemplate + " defined for class " + vclass.getName()); - try { - // Make sure the template exists - if (templateLoader.findTemplateSource(vClassCustomTemplate) != null) { - log.debug("Found defined custom template " + vClassCustomTemplate + " for class " + vclass.getName()); - customTemplate = vClassCustomTemplate; - } else { - log.warn("Custom template " + vClassCustomTemplate + " for class " + vclass.getName() + " defined but does not exist."); - } - } catch (IOException e) { - log.error("IOException looking for source for template " + vClassCustomTemplate); - } - } - - if (log.isDebugEnabled()) { - if (customTemplate != null) { - log.debug("Using custom template " + customTemplate + " for class " + vclass.getName()); - } else { - log.debug("No custom template found for class " + vclass.getName()); - } - } - return customTemplate; - } +// private String findCustomTemplateForVClass(VClass vclass, Method method, TemplateLoader templateLoader) { +// String customTemplate = null; +// String vClassCustomTemplate = null; +// +// try { +// vClassCustomTemplate = (String) method.invoke(vclass); +// } catch (IllegalArgumentException e) { +// log.error("Incorrect arguments passed to method " + method.getName() + " in findCustomTemplateForVClass()."); +// } catch (IllegalAccessException e) { +// log.error("Method " + method.getName() + " cannot be accessed in findCustomTemplateForVClass()."); +// } catch (InvocationTargetException e) { +// log.error("Exception thrown by method " + method.getName() + " in findCustomTemplateForVClass()."); +// } +// +// if (!StringUtils.isEmpty(vClassCustomTemplate)) { +// log.debug("Custom template " + vClassCustomTemplate + " defined for class " + vclass.getName()); +// try { +// // Make sure the template exists +// if (templateLoader.findTemplateSource(vClassCustomTemplate) != null) { +// log.debug("Found defined custom template " + vClassCustomTemplate + " for class " + vclass.getName()); +// customTemplate = vClassCustomTemplate; +// } else { +// log.warn("Custom template " + vClassCustomTemplate + " for class " + vclass.getName() + " defined but does not exist."); +// } +// } catch (IOException e) { +// log.error("IOException looking for source for template " + vClassCustomTemplate); +// } +// } +// +// if (log.isDebugEnabled()) { +// if (customTemplate != null) { +// log.debug("Using custom template " + customTemplate + " for class " + vclass.getName()); +// } else { +// log.debug("No custom template found for class " + vclass.getName()); +// } +// } +// return customTemplate; +// } }