/**
   * Writes title section.
   *
   * @param record record
   */
  private void writeTitle(SearchResultRecord record) {
    String sUuid = Val.chkStr(record.getUuid());
    String sTitle = Val.chkStr(record.getTitle());

    _writer.println("<div class=\"" + TITLE_STYLE_CLASS + "\">");

    // content type icon
    ResourceLink icon = record.getResourceLinks().getIcon();
    if (icon != null) {
      String sUrl = Val.chkStr(icon.getUrl());
      if ((sUrl.length() > 0) && getShowIcon()) {
        _writer.print("<img src=\"");
        _writer.print(Val.escapeXmlForBrowser(sUrl));
        _writer.print("\" alt=\"");
        _writer.print(Val.escapeXmlForBrowser(icon.getLabel()));
        _writer.print("\" title=\"");
        _writer.print(Val.escapeXmlForBrowser(icon.getLabel()));
        _writer.print("\"/>");
      }
    }

    // title (or uuid if no title)
    sTitle = sTitle.length() > 0 ? sTitle : sUuid;
    _writer.println(Val.escapeXmlForBrowser(sTitle));

    _writer.println("</div>");
  }
 /**
  * Write links.
  *
  * @param links the links
  */
 public void writeLinks(ResourceLinks links) {
   if (links == null) {
     return;
   }
   for (ResourceLink link : links) {
     writeLink(link.getUrl(), link.getLabel());
   }
 }
Пример #3
0
 /**
  * Prints a link.
  *
  * @param link resource link
  * @param more flag to indicate if there will be more arguments
  */
 protected void printLink(ResourceLink link, boolean more, String format) {
   if (!link.getTag().isEmpty() && !link.getUrl().isEmpty()) {
     println("{");
     levelUp();
     printLinkArg("accessURL", link.getUrl(), true);
     printLinkArg("format", format, false);
     levelDown();
     println("}" + (more ? "," : ""));
   }
 }
Пример #4
0
 /**
  * Finds metadata url from resource links
  *
  * @param links the resource links
  * @return the metadata url
  */
 private String getIdentifierUrl(ResourceLinks links) {
   String identifierUrl = "";
   for (int j = 0; j < links.size(); j++) {
     ResourceLink link = links.get(j);
     if (link.getTag().equals(ResourceLink.TAG_METADATA)) {
       identifierUrl = link.getUrl();
       return identifierUrl;
     }
   }
   return identifierUrl;
 }
Пример #5
0
 /**
  * Prints all links.
  *
  * @param links collection of resource links
  * @param before flag to indicate if there will be more arguments
  */
 protected void printLinks(ResourceLinks links, boolean more, boolean before) {
   if (before) {
     print(false, ",");
     print(false, "\r\n");
   }
   println("\"distribution\"" + sp() + ":" + sp() + "[");
   levelUp();
   boolean moreLinks = false;
   for (int j = 0; j < links.size(); j++) {
     boolean bPrintLink = false;
     String format = "";
     ResourceLink link = links.get(j);
     /*if (link.getTag().equals(ResourceLink.TAG_OPEN)) {
       defaultValues.put("webService", link.getUrl());
     }*/
     if (link.getTag().equals(ResourceLink.TAG_METADATA)) {
       bPrintLink = true;
       if (!moreLinks) {
         moreLinks = true;
       } else {
         moreLinks = false;
       }
       format = "text/xml";
     }
     if (link.getTag().equals(ResourceLink.TAG_DETAILS)) {
       bPrintLink = true;
       if (!moreLinks) {
         moreLinks = true;
       } else {
         moreLinks = false;
       }
       format = "text/html";
     }
     if (bPrintLink) {
       printLink(link, moreLinks, format);
     }
   }
   levelDown();
   println("]" + (more ? "," : ""));
 }
Пример #6
0
  /**
   * Writes fields value to response using field mappings.
   *
   * @param index the lucene index records
   * @param fieldName the lucene field
   * @param jsonKey the dcat field
   * @param delimiter the delimiter in lucene field
   * @param before the indentation flag
   * @param isDate true if date field
   * @return always <code>true</code>
   */
  private boolean writeField(
      IFeedRecord r,
      Map<String, IFeedAttribute> index,
      DcatField dcatField,
      String delimiter,
      boolean before) {
    String indexFieldName = dcatField.getIndex();
    String dcatFieldName = dcatField.getName();
    String fieldType = dcatField.getType();
    String fldValues = "";
    String[] flds = indexFieldName.split(",");
    for (String fld : flds) {
      IFeedAttribute indexValue = index.get(fld);
      String val = "";
      if (indexValue == null) {
        if (dcatField.isRequired()) {
          if (dcatFieldName.equalsIgnoreCase("accessURL")) {
            ResourceLinks links = r.getResourceLinks();
            for (int j = 0; j < links.size(); j++) {
              ResourceLink link = links.get(j);
              if (link.getTag().equals(ResourceLink.TAG_METADATA)) {
                val = link.getUrl();
                break;
              }
            }
          } else {
            val = defaultValues.get(dcatFieldName);
          }
        } else {
          continue;
        }
      } else {
        val = "" + indexValue;
        if (dcatFieldName.equalsIgnoreCase("format") && val.equalsIgnoreCase("[\"unknown\"]")) {
          val = defaultValues.get(dcatFieldName);
        }
      }
      String cleanedVal = cleanValue(val, fieldType, dcatFieldName, dcatField);
      if (dcatFieldName.equalsIgnoreCase("dataDictionary")
          && !(cleanedVal.startsWith("http://") || cleanedVal.startsWith("https://"))) {
        continue;
      }

      if (!fldValues.contains(cleanedVal)) {
        if (fldValues.length() > 0) {
          StringBuilder sb = new StringBuilder();
          if (fieldType.equalsIgnoreCase("array")) {
            if (!cleanedVal.equalsIgnoreCase(defaultValues.get(dcatFieldName))) {
              if (fldValues.startsWith("[") && fldValues.endsWith("]")) {
                fldValues = fldValues.replace("[", "").replace("]", "");
              }
              if (cleanedVal.startsWith("[") && cleanedVal.endsWith("]")) {
                cleanedVal = cleanedVal.replace("[", "").replace("]", "");
              }
              sb.append("[").append(fldValues).append(delimiter).append(cleanedVal).append("]");
              fldValues = sb.toString();
            }
          } else {
            sb.append(fldValues).append(delimiter).append(cleanedVal);
            fldValues = sb.toString();
          }
        } else {
          fldValues += cleanedVal;
        }
      }
    }
    if (fldValues.length() == 0) {
      fldValues = defaultValues.get(dcatFieldName);
      if (fldValues == null) {
        fldValues = "";
      }
    }
    if (fldValues.length() > 0) {
      fldValues = fldValues.replaceAll(",", ", ");
      if (before) {
        print(false, ",");
        print(false, "\r\n");
      }
      if (!fldValues.startsWith("\"")
          && !fldValues.startsWith("[")
          && !fldValues.endsWith("\"")
          && !fldValues.endsWith("]")) {
        fldValues = "\"" + fldValues + "\"";
      }
      print(before, "\"" + dcatFieldName + "\"" + sp() + ":" + sp() + fldValues);
      before = true;
    }
    return before;
  }