Package org.openrdf.model

Examples of org.openrdf.model.URI


    if (!writingStarted) {
      throw new RuntimeException("Document writing has not yet been started");
    }

    Resource subj = st.getSubject();
    URI pred = st.getPredicate();
    Value obj = st.getObject();

    try {
      if (!headerWritten) {
        header();
View Full Code Here


    if (predicateStack.isEmpty()) {
      openStartTag(0, topNode.getValue(), topNode.getTypes());
      endTag(0, topNode.getValue(), topNode.getTypes());
    }
    else {
      URI topPredicate = predicateStack.pop();
      Value obj = topNode.getValue();
      int indent = nodeStack.size() * 2 - 1;
      if (obj instanceof URI) {
        String relativize = relativize(obj.stringValue());
        assert topNode.getTypes().isEmpty();
        writer.handleURI(indent, topPredicate, relativize);
      }
      else if (obj instanceof BNode && topNode.getTypes().isEmpty()) {
        writer.handleBlankNode(indent, topPredicate, (BNode)obj);
      }
      else if (obj instanceof BNode) {
        writer.openProperty(indent, topPredicate);
        writer.startBlankNode(indent, (BNode)obj, topNode.getTypes());
        writer.endBlankNode(indent, (BNode)obj, topNode.getTypes());
        writer.closeProperty(indent, topPredicate);
      }
      else if (obj instanceof Literal) {
        writer.handleLiteral(indent, topPredicate, (Literal)obj);
      }

      // Write out the end tags until we find the subject
      while (!nodeStack.isEmpty()) {
        Node nextElement = nodeStack.peek();
        if (nextElement.getValue().equals(newSubject)) {
          break;
        }
        else {
          Node node = nodeStack.pop();
          // We have already written out the subject/object,
          // but we still need to close the tag
          indent = predicateStack.size() + nodeStack.size();
          endTag(indent, nextElement.getValue(), nextElement.getTypes());
          if (predicateStack.size() > 0) {
            URI predicate = predicateStack.pop();
            indent = predicateStack.size() + nodeStack.size();
            assert node.getValue() instanceof BNode;
            writer.closeProperty(indent, predicate);
          }
        }
View Full Code Here

  private String getStringRepForValue(Value value, Collection<Namespace> namespaces) {
    if (value == null) {
      return "";
    }
    else if (showPrefix && value instanceof URI) {
      URI uri = (URI)value;

      String prefix = getPrefixForNamespace(uri.getNamespace(), namespaces);

      if (prefix != null) {
        return prefix + ":" + uri.getLocalName();
      }
      else {
        return NTriplesUtil.toNTriplesString(value);
      }
    }
View Full Code Here

   */
  private void writeValue(Value value)
    throws IOException, RDFHandlerException
  {
    if (value instanceof URI) {
      URI uri = (URI)value;
      xmlWriter.textElement(URI_TAG, uri.toString());
    }
    else if (value instanceof BNode) {
      BNode bNode = (BNode)value;
      xmlWriter.textElement(BNODE_TAG, bNode.getID());
    }
    else if (value instanceof Literal) {
      Literal literal = (Literal)value;
      URI datatype = literal.getDatatype();

      if (datatype != null) {
        xmlWriter.setAttribute(DATATYPE_ATT, datatype.toString());
        xmlWriter.textElement(TYPED_LITERAL_TAG, literal.getLabel());
      }
      else {
        String language = literal.getLanguage();
        if (language != null) {
View Full Code Here

  @Override
  public void meet(StatementPattern node)
    throws StoreException
  {
    Resource subj = (Resource)node.getSubjectVar().getValue();
    URI pred = (URI)node.getPredicateVar().getValue();
    Value obj = node.getObjectVar().getValue();
    Resource[] ctx = getContexts(node.getContextVar());
    for (RepositoryConnection member : members) {
      if (member.hasMatch(subj, pred, obj, true, ctx)) {
        return;
View Full Code Here

      reportError("unexpected literal");
      return;
    }

    PropertyElement propEl = (PropertyElement)peekStack(0);
    URI datatype = propEl.getDatatype();

    Literal lit = createLiteral(text, xmlLang, datatype);

    NodeElement subject = (NodeElement)peekStack(1);
    PropertyElement predicate = (PropertyElement)peekStack(0);
View Full Code Here

      }
    }

    if (!localName.equals("Description") || !namespaceURI.equals(RDF.NAMESPACE)) {
      // element name is uri's type
      URI className = null;
      if ("".equals(namespaceURI)) {
        // No namespace, use base URI
        className = buildResourceFromLocalName(localName);
      }
      else {
        className = createURI(namespaceURI + localName);
      }
      reportStatement(nodeResource, RDF.TYPE, className);
    }

    Att type = atts.removeAtt(RDF.NAMESPACE, "type");
    if (type != null) {
      // rdf:type attribute, value is a URI-reference
      URI className = resolveURI(type.getValue());

      reportStatement(nodeResource, RDF.TYPE, className);
    }

    if (verifyData()) {
View Full Code Here

    Iterator<Att> iter = atts.iterator();

    while (iter.hasNext()) {
      Att att = iter.next();

      URI predicate = createURI(att.getURI());
      Literal lit = createLiteral(att.getValue(), xmlLang, null);

      reportStatement(subject, predicate, lit);
    }
  }
View Full Code Here

    if (verifyData()) {
      checkPropertyEltName(namespaceURI, localName, qName);
    }

    // Get the URI of the property
    URI propURI = null;
    if (namespaceURI.equals("")) {
      // no namespace URI
      reportError("unqualified property element <" + qName + "> not allowed");
      // Use base URI as namespace:
      propURI = buildResourceFromLocalName(localName);
    }
    else {
      propURI = createURI(namespaceURI + localName);
    }

    // List expansion rule
    if (propURI.equals(RDF.LI)) {
      NodeElement subject = (NodeElement)peekStack(0);
      propURI = createURI(RDF.NAMESPACE + "_" + subject.getNextLiCounter());
    }

    // Push the property on the stack.
    PropertyElement predicate = new PropertyElement(propURI);
    elementStack.push(predicate);

    // Check if property has a reification ID
    Att id = atts.removeAtt(RDF.NAMESPACE, "ID");
    if (id != null) {
      URI reifURI = buildURIFromID(id.getValue());
      predicate.setReificationURI(reifURI);
    }

    // Check for presence of rdf:parseType attribute
    Att parseType = atts.removeAtt(RDF.NAMESPACE, "parseType");

    if (parseType != null) {
      if (verifyData()) {
        checkNoMoreAtts(atts);
      }

      String parseTypeValue = parseType.getValue();

      if (parseTypeValue.equals("Resource")) {
        BNode objectResource = createBNode();
        NodeElement subject = (NodeElement)peekStack(1);

        reportStatement(subject.getResource(), propURI, objectResource);

        if (isEmptyElt) {
          handleReification(objectResource);
        }
        else {
          NodeElement object = new NodeElement(objectResource);
          object.setIsVolatile(true);
          elementStack.push(object);
        }
      }
      else if (parseTypeValue.equals("Collection")) {
        if (isEmptyElt) {
          NodeElement subject = (NodeElement)peekStack(1);
          reportStatement(subject.getResource(), propURI, RDF.NIL);
          handleReification(RDF.NIL);
        }
        else {
          predicate.setParseCollection(true);
        }
      }
      else {
        // other parseType
        if (!parseTypeValue.equals("Literal")) {
          reportWarning("unknown parseType: " + parseType.getValue());
        }

        if (isEmptyElt) {
          NodeElement subject = (NodeElement)peekStack(1);

          Literal lit = createLiteral("", null, RDF.XMLLITERAL);

          reportStatement(subject.getResource(), propURI, lit);

          handleReification(lit);
        }
        else {
          // The next string is an rdf:XMLLiteral
          predicate.setDatatype(RDF.XMLLITERAL);

          saxFilter.setParseLiteralMode();
        }
      }
    }
    // parseType == null
    else if (isEmptyElt) {
      // empty element without an rdf:parseType attribute

      // Note: we handle rdf:datatype attributes here to allow datatyped
      // empty strings in documents. The current spec does have a
      // production rule that matches this, which is likely to be an
      // omission on its part.
      Att datatype = atts.getAtt(RDF.NAMESPACE, "datatype");

      if (atts.size() == 0 || atts.size() == 1 && datatype != null) {
        // element had no attributes, or only the optional
        // rdf:ID and/or rdf:datatype attributes.
        NodeElement subject = (NodeElement)peekStack(1);

        URI dtURI = null;
        if (datatype != null) {
          dtURI = createURI(datatype.getValue());
        }

        Literal lit = createLiteral("", xmlLang, dtURI);

        reportStatement(subject.getResource(), propURI, lit);
        handleReification(lit);
      }
      else {
        // Create resource for the statement's object.
        Resource resourceRes = getPropertyResource(atts);

        // All special rdf attributes have been checked/removed.
        if (verifyData()) {
          checkRDFAtts(atts);
        }

        NodeElement resourceElt = new NodeElement(resourceRes);
        NodeElement subject = (NodeElement)peekStack(1);

        reportStatement(subject.getResource(), propURI, resourceRes);
        handleReification(resourceRes);

        Att type = atts.removeAtt(RDF.NAMESPACE, "type");
        if (type != null) {
          // rdf:type attribute, value is a URI-reference
          URI className = resolveURI(type.getValue());

          reportStatement(resourceRes, RDF.TYPE, className);
        }

        processSubjectAtts(resourceElt, atts);
      }
    }
    else {
      // Not an empty element, sub elements will follow.

      // Check for rdf:datatype attribute
      Att datatype = atts.removeAtt(RDF.NAMESPACE, "datatype");
      if (datatype != null) {
        URI dtURI = resolveURI(datatype.getValue());
        predicate.setDatatype(dtURI);
      }

      // No more attributes are expected.
      if (verifyData()) {
View Full Code Here

  {
    PropertyElement predicate = (PropertyElement)peekStack(0);

    if (predicate.isReified()) {
      NodeElement subject = (NodeElement)peekStack(1);
      URI reifRes = predicate.getReificationURI();
      reifyStatement(reifRes, subject.getResource(), predicate.getURI(), value);
    }
  }
View Full Code Here

TOP

Related Classes of org.openrdf.model.URI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.