public void testCreatePropertyStrangeURITwoArgs() {
   final String local = "_345";
   final Property p = model.createProperty(RDF.getURI(), local);
   Assert.assertEquals(RDF.getURI(), p.getNameSpace());
   Assert.assertEquals(local, p.getLocalName());
   Assert.assertEquals(RDF.getURI() + local, p.getURI());
 }
 public void testCreatePropertyStrangeURI() {
   final String uri = RDF.getURI() + "_345";
   final Property p = model.createProperty(uri);
   Assert.assertEquals(RDF.getURI(), p.getNameSpace());
   Assert.assertEquals("_345", p.getLocalName());
   Assert.assertEquals(uri, p.getURI());
 }
  public boolean doGet(
      MappedResource resource,
      Property property,
      boolean isInverse,
      HttpServletRequest request,
      HttpServletResponse response,
      Configuration config)
      throws IOException {
    Model descriptions = getAnonymousPropertyValues(resource, property, isInverse);
    if (descriptions.size() == 0) {
      return false;
    }

    Resource r = descriptions.getResource(resource.getWebURI());
    List resourceDescriptions = new ArrayList();
    StmtIterator it =
        isInverse ? descriptions.listStatements(null, property, r) : r.listProperties(property);
    while (it.hasNext()) {
      Statement stmt = it.nextStatement();
      RDFNode value = isInverse ? stmt.getSubject() : stmt.getObject();
      if (!value.isAnon()) {
        continue;
      }
      resourceDescriptions.add(
          new ResourceDescription((Resource) value.as(Resource.class), descriptions, config));
    }

    Model description = getResourceDescription(resource);
    ResourceDescription resourceDescription =
        new ResourceDescription(resource, description, config);

    String title =
        resourceDescription.getLabel()
            + (isInverse ? " ? " : " ? ")
            + config.getPrefixes().getNsURIPrefix(property.getNameSpace())
            + ":"
            + property.getLocalName();
    VelocityHelper template = new VelocityHelper(getServletContext(), response);
    Context context = template.getVelocityContext();
    context.put("project_name", config.getProjectName());
    context.put("project_link", config.getProjectLink());
    context.put("title", title);
    context.put("server_base", config.getWebApplicationBaseURI());
    context.put("sparql_endpoint", resource.getDataset().getDataSource().getEndpointURL());
    context.put("back_uri", resource.getWebURI());
    context.put("back_label", resourceDescription.getLabel());
    context.put(
        "rdf_link",
        isInverse ? resource.getInversePathDataURL(property) : resource.getPathDataURL(property));
    context.put("resources", resourceDescriptions);
    template.renderXHTML("pathpage.vm");
    return true;
  }
Exemple #4
0
 private void unifyRDFSVersion(String ns) {
   for (Iterator it = Jena.cloneIt(model.listStatements()); it.hasNext(); ) {
     Statement s = (Statement) it.next();
     Resource newSubject = s.getSubject();
     Property newPredicate = s.getPredicate();
     RDFNode newObject = s.getObject();
     boolean changed = false;
     if (ns.equals(newSubject.getNameSpace())) {
       changed = true;
       newSubject = model.getResource(RDFS.getURI() + newSubject.getLocalName());
     }
     if (ns.equals(newPredicate.getNameSpace())) {
       changed = true;
       newPredicate = model.getProperty(RDFS.getURI() + newPredicate.getLocalName());
     }
     if (newObject.canAs(Resource.class)) {
       Resource oldResource = (Resource) newObject.as(Resource.class);
       if (ns.equals(oldResource.getNameSpace())) {
         changed = true;
         newObject = model.getResource(RDFS.getURI() + oldResource.getLocalName());
       }
     }
     if (changed) {
       model.add(newSubject, newPredicate, newObject);
       if (log.isLoggable(Level.FINE)) {
         log.fine(
             "Replaced deprecated triple "
                 + s
                 + " with "
                 + newSubject
                 + ", "
                 + newPredicate
                 + ", "
                 + newObject);
       }
       it.remove();
     }
   }
 }
Exemple #5
0
  /**
   * Get the JCR property name for an RDF predicate
   *
   * @param namespaceRegistry
   * @param predicate
   * @param namespaceMapping
   * @return
   * @throws RepositoryException
   */
  public String getPropertyNameFromPredicate(
      final NamespaceRegistry namespaceRegistry,
      final com.hp.hpl.jena.rdf.model.Property predicate,
      final Map<String, String> namespaceMapping)
      throws RepositoryException {

    final String prefix;

    final String namespace = getJcrNamespaceForRDFNamespace(predicate.getNameSpace());

    assert (namespaceRegistry != null);

    if (namespaceRegistry.isRegisteredUri(namespace)) {
      LOGGER.debug("Discovered namespace: {} in namespace registry.", namespace);
      prefix = namespaceRegistry.getPrefix(namespace);
    } else {
      LOGGER.debug("Didn't discover namespace: {} in namespace registry.", namespace);
      final ImmutableBiMap<String, String> nsMap = ImmutableBiMap.copyOf(namespaceMapping);
      if (nsMap.containsValue(namespace)) {
        LOGGER.debug("Discovered namespace: {} in namespace map: {}.", namespace, nsMap);
        prefix = nsMap.inverse().get(namespace);
        namespaceRegistry.registerNamespace(prefix, namespace);
      } else {
        prefix = namespaceRegistry.registerNamespace(namespace);
      }
    }

    final String localName = predicate.getLocalName();

    final String propertyName = prefix + ":" + localName;

    LOGGER.debug(
        "Took RDF predicate {} and translated it to JCR property {}", predicate, propertyName);

    return propertyName;
  }
 public void testCreatePropertyTwoArgs() {
   final Property p = model.createProperty("abc/", "def");
   Assert.assertEquals("abc/", p.getNameSpace());
   Assert.assertEquals("def", p.getLocalName());
   Assert.assertEquals("abc/def", p.getURI());
 }