From f0576f82bd44c6626c2a19a0233709ab2d003f0c Mon Sep 17 00:00:00 2001 From: rjy7 Date: Wed, 24 Mar 2010 16:04:54 +0000 Subject: [PATCH] NIHVIVO-147 Fixed bug in last commit. NIHVIVO-142 Moved some code around to better locations. --- .../vitro/webapp/dao/VitroVocabulary.java | 22 - .../webapp/utils/FrontEndEditingUtils.java | 43 ++ .../webapp/web/jsptags/PropertyEditLinks.java | 10 +- .../VitroNamespacePropertyEditLinks.java | 496 ------------------ .../web/edit/forms/defaultVitroNsPropForm.jsp | 7 +- .../web/templates/entity/entityCitation.jsp | 1 + 6 files changed, 51 insertions(+), 528 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/VitroNamespacePropertyEditLinks.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java index d2798d2c3..e90134ace 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java @@ -284,27 +284,5 @@ public class VitroVocabulary { public static final String ONTOLOGY_PREFIX_ANNOT = vitroURI + "ontologyPrefixAnnot"; - - - public static final List VITRO_NS_PROPERTIES = Arrays.asList(BLURB, CITATION, DESCRIPTION, IMAGETHUMB, LABEL, LINK_ANCHOR, MONIKER, PRIMARY_LINK, RDF_TYPE, TIMEKEY); - - public static String getVitroNsPropDatatypeUri(String propName) { - Resource datatype = propName == TIMEKEY ? XSD.dateTime : XSD.xstring; - return datatype.getURI(); - } - -// public static final Map VITRO_NS_PROPERTIES = new HashMap() { -// { -// put(BLURB, XSD.xstring.getURI()); -// put(CITATION, XSD.xstring.getURI()); -// put(DESCRIPTION, XSD.xstring.getURI()); -// put(LABEL, XSD.xstring.getURI()); -// put(LINK_ANCHOR, XSD.xstring.getURI()); -// put(MONIKER, XSD.xstring.getURI()); -// put(PRIMARY_LINK, XSD.xstring.getURI()); -// put(RDF_TYPE, XSD.xstring.getURI()); -// put(TIMEKEY, XSD.dateTime.getURI()); -// } -// }; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java new file mode 100644 index 000000000..7a1ab5e11 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/FrontEndEditingUtils.java @@ -0,0 +1,43 @@ +package edu.cornell.mannlib.vitro.webapp.utils; + +import java.util.Arrays; +import java.util.List; + +//import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.vocabulary.XSD; + +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; + +public class FrontEndEditingUtils { + + public static final List VITRO_NS_PROPS_FOR_FRONT_END_EDITING = Arrays.asList(VitroVocabulary.BLURB, + VitroVocabulary.CITATION, + VitroVocabulary.DESCRIPTION, + VitroVocabulary.IMAGETHUMB, + VitroVocabulary.LABEL, + VitroVocabulary.LINK_ANCHOR, + VitroVocabulary.MONIKER, + VitroVocabulary.PRIMARY_LINK + //, RDF_TYPE, TIMEKEY + ); + + public static String getVitroNsPropDatatypeUri(String propName) { + //Resource datatype = propName == TIMEKEY ? XSD.dateTime : XSD.xstring; + //return datatype.getURI(); + return XSD.xstring.getURI(); + } + +// public static final Map VITRO_NS_PROPERTIES = new HashMap() { +// { +// put(BLURB, XSD.xstring.getURI()); +// put(CITATION, XSD.xstring.getURI()); +// put(DESCRIPTION, XSD.xstring.getURI()); +// put(LABEL, XSD.xstring.getURI()); +// put(LINK_ANCHOR, XSD.xstring.getURI()); +// put(MONIKER, XSD.xstring.getURI()); +// put(PRIMARY_LINK, XSD.xstring.getURI()); +// put(RDF_TYPE, XSD.xstring.getURI()); +// put(TIMEKEY, XSD.dateTime.getURI()); +// } +// }; +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java index fb952655b..bd716ad7f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java @@ -2,15 +2,10 @@ package edu.cornell.mannlib.vitro.webapp.web.jsptags; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; @@ -46,8 +41,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash; +import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils; /** * JSP tag to generate the HTML of links for edit, delete or @@ -604,7 +600,7 @@ public class PropertyEditLinks extends TagSupport{ private boolean isVitroNsProp(String predicateUri) { - return VitroVocabulary.VITRO_NS_PROPERTIES.contains(predicateUri); + return FrontEndEditingUtils.VITRO_NS_PROPS_FOR_FRONT_END_EDITING.contains(predicateUri); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/VitroNamespacePropertyEditLinks.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/VitroNamespacePropertyEditLinks.java deleted file mode 100644 index cfe8c959c..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/VitroNamespacePropertyEditLinks.java +++ /dev/null @@ -1,496 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.web.jsptags; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.tagext.TagSupport; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; -import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory; -import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList; -import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList; -import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; -import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; -import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; -import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants; -import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction; -import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash; - -/** - * JSP tag to generate the HTML of links for edit, delete or - * add of a Property. - * - * Maybe we should have a mode where it just sets a var to a - * map with "href" = "edit/editDatapropDispatch.jsp?subjectUri=..." and "type" = "delete" - * - * @author bdc34 - * - */ -public class VitroNamespacePropertyEditLinks extends TagSupport{ - Object item; - String var; - String icons; - - private static final Log log = LogFactory.getLog(VitroNamespacePropertyEditLinks.class.getName()); - - public static final String ICON_DIR = "/images/edit_icons/"; - - public Object getItem() { return item; } - public void setItem(Object item) { this.item = item; } - - public String getVar(){ return var; } - public void setVar(String var){ this.var = var; } - - public void setIcons(String ic){ icons = ic; } - public String getIcons(){ return icons; } - - @Override - public int doStartTag() throws JspException { - if( item == null ) { - log.error("item passed to tag is null"); - return SKIP_BODY; - } - //try the policy in the request first, the look for a policy in the servlet context - //request policy takes precedence - PolicyIface policy = RequestPolicyList.getPolicies(pageContext.getRequest()); - if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){ - policy = ServletPolicyList.getPolicies( pageContext.getServletContext() ); - if( policy == null || ( policy instanceof PolicyList && ((PolicyList)policy).size() == 0 )){ - log.error("No policy found in request at " + RequestPolicyList.POLICY_LIST); - return SKIP_BODY; - } - } - - IdentifierBundle ids = (IdentifierBundle)ServletIdentifierBundleFactory - .getIdBundleForRequest(pageContext.getRequest(), - pageContext.getSession(), - pageContext.getServletContext()); - - if( ids == null ){ - log.error("No IdentifierBundle objects for request"); - return SKIP_BODY; - } - - Individual entity = (Individual)pageContext.getRequest().getAttribute("entity"); - - LinkStruct[] links = null; - String themeDir = (String)pageContext.getAttribute("themeDir"); - - //get context prefix needs to end with a slash like "/vivo/" or "/" - String contextPath = ((HttpServletRequest)pageContext.getRequest()).getContextPath(); - if( ! contextPath.endsWith("/") ) - contextPath = contextPath + "/"; - if( ! contextPath.startsWith("/") ) - contextPath = "/" + contextPath; - - if( item instanceof ObjectPropertyStatement ){ - ObjectPropertyStatement prop = (ObjectPropertyStatement)item; - links = doObjPropStmt( prop, themeDir, policyToAccess(ids, policy, prop), contextPath ); - - } else if( item instanceof DataPropertyStatement ){ - DataPropertyStatement prop = (DataPropertyStatement)item; - links = doDataPropStmt( prop, themeDir, policyToAccess(ids, policy, prop), contextPath ); - - } else if( item instanceof ObjectProperty ){ - ObjectProperty prop = (ObjectProperty)item; - if( entity == null ) { - log.error("unable to find an Individual in request using var name 'entity'"); - return SKIP_BODY; - } - links = doObjProp( prop, entity, themeDir, policyToAccess(ids, policy, entity.getURI(), prop), contextPath ); - - } else if( item instanceof DataProperty ){ - DataProperty prop = (DataProperty)item; // a DataProperty populated for this subject individual - if( entity == null ) { - log.error("unable to find an Individual in request using var name 'entity'"); - return SKIP_BODY; - } - links = doDataProp( prop, entity, themeDir,policyToAccess(ids, policy, entity.getURI(), prop), contextPath ) ; - } else { - log.error("PropertyEditLinks cannot make links for an object of type "+item.getClass().getName()); - return SKIP_BODY; - } - - if( getVar() != null ){ - pageContext.getRequest().setAttribute(getVar(), links); - } else { - try{ - JspWriter out = pageContext.getOut(); - if( links != null ){ - for( LinkStruct ln : links ){ - if( ln != null ){ - out.print( makeElement( ln ) + '\n' ); - } - } - } - } catch(IOException ioe){ - log.error( ioe ); - } - } - - return SKIP_BODY; - } - - protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || dprop == null || allowedAccessTypeArray.length == 0 ) { - log.debug("null or empty access type array in doDataProp for dprop "+dprop.getPublicName()+"; most likely just a property prohibited from editing"); - return empty_array; - } - LinkStruct[] links = new LinkStruct[1]; - - if (dprop.getDataPropertyStatements()!= null && dprop.getDisplayLimit()==1 && dprop.getDataPropertyStatements().size()>=1) { - log.debug("not showing an \"add\" link for data property because it has a display limit of 1 (a hack until expose a choice to make the dataproperty functional)"); - } else { - if( contains( allowedAccessTypeArray, EditLinkAccess.ADDNEW ) ){ - log.debug("data property "+dprop.getPublicName()+" gets an \"add\" link"); - String url = makeRelativeHref(contextPath + "edit/editDatapropStmtRequestDispatch.jsp", - "subjectUri", entity.getURI(), - "predicateUri", dprop.getURI()); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("add"); - ls.setMouseoverText("add a new entry"); - links[0] = ls; - } else { - log.debug("no add link generated for property "+dprop.getPublicName()); - } - } - return links; - } - - - protected LinkStruct[] doObjProp(ObjectProperty oprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || oprop == null || allowedAccessTypeArray.length == 0 ) { - log.debug("null or empty access type array in doObjProp for oprop "+oprop.getDomainPublic()+"; most likely just a property prohibited from editing"); - return empty_array; - } - LinkStruct[] links = new LinkStruct[1]; - - if( contains( allowedAccessTypeArray, EditLinkAccess.ADDNEW )){ - String url= makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", entity.getURI(), - "predicateUri", oprop.getURI()); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("add"); - ls.setMouseoverText("add relationship"); - links[0]=ls; - } - return links; - } - - protected LinkStruct[] doDataPropStmt(DataPropertyStatement dpropStmt, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || dpropStmt == null || allowedAccessTypeArray.length == 0 ) { - log.info("null or empty access type array in doDataPropStmt for "+dpropStmt.getDatapropURI()); - return empty_array; - } - LinkStruct[] links = new LinkStruct[2]; - int index=0; - - String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt )); - - if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){ - log.debug("permission found to UPDATE data property statement "+dpropStmt.getDatapropURI()+" ("+dpropStmt.getData()+") so icon created"); - String url = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ) - ? makeRelativeHref(contextPath + "edit/editDatapropStmtRequestDispatch.jsp", - "subjectUri", dpropStmt.getIndividualURI(), - "predicateUri", dpropStmt.getDatapropURI(), - "datapropKey", dpropHash) - : makeRelativeHref(contextPath + "edit/editDatapropStmtRequestDispatch.jsp", - "subjectUri", dpropStmt.getIndividualURI(), - "predicateUri", dpropStmt.getDatapropURI(), - "datapropKey", dpropHash, - "deleteProhibited", "prohibited"); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("edit"); - ls.setMouseoverText("edit this text"); - links[index] = ls; index++; - - -// String imgUrl = makeRelativeHref( themeDir + "site_icons/pencil.gif"); - -// str += "" + -// "\"(edit)\"/\n"; - } else { - log.debug("NO permission to UPDATE this data property statement ("+dpropStmt.getDatapropURI()+") found in policy"); - } - if( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){ - log.debug("permission found to DELETE data property statement "+dpropStmt.getDatapropURI()+" so icon created"); - String url = makeRelativeHref(contextPath + "edit/editDatapropStmtRequestDispatch.jsp", - "subjectUri", dpropStmt.getIndividualURI(), - "predicateUri", dpropStmt.getDatapropURI(), - "datapropKey", dpropHash, - "cmd", "delete"); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("delete"); - ls.setMouseoverText("delete this text"); - links[index] = ls; index++; - -// String imgUrl = makeRelativeHref( themeDir + "site_icons/trashcan.gif"); - -// str += "" + -// "\"(delete)\"/\n"; - } else { - log.debug("NO permission to DELETE this data property statement ("+dpropStmt.getDatapropURI()+") found in policy"); - } - return links; - } - - protected LinkStruct[] doObjPropStmt(ObjectPropertyStatement opropStmt, String themeDir2, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { - if( allowedAccessTypeArray == null || opropStmt == null || allowedAccessTypeArray.length == 0 ) { - log.info("null or empty access type array in doObjPropStmt for "+opropStmt.getPropertyURI()); - return empty_array; - } - LinkStruct[] links = new LinkStruct[2]; - int index=0; - - if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){ - log.debug("permission found to UPDATE object property statement "+opropStmt.getPropertyURI()+" so icon created"); - String url = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ) - ? makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI()) - : makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI(), - "deleteProhibited", "prohibited"); - - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("edit"); - ls.setMouseoverText("change this relationship"); - links[index] = ls; index++; - -// String imgUrl = makeRelativeHref( themeDir + "site_icons/pencil.gif"); - -// str += "" + -// "\"(edit)\"/\n"; - } else { - log.debug("NO permission to UPDATE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); - } - if( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){ - log.debug("permission found to DELETE object property statement "+opropStmt.getPropertyURI()+" so icon created"); - String url = makeRelativeHref(contextPath + "edit/editRequestDispatch.jsp", - "subjectUri", opropStmt.getSubjectURI(), - "predicateUri", opropStmt.getPropertyURI(), - "objectUri", opropStmt.getObjectURI(), - "cmd", "delete"); - LinkStruct ls = new LinkStruct(); - ls.setHref( url ); - ls.setType("delete"); - ls.setMouseoverText("delete this relationship"); - links[index] = ls; index++; - -// String imgUrl = makeRelativeHref( themeDir + "site_icons/trashcan.gif"); - -// str += "" + -// "\"(delete)\"/\n"; - } else { - log.debug("NO permission to DELETE this object property statement ("+opropStmt.getPropertyURI()+") found in policy"); - } - return links; - } - - /* ********************* utility methods ********************************* */ - protected static String makeRelativeHref( String baseUrl, String ... queries ) { - String href = baseUrl; - if( queries == null || queries.length % 2 != 0 ) - log.debug("makeRelativeHref() needs a even number of queries"); - - for( int i=0; i < queries.length; i=i+2){ - String separator = ( i==0 ? "?" : "&" ); - try { - href = href + separator + URLEncoder.encode(queries[i], "UTF-8") + '=' + URLEncoder.encode(queries[i+1],"UTF-8"); - } catch (UnsupportedEncodingException e) { log.error( e ); } - } - return href; - } - - protected static boolean contains(EditLinkAccess[] allowedAccessTypeArray, EditLinkAccess accessType) { - if( allowedAccessTypeArray == null || allowedAccessTypeArray.length == 0 || accessType == null ) - return false; - - for( int i=0; i< allowedAccessTypeArray.length ; i ++ ){ - if( allowedAccessTypeArray[i] == accessType ) return true; - } - return false; - } - - protected String makeElement( LinkStruct ln ){ - String element = - "" ; - - if( "true".equalsIgnoreCase(getIcons()) ){ - String contextPath=((HttpServletRequest)pageContext.getRequest()).getContextPath(); - String imagePath=null; - if (contextPath==null) { - imagePath = ICON_DIR + ln.getType() + ".gif"; - log.debug("image path when context path null: \""+imagePath+"\"."); - } else if (contextPath.equals("")) { - imagePath = ICON_DIR + ln.getType() + ".gif"; - log.debug("image path when context path blank: \""+imagePath+"\"."); - } else { - imagePath = contextPath + ICON_DIR + ln.getType() + ".gif"; - log.debug("image path when non-zero context path (\""+contextPath+"\"): \""+imagePath+"\"."); - } - element += "\"""; - } else { - element += ln.getType() ; - } - return element + "\n"; - } - - - -// protected Map getAccess(){ -// //right now we return an all access, all the time hashmap. -// return new HashMap(){ -// -// public boolean containsKey(Object key) { return true; } -// -// public EditLinkAccess[] get(Object key) { -// EditLinkAccess[] ela = { EditLinkAccess.MODIFY, -// EditLinkAccess.DELETE, EditLinkAccess.ADDNEW, -// EditLinkAccess.INFO, EditLinkAccess.ADMIN }; -// return ela; -// } -// public boolean isEmpty() { return false; } -// }; -// } -// - - public static final EditLinkAccess[] NO_ACCESS = {}; - public static final EditLinkAccess[] ACCESS_TEMPLATE = {}; - - protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, ObjectProperty item){ - EditLinkAccess[] allowedAccessTypeArray; - - RequestedAction action = new AddObjectPropStmt(subjectUri, item.getURI(), RequestActionConstants.SOME_URI); - PolicyDecision dec = policy.isAuthorized(ids, action); - - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - allowedAccessTypeArray = new EditLinkAccess[1]; - allowedAccessTypeArray[0] = EditLinkAccess.ADDNEW; - }else - allowedAccessTypeArray = NO_ACCESS; - - return allowedAccessTypeArray; - } - - protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, ObjectPropertyStatement item){ - ArrayList list = new ArrayList(2); - - RequestedAction action = new EditObjPropStmt( item ); - PolicyDecision dec = policy.isAuthorized(ids, action); - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - list.add( EditLinkAccess.MODIFY); - } - - action = new DropObjectPropStmt(item.getSubjectURI(), item.getPropertyURI(), item.getObjectURI()); - dec = policy.isAuthorized(ids, action); - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - list.add( EditLinkAccess.DELETE ); - } - return list.toArray(ACCESS_TEMPLATE); - } - - protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, DataPropertyStatement item) { - ArrayList list = new ArrayList(2); - - RequestedAction action = new EditDataPropStmt( item ); - PolicyDecision dec = policy.isAuthorized(ids, action); - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - list.add( EditLinkAccess.MODIFY); - } - - action = new DropDataPropStmt( item ); - dec = policy.isAuthorized(ids, action); - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - list.add( EditLinkAccess.DELETE ); - } - return list.toArray(ACCESS_TEMPLATE); - } - - protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, DataProperty item) { - EditLinkAccess[] access; - - RequestedAction action = new AddDataPropStmt(subjectUri, item.getURI(), RequestActionConstants.SOME_LITERAL, null, null); - PolicyDecision dec = policy.isAuthorized(ids, action); - - if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){ - access = new EditLinkAccess[1]; - access[0] = EditLinkAccess.ADDNEW; - }else - access = NO_ACCESS; - - return access; - } - - public enum EditLinkAccess{ MODIFY, DELETE, ADDNEW, INFO, ADMIN }; - - public class LinkStruct { - String href; - String type; - String mouseoverText; - - public String getHref() { - return href; - } - public void setHref(String href) { - this.href = href; - } - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - - public String getMouseoverText() { - return mouseoverText; - } - - public void setMouseoverText(String s) { - mouseoverText = s; - } - - } - -// public interface CheckAccess{ -// boolean access(ObjectProperty prop, EditLinkAccess access ); -// boolean access(DataProperty prop, EditLinkAccess access ); -// boolean access(ObjectPropertyStatement stmt, EditLinkAccess access ); -// boolean access(DataPropertyStatement stmt, EditLinkAccess access ); -// } - - private LinkStruct[] empty_array = {}; -} diff --git a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp index d4926a673..423f9af35 100644 --- a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp +++ b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp @@ -13,8 +13,9 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> -<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> -<%@page import="edu.cornell.mannlib.vitro.webapp.utils.StringUtils" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.StringUtils" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> @@ -76,7 +77,7 @@ } else { log.debug("No incoming vitro namespace property statement for property "+predicateUri+"; adding a new statement"); - rangeDatatypeUri = VitroVocabulary.getVitroNsPropDatatypeUri(predicateUri); + rangeDatatypeUri = FrontEndEditingUtils.getVitroNsPropDatatypeUri(predicateUri); } String rangeDatatypeUriJson = rangeDatatypeUri == null ? "" : MiscWebUtils.escape(rangeDatatypeUri); diff --git a/webapp/web/templates/entity/entityCitation.jsp b/webapp/web/templates/entity/entityCitation.jsp index 2706211e1..70ceb8311 100644 --- a/webapp/web/templates/entity/entityCitation.jsp +++ b/webapp/web/templates/entity/entityCitation.jsp @@ -2,6 +2,7 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> +<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>