Esempio n. 1
0
  public static boolean equalResources(Resource t, Resource that) throws ModelException {

    return t.getURI().equals(that.getURI());

    /*

       boolean b = false;

       String tns = t.getNamespace();
       String tn = t.getLocalName();

       String thatns = that.getNamespace();
       String thatn = that.getLocalName();

       //    System.err.print("Comparing " + t + " vs " + that + ": ");

       if(thatns == null) {
         if(tns == null) { // (null, null)
    //	System.err.println("true");
    return thatn.equals(tn);
         } else // (null, not null) maybe "that" did not detect names
    b = thatn.equals(t.getURI());
       } else {
         if(tns != null) // (not null, not null)
    b = thatn.equals(tn) && thatns.equals(tns);
         else // (not null, null) maybe "this" did not detect names
    b = that.getURI().equals(tn);
       }

       if(b)
         return true;

       // else we need to check whether different namespace splitting is used

       if((tns != null ? tns.length() : 0) + (tn != null ? tn.length() : 0) ==
          (thatns != null ? thatns.length() : 0) + (thatn != null ? thatn.length() : 0)) {

         b = t.getURI().equals(that.getURI());

       }

       //    System.err.println("" + b);
       return b;
       */
  }
Esempio n. 2
0
  private Resource createMetadata(final boolean isListEndpoint, Integer totalResults)
      throws URISyntaxException {
    Model objectModel = ModelFactory.createDefaultModel();
    MergedModels mergedModels = new MergedModels(objectModel);
    //
    Model meta = mergedModels.getMetaModel();
    //
    Resource thisMetaPage = meta.createResource("eh:/thisMetaPage");
    Resource SEP = meta.createResource("eh:/sparqlEndpoint");
    thisMetaPage.addProperty(API.sparqlEndpoint, SEP);

    Bindings bindings = new Bindings();
    URI ru = new URI(thisMetaPage.getURI());
    Resource uriForDefinition = objectModel.createResource(thisMetaPage.getURI());
    boolean suppressIPTO = true;
    int page = 1, perPage = 10;
    boolean hasMorePages = true;
    Context context = new Context();
    CompleteContext cc = new CompleteContext(Mode.PreferLocalnames, context, objectModel);
    //
    SetsMetadata setsMeta =
        new SetsMetadata() {

          @Override
          public void setMetadata(String type, Model meta) {}
        };
    WantsMetadata wantsMeta =
        new WantsMetadata() {

          @Override
          public boolean wantsMetadata(String name) {
            return true;
          }
        };
    //
    Map<String, View> views = new HashMap<String, View>();
    Set<FormatNameAndType> formats = new HashSet<FormatNameAndType>();
    //
    EndpointDetails details =
        new EndpointDetails() {

          @Override
          public boolean isListEndpoint() {
            return isListEndpoint;
          }

          @Override
          public boolean hasParameterBasedContentNegotiation() {
            return false;
          }
        };
    //
    EndpointMetadata.addAllMetadata(
        mergedModels,
        ru,
        uriForDefinition,
        bindings,
        cc,
        suppressIPTO,
        thisMetaPage,
        page,
        perPage,
        totalResults,
        hasMorePages,
        CollectionUtils.list(objectModel.createResource("eh:/item/_1")),
        setsMeta,
        wantsMeta,
        "SELECT",
        "VIEW",
        new TestCaches.FakeSource("Nemos"),
        views,
        formats,
        details);
    return thisMetaPage;
  }
Esempio n. 3
0
  /** Extracts the namespace prefix out of a URI. */
  public static String getNamespace(Resource r) throws ModelException {

    String ns = r.getNamespace();
    return ns != null ? ns : guessNamespace(r.getURI());
  }
Esempio n. 4
0
 /** Tests if the resource belongs to the RDF syntax/model namespace. */
 public static boolean isRDF(Resource r) throws ModelException {
   return isRDF(r.getURI());
 }
Esempio n. 5
0
  /** Delivers the name out of the URI (without the namespace prefix). */
  public static String getLocalName(Resource r) throws ModelException {

    if (r.getNamespace() == null) return guessName(r.getURI());
    else return r.getLocalName();
  }