* @see ch.osar.cms.rssedit.RSSPostAction#perform(com.hp.hpl.jena.rdf.model.Resource,
* org.wymiwyg.commons.util.http.MultiPartServletRequest)
*/
private void perform(Resource relationSource, Request request, String strengthString, String childStrengthString)
throws HandlerException {
MultiPartBody requestBody = (MultiPartBody) request.getBody();
String language = requestBody.getParameter("language");
String relationTargetString = requestBody.getParameter("target");
String relationSourceString = requestBody.getParameter("source");
if ((relationSourceString != null)
&& (!"".equals(relationSourceString))) {
relationSource = model.createResource(relationSourceString);
}
boolean inline = "inline".equals(requestBody.getParameter("linkType"));
boolean highlight = "checked".equals(requestBody
.getParameter("highlight"));
boolean comment = "checked".equals(requestBody
.getParameter("comment"));
Resource relationTarget;
if (relationTargetString != null) {
String relationTargetURL;
try {
if (relationTargetString.startsWith("http:")) {
relationTargetURL = new URL(relationTargetString)
.toString();
} else {
relationTargetURL = new URL(
new URL(relationSource.getURI()),
relationTargetString).toString();
}
relationTarget = model.createResource(relationTargetURL);
} catch (MalformedURLException e) {
throw new HandlerException(e);
}
} else {
String targetDescriptionString = requestBody.getParameter("targetDescription");
URL targetDescriptionURL;
try {
if (targetDescriptionString.startsWith("http")) {
targetDescriptionURL = new URL(targetDescriptionString);
} else {
targetDescriptionURL = new URL(new URL(relationSource
.getURI()), targetDescriptionString);
}
Resource targetDescription = model
.createResource(targetDescriptionURL.toString());
relationTarget = BaseItemPostHandler.lookUpByIFP(model,
FOAF.isPrimaryTopicOf, targetDescription);
} catch (MalformedURLException e) {
throw new HandlerException(e);
}
}
float strength;
if ((strengthString != null) && (!strengthString.equals(""))) {
strength = Float.parseFloat(strengthString);
} else {
strength = 1;
}
float strengthOrig = Float.parseFloat(requestBody
.getParameter("strengthOrig"));
String childStrengthOrig = requestBody
.getParameter("childStrengthOrig");
// if the user did not modify the strength the strength isn't changed,
// i.e. the time reduced value is kept
boolean keepStrength = (strength == strengthOrig)
&& ((childStrengthString == null) || (childStrengthString
.equals(childStrengthOrig)));
Resource relation = getRelation(relationSource, relationTarget);
String effectiveDateString = requestBody.getParameter("effectiveDate");
Literal effectiveDateLiteral;
if (effectiveDateString == null) {
effectiveDateLiteral = model.createTypedLiteral(new W3CDateFormat()
.format(new Date()), XSDDatatype.XSDdateTime);
} else {
effectiveDateLiteral = model.createTypedLiteral(effectiveDateString, XSDDatatype.XSDdateTime);
}
if (relation == null) {
relation = model.createResource();
relation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
Literal strengthLit = model.createTypedLiteral(strength);
relation.addProperty(KNOBOT.strength, strengthLit);
} else {
cleanRelation(relation, keepStrength, language);
if (!keepStrength) {
relation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
relation.addProperty(KNOBOT.strength, model.createTypedLiteral(strength));
}
}
if (inline) {
relation.addProperty(RDF.type, KNOBOT.InlineRelation);
}
relation.addProperty(RDF.type, KNOBOT.Relation);
String targetLabel = requestBody.getParameter("targetLabel");
if ((targetLabel != null) && (!targetLabel.equals(""))) {
relation.addProperty(KNOBOT.targetLabel, targetLabel, language);
}
String sourceLabel = requestBody.getParameter("sourceLabel");
if ((sourceLabel != null) && (!sourceLabel.equals(""))) {
relation.addProperty(KNOBOT.sourceLabel, sourceLabel, language);
}
String strengthReductionString = requestBody
.getParameter("strengthReduction");
float strengthReduction;
if ((strengthReductionString != null) && (!strengthReductionString.equals(""))) {
strengthReduction = Float.parseFloat(strengthReductionString);
} else {
strengthReduction = DefaultValuesHandler.getDefaultStrengthReduction(model);
}
relation.addProperty(KNOBOT.strengthReduction, model.createTypedLiteral(strengthReduction));
float childStrength = 0;
if ((!keepStrength) && (childStrengthString != null)
&& (!childStrengthString.equals(""))) {
childStrength = Float.parseFloat(childStrengthString);
relation.addProperty(KNOBOT.childStrength, model.createTypedLiteral(childStrength));
}
String childStrengthReduction = requestBody
.getParameter("minimumChildStrengthReduction");
if ((childStrengthReduction != null)
&& (!childStrengthReduction.equals(""))) {
relation.addProperty(KNOBOT.minimumChildStrengthReduction, model.createTypedLiteral(Float
.parseFloat(childStrengthReduction)));
}
String comparativeStrengthString = requestBody
.getParameter("comparativeStrength");
if ((!keepStrength) && (comparativeStrengthString != null)
&& (!comparativeStrengthString.equals(""))) {
float comparativeStrength = Float
.parseFloat(comparativeStrengthString);