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 81a50fd47..7b85f4ce1 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 @@ -159,9 +159,9 @@ public class PropertyEditLinks extends TagSupport{ return SKIP_BODY; } - private String getNameFromUri(String predicateUri) { - return predicateUri.substring(predicateUri.lastIndexOf('#')+1); - } +// private String getNameFromUri(String predicateUri) { +// return predicateUri.substring(predicateUri.lastIndexOf('#')+1); +// } protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || dprop == null || allowedAccessTypeArray.length == 0 ) { @@ -329,8 +329,8 @@ public class PropertyEditLinks extends TagSupport{ String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt )); String dispatchUrl = contextPath + "edit/editDatapropStmtRequestDispatch.jsp"; - String propName = getNameFromUri(predicateUri); - String editForm = "vitroNsEdit" + StringUtils.capitalize(propName) + "Form.jsp"; + //String propName = getNameFromUri(predicateUri); + //String editForm = "defaultVitroNsPropForm.jsp"; LinkStruct ls = new LinkStruct(); int index = 0; @@ -341,11 +341,11 @@ public class PropertyEditLinks extends TagSupport{ "subjectUri", subjectUri, "predicateUri", predicateUri, "datapropKey", dpropHash, - "vitroNsProp", "true", + "vitroNsProp", "true"); // RY If we use a single vitro ns form for all vitro ns props, we won't need the editForm param. // See if they can reasonably be combined into a single form, then have // editDatapropStmtRequestDispatch use a default vitro ns form if no custom form is specified. - "editForm", editForm); + //"editForm", editForm); ls.setHref(url); ls.setType("edit"); ls.setMouseoverText("edit this property"); @@ -364,7 +364,8 @@ public class PropertyEditLinks extends TagSupport{ "subjectUri", subjectUri, "predicateUri", predicateUri, "datapropKey", dpropHash, - "editForm", editForm); + "vitroNsProp", "true"); + //"editForm", editForm); ls.setHref(url); ls.setType("delete"); ls.setMouseoverText("delete this property"); @@ -429,25 +430,6 @@ public class PropertyEditLinks extends TagSupport{ 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 = {}; diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index 73fa2efef..c2bdba6af 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -33,8 +33,8 @@ ************************************** */ final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp"; - final String DEFAULT_ERROR_FORM = "error.jsp"; final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsPropForm.jsp"; + final String DEFAULT_ERROR_FORM = "error.jsp"; if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) { %> <% @@ -51,7 +51,8 @@ String predicateUri = vreq.getParameter("predicateUri"); String formParam = vreq.getParameter("editForm"); String command = vreq.getParameter("cmd"); - boolean isVitroNsProp = vreq.getParameter("vitroNsProp").equals("true") ? true : false; + String vitroNsProp = vreq.getParameter("vitroNsProp"); + boolean isVitroNsProp = vitroNsProp != null && vitroNsProp.equals("true") ? true : false; if( subjectUri == null || subjectUri.trim().length() == 0 ) { log.error("required subjectUri parameter missing"); @@ -105,10 +106,6 @@ } DataPropertyStatement dps = null; - // We don't need a dataprop statement in the request if we're using a custom form - // RY But we need the dps to call the edit config's prepareForDataPropUpdate. - // So we can either create the dps here, or in the custom form, or change - // prepareForDataPropUpdate to use the datahash to get the dps if( dataHash != 0) { if (isVitroNsProp) { Model model = (Model)application.getAttribute("jenaOntModel"); @@ -150,19 +147,26 @@ <% return; } - if( formParam == null ){ - String form = dataproperty.getCustomEntryForm(); + String form = null; + if (formParam != null) { + form = formParam; + } + else if (isVitroNsProp) { // dataproperty is null here + form = DEFAULT_VITRO_NS_FORM; + } + else { + form = dataproperty.getCustomEntryForm(); if (form != null && form.length()>0) { log.warn("have a custom form for this data property: "+form); vreq.setAttribute("hasCustomForm","true"); } else { form = DEFAULT_DATA_FORM; } - vreq.setAttribute("form", form); - } else { - vreq.setAttribute("form", formParam); } - if( session.getAttribute("requestedFromEntity") == null ) + vreq.setAttribute("form", form); + + if( session.getAttribute("requestedFromEntity") == null ) { session.setAttribute("requestedFromEntity", subjectUri ); + } %> diff --git a/webapp/web/edit/forms/vitroNsEditLabelForm.jsp b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp similarity index 76% rename from webapp/web/edit/forms/vitroNsEditLabelForm.jsp rename to webapp/web/edit/forms/defaultVitroNsPropForm.jsp index 03838f520..670bf70cf 100644 --- a/webapp/web/edit/forms/vitroNsEditLabelForm.jsp +++ b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp @@ -11,11 +11,12 @@ <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> <% - org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.vitroNsEditLabelForm.jsp"); - log.debug("Starting vitroNsEditLabelForm.jsp"); + org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultVitroNsPropForm.jsp"); + log.debug("Starting defaultVitroNsPropForm.jsp"); VitroRequest vreq = new VitroRequest(request); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); @@ -32,6 +33,7 @@ if( subject == null ) { throw new Error("In vitroNsEditLabelForm.jsp, could not find subject " + subjectUri); } + %> <%-- RY Once this is working, change to just one vitroNsEditForm for all vitro ns props, by parameterizing the predicate. @@ -42,44 +44,50 @@ Not sure sparqlForExistingLiterals is needed: see defaultDatapropForm - doesn't so it can be more easily copied to another form. Also change hard-coded predicate to ?predicate, so it will be picked up from the editConfig predicate --%> + + + <%-- Then enter a SPARQL query for the field, by convention concatenating the field id with "Existing" to convey that the expression is used to retrieve any existing value for the field in an existing individual. This must then be referenced in the sparqlForExistingLiterals section of the JSON block below and in the literalsOnForm --%> - - SELECT ?labelExisting WHERE { - ?subject ?labelExisting } + + SELECT ?dataExisting WHERE { + ?subject <${predicate}> ?dataExisting } <%-- Pair the "existing" query with the skeleton of what will be asserted for a new statement involving this field. The actual assertion inserted in the model will be created via string substitution into the ? variables. NOTE the pattern of punctuation (a period after the prefix URI and after the ?field) --%> - - ?subject ?label . + + ?subject <${predicate}> ?label . +<%-- RY This will be the default, but base it on propertyName --%> + + { "formUrl" : "${formUrl}", "editKey" : "${editKey}", - "datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>", + "datapropKey" : "<%= datapropKeyStr == null ? "" : datapropKeyStr %>", "urlPatternToReturnTo" : "/entity", "subject" : ["subject", "${subjectUriJson}" ], "predicate" : ["predicate", "${predicateUriJson}" ], - "object" : ["label", "", "DATAPROPHASH" ], + "object" : ["${propertyName}", "", "DATAPROPHASH" ], - "n3required" : [ "${labelAssertion}" ], + "n3required" : [ "${dataAssertion}" ], "n3optional" : [ ], "newResources" : { }, "urisInScope" : { }, "literalsInScope": { }, "urisOnForm" : [ ], - "literalsOnForm" : [ "label" ], + "literalsOnForm" : [ "${propertyName}" ], "filesOnForm" : [ ], "sparqlForLiterals" : { }, "sparqlForUris" : { }, - "sparqlForExistingLiterals" : { "label" : "${labelExisting}" }, + "sparqlForExistingLiterals" : { "${propertyName}" : "${dataExisting}" }, "sparqlForExistingUris" : { }, "fields" : { "label" : { @@ -89,9 +97,9 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the "literalOptions" : [ ], "predicateUri" : "", "objectClassUri" : "", - "rangeDatatypeUri" : "http://www.w3.org/2001/XMLSchema#string", + "rangeDatatypeUri" : "${rangeDatatypeUri}", "rangeLang" : "", - "assertions" : [ "${labelAssertion}" ] + "assertions" : [ "${dataAssertion}" ] } } } @@ -109,19 +117,18 @@ Also change hard-coded predicate to ?predicate, so it will be picked up from the editConfig.prepareForDataPropUpdate(model,dps); } - /* prepare the and text for the submit button */ - // RY Generalize this if we use the same form for all vitro ns props - String submitLabel = "Edit name"; - request.setAttribute("title", "Edit the name of " + subject.getName() + ":"); - %> +<c:set var="propertyLabel" value="${propertyName == 'label' ? 'name' : propertyName}" /> +<c:set var="submitLabel" value="Edit ${propertyLabel}" /> +<c:set var="title" scope="request" value="Edit the ${propertyLabel} of ${subject.name}:" /> + <jsp:include page="${preForm}"/> <h2>${title}</h2> <form action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" > <v:input type="text" id="label" size="30" /> - <p class="submit"><v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/></p> + <p class="submit"><v:input type="submit" id="submit" value="${submitLabel}" cancel="${param.subjectUri}"/></p> </form> <jsp:include page="${postForm}"/>