/**
   * Builds a String result for Elastic Search from an RDFNode
   *
   * @param node An RDFNode representing the value of a property for a given resource
   * @return If the RDFNode has a Literal value, among Boolean, Byte, Double, Float, Integer Long,
   *     Short, this value is returned, converted to String
   *     <p>If the RDFNode has a String Literal value, this value will be returned, surrounded by
   *     double quotes
   *     <p>If the RDFNode has a Resource value (URI) and toDescribeURIs is set to true, the value
   *     of @getLabelForUri for the resource is returned, surrounded by double quotes. Otherwise,
   *     the URI will be returned
   */
  private String getStringForResult(RDFNode node, boolean getNodeLabel) {
    String result = "";
    boolean quote = false;

    if (node.isLiteral()) {
      Object literalValue = node.asLiteral().getValue();
      try {
        Class<?> literalJavaClass = node.asLiteral().getDatatype().getJavaClass();

        if (literalJavaClass.equals(Boolean.class)
            || Number.class.isAssignableFrom(literalJavaClass)) {

          result += literalValue;
        } else {
          result = EEASettings.parseForJson(node.asLiteral().getLexicalForm());
          quote = true;
        }
      } catch (java.lang.NullPointerException npe) {
        result = EEASettings.parseForJson(node.asLiteral().getLexicalForm());
        quote = true;
      }

    } else if (node.isResource()) {
      result = node.asResource().getURI();
      if (getNodeLabel) {
        result = getLabelForUri(result);
      }
      quote = true;
    }
    if (quote) {
      result = "\"" + result + "\"";
    }
    return result;
  }
Exemplo n.º 2
0
 protected static Class<?> loadClass(Resource root, String className) {
   try {
     return Class.forName(className);
   } catch (ClassNotFoundException e) {
     throw new CannotLoadClassException(root, className, e);
   }
 }