Exemplo n.º 1
0
 /**
  * Create a string pool object to represent the beginning of a search range.
  *
  * @param factory The string pool factory that will create the object
  * @param prefixNode The data for the object.
  * @param predType Predicate to indicate the type of data to get from the string pool.
  * @return An object representing the start of a range of data to get from the string pool.
  * @throws QueryException If the predicate indicates a URI but the prefix data is not a valid URI.
  */
 private SPObject getStartObject(SPObjectFactory factory, Node prefixNode, long predType)
     throws QueryException {
   if (prefixNode instanceof Literal) {
     String prefix = ((Literal) prefixNode).getLexicalForm();
     if (predType == mulgaraPrefix) {
       try {
         return factory.newSPURI(new URI(prefix));
       } catch (URISyntaxException e) {
         throw new QueryException(
             "Bad URI prefix provided: "
                 + prefix
                 + " (should this be using mulgara:stringPrefix?)");
       }
     } else return factory.newSPString(prefix);
   } else {
     URI startPrefixUri = ((URIReference) prefixNode).getURI();
     if (predType == mulgaraPrefix) return factory.newSPURI(startPrefixUri);
     else return factory.newSPString(startPrefixUri.toString());
   }
 }
Exemplo n.º 2
0
  /**
   * Evaluates a URI and adds it to the namespace map as a namespace.
   *
   * @param uri URI
   */
  protected void addNamespaceURI(URI uri) {

    if (uri == null) {
      throw new IllegalArgumentException("URI argument is null.");
    }

    // extract URI without fragment
    String uriString = uri.toString();
    String newURI = null;

    if (uriString != null) {

      // determine what comes last a '#' or '/'
      int hashindex = uriString.lastIndexOf('#');
      int slashindex = uriString.lastIndexOf('/');

      // validate (URI must contain a forward slash)
      if (slashindex == -1) {
        // namespace may have been evaluated already
        return;
      }

      // is there a '/' after the '#'?
      if (slashindex > hashindex) {

        // remove everything after the last '/'
        int index = uriString.lastIndexOf('/');
        newURI = uriString.substring(0, index) + "/";
      } else {

        // '#' comes after last '/' (remove entire fragment)
        newURI = uriString.replaceAll(uri.getFragment(), "");
      }

      // only add namespace if it is new
      if ((newURI != null) && (!namespaces.containsValue(newURI))) {
        // add to namespaces
        namespaces.put("ns" + namespaces.size(), newURI);
      }
    }
  }