use of org.eclipse.rdf4j.http.protocol.transaction.operations.SetNamespaceOperation in project rdf4j by eclipse.
the class TransactionSAXParser method startTag.
@Override
public void startTag(String tagName, Map<String, String> atts, String text) throws SAXException {
if (TransactionXMLConstants.URI_TAG.equals(tagName)) {
parsedValues.add(valueFactory.createIRI(text));
} else if (TransactionXMLConstants.BNODE_TAG.equals(tagName)) {
parsedValues.add(valueFactory.createBNode(text));
} else if (TransactionXMLConstants.LITERAL_TAG.equals(tagName)) {
String lang = atts.get(TransactionXMLConstants.LANG_ATT);
String datatype = atts.get(TransactionXMLConstants.DATATYPE_ATT);
String encoding = atts.get(TransactionXMLConstants.ENCODING_ATT);
if (encoding != null && "base64".equalsIgnoreCase(encoding)) {
text = new String(javax.xml.bind.DatatypeConverter.parseBase64Binary(text));
}
Literal lit;
if (lang != null) {
lit = valueFactory.createLiteral(text, lang);
} else if (datatype != null) {
IRI dtURI = valueFactory.createIRI(datatype);
lit = valueFactory.createLiteral(text, dtURI);
} else {
lit = valueFactory.createLiteral(text);
}
parsedValues.add(lit);
} else if (TransactionXMLConstants.NULL_TAG.equals(tagName)) {
parsedValues.add(null);
} else if (TransactionXMLConstants.SET_NAMESPACE_TAG.equals(tagName)) {
String prefix = atts.get(TransactionXMLConstants.PREFIX_ATT);
String name = atts.get(TransactionXMLConstants.NAME_ATT);
txn.add(new SetNamespaceOperation(prefix, name));
} else if (TransactionXMLConstants.REMOVE_NAMESPACE_TAG.equals(tagName)) {
String prefix = atts.get(TransactionXMLConstants.PREFIX_ATT);
txn.add(new RemoveNamespaceOperation(prefix));
} else if (TransactionXMLConstants.CLEAR_NAMESPACES_TAG.equals(tagName)) {
txn.add(new ClearNamespacesOperation());
} else if (TransactionXMLConstants.SPARQL_UPDATE_TAG.equals(tagName)) {
if (currentSPARQLUpdate != null) {
throw new SAXException("unexpected start of SPARQL Update operation");
}
currentSPARQLUpdate = new SPARQLUpdateOperation();
String baseURI = atts.get(TransactionXMLConstants.BASE_URI_ATT);
boolean includeInferred = Boolean.parseBoolean(atts.get(TransactionXMLConstants.INCLUDE_INFERRED_ATT));
currentSPARQLUpdate.setIncludeInferred(includeInferred);
currentSPARQLUpdate.setBaseURI(baseURI);
} else if (TransactionXMLConstants.UPDATE_STRING_TAG.equals(tagName)) {
currentSPARQLUpdate.setUpdateString(text);
} else if (TransactionXMLConstants.DATASET_TAG.equals(tagName)) {
currentDataset = new SimpleDataset();
} else if (TransactionXMLConstants.DEFAULT_INSERT_GRAPH.equals(tagName)) {
currentDataset.setDefaultInsertGraph(valueFactory.createIRI(text));
} else if (TransactionXMLConstants.GRAPH_TAG.equals(tagName)) {
parsedValues.add(valueFactory.createIRI(text));
} else if (TransactionXMLConstants.BINDINGS.equals(tagName)) {
if (bindings != null) {
throw new SAXException("unexpected start of SPARQL Update operation bindings");
}
bindings = new ArrayList<Binding>();
} else if (TransactionXMLConstants.BINDING_URI.equals(tagName) || TransactionXMLConstants.BINDING_BNODE.equals(tagName) || TransactionXMLConstants.BINDING_LITERAL.equals(tagName)) {
if (bindings == null) {
throw new SAXException("unexpected start of SPARQL Update operation binding (without <bindings>)");
}
String value = text;
String name = atts.get(TransactionXMLConstants.NAME_ATT);
if (name != null && value != null) {
Value v;
if (TransactionXMLConstants.BINDING_URI.equals(tagName)) {
v = valueFactory.createIRI(value);
} else if (TransactionXMLConstants.BINDING_BNODE.equals(tagName)) {
v = valueFactory.createBNode(value);
} else {
String language = atts.get(TransactionXMLConstants.LANGUAGE_ATT);
String dataType = atts.get(TransactionXMLConstants.DATA_TYPE_ATT);
if (language != null) {
v = valueFactory.createLiteral(value, language);
} else if (dataType != null) {
v = valueFactory.createLiteral(value, valueFactory.createIRI(dataType));
} else {
v = valueFactory.createLiteral(value);
}
}
bindings.add(new SimpleBinding(name, v));
}
}
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.SetNamespaceOperation in project rdf4j by eclipse.
the class HTTPRepositoryConnection method setNamespace.
public void setNamespace(String prefix, String name) throws RepositoryException {
if (prefix == null) {
throw new NullPointerException("prefix must not be null");
}
if (name == null) {
throw new NullPointerException("name must not be null");
}
if (this.getRepository().useCompatibleMode()) {
boolean localTransaction = startLocalTransaction();
txn.add(new SetNamespaceOperation(prefix, name));
conditionalCommit(localTransaction);
return;
}
try {
client.setNamespacePrefix(prefix, name);
} catch (IOException e) {
throw new RepositoryException(e);
}
}
Aggregations