org.openprovenance.prov.notation.HTMLConstructor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prov-n Show documentation
Show all versions of prov-n Show documentation
A Parser for PROV-N Provenance Notation.
package org.openprovenance.prov.notation;
import java.io.Writer;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import org.openprovenance.prov.model.Attribute;
import org.openprovenance.prov.model.QualifiedName;
/* FIXME: this does not work, since methods define here do not override those of NotationConstructor. */
public class HTMLConstructor extends NotationConstructor {
public HTMLConstructor(Writer writer) {
super(writer);
}
public String keyword(String s) {
return "" + s + "";
}
public String symbol(String s) {
return "" + s + "";
}
public String showprefix(String s) {
return "" + s + "";
}
public String showlocal(String s, String prefix) {
return "" + s + "";
}
public String breakline() {
return "
\n";
}
public String showuri(String s) {
String stripped=s.substring(1,s.length()-1);
return "<" + "" + stripped + "" + ">";
}
public String optionalTime(Object time) {
return ((time==null)? "" : (", " + time));
}
public Object optional2(Object str) {
return ((str==null)? "" : str);
}
public Object optional(Object str) {
return ((str==null)? "-" : str);
}
public Object convertId(String id) {
if (id==null) return null;
int index=id.indexOf(':');
String prefix=id.substring(0,index);
String local=id.substring(index+1,id.length());
return "" + showprefix(prefix) + ":" + showlocal(local,prefix) + "";
}
public Object convertAttribute(Object name, Object value) {
return "" + name + "" + symbol("=") + value;
}
public Object convertTypedLiteral(String datatype, Object value) {
if ("xsd:QName".equals(datatype)) { //TODO: probably, never satisfied
String val=(String)value;
return "'" + convertId(val.substring(1, val.length() -1 )) + "'";
} else {
if ("prov:QUALIFIED_NAME".equals(datatype)) {
String val=(String)value;
return "'" + val.substring(1, val.length() -1 ) + "'";
} else {
return " " + value + " " + symbol("%%") + " " + datatype + "";
}
}
}
public Object convertStart(String start) {
return start;
}
public Object convertEnd(String end) {
return end;
}
public Object convertString(String s) {
return "" + s + "";
}
public Object convertInt(int i) {
return i;
}
public String optionalId(Object id) {
return ((id==null)? "" : (id + ";"));
}
public Object convertQualifiedName(String qualifedName) {
return qualifedName;
}
public Object convertIRI(String iri) {
return iri;
}
public Object newActivity(QualifiedName id, XMLGregorianCalendar startTime,XMLGregorianCalendar endTime, List aAttrs) {
return " " + super.newActivity(id,startTime,endTime,aAttrs) + "";
}
public Object newEntity(QualifiedName id, List attrs) {
return " " + super.newEntity(id,attrs) + "";
}
}