work on VIVO-303 picklist sorting and display
This commit is contained in:
parent
967278217f
commit
5293824fa2
37 changed files with 280 additions and 349 deletions
|
@ -2,13 +2,19 @@
|
|||
|
||||
package edu.cornell.mannlib.vedit.controller;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -21,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||
import edu.cornell.mannlib.vedit.beans.Option;
|
||||
import edu.cornell.mannlib.vedit.util.FormUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
|
@ -155,6 +162,41 @@ public class BaseEditController extends VitroHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
public List<Option> getSortedList(HashMap<String,Option> hashMap, List<Option> optionList, VitroRequest vreq){
|
||||
|
||||
class ListComparator implements Comparator<String>{
|
||||
|
||||
Collator collator;
|
||||
|
||||
public ListComparator(Collator collator) {
|
||||
this.collator = collator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
return collator.compare(str1, str2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> bodyVal = new ArrayList<String>();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
Iterator<Option> itr = optionList.iterator();
|
||||
while(itr.hasNext()){
|
||||
Option option = itr.next();
|
||||
hashMap.put(option.getBody(),option);
|
||||
bodyVal.add(option.getBody());
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(bodyVal, new ListComparator(vreq.getCollator()));
|
||||
ListIterator<String> itrStr = bodyVal.listIterator();
|
||||
while(itrStr.hasNext()){
|
||||
options.add(hashMap.get(itrStr.next()));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
protected WebappDaoFactory getWebappDaoFactory() {
|
||||
return ModelAccess.on(getServletContext()).getBaseWebappDaoFactory();
|
||||
}
|
||||
|
|
|
@ -133,6 +133,10 @@ public class BaseResourceBean implements ResourceBean {
|
|||
this.URI = namespace + localName;
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return getLocalName();
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
if( localName == null && this.URI != null)
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.LinkedList;
|
|||
* @author bjl23
|
||||
*
|
||||
*/
|
||||
public class DataProperty extends Property implements Comparable<DataProperty> {
|
||||
public class DataProperty extends Property implements Comparable<DataProperty>, ResourceBean {
|
||||
|
||||
private String name = null;
|
||||
private String publicName = null;
|
||||
|
@ -62,6 +62,10 @@ public class DataProperty extends Property implements Comparable<DataProperty> {
|
|||
public void setPublicName(String publicName) {
|
||||
this.publicName = publicName;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return getPublicName();
|
||||
}
|
||||
|
||||
public String getDomainClassURI() {
|
||||
return domainClassURI;
|
||||
|
|
|
@ -22,7 +22,7 @@ import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
|||
* a class representing an object property
|
||||
*
|
||||
*/
|
||||
public class ObjectProperty extends Property implements Comparable<ObjectProperty>
|
||||
public class ObjectProperty extends Property implements Comparable<ObjectProperty>, ResourceBean
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(ObjectProperty.class.getName());
|
||||
|
||||
|
@ -95,6 +95,10 @@ public class ObjectProperty extends Property implements Comparable<ObjectPropert
|
|||
this.domainEntityURI = domainEntityURI;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return getDomainPublic();
|
||||
}
|
||||
|
||||
public String getDomainPublic() {
|
||||
return domainPublic;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.Comparator;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class Property extends BaseResourceBean {
|
||||
public class Property extends BaseResourceBean implements ResourceBean {
|
||||
|
||||
private static Log log = LogFactory.getLog( Property.class );
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
|||
* Time: 3:41:23 PM
|
||||
*/
|
||||
public interface ResourceBean {
|
||||
|
||||
String getURI();
|
||||
|
||||
boolean isAnonymous();
|
||||
|
@ -24,28 +25,20 @@ public interface ResourceBean {
|
|||
|
||||
void setLocalName(String localName);
|
||||
|
||||
String getLabel();
|
||||
|
||||
public RoleLevel getHiddenFromDisplayBelowRoleLevel() ;
|
||||
|
||||
public void setHiddenFromDisplayBelowRoleLevel(RoleLevel eR) ;
|
||||
|
||||
public void setHiddenFromDisplayBelowRoleLevelUsingRoleUri(String roleUri) ;
|
||||
/*
|
||||
public RoleLevel getProhibitedFromCreateBelowRoleLevel() ;
|
||||
|
||||
public void setProhibitedFromCreateBelowRoleLevel(RoleLevel eR) ;
|
||||
|
||||
public void setProhibitedFromCreateBelowRoleLevelUsingRoleUri(String roleUri) ;
|
||||
*/
|
||||
|
||||
public RoleLevel getProhibitedFromUpdateBelowRoleLevel() ;
|
||||
|
||||
public void setProhibitedFromUpdateBelowRoleLevel(RoleLevel eR) ;
|
||||
|
||||
public void setProhibitedFromUpdateBelowRoleLevelUsingRoleUri(String roleUri) ;
|
||||
/*
|
||||
public RoleLevel getProhibitedFromDeleteBelowRoleLevel() ;
|
||||
|
||||
public String getPickListName();
|
||||
|
||||
public void setProhibitedFromDeleteBelowRoleLevel(RoleLevel eR) ;
|
||||
|
||||
public void setProhibitedFromDeleteBelowRoleLevelUsingRoleUri(String roleUri) ;
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -5,10 +5,13 @@ package edu.cornell.mannlib.vitro.webapp.controller;
|
|||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.Collator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -27,7 +30,9 @@ import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
||||
|
@ -186,6 +191,25 @@ public class VitroHttpServlet extends HttpServlet {
|
|||
return request.getContextPath() + Controllers.AUTHENTICATE
|
||||
+ "?afterLogin=" + encodedAfterLoginUrl;
|
||||
}
|
||||
|
||||
protected void sortForPickList(List<? extends ResourceBean> beans,
|
||||
VitroRequest vreq) {
|
||||
Collections.sort(beans, new PickListSorter(vreq));
|
||||
}
|
||||
|
||||
protected class PickListSorter implements Comparator<ResourceBean> {
|
||||
|
||||
Collator collator;
|
||||
|
||||
public PickListSorter(VitroRequest vreq) {
|
||||
this.collator = vreq.getCollator();
|
||||
}
|
||||
|
||||
public int compare(ResourceBean b1, ResourceBean b2) {
|
||||
return collator.compare(b1.getPickListName(), b2.getPickListName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If logging on the subclass is set to the TRACE level, dump the HTTP
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -213,7 +214,15 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
|||
|
||||
public OntModel getLanguageNeutralUnionFullModel() {
|
||||
return (OntModel) getAttribute("languageNeutralUnionFullModel");
|
||||
}
|
||||
}
|
||||
|
||||
public void setCollator(Collator collator) {
|
||||
setAttribute("collator", collator);
|
||||
}
|
||||
|
||||
public Collator getCollator() {
|
||||
return (Collator) getAttribute("collator");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -64,11 +64,12 @@ public class IndividualTypeRetryController extends BaseEditController {
|
|||
request.setAttribute("individual", ind);
|
||||
|
||||
List<VClass> allVClasses = vcDao.getAllVclasses();
|
||||
sortForPickList(allVClasses, vreq);
|
||||
Set<String> allClassURISet = new HashSet<String>();
|
||||
Map<String,String> classNameMap = new HashMap<String,String>();
|
||||
for (Iterator allClassIt = allVClasses.iterator(); allClassIt.hasNext(); ) {
|
||||
VClass vc = (VClass) allClassIt.next();
|
||||
classNameMap.put(vc.getURI(),vc.getLocalNameWithPrefix());
|
||||
classNameMap.put(vc.getURI(),vc.getPickListName());
|
||||
allClassURISet.add(vc.getURI());
|
||||
}
|
||||
|
||||
|
@ -98,7 +99,6 @@ public class IndividualTypeRetryController extends BaseEditController {
|
|||
typeOptionList.add(opt);
|
||||
}
|
||||
|
||||
Collections.sort(typeOptionList,new OptionCollator());
|
||||
optionMap.put("types",typeOptionList);
|
||||
|
||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||
|
@ -124,23 +124,4 @@ public class IndividualTypeRetryController extends BaseEditController {
|
|||
// shouldn't be posting to this controller
|
||||
}
|
||||
|
||||
static class OptionCollator implements Comparator<Option> {
|
||||
public int compare (Option o1, Option o2) {
|
||||
// Collator collator = Collator.getInstance();
|
||||
return getLocalName ( o1.getBody().toString() )
|
||||
.compareTo(
|
||||
getLocalName ( o2.getBody().toString() ) );
|
||||
}
|
||||
|
||||
private String getLocalName( String in ){
|
||||
if( in == null )
|
||||
return "";
|
||||
int i = in.indexOf(':');
|
||||
if( i >= 0 )
|
||||
return in.substring( i );
|
||||
else
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class ObjectPropertyStatementRetryController extends BaseEditController {
|
|||
}
|
||||
List<Individual> indList = new LinkedList();
|
||||
indList.addAll(possIndSet);
|
||||
Collections.sort(indList, new IndComparator());
|
||||
sortForPickList(indList, vreq);
|
||||
List objectEntOptionList = new LinkedList();
|
||||
Iterator<Individual> indIt = indList.iterator();
|
||||
while (indIt.hasNext()) {
|
||||
|
@ -168,12 +168,4 @@ public class ObjectPropertyStatementRetryController extends BaseEditController {
|
|||
doPost(request, response);
|
||||
}
|
||||
|
||||
private class IndComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(((Individual)o1).getName() , ((Individual)o2).getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -65,10 +65,10 @@ public class Properties2PropertiesRetryController extends BaseEditController {
|
|||
String subpropertyURIstr = request.getParameter("SubpropertyURI");
|
||||
|
||||
HashMap<String,Option> hashMap = new HashMap<String,Option>();
|
||||
List<Option> optionList = FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",superpropertyURIstr,null);
|
||||
List<Option> superPropertyOptions = getSortedList(hashMap,optionList);
|
||||
optionList = FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",subpropertyURIstr,null);
|
||||
List<Option> subPropertyOptions = getSortedList(hashMap, optionList);
|
||||
List<Option> optionList = FormUtils.makeOptionListFromBeans(propList,"URI","PickListName",superpropertyURIstr,null);
|
||||
List<Option> superPropertyOptions = getSortedList(hashMap, optionList, request);
|
||||
optionList = FormUtils.makeOptionListFromBeans(propList,"URI","PickListName",subpropertyURIstr,null);
|
||||
List<Option> subPropertyOptions = getSortedList(hashMap, optionList, request);
|
||||
|
||||
HashMap hash = new HashMap();
|
||||
hash.put("SuperpropertyURI", superPropertyOptions);
|
||||
|
@ -105,34 +105,4 @@ public class Properties2PropertiesRetryController extends BaseEditController {
|
|||
|
||||
}
|
||||
|
||||
public List<Option> getSortedList(HashMap<String,Option> hashMap, List<Option> optionList){
|
||||
|
||||
class ListComparator implements Comparator<String>{
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
// TODO Auto-generated method stub
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(str1, str2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> bodyVal = new ArrayList<String>();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
Iterator<Option> itr = optionList.iterator();
|
||||
while(itr.hasNext()){
|
||||
Option option = itr.next();
|
||||
hashMap.put(option.getBody(),option);
|
||||
bodyVal.add(option.getBody());
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(bodyVal, new ListComparator());
|
||||
ListIterator<String> itrStr = bodyVal.listIterator();
|
||||
while(itrStr.hasNext()){
|
||||
options.add(hashMap.get(itrStr.next()));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class PropertyRetryController extends BaseEditController {
|
|||
|
||||
List groupOptList = FormUtils.makeOptionListFromBeans(request.getUnfilteredWebappDaoFactory().getPropertyGroupDao().getPublicGroups(true),"URI","Name", ((propertyForEditing.getGroupURI()==null) ? "" : propertyForEditing.getGroupURI()), null, (propertyForEditing.getGroupURI()!=null));
|
||||
HashMap<String,Option> hashMap = new HashMap<String,Option>();
|
||||
groupOptList = getSortedList(hashMap,groupOptList);
|
||||
groupOptList = getSortedList(hashMap,groupOptList,request);
|
||||
groupOptList.add(0,new Option("","none"));
|
||||
optionMap.put("GroupURI", groupOptList);
|
||||
|
||||
|
@ -241,24 +241,10 @@ public class PropertyRetryController extends BaseEditController {
|
|||
List<Option> parentIdList = FormUtils.makeOptionListFromBeans(
|
||||
objPropList,"URI","PickListName",propertyForEditing.getParentURI(),null);
|
||||
HashMap<String,Option> hashMap = new HashMap<String,Option>();
|
||||
parentIdList = getSortedList(hashMap,parentIdList);
|
||||
parentIdList = getSortedList(hashMap,parentIdList,request);
|
||||
parentIdList.add(0,new Option("-1","none (root property)", false));
|
||||
optionMap.put("ParentURI", parentIdList);
|
||||
|
||||
/*
|
||||
List<DataProperty> dpList = dpDao.getAllDataProperties();
|
||||
Collections.sort(dpList);
|
||||
List<Option> objectIndividualSortPropertyList =
|
||||
FormUtils.makeOptionListFromBeans(
|
||||
dpList, "URI", "Name",
|
||||
propertyForEditing.getObjectIndividualSortPropertyURI(),
|
||||
null);
|
||||
objectIndividualSortPropertyList.add(0, new Option(
|
||||
"","- name (rdfs:label) -"));
|
||||
optionMap.put("ObjectIndividualSortPropertyURI",
|
||||
objectIndividualSortPropertyList);
|
||||
*/
|
||||
|
||||
List<Option> domainOptionList = FormUtils.makeVClassOptionList(
|
||||
request.getUnfilteredWebappDaoFactory(),
|
||||
propertyForEditing.getDomainVClassURI());
|
||||
|
@ -266,7 +252,7 @@ public class PropertyRetryController extends BaseEditController {
|
|||
&& propertyForEditing.getDomainVClass().isAnonymous()) {
|
||||
domainOptionList.add(0, new Option(
|
||||
propertyForEditing.getDomainVClass().getURI(),
|
||||
propertyForEditing.getDomainVClass().getName(),
|
||||
propertyForEditing.getDomainVClass().getPickListName(),
|
||||
true));
|
||||
}
|
||||
domainOptionList.add(0, new Option("","(none specified)"));
|
||||
|
@ -279,7 +265,7 @@ public class PropertyRetryController extends BaseEditController {
|
|||
&& propertyForEditing.getRangeVClass().isAnonymous()) {
|
||||
rangeOptionList.add(0, new Option(
|
||||
propertyForEditing.getRangeVClass().getURI(),
|
||||
propertyForEditing.getRangeVClass().getName(),
|
||||
propertyForEditing.getRangeVClass().getPickListName(),
|
||||
true));
|
||||
}
|
||||
rangeOptionList.add(0, new Option("","(none specified)"));
|
||||
|
@ -316,33 +302,5 @@ public class PropertyRetryController extends BaseEditController {
|
|||
}
|
||||
}
|
||||
|
||||
public List<Option> getSortedList(HashMap<String,Option> hashMap, List<Option> optionList){
|
||||
|
||||
class ListComparator implements Comparator<String>{
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
// TODO Auto-generated method stub
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(str1, str2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> bodyVal = new ArrayList<String>();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
Iterator<Option> itr = optionList.iterator();
|
||||
while(itr.hasNext()){
|
||||
Option option = itr.next();
|
||||
hashMap.put(option.getBody(),option);
|
||||
bodyVal.add(option.getBody());
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(bodyVal, new ListComparator());
|
||||
ListIterator<String> itrStr = bodyVal.listIterator();
|
||||
while(itrStr.hasNext()){
|
||||
options.add(hashMap.get(itrStr.next()));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,14 +63,14 @@ public class RefactorRetryController extends BaseEditController {
|
|||
if (epo.getAttribute("propertyType").equals("ObjectProperty")) {
|
||||
List<ObjectProperty> opList = request.getUnfilteredWebappDaoFactory().getObjectPropertyDao().getAllObjectProperties();
|
||||
Collections.sort(opList);
|
||||
newPropertyOpts = FormUtils.makeOptionListFromBeans(opList,"URI","LocalNameWithPrefix", null, null);
|
||||
newPropertyOpts = FormUtils.makeOptionListFromBeans(opList,"URI","PickListName", null, null);
|
||||
} else {
|
||||
List<DataProperty> dpList = request.getUnfilteredWebappDaoFactory().getDataPropertyDao().getAllDataProperties();
|
||||
Collections.sort(dpList);
|
||||
newPropertyOpts = FormUtils.makeOptionListFromBeans(dpList,"URI","Name", null, null);
|
||||
newPropertyOpts = FormUtils.makeOptionListFromBeans(dpList,"URI","PickListName", null, null);
|
||||
}
|
||||
HashMap<String,Option> hashMap = new HashMap<String,Option>();
|
||||
newPropertyOpts = getSortedList(hashMap,newPropertyOpts);
|
||||
newPropertyOpts = getSortedList(hashMap,newPropertyOpts,request);
|
||||
newPropertyOpts.add(new Option("","(move to trash)"));
|
||||
optMap.put("NewPropertyURI", newPropertyOpts);
|
||||
|
||||
|
@ -137,34 +137,6 @@ public class RefactorRetryController extends BaseEditController {
|
|||
|
||||
}
|
||||
|
||||
public List<Option> getSortedList(HashMap<String,Option> hashMap, List<Option> optionList){
|
||||
|
||||
class ListComparator implements Comparator<String>{
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
// TODO Auto-generated method stub
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(str1, str2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> bodyVal = new ArrayList<String>();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
Iterator<Option> itr = optionList.iterator();
|
||||
while(itr.hasNext()){
|
||||
Option option = itr.next();
|
||||
hashMap.put(option.getBody(),option);
|
||||
bodyVal.add(option.getBody());
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(bodyVal, new ListComparator());
|
||||
ListIterator<String> itrStr = bodyVal.listIterator();
|
||||
while(itrStr.hasNext()){
|
||||
options.add(hashMap.get(itrStr.next()));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,7 +15,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.ibm.icu.text.Collator;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||
|
@ -25,6 +23,7 @@ import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -58,12 +57,12 @@ public class RestrictionRetryController extends BaseEditController {
|
|||
// default to object property restriction
|
||||
boolean propertyType = ("data".equals(request.getParameter("propertyType"))) ? DATA : OBJECT ;
|
||||
|
||||
List<? extends Property> pList = (propertyType == OBJECT)
|
||||
List<? extends ResourceBean> pList = (propertyType == OBJECT)
|
||||
? request.getUnfilteredWebappDaoFactory().getObjectPropertyDao().getAllObjectProperties()
|
||||
: request.getUnfilteredWebappDaoFactory().getDataPropertyDao().getAllDataProperties();
|
||||
List<Option> onPropertyList = new LinkedList<Option>();
|
||||
Collections.sort(pList, new PropSorter());
|
||||
for (Property p: pList) {
|
||||
sortForPickList(pList, request);
|
||||
for (ResourceBean p: pList) {
|
||||
onPropertyList.add( new Option(p.getURI(),p.getPickListName()));
|
||||
}
|
||||
|
||||
|
@ -146,14 +145,5 @@ public class RestrictionRetryController extends BaseEditController {
|
|||
return valueDatatypeOptionList;
|
||||
}
|
||||
|
||||
private class PropSorter implements Comparator<Property> {
|
||||
|
||||
public int compare(Property p1, Property p2) {
|
||||
if (p1.getLocalNameWithPrefix() == null) return 1;
|
||||
if (p2.getLocalNameWithPrefix() == null) return -1;
|
||||
return Collator.getInstance().compare(p1.getLocalNameWithPrefix(), p2.getLocalNameWithPrefix());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -236,11 +236,5 @@ public class DataPropertyHierarchyListingController extends BaseEditController {
|
|||
}
|
||||
return colIndex-1;
|
||||
}
|
||||
|
||||
private class DataPropertyAlphaComparator implements Comparator {
|
||||
public int compare(Object o1, Object o2) {
|
||||
return Collator.getInstance().compare( ((DataProperty)o1).getName(), ((DataProperty)o2).getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -170,19 +170,4 @@ public class DatatypePropertiesListingController extends BaseEditController {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private class DatatypePropertyAlphaComparator implements Comparator {
|
||||
public int compare (Object o1, Object o2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
DataProperty dp1 = (DataProperty) o1;
|
||||
DataProperty dp2 = (DataProperty) o2;
|
||||
String dp1Str = (dp1.getPublicName()==null) ? dp1.getName() : dp1.getPublicName();
|
||||
dp1Str = (dp1Str == null) ? "" : dp1Str;
|
||||
String dp2Str = (dp2.getPublicName()==null) ? dp2.getName() : dp2.getPublicName();
|
||||
dp2Str = (dp2Str == null) ? "" : dp2Str;
|
||||
return collator.compare(dp1Str,dp2Str);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class ObjectPropertyHierarchyListingController extends BaseEditController
|
|||
} else {
|
||||
roots = opDao.getRootObjectProperties();
|
||||
if (roots!=null){
|
||||
Collections.sort(roots, new ObjectPropertyAlphaComparator()); // sorts by domain public
|
||||
Collections.sort(roots, new ObjectPropertyAlphaComparator(vrequest.getCollator())); // sorts by domain public
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,6 +237,13 @@ public class ObjectPropertyHierarchyListingController extends BaseEditController
|
|||
}
|
||||
|
||||
public static class ObjectPropertyAlphaComparator implements Comparator<ObjectProperty> {
|
||||
|
||||
Collator collator;
|
||||
|
||||
public ObjectPropertyAlphaComparator(Collator collator) {
|
||||
this.collator = collator;
|
||||
}
|
||||
|
||||
public int compare(ObjectProperty op1, ObjectProperty op2) {
|
||||
if (op1 == null) {
|
||||
return 1;
|
||||
|
@ -250,7 +257,7 @@ public class ObjectPropertyHierarchyListingController extends BaseEditController
|
|||
} else if (propLabel2 == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return Collator.getInstance().compare( propLabel1, propLabel2 );
|
||||
return collator.compare( propLabel1, propLabel2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PropertyGroupsListingController extends BaseEditController {
|
|||
|
||||
List<PropertyGroup> groups = dao.getPublicGroups(WITH_PROPERTIES);
|
||||
|
||||
Comparator<Property> comparator = new PropertySorter();
|
||||
Comparator<Property> comparator = new PropertySorter(vreq.getCollator());
|
||||
|
||||
List<String> results = new ArrayList<String>();
|
||||
results.add("XX");
|
||||
|
@ -138,7 +138,11 @@ public class PropertyGroupsListingController extends BaseEditController {
|
|||
|
||||
private class PropertySorter implements Comparator<Property> {
|
||||
|
||||
private Collator coll = Collator.getInstance();
|
||||
Collator collator;
|
||||
|
||||
public PropertySorter(Collator collator) {
|
||||
this.collator = collator;
|
||||
}
|
||||
|
||||
public int compare(Property p1, Property p2) {
|
||||
String name1 = getName(p1);
|
||||
|
@ -150,7 +154,7 @@ public class PropertyGroupsListingController extends BaseEditController {
|
|||
} else if (name1 == null && name2 == null) {
|
||||
return 0;
|
||||
}
|
||||
return coll.compare(name1, name2);
|
||||
return collator.compare(name1, name2);
|
||||
}
|
||||
|
||||
private String getName(Property prop) {
|
||||
|
|
|
@ -125,7 +125,9 @@ public class PropertyWebappsListingController extends BaseEditController {
|
|||
}
|
||||
|
||||
if (props != null) {
|
||||
Collections.sort(props, new ObjectPropertyHierarchyListingController.ObjectPropertyAlphaComparator());
|
||||
Collections.sort(
|
||||
props, new ObjectPropertyHierarchyListingController
|
||||
.ObjectPropertyAlphaComparator(vrequest.getCollator()));
|
||||
}
|
||||
|
||||
ArrayList results = new ArrayList();
|
||||
|
|
|
@ -115,11 +115,4 @@ public class VClassWebappWithInstancesListingController extends BaseEditControll
|
|||
|
||||
}
|
||||
|
||||
private class EntityWebappAlphaComparator implements Comparator {
|
||||
public int compare (Object o1, Object o2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(((ObjectProperty)o1).getLocalName(),((ObjectProperty)o2).getLocalName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,8 +49,7 @@ public class ListPropertyGroupsController extends FreemarkerHttpServlet {
|
|||
PropertyGroupDao dao = vreq.getUnfilteredWebappDaoFactory().getPropertyGroupDao();
|
||||
|
||||
List<PropertyGroup> groups = dao.getPublicGroups(WITH_PROPERTIES);
|
||||
|
||||
// Comparator<Property> comparator = new PropertySorter();
|
||||
sortForPickList(groups, vreq);
|
||||
|
||||
String json = new String();
|
||||
int counter = 0;
|
||||
|
@ -124,34 +123,5 @@ public class ListPropertyGroupsController extends FreemarkerHttpServlet {
|
|||
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
|
||||
/*
|
||||
private class PropertySorter implements Comparator<Property> {
|
||||
|
||||
private Collator coll = Collator.getInstance();
|
||||
|
||||
public int compare(Property p1, Property p2) {
|
||||
String name1 = getName(p1);
|
||||
String name2 = getName(p2);
|
||||
if (name1 == null && name2 != null) {
|
||||
return 1;
|
||||
} else if (name2 == null && name1 != null) {
|
||||
return -1;
|
||||
} else if (name1 == null && name2 == null) {
|
||||
return 0;
|
||||
}
|
||||
return coll.compare(name1, name2);
|
||||
}
|
||||
|
||||
private String getName(Property prop) {
|
||||
if (prop instanceof ObjectProperty) {
|
||||
return ((ObjectProperty) prop).getDomainPublic();
|
||||
} else if (prop instanceof DataProperty) {
|
||||
return ((DataProperty) prop).getName();
|
||||
} else {
|
||||
return prop.getLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public class ListPropertyWebappsController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
if (props != null) {
|
||||
Collections.sort(props, new ShowObjectPropertyHierarchyController.ObjectPropertyAlphaComparator());
|
||||
sortForPickList(props, vreq);
|
||||
}
|
||||
|
||||
String json = new String();
|
||||
|
|
|
@ -96,7 +96,7 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
|
|||
} else {
|
||||
roots = opDao.getRootObjectProperties();
|
||||
if (roots!=null){
|
||||
Collections.sort(roots, new ObjectPropertyAlphaComparator()); // sorts by domain public
|
||||
Collections.sort(roots, new ObjectPropertyAlphaComparator(vreq)); // sorts by domain public
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,6 +254,13 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
|
|||
}
|
||||
|
||||
public static class ObjectPropertyAlphaComparator implements Comparator<ObjectProperty> {
|
||||
|
||||
Collator collator;
|
||||
|
||||
public ObjectPropertyAlphaComparator(VitroRequest vreq) {
|
||||
this.collator = vreq.getCollator();
|
||||
}
|
||||
|
||||
public int compare(ObjectProperty op1, ObjectProperty op2) {
|
||||
if (op1 == null) {
|
||||
return 1;
|
||||
|
@ -267,7 +274,7 @@ public class ShowObjectPropertyHierarchyController extends FreemarkerHttpServlet
|
|||
} else if (propLabel2 == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return Collator.getInstance().compare( propLabel1, propLabel2 );
|
||||
return collator.compare( propLabel1, propLabel2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -450,7 +450,7 @@ public class JenaIngestController extends BaseEditController {
|
|||
vreq.setAttribute("bodyJsp",INGEST_MENU_JSP);
|
||||
} else {
|
||||
List<String> dbTypes = DatabaseType.allNames();
|
||||
Collections.sort(dbTypes, new CollationSort());
|
||||
Collections.sort(dbTypes, new CollationSort(vreq));
|
||||
vreq.setAttribute("dbTypes", dbTypes);
|
||||
vreq.setAttribute("title", "Connect Jena Database");
|
||||
vreq.setAttribute("bodyJsp",CONNECT_DB_JSP);
|
||||
|
@ -1295,7 +1295,11 @@ public class JenaIngestController extends BaseEditController {
|
|||
|
||||
private class CollationSort implements Comparator<String> {
|
||||
|
||||
Collator collator = Collator.getInstance();
|
||||
Collator collator;
|
||||
|
||||
public CollationSort(VitroRequest vreq) {
|
||||
this.collator = vreq.getCollator();
|
||||
}
|
||||
|
||||
public int compare(String s1, String s2) {
|
||||
return collator.compare(s1, s2);
|
||||
|
|
|
@ -258,6 +258,16 @@ public class IndividualFiltering implements Individual {
|
|||
public String getName() {
|
||||
return _innerIndividual.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return _innerIndividual.getLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPickListName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRdfsLabel(){
|
||||
|
|
|
@ -177,18 +177,8 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
dp.setURI(op.getURI());
|
||||
dp.setNamespace(op.getNameSpace());
|
||||
dp.setLocalName(op.getLocalName());
|
||||
OntologyDao oDao=getWebappDaoFactory().getOntologyDao();
|
||||
Ontology o = oDao.getOntologyByURI(dp.getNamespace());
|
||||
if (o==null) {
|
||||
if (!VitroVocabulary.vitroURI.equals(dp.getNamespace())) {
|
||||
log.debug("datapropFromOntProperty(): no ontology object found for the namespace "+dp.getNamespace());
|
||||
}
|
||||
dp.setLocalNameWithPrefix(dp.getLocalName());
|
||||
dp.setPickListName(getLabelOrId(op));
|
||||
} else {
|
||||
dp.setLocalNameWithPrefix(o.getPrefix()==null?(o.getName()==null?"unspec:"+dp.getLocalName():o.getName()+":"+dp.getLocalName()):o.getPrefix()+":"+dp.getLocalName());
|
||||
dp.setPickListName(getLabelOrId(op)+o.getPrefix()==null?(o.getName()==null?" (unspec:)":" ("+o.getName()+")"):" ("+o.getPrefix()+")");
|
||||
}
|
||||
dp.setLocalNameWithPrefix(getWebappDaoFactory().makeLocalNameWithPrefix(dp));
|
||||
dp.setPickListName(getWebappDaoFactory().makePickListName(dp));
|
||||
dp.setName(op.getLocalName());
|
||||
dp.setPublicName(getLabelOrId(op));
|
||||
Resource dRes = op.getDomain();
|
||||
|
|
|
@ -78,6 +78,10 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return getRdfsLabel();
|
||||
}
|
||||
|
||||
public String getRdfsLabel() {
|
||||
if (this.rdfsLabel != null) {
|
||||
|
|
|
@ -94,20 +94,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
p.setURI(op.getURI());
|
||||
p.setNamespace(op.getNameSpace());
|
||||
p.setLocalName(op.getLocalName());
|
||||
OntologyDao oDao=getWebappDaoFactory().getOntologyDao();
|
||||
Ontology o = oDao.getOntologyByURI(p.getNamespace());
|
||||
if (o == null) {
|
||||
if (!VitroVocabulary.vitroURI.equals(p.getNamespace())) {
|
||||
log.debug("propertyFromOntProperty(): no ontology object found for the namespace "+p.getNamespace());
|
||||
}
|
||||
p.setLocalNameWithPrefix(p.getLocalName());
|
||||
p.setPickListName(getLabelOrId(op));
|
||||
} else {
|
||||
String prefix = o.getPrefix()==null?(o.getName()==null?"unspec":o.getName()):o.getPrefix();
|
||||
p.setLocalNameWithPrefix(prefix+":"+p.getLocalName());
|
||||
//log.warn("setting pickListName to: "+p.getLocalName()+" ("+prefix+")");
|
||||
p.setPickListName(getLabelOrId(op) + " ("+prefix+")");
|
||||
}
|
||||
p.setLocalNameWithPrefix(getWebappDaoFactory().makeLocalNameWithPrefix(p));
|
||||
p.setPickListName(getWebappDaoFactory().makePickListName(p));
|
||||
String propertyName = getPropertyStringValue(op,PROPERTY_FULLPROPERTYNAMEANNOT);
|
||||
if (op.getLabel(null) != null)
|
||||
p.setDomainPublic(getLabelOrId(op));
|
||||
|
|
|
@ -74,51 +74,28 @@ public class VClassJena extends VClass {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalNameWithPrefix() {
|
||||
|
||||
public String getLocalNameWithPrefix() {
|
||||
if (this.localNameWithPrefix != null) {
|
||||
return localNameWithPrefix;
|
||||
} else {
|
||||
cls.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
VClassDao vClassDao = webappDaoFactory.getVClassDao();
|
||||
|
||||
if (vClassDao instanceof VClassDaoJena) {
|
||||
this.localNameWithPrefix = ((VClassDaoJena) vClassDao).getLabelForClass(cls,true,false);
|
||||
} else {
|
||||
log.error("WebappDaoFactory returned a type of " + vClassDao.getClass().getName() + ". Expected VClassDaoJena");
|
||||
this.localNameWithPrefix = webappDaoFactory.getJenaBaseDao().getLabelOrId(cls);
|
||||
}
|
||||
|
||||
return this.localNameWithPrefix;
|
||||
} finally {
|
||||
cls.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
this.localNameWithPrefix = webappDaoFactory.makeLocalNameWithPrefix(this);
|
||||
return this.localNameWithPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPickListName() {
|
||||
|
||||
if (this.pickListName != null) {
|
||||
return pickListName;
|
||||
} else {
|
||||
cls.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
VClassDao vClassDao = webappDaoFactory.getVClassDao();
|
||||
|
||||
if (vClassDao instanceof VClassDaoJena) {
|
||||
this.pickListName = ((VClassDaoJena) vClassDao).getLabelForClass(cls,false,true);
|
||||
} else {
|
||||
log.error("WebappDaoFactory returned a type of " + vClassDao.getClass().getName() + ". Expected VClassDaoJena");
|
||||
this.pickListName = webappDaoFactory.getJenaBaseDao().getLabelOrId(cls);
|
||||
}
|
||||
|
||||
return this.pickListName;
|
||||
} finally {
|
||||
cls.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
this.pickListName = webappDaoFactory.makePickListName(this);
|
||||
return this.pickListName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
@ -20,14 +23,12 @@ import com.hp.hpl.jena.query.DatasetFactory;
|
|||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
|
@ -44,6 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||
|
@ -53,6 +55,8 @@ import edu.cornell.mannlib.vitro.webapp.utils.jena.URIUtils;
|
|||
|
||||
public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(WebappDaoFactoryJena.class);
|
||||
|
||||
protected IndividualDao entityWebappDao;
|
||||
protected ApplicationDaoJena applicationDao;
|
||||
protected UserAccountsDao userAccountsDao;
|
||||
|
@ -532,5 +536,42 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
|||
ontModelSelector = specialSelector;
|
||||
|
||||
}
|
||||
|
||||
public String makeLocalNameWithPrefix(ResourceBean bean) {
|
||||
OntologyDao oDao = this.getOntologyDao();
|
||||
Ontology o = oDao.getOntologyByURI(bean.getNamespace());
|
||||
if (o == null) {
|
||||
if (VitroVocabulary.vitroURI.equals(bean.getNamespace())) {
|
||||
return "vitro:" + bean.getLocalName();
|
||||
} else {
|
||||
log.debug("no ontology object found for namespace " + bean.getNamespace());
|
||||
return bean.getLocalName();
|
||||
}
|
||||
} else {
|
||||
String prefix = o.getPrefix() == null ? (
|
||||
o.getName() == null ?
|
||||
"unspec" : o.getName()) : o.getPrefix();
|
||||
return prefix + ":" + bean.getLocalName();
|
||||
}
|
||||
}
|
||||
|
||||
public String makePickListName(ResourceBean bean) {
|
||||
OntologyDao oDao = this.getOntologyDao();
|
||||
Ontology o = oDao.getOntologyByURI(bean.getNamespace());
|
||||
if (o == null) {
|
||||
if (VitroVocabulary.vitroURI.equals(bean.getNamespace())) {
|
||||
return bean.getLabel() + " (vitro)";
|
||||
} else {
|
||||
log.debug("no ontology object found for namespace " + bean.getNamespace());
|
||||
return bean.getLabel();
|
||||
}
|
||||
} else {
|
||||
String prefix = o.getPrefix() == null ? (
|
||||
o.getName() == null ?
|
||||
"unspec" : o.getName()) : o.getPrefix();
|
||||
return bean.getLabel() + " (" + prefix + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import java.util.Map;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
||||
|
@ -58,7 +60,8 @@ public class SelectListGeneratorVTwo {
|
|||
//Methods to sort the options map
|
||||
// from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708
|
||||
//Modified to allow for a custom comparator to be sent in, defaults to mapPairsComparator
|
||||
public static Map<String,String> getSortedMap(Map<String,String> hmap, Comparator<String[]> comparator){
|
||||
public static Map<String,String> getSortedMap(Map<String,String> hmap,
|
||||
Comparator<String[]> comparator, VitroRequest vreq){
|
||||
// first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator
|
||||
List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size());
|
||||
for (String key:hmap.keySet()) {
|
||||
|
@ -70,7 +73,7 @@ public class SelectListGeneratorVTwo {
|
|||
|
||||
//if no comparator is passed in, utilize MapPairsComparator
|
||||
if(comparator == null) {
|
||||
comparator = new MapPairsComparator();
|
||||
comparator = new MapPairsComparator(vreq);
|
||||
}
|
||||
|
||||
Collections.sort(objectsToSort, comparator);
|
||||
|
@ -84,8 +87,13 @@ public class SelectListGeneratorVTwo {
|
|||
|
||||
//Sorts by the value of the 2nd element in each of the arrays
|
||||
private static class MapPairsComparator implements Comparator<String[]> {
|
||||
|
||||
private Collator collator;
|
||||
|
||||
public MapPairsComparator(VitroRequest vreq) {
|
||||
this.collator = vreq.getCollator();
|
||||
}
|
||||
public int compare (String[] s1, String[] s2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
if (s2 == null) {
|
||||
return 1;
|
||||
} else if (s1 == null) {
|
||||
|
|
|
@ -6,7 +6,10 @@ import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup
|
|||
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_INF_MODEL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.Collator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
@ -149,6 +152,8 @@ public class RequestModelsPrep implements Filter {
|
|||
|
||||
wrapModelsWithLanguageAwareness(vreq);
|
||||
|
||||
setCollator(vreq);
|
||||
|
||||
setWebappDaoFactories(vreq, rdfService);
|
||||
}
|
||||
|
||||
|
@ -289,9 +294,19 @@ public class RequestModelsPrep implements Filter {
|
|||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is also used by VitroHttpServlet to retrieve the right Collator
|
||||
* instance for picklist sorting
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public static Enumeration<Locale> getPreferredLocales(HttpServletRequest req) {
|
||||
return req.getLocales();
|
||||
}
|
||||
|
||||
private List<String> getPreferredLanguages(HttpServletRequest req) {
|
||||
log.debug("Accept-Language: " + req.getHeader("Accept-Language"));
|
||||
return LanguageFilteringUtils.localesToLanguages(req.getLocales());
|
||||
return LanguageFilteringUtils.localesToLanguages(getPreferredLocales(req));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,6 +326,19 @@ public class RequestModelsPrep implements Filter {
|
|||
return rawRDFService;
|
||||
}
|
||||
}
|
||||
|
||||
private void setCollator(VitroRequest vreq) {
|
||||
Enumeration<Locale> locales = getPreferredLocales(vreq);
|
||||
while(locales.hasMoreElements()) {
|
||||
Locale locale = locales.nextElement();
|
||||
Collator collator = Collator.getInstance(locale);
|
||||
if(collator != null) {
|
||||
vreq.setCollator(collator);
|
||||
return;
|
||||
}
|
||||
}
|
||||
vreq.setCollator(Collator.getInstance());
|
||||
}
|
||||
|
||||
private boolean isStoreReasoned(ServletRequest req) {
|
||||
String isStoreReasoned = ConfigurationProperties.getBean(req).getProperty(
|
||||
|
|
|
@ -72,7 +72,7 @@ public class GetAllPrefix extends BaseEditController {
|
|||
respo += "<options>";
|
||||
List<String> prefixList = new ArrayList<String>();
|
||||
prefixList.addAll(prefixMap.keySet());
|
||||
Collections.sort(prefixList, Collator.getInstance());
|
||||
Collections.sort(prefixList, vreq.getCollator());
|
||||
for (String prefix : prefixList) {
|
||||
respo += makeOption(prefix, prefixMap.get(prefix));
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
|||
field.setOptions(new ConstantFieldOptions());
|
||||
}
|
||||
Map<String, String> optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf);
|
||||
optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap, field.getFieldOptions().getCustomComparator());
|
||||
optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap, field.getFieldOptions().getCustomComparator(), vreq);
|
||||
if(pageData.containsKey(fieldName)) {
|
||||
log.error("Check the edit configuration setup as pageData already contains " + fieldName + " and this will be overwritten now with empty collection");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue