Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.

This commit is contained in:
jeb228 2010-01-29 22:13:57 +00:00
commit 4f2e303079
1839 changed files with 235630 additions and 0 deletions

View file

@ -0,0 +1,270 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%
Individual subject = (Individual)request.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
if (prop == null) throw new Error("no object property specified via incoming predicate attribute in defaultAddMissingIndividualForm.jsp");
String propDomainPublic = (prop.getDomainPublic() == null) ? "affiliation" : prop.getDomainPublic();
VitroRequest vreq = new VitroRequest(request);
//String contextPath = vreq.getContextPath();
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
if( prop.getRangeVClassURI() == null )throw new Error("Property has null for its range class URI");
VClass rangeClass = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI());
if( rangeClass == null ) throw new Error ("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
//vreq.setAttribute("rangeClassLocalName",rangeClass.getLocalName());
//vreq.setAttribute("rangeClassNamespace",rangeClass.getNamespace());
vreq.setAttribute("rangeClassUri",prop.getRangeVClassURI());
vreq.setAttribute("curatorReviewUri","http://vivo.library.cornell.edu/ns/0.1#CuratorReview");
//get the current portal and make this new individual a member of that portal
vreq.setAttribute("portalUri", vreq.getPortal().getTypeUri());
%>
<v:jsonset var="queryForInverse" >
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?inverse_property
WHERE { ?inverse_property owl:inverseOf ?predicate }
</v:jsonset>
<%-- Enter here the class names to be used for constructing MONIKERS_VIA_VCLASS pick lists
These are then referenced in the field's ObjectClassUri but not elsewhere.
Note that you can't reference a jsonset variable inside another jsonset expression
or you get double escaping problems --%>
<v:jsonset var="newIndividualVClassUri">${rangeClassUri}</v:jsonset>
<%-- Then enter a SPARQL query for each 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.
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
and in the literalsOnForm --%>
<v:jsonset var="nameExisting" >
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?existingName
WHERE { ?newIndividual rdfs:label ?existingName }
</v:jsonset>
<%-- 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) --%>
<v:jsonset var="nameAssertion" >
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
?newIndividual rdfs:label ?name .
</v:jsonset>
<v:jsonset var="monikerExisting" >
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?existingMoniker
WHERE { ?newIndividual vitro:moniker ?existingMoniker }
</v:jsonset>
<v:jsonset var="monikerAssertion" >
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
?newIndividual vitro:moniker ?moniker .
</v:jsonset>
<v:jsonset var="linkUrlExisting" >
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
SELECT ?existingLinkUrl
WHERE { ?newIndividual vitro:primaryLink ?newLink ;
?newLink vitro:linkURL ?existingLinkUrl .
}
</v:jsonset>
<v:jsonset var="linkUrlAssertion" >
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?newLink vitro:linkURL ?linkUrl .
</v:jsonset>
<v:jsonset var="n3ForEdit" >
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vivo: <http://vivo.library.cornell.edu/ns/0.1#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?newIndividual rdf:type <${curatorReviewUri}> .
?newIndividual rdf:type <${rangeClassUri}> .
?subject ?predicate ?newIndividual .
?newIndividual rdfs:label ?name .
</v:jsonset>
<v:jsonset var="n3Inverse" >
?newIndividual ?inverseProp ?subject .
</v:jsonset>
<%-- make sure you have all the @prefix entries to cover the statements in each block --%>
<v:jsonset var="n3optional" >
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?newIndividual vitro:moniker ?moniker .
</v:jsonset>
<%-- set the portal of the new individual to the current portal. --%>
<v:jsonset var="n3portal">
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
?newIndividual rdf:type <${portalUri}> .
</v:jsonset>
<%-- note that it's safer to have multiple distinct optional blocks so that a failure in one
will not prevent correct sections from being inserted --%>
<v:jsonset var="n3link" >
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?newLink
rdf:type vitro:Link ;
vitro:linkURL ?linkUrl ;
vitro:linkAnchor ?name ;
vitro:linkDisplayRank "1" .
?newIndividual vitro:primaryLink ?newLink .
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : [ "subject", "${subjectUriJson}" ],
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "newIndividual", "${objectUriJson}", "URI" ],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ "${n3optional}", "${n3Inverse}", "${n3link}", "${n3portal}" ],
"newResources" : {
"newIndividual" : "http://vivo.library.cornell.edu/ns/0.1#individual",
"newLink" : "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#Link"
},
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : [ "name","moniker","linkUrl" ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { "inverseProp" : "${queryForInverse}" },
"sparqlForExistingLiterals" : {
"name" : "${nameExisting}",
"moniker" : "${monikerExisting}",
"linkUrl" : "${linkUrlExisting}"
},
"sparqlForExistingUris" : { },
"fields" : {
"name" : {
"newResource" : "false",
"validators" : [ "nonempty" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${nameAssertion}" ]
},
"moniker" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "MONIKERS_VIA_VCLASS",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "${newIndividualVClassUri}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${monikerAssertion}" ]
},
"linkUrl" : {
"newResource" : "false",
"validators" : [],
"optionsType" : "UNDEFINED",
"literalOptions" : [],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${linkUrlAssertion}" ]
}
}
}
</c:set>
<%
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
if( editConfig == null ){
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
}
Model model = (Model)application.getAttribute("jenaOntModel");
String objectUri = (String)request.getAttribute("objectUri");
if( objectUri != null ){
editConfig.prepareForObjPropUpdate(model);
}else{
editConfig.prepareForNonUpdate(model);
}
String submitButtonLabel=""; // don't put local variables into the request
/* title is used by pre and post form fragments */
if (objectUri != null) {
request.setAttribute("title", "Edit \""+propDomainPublic+"\" entry for " + subject.getName());
submitButtonLabel = "Save changes";
} else {
request.setAttribute("title","Create a new \""+propDomainPublic+"\" entry for " + subject.getName());
submitButtonLabel = "Create new \""+propDomainPublic+"\" entry";
}
%>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="false"/>
<jsp:param name="useAutoComplete" value="true"/>
</jsp:include>
<script type="text/javascript" language="javascript">
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
$(document).ready(function() {
var key = $("input[name='editKey']").attr("value");
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "moniker", editKey: key}, function(json){
$("select#moniker").replaceWith("<input type='text' id='moniker' name='moniker' />");
$("#moniker").autocomplete(json, {
minChars: 0,
width: 320,
matchContains: true,
mustMatch: 0,
autoFill: false,
formatItem: function(row, i, max) {
return row[0];
},
formatMatch: function(row, i, max) {
return row[0];
},
formatResult: function(row) {
return row[0];
}
}).result(function(event, data, formatted) {
$("input#moniker").attr("value", data[1]);
});
}
);
})
</script>
<h2>${title}</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<v:input type="text" label="name (required)" id="name" size="30"/>
<hr/>
<v:input type="select" label="label (optional)" id="moniker"/> <em>start typing to see existing choices, or add a new label</em>
<v:input type="text" label="associated web page (optional)" id="linkUrl" size="50"/>
<v:input type="submit" id="submit" value="<%=submitButtonLabel%>" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,118 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.admin.mayEditAs.jsp");
public static String RANGE_CLASS = "http://xmlns.com/foaf/0.1/Agent";
public static String PREDICATE = VitroVocabulary.MAY_EDIT_AS;
%>
<%
String subjectUri = (String)request.getAttribute("subjectUri");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
VClass rangeClass = wdf.getVClassDao().getVClassByURI( RANGE_CLASS );
if( rangeClass == null ) log.debug("Cannot find class for range for property."
+ " Looking for " + RANGE_CLASS);
request.setAttribute("rangeClassUriJson", MiscWebUtils.escape(RANGE_CLASS));
request.setAttribute("predicateUriJson", MiscWebUtils.escape(PREDICATE));
%>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?objectVar.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/userEdit",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : ["objectVar"],
"literalsOnForm" : [ ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"fields" : { "objectVar" : {
"newResource" : "false",
"queryForExisting" : { },
"validators" : [ ],
"optionsType" : "INDIVIDUALS_VIA_VCLASS",
"subjectUri" : "${subjectUriJson}",
"subjectClassUri" : "",
"predicateUri" : "",
"objectClassUri" : "${rangeClassUriJson}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ] ,
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle ="";
String submitLabel ="";
Model model = (Model)application.getAttribute("jenaOntModel");
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
editConfig.prepareForObjPropUpdate( model );
formTitle = "Change person that user may edit as";
submitLabel = "save change";
} else {
editConfig.prepareForNonUpdate( model );
formTitle = "Add person that user may edit as";
submitLabel = "add edit right";
}
%>
<jsp:include page="${preForm}"/>
<h2><%=formTitle%></h2>
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" method="post">
<v:input type="select" id="objectVar" size="80" />
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</form>
<c:if test="${!empty param.objectUri}" >
<form class="deleteForm" action="<c:url value="/edit/n3Delete.jsp"/>" method="post">
<label for="delete"><h3>Remove the right to edit as this person?</h3></label>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
<input type="hidden" name="editform" value="edit/admin/mayEditAs.jsp"/>
<v:input type="submit" id="delete" value="Remove" cancel="" />
</form>
</c:if>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,135 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.admin.resourceDisplayVisibility.jsp");
%>
<% /* Here is the calling form, as implemented for props_edit.jsp */
// <form action="edit/editRequestDispatch.jsp" method="get"> */
// <input name="home" type="hidden" value="${portalBean.portalId}" />
// <input name="subjectUri" type= "hidden" value="${property.URI}" />
// <input name="urlPattern" type="hidden" value="/propertyEdit" />
// <input name="editform" type="hidden" value="admin/resourceDisplayVisibility.jsp"/>
// <input type="submit" class="form-button" value="Set Property Display Visibility"/>
// </form>
// <form action="edit/editRequestDispatch.jsp" method="get">
// <input name="home" type="hidden" value="${portalBean.portalId}" />
// <input name="subjectUri" type="hidden" value="${property.URI}" />
// <input name="urlPattern" type="hidden" value="/propertyEdit" />
// <input name="editform" type="hidden" value="admin/resourceEditVisibility.jsp"/>
// <input type="submit" class="form-button" value="Set Property Editing Visibility"/>
// </form>
/* This form uses the unusual tactic of always configuring itself as if it were doing an update. */
Individual subject = (Individual)request.getAttribute("subject");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
String urlPatternToReturnTo = (String)request.getAttribute("urlPatternToReturnTo");
if (urlPatternToReturnTo==null || urlPatternToReturnTo.length()==0) {
log.warn("urlPatternToReturnTo is null when starting resourceDisplayVisibility.jsp");
System.out.println("urlPatternToReturnTo is null when starting resourceDisplayVisibility.jsp");
} else {
log.warn("urlPatternToReturnTo is "+urlPatternToReturnTo+" when starting resourceDisplayVisibility.jsp");
System.out.println("urlPatternToReturnTo is "+urlPatternToReturnTo+" when starting resourceDisplayVisibility.jsp");
}
%>
<c:choose>
<c:when test="${!empty urlPatternToReturnTo}"><c:set var="urlPattern" value="${urlPatternToReturnTo}"/></c:when>
<c:otherwise><c:set var="urlPattern" value="/entity" /></c:otherwise>
</c:choose>
<c:set var="roleOptions">
["<%=BaseResourceBean.RoleLevel.PUBLIC.getURI()%>","<%=BaseResourceBean.RoleLevel.PUBLIC.getLabel() %>" ],
["<%=BaseResourceBean.RoleLevel.SELF.getURI()%>","<%=BaseResourceBean.RoleLevel.SELF.getLabel() %>" ],
["<%=BaseResourceBean.RoleLevel.EDITOR.getURI()%>","<%=BaseResourceBean.RoleLevel.EDITOR.getLabel() %>" ],
["<%=BaseResourceBean.RoleLevel.CURATOR.getURI()%>","<%=BaseResourceBean.RoleLevel.CURATOR.getLabel() %>" ],
["<%=BaseResourceBean.RoleLevel.DB_ADMIN.getURI()%>","<%=BaseResourceBean.RoleLevel.DB_ADMIN.getLabel() %>" ],
["<%=BaseResourceBean.RoleLevel.NOBODY.getURI()%>","<%=BaseResourceBean.RoleLevel.NOBODY.getLabel() %>" ]
</c:set>
<v:jsonset var="displayRoleAssertions">
@prefix vitro: <http://vitro.mannlib.connell.edu/ns/vitro/0.7#> .
?subject vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayRole .
</v:jsonset>
<v:jsonset var="displayRoleExisting">
prefix vitro: <http://vitro.mannlib.connell.edu/ns/vitro/0.7#>
SELECT ?existingDisplayRole
WHERE {
?subject vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayRole .
}
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "${urlPattern}",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "objectVar" , "http://example.org/valueJustToMakeItLookLikeAnUpdate" , "URI"],
"n3required" : [ "" ],
"n3optional" : [ "" ],
"newResources" : { },
"urisInScope" : { "displayRole" : "http://vitro.mannlib.cornell.edu/ns/vitro/role#public" },
"literalsInScope" : { },
"urisOnForm" : ["displayRole"],
"literalsOnForm" : [ ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { "displayRole" : "${displayRoleExisting}" },
"fields" : { "displayRole" : {
"newResource" : "false",
"validators" : [ ],
"optionsType" : "LITERALS",
"predicateUri" : "${predicateUriJson}",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ${roleOptions} ],
"assertions" : ["${displayRoleAssertions}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
if (editConfig.getUrlPatternToReturnTo()==null) {
System.out.println("urlPatternToReturnTo not initialized in resourceDisplayVisibility.jsp");
log.debug("urlPatternToReturnTo not initialized");
} else {
System.out.println("urlPatternToReturnTo initialized to "+editConfig.getUrlPatternToReturnTo()+" in resourceDisplayVisibility.jsp");
log.debug("urlPatternToReturnTo initialized to "+editConfig.getUrlPatternToReturnTo()+"\n");
}
EditConfiguration.putConfigInSession(editConfig, session);
Model model = (Model)application.getAttribute("jenaOntModel");
editConfig.prepareForObjPropUpdate( model );
%>
<jsp:include page="${preForm}"/>
<h2>Set Display Visibility</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<v:input type="select" id="displayRole" size="80" />
<v:input type="submit" id="submit" value="submit" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,179 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.autoCompleteDatapropForm.jsp");
log.debug("Starting autoCompleteDatapropForm.jsp");
String subjectUri = request.getParameter("subjectUri");
String predicateUri = request.getParameter("predicateUri");
DataPropertyStatement dps = (DataPropertyStatement)request.getAttribute("dataprop");
String datapropKeyStr = request.getParameter("datapropKey");
int dataHash=0;
DataProperty prop = (DataProperty)request.getAttribute("predicate");
if( prop == null ) throw new Error("In autoCompleteDatapropForm.jsp, could not find predicate " + predicateUri);
request.setAttribute("propertyName",prop.getPublicName());
Individual subject = (Individual)request.getAttribute("subject");
if( subject == null ) throw new Error("In autoCompleteDatapropForm.jsp, could not find subject " + subjectUri);
request.setAttribute("subjectName",subject.getName());
String rangeDatatypeUri = prop.getRangeDatatypeURI();
request.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
if( dps != null ){
try {
dataHash = Integer.parseInt(datapropKeyStr);
log.debug("dataHash is " + dataHash);
} catch (NumberFormatException ex) {
log.debug("could not parse dataprop hash "+
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
}
String rangeDatatype = dps.getDatatypeURI();
if( rangeDatatype == null ){
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in autoCompleteDatapropForm.jsp");
request.setAttribute("rangeDatatypeUriJson","");
}else{
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in autoCompleteDatapropForm.jsp");
request.setAttribute("rangeDatatypeUriJson",rangeDatatype);
}
String rangeLang = dps.getLanguage();
if( rangeLang == null ) {
log.debug("no language attribute on data property statement in autoCompleteDatapropForm.jsp");
request.setAttribute("rangeLangJson","");
}else{
log.debug("language attribute of ["+rangeLang+"] on data property statement in autoCompleteDatapropForm.jsp");
request.setAttribute("rangeLangJson", rangeLang);
}
} else {
log.error("No incoming dataproperty statement attribute in autoCompleteDatapropForm.jsp");
}
%>
<c:set var="dataLiteral" value="<%=prop.getLocalName()%>"/>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?${dataLiteral}.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>",
"urlPatternToReturnTo" : "/entity",
"subject" : ["subject", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}"],
"object" : ["${dataLiteral}","","DATAPROPHASH"],
"n3required" : ["${n3ForEdit}"],
"n3optional" : [ ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : ["${dataLiteral}"],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"optionsForFields" : { },
"fields" : { "${dataLiteral}" : {
"newResource" : "false",
"validators" : ["nonempty"],
"optionsType" : "STRINGS_VIA_DATATYPE_PROPERTY",
"literalOptions" : [],
"predicateUri" : "${predicateUriJson}",
"objectClassUri" : "",
"rangeDatatypeUri" : "${rangeDatatypeUriJson}" ,
"rangeLang" : "${rangeLangJson}",
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<%
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle =""; // dont add local page variables to the request
String submitLabel ="";
if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
Model model = (Model)application.getAttribute("jenaOntModel");
editConfig.prepareForDataPropUpdate(model,dps);
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
submitLabel = "save change";
} else {
formTitle = "Add new entry for: <em>"+prop.getPublicName()+"</em>";
submitLabel = "save entry";
}
%>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="false"/>
<jsp:param name="useAutoComplete" value="true"/>
</jsp:include>
<script type="text/javascript" language="javascript">
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
$(document).ready(function() {
var key = $("input[name='editKey']").attr("value");
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "${dataLiteral}", editKey: key}, function(json){
$("select#${dataLiteral}").replaceWith("<input type='hidden' id='${dataLiteral}' name='${dataLiteral}' /><input type='text' id='${dataLiteral}-entry' name='${dataLiteral}-entry' />");
$("#${dataLiteral}-entry").autocomplete(json, {
minChars: 1,
width: 320,
matchContains: true,
mustMatch: 0,
autoFill: false,
// formatItem: function(row, i, max) {
// return row[0];
// },
// formatMatch: function(row, i, max) {
// return row[0];
// },
// formatResult: function(row) {
// return row[0];
// }
}).result(function(event, data, formatted) {
$("input#${dataLiteral}-entry").attr("value", data[0]); // dump the string into the text box
$("input#${dataLiteral}").attr("value", data[1]); // dump the uri into the hidden form input
});
}
);
})
</script>
<h2><%=formTitle%></h2>
<form class="editForm" action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" >
<c:if test="${!empty predicate.publicDescription}">
<p class="propEntryHelpText">${predicate.publicDescription}</p>
</c:if>
<v:input type="select" id="${dataLiteral}"/>
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,193 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.autoCompleteObjPropForm.jsp");
%>
<%
log.warn("Starting autoCompleteObjPropForm.jsp");
Individual subject = (Individual)request.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
if( prop.getRangeVClassURI() == null ) {
log.debug("Property has null for its range class URI");
// If property has no explicit range, we will use e.g. owl:Thing.
// Typically an allValuesFrom restriction will come into play later.
VClass top = wdf.getVClassDao().getTopConcept();
prop.setRangeVClassURI(top.getURI());
log.debug("Using "+prop.getRangeVClassURI());
}
VClass rangeClass = wdf.getVClassDao().getVClassByURI( prop.getRangeVClassURI());
if( rangeClass == null ) log.debug("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
%>
<v:jsonset var="queryForInverse" >
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?inverse_property
WHERE {
?inverse_property owl:inverseOf ?predicate
}
</v:jsonset>
<c:set var="objectVar" value="<%=prop.getLocalName()%>"/>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?${objectVar}.
</v:jsonset>
<v:jsonset var="n3Inverse" >
?${objectVar} ?inverseProp ?subject.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "${objectVar}" , "${objectUriJson}" , "URI"],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ "${n3Inverse}" ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : ["${objectVar}"],
"literalsOnForm" : [ ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"fields" : { "${objectVar}" : {
"newResource" : "false",
"queryForExisting" : { },
"validators" : [ ],
"optionsType" : "INDIVIDUALS_VIA_OBJECT_PROPERTY",
"subjectUri" : "${subjectUriJson}",
"subjectClassUri" : "",
"predicateUri" : "${predicateUriJson}",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ] ,
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle ="";
String submitLabel ="";
Model model = (Model)application.getAttribute("jenaOntModel");
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
editConfig.prepareForObjPropUpdate( model );
formTitle = "Change entry for: <em>"+prop.getDomainPublic()+"</em>";
submitLabel = "save change";
} else {
editConfig.prepareForNonUpdate( model );
if ( prop.getOfferCreateNewOption() ) {
log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]");
formTitle = "Select an existing "+rangeClass.getName()+" for "+subject.getName();
submitLabel = "select existing";
} else {
formTitle = "Add an entry to: <em>"+prop.getDomainPublic()+"</em>";
submitLabel = "save entry";
}
}
%>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="false"/>
<jsp:param name="useAutoComplete" value="true"/>
</jsp:include>
<script type="text/javascript" language="javascript">
$(this).load($(this).parent().children('a').attr('src')+" .editForm");
$(document).ready(function() {
var key = $("input[name='editKey']").attr("value");
$.getJSON("<c:url value="/dataservice"/>", {getN3EditOptionList:"1", field: "${objectVar}", editKey: key}, function(json){
$("select#${objectVar}").replaceWith("<input type='hidden' id='${objectVar}' name='${objectVar}' /><input type='text' id='${objectVar}-entry' name='${objectVar}-entry' />");
$("#${objectVar}-entry").autocomplete(json, {
minChars: 1,
width: 320,
matchContains: true,
mustMatch: 1,
autoFill: true,
// formatItem: function(row, i, max) {
// return row[0];
// },
// formatMatch: function(row, i, max) {
// return row[0];
// },
// formatResult: function(row) {
// return row[0];
// }
}).result(function(event, data, formatted) {
$("input#${objectVar}-entry").attr("value", data[0]); // dump the string into the text box
$("input#${objectVar}").attr("value", data[1]); // dump the uri into the hidden form input
});
}
);
})
</script>
<h2><%=formTitle%></h2>
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<c:if test="${predicate.offerCreateNewOption == true}">
<c:url var="createNewUrl" value="/edit/editRequestDispatch.jsp">
<c:param name="subjectUri" value="${param.subjectUri}"/>
<c:param name="predicateUri" value="${param.predicateUri}"/>
<c:param name="clearEditConfig" value="true"/>
<c:param name="cmd" value="create"/>
</c:url>
</c:if>
<c:if test="${!empty predicate.publicDescription}">
<p>${predicate.publicDescription}</p>
</c:if>
<v:input type="select" id="${objectVar}" size="80" />
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
<c:if test="${predicate.offerCreateNewOption == true}">
<p>If you don't find the appropriate entry on the selection list,
<button type="button" onclick="javascript:document.location.href='${createNewUrl}'">add a new item to this list</button>
</p>
</c:if>
</form>
<c:if test="${!empty param.objectUri}" >
<form class="deleteForm" action="editRequestDispatch.jsp" method="get">
<label for="delete"><h3>Delete this entry?</h3></label>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
<input type="hidden" name="cmd" value="delete"/>
<v:input type="submit" id="delete" value="Delete" cancel="" />
</form>
</c:if>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,100 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/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.datapropStmtDelete");
if( session == null)
throw new Error("need to have session");
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%>
<c:redirect url="<%= Controllers.LOGIN %>" />
<% }
String subjectUri = request.getParameter("subjectUri");
String predicateUri = request.getParameter("predicateUri");
String datapropKeyStr = request.getParameter("datapropKey");
int dataHash = 0;
if (datapropKeyStr!=null && datapropKeyStr.trim().length()>0) {
try {
dataHash = Integer.parseInt(datapropKeyStr);
} catch (NumberFormatException ex) {
throw new JspException("Cannot decode incoming datapropKey String value "+datapropKeyStr+" as an integer hash in datapropStmtDelete.jsp");
}
}
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
String editorUri = EditN3Utils.getEditorUri(request,session,application);
wdf = wdf.getUserAwareDaoFactory(editorUri);
DataProperty prop = wdf.getDataPropertyDao().getDataPropertyByURI(predicateUri);
if( prop == null ) throw new Error("In datapropStmtDelete.jsp, could not find property " + predicateUri);
request.setAttribute("propertyName",prop.getPublicName());
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
if( subject == null ) throw new Error("could not find subject " + subjectUri);
request.setAttribute("subjectName",subject.getName());
String dataValue=null;
// DataPropertyStatement dps=EditConfiguration.findDataPropertyStatementViaHashcode(subject,predicateUri,dataHash);
DataPropertyStatement dps= RdfLiteralHash.getDataPropertyStmtByHash(subject,dataHash);
if( log.isDebugEnabled() ){
log.debug("attempting to delete dataPropertyStatement: subjectURI <" + dps.getIndividualURI() +">");
log.debug( "predicateURI <" + dps.getDatapropURI() + ">");
log.debug( "literal \"" + dps.getData() + "\"" );
log.debug( "lang @" + (dps.getLanguage() == null ? "null" : dps.getLanguage()));
log.debug( "datatype ^^" + (dps.getDatatypeURI() == null ? "null" : dps.getDatatypeURI() ));
}
if( dps.getIndividualURI() == null || dps.getIndividualURI().trim().length() == 0){
log.debug("adding missing subjectURI to DataPropertyStatement" );
dps.setIndividualURI( subjectUri );
}
if( dps.getDatapropURI() == null || dps.getDatapropURI().trim().length() == 0){
log.debug("adding missing datapropUri to DataPropertyStatement");
dps.setDatapropURI( predicateUri );
}
if (dps!=null) {
dataValue = dps.getData().trim();
if( request.getParameter("y") != null ) { //do the delete
wdf.getDataPropertyStatementDao().deleteDataPropertyStatement(dps);%>
<%-- grab the predicate URI and trim it down to get the Local Name so we can send the user back to the appropriate property --%>
<c:set var="predicateUri" value="${param.predicateUri}" />
<c:set var="localName" value="${fn:substringAfter(predicateUri, '#')}" />
<c:url var="redirectUrl" value="../entity">
<c:param name="uri" value="${param.subjectUri}"/>
</c:url>
<c:redirect url="${redirectUrl}${'#'}${localName}"/>
<% } else { %>
<jsp:include page="${preForm}"/>
<form action="editDatapropStmtRequestDispatch.jsp" method="get">
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
<div class="toBeDeleted dataProp"><%=dataValue%></div>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="datapropKey" value="${param.datapropKey}"/>
<input type="hidden" name="y" value="1"/>
<input type="hidden" name="cmd" value="delete"/>
<v:input type="submit" id="submit" value="Delete" cancel="${param.subjectUri}" />
</form>
<jsp:include page="${postForm}"/>
<% }
} else {
throw new Error("In datapropStmtDelete.jsp, no match via hashcode to existing datatype property "+predicateUri+" for subject "+subject.getName()+"\n");
}%>

View file

@ -0,0 +1,255 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.ModelChangePreprocessor"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.DefaultAddMissingIndividualFormModelPreprocessor"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%
Individual subject = (Individual)request.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
if (prop == null) throw new Error("no object property specified via incoming predicate attribute in defaultAddMissingIndividualForm.jsp");
String propDomainPublic = (prop.getDomainPublic() == null) ? "affiliation" : prop.getDomainPublic();
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
if( prop.getRangeVClassURI() == null ) {
// If property has no explicit range, we will use e.g. owl:Thing.
// Typically an allValuesFrom restriction will come into play later.
VClass top = wdf.getVClassDao().getTopConcept();
prop.setRangeVClassURI(top.getURI());
}
String objectUri = (String)request.getAttribute("objectUri");
String predicateUri = (String)request.getAttribute("predicateUri");
boolean isForwardToCreateNew = request.getAttribute("isForwardToCreateNew") != null &&
(Boolean)request.getAttribute("isForwardToCreateNew") == true;
// If this request is the first forward to this form we need to create a new
// edit key because the request will be coming from a defaultObjPropForm and
// will have an edit key that will be reused by the EditConfiguration that
// is being created below. This also preserves back button functionality to
// the form this request is coming from. If the edit key was not cleared
// the new editConfig below would overwrite the previous form's editConfig
// in the Session.
if( isForwardToCreateNew )
request.setAttribute("editKey", EditConfiguration.newEditKey(session));
//If a objectProperty is both provideSelect and offerCreateNewOption
// then when the user gos to a default ObjectProperty edit for an existing
// object property statement then the user can create a new Individual,
// and replace the object in the existing objectPropertyStatement with
// this new individual.
boolean isReplaceWithNew = request.getAttribute("isReplaceWithNew") != null &&
(Boolean)request.getAttribute("isReplaceWithNew") == true;
// If an objectProperty is selectFromExisitng==false and offerCreateNewOption == true
// the we want to forward to the create new form but edit the existing object
// of the objPropStmt.
boolean isForwardToCreateButEdit = request.getAttribute("isForwardToCreateButEdit") != null
&& (Boolean)request.getAttribute("isForwardToCreateButEdit") == true;
vreq.setAttribute("defaultNamespace",wdf.getDefaultNamespace());
StringBuffer n3AssertedTypesUnescapedBuffer = new StringBuffer();
// TODO: redo to query restrictions directly. getVClassesForProperty returns the subclasses, which we don't want.
//for ( VClass vclass : assertionsWdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(),prop.getURI()) ) {
// if (vclass.getURI()!=null) {
// n3AssertedTypesUnescapedBuffer.append("?newIndividual ").append(" rdf:type <")
// .append(vclass.getURI()).append("> .\n");
// }
//}
vreq.setAttribute("n3AssertedTypesUnescaped",n3AssertedTypesUnescapedBuffer.toString());
// if we don't check it into the portal, we won't be able to see it
vreq.setAttribute("portalUri", vreq.getPortal().getTypeUri());
String flagURI = null;
if (vreq.getAppBean().isFlag1Active()) {
flagURI = VitroVocabulary.vitroURI+"Flag1Value"+vreq.getPortal().getPortalId()+"Thing";
} else {
flagURI = wdf.getVClassDao().getTopConcept().getURI(); // fall back to owl:Thing if not portal filtering
}
vreq.setAttribute("flagURI",flagURI);
VClass rangeClass = null;
String typeOfNew = (String)vreq.getAttribute("typeOfNew");
if(typeOfNew != null )
rangeClass = wdf.getVClassDao().getVClassByURI( typeOfNew );
if( rangeClass == null ){
rangeClass = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI());
if( rangeClass == null ) throw new Error ("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
}
//vreq.setAttribute("rangeClassLocalName",rangeClass.getLocalName());
//vreq.setAttribute("rangeClassNamespace",rangeClass.getNamespace());
vreq.setAttribute("rangeClassUri",rangeClass.getURI());
//todo: set additional ranges using allValuesFrom.
//vreq.setAttribute("curatorReviewUri","http://vivo.library.cornell.edu/ns/0.1#CuratorReview");
%>
<v:jsonset var="queryForInverse" >
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?inverse_property
WHERE {
?inverse_property owl:inverseOf ?predicate
}
</v:jsonset>
<%-- Enter a SPARQL query for each 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.
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
and in the literalsOnForm --%>
<v:jsonset var="nameExisting" >
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?existingName
WHERE { ?newIndividual rdfs:label ?existingName }
</v:jsonset>
<%-- 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) --%>
<v:jsonset var="n3ForName" >
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
?newIndividual rdfs:label ?name .
</v:jsonset>
<v:jsonset var="n3ForRelation" >
?subject ?predicate ?newIndividual .
</v:jsonset>
<v:jsonset var="n3ForType" >
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
?newIndividual rdf:type <${rangeClassUri}> .
</v:jsonset>
<v:jsonset var="n3ForFlag" >
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
?newIndividual rdf:type <${flagURI}> .
</v:jsonset>
<%-- using v:jsonset here so everything goes through the same JSON escaping --%>
<v:jsonset var="n3AssertedTypes">
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
${n3AssertedTypesUnescaped}
</v:jsonset>
<v:jsonset var="n3Inverse" >
?newIndividual ?inverseProp ?subject .
</v:jsonset>
<%-- note that it's safer to have multiple distinct optional blocks so that a failure in one
will not prevent correct sections from being inserted --%>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : [ "subject", "${subjectUriJson}" ],
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "newIndividual", "${objectUriJson}", "URI" ],
"n3required" : [ "${n3ForName}" , "${n3ForRelation}", "${n3ForType}"],
"n3optional" : [ "${n3Inverse}", "${n3AssertedTypes}", "${n3ForFlag}" ],
"newResources" : {
"newIndividual" : "${defaultNamespace}individual"
},
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : [ "name" ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { "inverseProp" : "${queryForInverse}" },
"sparqlForExistingLiterals" : {
"name" : "${nameExisting}"
},
"sparqlForExistingUris" : { },
"fields" : {
"name" : {
"newResource" : "false",
"validators" : ["nonempty"],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${n3ForName}" ]
}
}
}
</c:set>
<%
EditConfiguration editConfig = null;
if( ! isForwardToCreateNew )
editConfig = EditConfiguration.getConfigFromSession(session,request);
//else
// don't want to get the editConfig because it was for the defaultObjPropForm
if( editConfig == null ){
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
}
Model model = (Model)application.getAttribute("jenaOntModel");
if( isReplaceWithNew){
// this is very specialized for the defaultAddMissingIndividual.jsp
// to support objPropStmt edits where the user wants to
// create a new Individual. Here we trick the processRdfForm2 into
// creating a new Individual and use the preprocessor to do the
// removal of the old objPropStmt
editConfig.addModelChangePreprocessor(
new DefaultAddMissingIndividualFormModelPreprocessor(
subject.getURI(),predicateUri ,objectUri ) );
editConfig.setObject(null);
editConfig.prepareForNonUpdate(model);
}else if ( isForwardToCreateButEdit) {
editConfig.prepareForObjPropUpdate(model);
}else if(request.getAttribute("object") != null ){
editConfig.prepareForObjPropUpdate(model);
} else{
editConfig.prepareForNonUpdate(model);
}
String submitButtonLabel="";
/* title is used by pre and post form fragments */
if (objectUri != null) {
request.setAttribute("title", "Edit \""+propDomainPublic+"\" entry for " + subject.getName());
submitButtonLabel = "Save changes";
} else {
request.setAttribute("title","Create a new \""+propDomainPublic+"\" entry for " + subject.getName());
submitButtonLabel = "Create new \""+propDomainPublic+"\" entry";
}
%>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="false"/>
<jsp:param name="useAutoComplete" value="false"/>
</jsp:include>
<h2>${title}</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" ><br/>
<v:input type="text" label="name (required)" id="name" size="30"/><br/>
<v:input type="submit" id="submit" value="<%=submitButtonLabel%>" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,176 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%>
<%@ page import="java.util.HashMap"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%! private static HashMap<String,String> defaultsForXSDtypes ;
static {
defaultsForXSDtypes = new HashMap<String,String>();
//defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","2001-01-01T12:00:00");
defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","#Unparseable datetime defaults to now");
}
%>
<%
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultDatapropForm.jsp");
log.debug("Starting defaultDatapropForm.jsp");
VitroRequest vreq = new VitroRequest(request);
String subjectUri = vreq.getParameter("subjectUri");
String predicateUri = vreq.getParameter("predicateUri");
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
String datapropKeyStr = vreq.getParameter("datapropKey");
int dataHash=0;
DataProperty prop = (DataProperty)vreq.getAttribute("predicate");
if( prop == null ) throw new Error("In defaultDatapropForm.jsp, could not find predicate " + predicateUri);
vreq.setAttribute("propertyName",prop.getPublicName());
Individual subject = (Individual)vreq.getAttribute("subject");
if( subject == null ) throw new Error("In defaultDatapropForm.jsp, could not find subject " + subjectUri);
vreq.setAttribute("subjectName",subject.getName());
String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop);
//String rangeDatatypeUri = prop.getRangeDatatypeURI();
vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri));
if( dps != null ){
try {
dataHash = Integer.parseInt(datapropKeyStr);
log.debug("dataHash is " + dataHash);
} catch (NumberFormatException ex) {
log.debug("could not parse dataprop hash "+
"but there was a dataproperty; hash: '"+datapropKeyStr+"'");
}
String rangeDatatype = dps.getDatatypeURI();
if( rangeDatatype == null ){
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in defaultDatapropForm.jsp");
vreq.setAttribute("rangeDatatypeUriJson","");
} else {
log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in defaultDatapropForm.jsp");
vreq.setAttribute("rangeDatatypeUriJson",rangeDatatype);
}
String rangeLang = dps.getLanguage();
if( rangeLang == null ) {
log.debug("no language attribute on data property statement in defaultDatapropForm.jsp");
vreq.setAttribute("rangeLangJson","");
}else{
log.debug("language attribute of ["+rangeLang+"] on data property statement in defaultDatapropForm.jsp");
vreq.setAttribute("rangeLangJson", rangeLang);
}
} else {
log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+", adding a new statement");
if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) {
String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri);
if( defaultVal == null )
vreq.setAttribute("rangeDefaultJson", "");
else
vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' );
}
}
%>
<c:set var="localName" value="<%=prop.getLocalName()%>"/>
<c:set var="dataLiteral" value="${localName}Edited"/>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?${dataLiteral}.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"datapropKey" : "<%=datapropKeyStr==null?"":datapropKeyStr%>",
"urlPatternToReturnTo" : "/entity",
"subject" : ["subject", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}"],
"object" : ["${dataLiteral}","","DATAPROPHASH"],
"n3required" : ["${n3ForEdit}"],
"n3optional" : [ ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : ["${dataLiteral}"],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"optionsForFields" : { },
"fields" : { "${dataLiteral}" : {
"newResource" : "false",
"validators" : ["datatype:${rangeDatatypeUriJson}"],
"optionsType" : "LITERALS",
"literalOptions" : [ ${rangeDefaultJson} ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "${rangeDatatypeUriJson}" ,
"rangeLang" : "${rangeLangJson}",
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<%
if( log.isDebugEnabled()) log.debug(request.getAttribute("editjson"));
EditConfiguration editConfig = new EditConfiguration((String)vreq.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle =""; // don't add local page variables to the request
String submitLabel ="";
if( datapropKeyStr != null && datapropKeyStr.trim().length() > 0 ) {
Model model = (Model)application.getAttribute("jenaOntModel");
editConfig.prepareForDataPropUpdate(model,dps);
formTitle = "Change text for: <em>"+prop.getPublicName()+"</em>";
submitLabel = "save change";
} else {
formTitle ="Add new entry for: <em>"+prop.getPublicName()+"</em>";
submitLabel ="save entry";
}
%>
<%--the following parameters configure the tinymce textarea --%>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="true"/>
</jsp:include>
<h2><%=formTitle%></h2>
<form class="editForm" action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" method="post" > <%-- see VITRO-435 Jira issue: need POST, not GET --%>
<c:if test="${!empty predicate.publicDescription}">
<label for="${dataLiteral}"><p class="propEntryHelpText">${predicate.publicDescription}</p></label>
</c:if>
<v:input type="textarea" id="${dataLiteral}" rows="2"/>
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</form>
<c:if test="${ (!empty param.datapropKey) && (empty param.deleteProhibited) }">
<form class="deleteForm" action="editDatapropStmtRequestDispatch.jsp" method="post">
<label for="delete"><h3>Delete this entry?</h3></label>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="datapropKey" value="${param.datapropKey}"/>
<input type="hidden" name="cmd" value="delete"/>
<v:input type="submit" id="delete" value="Delete" cancel="" />
</form>
</c:if>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,167 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal" %>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.defaultLinkForm.jsp");
%>
<%-- Enter here any class names to be used for constructing INDIVIDUALS_VIA_VCLASS pick lists
These are then referenced in the field's ObjectClassUri but not elsewhere.
NOTE that this class may not exist in the model, in which the only choice of type
that will show up is "web page", which will insert no new statements and just create
links of type vitro:Link --%>
<%-- Then enter a SPARQL query for each 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.
Each of these must then be referenced in the sparqlForExistingLiterals section of the JSON block below
and in the literalsOnForm --%>
<v:jsonset var="urlExisting" >
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
SELECT ?urlExisting
WHERE { ?link vitro:linkURL ?urlExisting }
</v:jsonset>
<%-- 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) --%>
<v:jsonset var="urlAssertion" >
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?link vitro:linkURL ?url .
</v:jsonset>
<v:jsonset var="anchorExisting" >
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
SELECT ?anchorExisting
WHERE { ?link vitro:linkAnchor ?anchorExisting }
</v:jsonset>
<v:jsonset var="anchorAssertion" >
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?link vitro:linkAnchor ?anchor .
</v:jsonset>
<%-- When not retrieving a literal via a datatype property, put the SPARQL statement into
the SparqlForExistingUris --%>
<v:jsonset var="n3ForEdit">
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
?subject vitro:additionalLink ?link .
?link rdf:type vitro:Link .
?link
vitro:linkURL ?url ;
vitro:linkAnchor ?anchor .
</v:jsonset>
<v:jsonset var="n3Optional">
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
?link rdf:type ?type .
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : ["subject", "${subjectUriJson}" ],
"predicate" : ["predicate", "${predicateUriJson}" ],
"object" : ["link", "${objectUriJson}", "URI" ],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ "${n3Optional}" ],
"newResources" : { "link" : "http://vivo.library.cornell.edu/ns/0.1#individual" },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : [ "url", "anchor" ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : { },
"sparqlForExistingLiterals" : {
"url" : "${urlExisting}",
"anchor" : "${anchorExisting}"
},
"sparqlForExistingUris" : { },
"fields" : {
"url" : {
"newResource" : "false",
"validators" : [ "nonempty" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${urlAssertion}" ]
},
"anchor" : {
"newResource" : "false",
"validators" : [ "nonempty" ],
"optionsType" : "UNDEFINED",
"literalOptions" : [ ],
"predicateUri" : "",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"assertions" : [ "${anchorAssertion}" ]
}
}
}
</c:set>
<%
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
if( editConfig == null ){
editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
}
Model model = (Model)application.getAttribute("jenaOntModel");
String objectUri = (String)request.getAttribute("objectUri");
if( objectUri != null ){
editConfig.prepareForObjPropUpdate(model);
}else{
editConfig.prepareForNonUpdate(model);
}
/* get some data to make the form more useful */
Individual subject = (Individual)request.getAttribute("subject");
String submitLabel=""; // don't put local variables into the request
/* title is used by pre and post form fragments */
if (objectUri != null) {
request.setAttribute("title", "Edit link for " + subject.getName());
submitLabel = "Save changes";
} else {
request.setAttribute("title","Create a new link for " + subject.getName());
submitLabel = "Create new link";
}
%>
<jsp:include page="${preForm}"/>
<h2>${title}</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<v:input type="text" label="URL" id="url" size="70"/>
<v:input type="text" label="label" id="anchor" size="60"/>
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,188 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.defaultObjPropForm.jsp");
%>
<%
Individual subject = (Individual)request.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
if( prop.getRangeVClassURI() == null ) {
log.debug("Property has null for its range class URI");
// If property has no explicit range, we will use e.g. owl:Thing.
// Typically an allValuesFrom restriction will come into play later.
VClass top = wdf.getVClassDao().getTopConcept();
prop.setRangeVClassURI(top.getURI());
log.debug("Using "+prop.getRangeVClassURI());
}
VClass rangeClass = wdf.getVClassDao().getVClassByURI( prop.getRangeVClassURI());
if( rangeClass == null ) log.debug("Cannot find class for range for property. Looking for " + prop.getRangeVClassURI() );
%>
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator"%>
<%@page import="java.util.Map"%><v:jsonset var="queryForInverse" >
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?inverse_property
WHERE {
?inverse_property owl:inverseOf ?predicate
}
</v:jsonset>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?objectVar.
</v:jsonset>
<v:jsonset var="n3Inverse" >
?objectVar ?inverseProp ?subject.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "objectVar" , "${objectUriJson}" , "URI"],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ "${n3Inverse}" ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : ["objectVar"],
"literalsOnForm" : [ ],
"filesOnForm" : [ ],
"sparqlForLiterals" : { },
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"fields" : { "objectVar" : {
"newResource" : "false",
"queryForExisting" : { },
"validators" : [ "nonempty" ],
"optionsType" : "INDIVIDUALS_VIA_OBJECT_PROPERTY",
"subjectUri" : "${subjectUriJson}",
"subjectClassUri" : "",
"predicateUri" : "${predicateUriJson}",
"objectClassUri" : "",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ] ,
"assertions" : ["${n3ForEdit}", "${n3Inverse}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
String formTitle ="";
String submitLabel ="";
Model model = (Model)application.getAttribute("jenaOntModel");
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
editConfig.prepareForObjPropUpdate( model );
formTitle = "Change entry for: <em>"+prop.getDomainPublic()+"</em>";
submitLabel = "save change";
} else {
editConfig.prepareForNonUpdate( model );
if ( prop.getOfferCreateNewOption() ) {
log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]");
formTitle = "Select an existing "+rangeClass.getName()+" for "+subject.getName();
submitLabel = "select existing";
} else {
formTitle = "Add an entry to: <em>"+prop.getDomainPublic()+"</em>";
submitLabel = "save entry";
}
}
if( prop.getSelectFromExisting() ){
Map<String,String> rangeOptions = SelectListGenerator.getOptions(editConfig, "objectVar" , wdf);
if( rangeOptions != null && rangeOptions.size() > 0 )
request.setAttribute("rangeOptionsExist", true);
else
request.setAttribute("rangeOptionsExist",false);
}
%>
<jsp:include page="${preForm}"/>
<h2><%=formTitle%></h2>
<c:if test="${requestScope.predicate.selectFromExisting == true }">
<c:if test="${requestScope.rangeOptionsExist == true }">
<form class="editForm" action="<c:url value="/edit/processRdfForm2.jsp"/>" >
<c:if test="${!empty predicate.publicDescription}">
<p>${predicate.publicDescription}</p>
</c:if>
<v:input type="select" id="objectVar" size="80" />
<div style="margin-top: 1em">
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="${param.subjectUri}"/>
</div>
</form>
</c:if>
<c:if test="${requestScope.rangeOptionsExist == false }">
<p>There are no entries in the system to select from.</p>
</c:if>
</c:if>
<c:if test="${requestScope.predicate.offerCreateNewOption == true}">
<c:if test="${requestScope.rangeOptionsExist == true }">
<p>If you don't find the appropriate entry on the selection list:</p>
</c:if>
<c:if test="${requestScope.rangeOptionsExist == false }">
<p style="margin-top: 5em">Please create a new entry.</p>
</c:if>
<c:url var="createNewUrl" value="/edit/editRequestDispatch.jsp"/>
<form class="editForm" action="${createNewUrl}">
<input type="hidden" value="${param.subjectUri}" name="subjectUri"/>
<input type="hidden" value="${param.predicateUri}" name="predicateUri"/>
<input type="hidden" value="${param.objectUri}" name="objectUri"/>
<input type="hidden" value="create" name="cmd"/>
<v:input type="typesForCreateNew" id="typeOfNew" />
<v:input type="submit" id="submit" value="add a new item to this list"/>
</form>
</c:if>
<c:if test="${(requestScope.predicate.offerCreateNewOption == false) && (requestScope.predicate.selectFromExisting == false)}">
<p>This property is currently configured to prohibit editing. </p>
</c:if>
<c:if test="${ (!empty param.objectUri) && (empty param.deleteProhibited) }" >
<form class="deleteForm" action="editRequestDispatch.jsp" method="get">
<label for="delete"><h3>Delete this entry?</h3></label>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
<input type="hidden" name="cmd" value="delete"/>
<c:if test="${(requestScope.predicate.offerCreateNewOption == false) && (requestScope.predicate.selectFromExisting == false)}">
<v:input type="submit" id="delete" value="Delete" cancel="cancel" />
</c:if>
<c:if test="${(requestScope.predicate.offerCreateNewOption == true) || (requestScope.predicate.selectFromExisting == true)}">
<v:input type="submit" id="delete" value="Delete" cancel="" />
</c:if>
</form>
</c:if>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,153 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory.SelfEditing"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils"%><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jstl/functions" %>
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty"%>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Link" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.LinksDao" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
<%!
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.edit.forms.propDelete.jsp");
public WebappDaoFactory getUnfilteredDaoFactory() {
return (WebappDaoFactory) getServletContext().getAttribute("webappDaoFactory");
}
%>
<%-- grab the predicate URI and trim it down to get the Local Name so we can send the user back to the appropriate property --%>
<c:set var="predicateUri" value="${param.predicateUri}" />
<c:set var="localName" value="${fn:substringAfter(predicateUri, '#')}" />
<c:url var="redirectUrl" value="../entity">
<c:param name="uri" value="${param.subjectUri}"/>
</c:url>
<%
if( session == null) {
throw new Error("need to have session");
}
boolean selfEditing = VitroRequestPrep.isSelfEditing(request);
if (!selfEditing && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%>
<c:redirect url="<%= Controllers.LOGIN %>" />
<% }
String subjectUri = request.getParameter("subjectUri");
String predicateUri = request.getParameter("predicateUri");
String objectUri = request.getParameter("objectUri");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
if( wdf == null ) {
throw new Error("could not get a WebappDaoFactory");
}
ObjectProperty prop = wdf.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
if( prop == null ) {
throw new Error("In propDelete.jsp, could not find property " + predicateUri);
}
request.setAttribute("propertyName",prop.getDomainPublic());
//do the delete
if( request.getParameter("y") != null ) {
String editorUri = EditN3Utils.getEditorUri(request,session,application);
wdf = wdf.getUserAwareDaoFactory(editorUri);
if (prop.getForceStubObjectDeletion()) {
Individual object = (Individual)request.getAttribute("object");
if (object==null) {
object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
}
if( object != null ) {
log.warn("Deleting individual "+object.getName()+" since property has been set to force range object deletion");
wdf.getIndividualDao().deleteIndividual(object);
} else {
throw new Error("Could not find object as request attribute or in model: '" + objectUri + "'");
}
}
wdf.getPropertyInstanceDao().deleteObjectPropertyStatement(subjectUri,predicateUri,objectUri); %>
<c:redirect url="${redirectUrl}${'#'}${localName}"/>
<% }
Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri);
if( subject == null ) throw new Error("could not find subject " + subjectUri);
request.setAttribute("subjectName",subject.getName());
boolean foundClass = false;
String customShortView = null;
String shortViewPrefix = "/templates/entity/";
Individual object = getUnfilteredDaoFactory().getIndividualDao().getIndividualByURI(objectUri);
if( object == null ) {
log.warn("Could not find object individual "+objectUri+" via wdf.getIndividualDao().getIndividualByURI(objectUri)");
request.setAttribute("objectName","(name unspecified)");
} else {
for (VClass clas : object.getVClasses(true)) { // direct VClasses, not inferred, and not including Vitro namespace
request.setAttribute("rangeClassName", clas.getName());
foundClass = true;
customShortView = clas.getCustomShortView();
if (customShortView != null && customShortView.trim().length()>0) {
log.debug("setting object name from VClass custom short view");
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
request.setAttribute("individual",object);
} else {
log.debug("No custom short view for class, so setting object name from object individual name");
request.setAttribute("objectName",object.getName());
}
}
if (!foundClass) {
VClass clas = prop.getRangeVClass();
if (clas != null) {
customShortView = clas.getCustomShortView();
if (customShortView != null && customShortView.trim().length()>0) {
log.warn("setting object name from VClass custom short view \""+customShortView.trim()+"\"");
request.setAttribute("customShortView",shortViewPrefix + customShortView.trim());
request.setAttribute("individual",object);
} else {
log.error("No custom short view jsp set for VClass "+clas.getName()+" so cannot render link name correctly");
request.setAttribute("objectName",object.getName());
}
}
}
}%>
<jsp:include page="${preForm}"/>
<form action="editRequestDispatch.jsp" method="get">
<label for="submit"><h2>Are you sure you want to delete the following entry from <em>${propertyName}</em>?</h2></label>
<div class="toBeDeleted objProp">
<c:choose>
<c:when test="${!empty customShortView}">
<c:set scope="request" var="individual" value="${individual}"/>
<jsp:include page="${customShortView}" flush="true"/>
<c:remove var="customShortView"/>
</c:when>
<c:otherwise>${objectName}</c:otherwise>
</c:choose>
</div>
<input type="hidden" name="subjectUri" value="${param.subjectUri}"/>
<input type="hidden" name="predicateUri" value="${param.predicateUri}"/>
<input type="hidden" name="objectUri" value="${param.objectUri}"/>
<input type="hidden" name="y" value="1"/>
<input type="hidden" name="cmd" value="delete"/>
<v:input type="submit" id="submit" value="Delete" cancel="${param.subjectUri}" />
</form>
<jsp:include page="${postForm}"/>

View file

@ -0,0 +1,104 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%
/* Prompts the user for a file to upload and adds a statement between a newly created
file resource and the Subject using the incoming predicate. Also try to make
an inverse statement. */
Individual subject = (Individual)request.getAttribute("subject");
ObjectProperty prop = (ObjectProperty)request.getAttribute("predicate");
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
%>
<v:jsonset var="queryForInverse" >
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?inverse_property
WHERE {
?inverse_property owl:inverseOf ?predicate
}
</v:jsonset>
<v:jsonset var="n3ForEdit" >
?subject ?predicate ?fileResource .
</v:jsonset>
<v:jsonset var="n3Inverse" >
?fileResource ?inverseProp ?subject.
</v:jsonset>
<c:set var="editjson" scope="request">
{
"formUrl" : "${formUrl}",
"editKey" : "${editKey}",
"urlPatternToReturnTo" : "/entity",
"subject" : [ "subject", "${subjectUriJson}" ] ,
"predicate" : [ "predicate", "${predicateUriJson}" ],
"object" : [ "fileResource" , "${objectUriJson}" , "URI"],
"n3required" : [ "${n3ForEdit}" ],
"n3optional" : [ "${n3Inverse}" ],
"newResources" : { },
"urisInScope" : { },
"literalsInScope" : { },
"urisOnForm" : [ ],
"literalsOnForm" : [ ],
"filesOnForm" : [ "fileResource" ],
"sparqlForLiterals" : { },
"sparqlForUris" : {"inverseProp" : "${queryForInverse}" },
"sparqlForExistingLiterals" : { },
"sparqlForExistingUris" : { },
"fields" : { "fileResource" : {
"newResource" : "false",
"queryForExisting" : { },
"validators" : [ "nonempty" ],
"optionsType" : "FILE_UPLOAD",
"subjectUri" : "",
"subjectClassUri" : "",
"predicateUri" : "",
"objectClassUri" : "${fileResourceClass}",
"rangeDatatypeUri" : "",
"rangeLang" : "",
"literalOptions" : [ ] ,
"assertions" : ["${n3ForEdit}"]
}
}
}
</c:set>
<% /* now put edit configuration Json object into session */
EditConfiguration editConfig = new EditConfiguration((String)request.getAttribute("editjson"));
EditConfiguration.putConfigInSession(editConfig, session);
Model model = (Model)application.getAttribute("jenaOntModel");
if( request.getAttribute("object") != null ){//this block is for an edit of an existing object property statement
editConfig.prepareForObjPropUpdate( model );
} else {
editConfig.prepareForNonUpdate( model );
}
%>
<jsp:include page="${preForm}"/>
<h2>Upload a File</h2>
<form action="<c:url value="/edit/processRdfForm2.jsp"/>" ENCTYPE="multipart/form-data" method="POST">
File <v:input type="file" id="fileResource" />
<v:input type="submit" id="submit" value="submit" cancel="${param.subjectUri}"/>
</form>
<jsp:include page="${postForm}"/>