コード例 #1
0
  /**
   * Add an new empty feed::dasextension element with only a completed management element to the
   * given Feed. Sets the responseTime value to now. Note: A proper sites::site element must be
   * added to the new feed::dasextension element for this new feed::dasextension element to be
   * valid.
   *
   * @param feed - mandatory
   * @return
   */
  private Feed addEmptyDasExtension(Feed feed) {

    // check to make sure there's a dasextension
    QName dasextensionQname = new QName(this.dasextensionNamespace, "dasextension");
    ExtensibleElement dasExt = feed.getExtension(dasextensionQname);
    if (NullChecker.isEmpty(dasExt)) {

      dasExt = feed.addExtension(dasextensionQname);

      // add the dasextension::management element
      QName managementQname = new QName(this.dasextensionNamespace, "management");
      ExtensibleElement management = dasExt.getExtension(managementQname);
      if (NullChecker.isEmpty(management)) {
        management = dasExt.addExtension(managementQname);
      }

      QName responseTimeQname = new QName(this.dasextensionNamespace, "responseTime");
      ExtensibleElement responseTime = management.getExtension(responseTimeQname);
      if (NullChecker.isEmpty(responseTime)) {
        responseTime = management.addExtension(responseTimeQname);
      }

      // set/reset the response time to now
      XMLGregorianCalendar xmlGregCalResponseTime =
          GregorianDateUtil.getGregorianCalendarByDate(new Date());
      responseTime.setText(xmlGregCalResponseTime.toString()); // TODO: Verify date format
    }
    return feed;
  }
コード例 #2
0
  /**
   * Find the current dasextension::query::sites element or create a new one in the proper place in
   * the given dasextension element.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  public ExtensibleElement getSites(ExtensibleElement dasExt) {

    // get reference to the dasextension::query element in feed
    ExtensibleElement query = this.getQuery(dasExt);

    // get reference to the dasextension::query::sites element in feed
    QName sitesQname = new QName(this.dasextensionNamespace, "sites");
    ExtensibleElement sites = query.getExtension(sitesQname);
    if (NullChecker.isEmpty(sites)) {
      ExtensibleElement queryFirstChild = query.getFirstChild();
      if (NullChecker.isEmpty(queryFirstChild)) {
        // no children in query, so merely add sites element
        sites = query.addExtension(sitesQname);
      } else {
        QName fCQname = queryFirstChild.getQName();
        if ("parameters".equals(fCQname.getLocalPart())) {
          ExtensibleElement querySecondChild = query.getNextSibling();
          if (NullChecker.isEmpty(querySecondChild)) {
            // no second child in query, so add sites after parameters
            sites = query.addExtension(sitesQname);
          } else {
            // add sites after parameters, and before the second child
            QName sCQname = querySecondChild.getQName();
            sites = query.addExtension(sitesQname, sCQname);
          }
        } else {
          // another element besides parameters is first child,
          //  so add sites before this
          sites = dasExt.addExtension(sitesQname, fCQname);
        }
      }
    }
    return sites;
  }
コード例 #3
0
  /**
   * Find the current dasextension::query element or create a new one in the proper place in the
   * given dasextension element.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  private ExtensibleElement getQuery(ExtensibleElement dasExt) {

    QName queryQname = new QName(this.dasextensionNamespace, "query");
    // attempt to get query element
    ExtensibleElement query = dasExt.getExtension(queryQname);
    if (NullChecker.isEmpty(query)) {
      // there is no query element, so create one in the proper place
      ExtensibleElement firstChild = dasExt.getFirstChild();
      if (NullChecker.isEmpty(firstChild)) {
        // no children, so merely add query
        query = dasExt.addExtension(queryQname);
      } else {
        QName fCQname = firstChild.getQName();
        if ("path".equals(fCQname.getLocalPart())) {
          // path is the firstChild, so get the second child
          ExtensibleElement secondChild = firstChild.getNextSibling();
          if (NullChecker.isEmpty(secondChild)) {
            // no second child, so add query after path
            query = dasExt.addExtension(queryQname);
          } else {
            QName sCQname = secondChild.getQName();
            // have a second child, so add query after
            // path element and before second child
            query = dasExt.addExtension(queryQname, sCQname);
          }
        } else {
          // add query before the first child element
          query = dasExt.addExtension(queryQname, fCQname);
        }
      }
    }
    return query;
  }
コード例 #4
0
 /**
  * Adds a single site element into the given DAS dasextension Atom Feed at
  * feed::dasextension::query::sites.
  *
  * @param feed
  * @param site - mandatory - must contain a valid dasextension::query::sites::site Element
  * @return
  */
 private Feed addSite(Feed feed, final ExtensibleElement site) {
   if (NullChecker.isNotEmpty(feed)) {
     // get reference to the dasextension element in feed
     ExtensibleElement dasExt =
         feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
     if (NullChecker.isNotEmpty(dasExt)) {
       // get feed::dasextension::query::sites and add the new
       //	site into it in the feed
       ExtensibleElement sites = this.getSites(dasExt);
       sites.addExtension(site);
     }
   }
   return feed;
 }
コード例 #5
0
 /**
  * Adds a single error element into the DAS dasextension Atom Feed at
  * feed::dasextension::query::errors.
  *
  * @param feed - mandatory - must contain a valid feed::dasextension Element
  * @param errorsError - mandatory - must contain a valid dasextension::query::errors::error
  *     Element
  * @return
  */
 private Feed addError(Feed feed, final ExtensibleElement errorsError) {
   if (NullChecker.isNotEmpty(feed)) {
     // get reference to the dasextension element in feed
     ExtensibleElement dasExt =
         feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
     if (NullChecker.isNotEmpty(dasExt)) {
       // get feed::dasextension::query::errors and add the new
       //   error into it in the feed
       ExtensibleElement errors = this.getErrors(dasExt);
       errors.addExtension(errorsError);
     }
   }
   return feed;
 }
コード例 #6
0
  /**
   * Adds a new feed::dasextension element into the given feed parameter, which contains the given
   * parameter values within the dasextension Element, and which includes the optional
   * feed::dasextension::query::errors::error Element.
   *
   * @param feed - mandatory - must contain a valid Atom feed
   * @param siteName - mandatory
   * @param siteId - optional
   * @param siteHttpStatus - mandatory
   * @param requestUriInfo - optional
   * @param siteErrorMessage - optional
   * @param errorSeverity - optional
   * @param errorCode - optional
   * @param errorValue - optional
   * @param errorLocation - optional
   * @return
   */
  public Feed addErrorDasExtension(
      Feed feed,
      final String siteName,
      final String siteId,
      final int siteHttpStatus,
      final javax.ws.rs.core.UriInfo requestUriInfo,
      final String siteErrorMessage,
      final String errorSeverity,
      final String errorCode,
      final String errorValue,
      final String errorLocation) {
    if (NullChecker.isNotEmpty(feed)) {
      // add on the base dasextension
      feed = this.addEmptyDasExtension(feed);

      // add on the path parameters
      feed = this.addPathParameters(feed, requestUriInfo);

      // add on the query parameters
      feed = this.addQueryParameters(feed, requestUriInfo);

      // add on the site element
      feed = this.addSite(feed, siteName, siteId, siteHttpStatus, "", "", siteErrorMessage);

      // add on the error element
      feed = this.addError(feed, errorSeverity, errorCode, errorValue, errorLocation);
    }
    return feed;
  }
コード例 #7
0
  /**
   * Creates a default DAS dasextention Atom Feed with the site and error values from an
   * Http-related Exception.
   *
   * @param clientRequestUriInfo
   * @param producerUri
   * @param siteHttpStatus
   * @param errorMessage
   * @param componentName
   * @param componentId
   * @return
   * @throws MalformedURLException
   */
  public Feed getDefaultFeedForHttpException(
      Feed defaultFeed,
      final org.osehra.integration.http.uri.UriInfo clientRequestUriInfo,
      final URI producerUri,
      final int siteHttpStatus,
      final String errorMessage,
      final String componentName,
      final String componentId)
      throws MalformedURLException {

    String producerUrl = "";
    if (NullChecker.isNotEmpty(producerUri)) {
      producerUrl = producerUri.toURL().toString();
    }

    this.addErrorDasExtension(
        defaultFeed,
        componentName,
        componentId,
        siteHttpStatus,
        clientRequestUriInfo,
        errorMessage,
        "",
        new Integer(siteHttpStatus).toString(),
        errorMessage,
        producerUrl);

    return defaultFeed;
  }
コード例 #8
0
  /**
   * Returns true if the the given dasExt contains a feed::dasextension::path::parameters element,
   * else false.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  private boolean pathParametersExists(ExtensibleElement dasExt) {

    boolean pathParametersExists = false;

    if (NullChecker.isNotEmpty(dasExt)) {
      QName pathQname = new QName(this.dasextensionNamespace, "path");
      ExtensibleElement path = dasExt.getExtension(pathQname);
      if (NullChecker.isNotEmpty(path)) {
        QName parametersQname = new QName(this.dasextensionNamespace, "parameters");
        ExtensibleElement parameters = path.getExtension(parametersQname);
        if (NullChecker.isNotEmpty(parameters)) {
          pathParametersExists = true;
        }
      }
    }
    return pathParametersExists;
  }
コード例 #9
0
  /**
   * Returns true if the the given dasExt contains a feed::dasextension::query::parameters element,
   * else false.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  private boolean queryParametersExists(ExtensibleElement dasExt) {

    boolean queryParametersExists = false;

    if (NullChecker.isNotEmpty(dasExt)) {
      QName queryQname = new QName(this.dasextensionNamespace, "query");
      ExtensibleElement query = dasExt.getExtension(queryQname);
      if (NullChecker.isNotEmpty(query)) {
        QName parametersQname = new QName(this.dasextensionNamespace, "parameters");
        ExtensibleElement parameters = query.getExtension(parametersQname);
        if (NullChecker.isNotEmpty(parameters)) {
          queryParametersExists = true;
        }
      }
    }
    return queryParametersExists;
  }
コード例 #10
0
 public String evaluteExpression(final Document document, final XPathExpression expression) {
   if (NullChecker.isNotEmpty(expression)) {
     try {
       return expression.evaluate(document);
     } catch (final XPathExpressionException ex) {
       throw new RuntimeException(ex);
     }
   }
   return null;
 }
コード例 #11
0
  /**
   * Find the current dasextension::query::errors element or create a new one in the proper place in
   * the given dasextension element.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  public ExtensibleElement getErrors(ExtensibleElement dasExt) {

    // get reference to the dasextension::query element in feed
    ExtensibleElement query = this.getQuery(dasExt);

    // get reference to the dasextension::query::errors element in feed
    QName errorsQname = new QName(this.dasextensionNamespace, "errors");
    ExtensibleElement errors = query.getExtension(errorsQname);
    if (NullChecker.isEmpty(errors)) {
      List<Element> queryChildren = query.getElements();
      if (NullChecker.isEmpty(queryChildren)) {
        // no children in query, so merely add errors element
        errors = query.addExtension(errorsQname);
      } else {
        // add errors after the last child
        errors = query.addExtension(errorsQname);
      }
    }
    return errors;
  }
コード例 #12
0
 public String getSummary(final Document document) {
   try {
     if (NullChecker.isNotEmpty(this.summaryTransformer)) {
       final String summary = this.summaryTransformer.transform(document);
       return summary;
     }
     return null;
   } catch (final TransformerException ex) {
     throw new RuntimeException(ex);
   }
 }
コード例 #13
0
 @Override
 public String get(String arg0) {
   CustomProfileValueSource.LOG.debug(
       "Value of " + this.testProp + " is " + this.sysProps.getProperty(this.testProp));
   final String value = this.sysProps.getProperty(this.testProp);
   if (NullChecker.isEmpty(value)) {
     return "all";
   } else {
     return value;
   }
 }
コード例 #14
0
 /**
  * Adds the given dasextension::query::parameters Element into the given feed. Note: This method
  * will merge the given queryParameters with any existing query::parameters in the given feed.
  *
  * @param feed - mandatory - must contain a valid feed::dasextension Element
  * @param queryParameters - mandatory - must contain a valid and non-empty
  *     dasextension::query::parameters Element.
  * @return
  */
 private Feed addQueryParameters(Feed feed, final ExtensibleElement queryParameters) {
   if (NullChecker.isNotEmpty(feed)) {
     if (NullChecker.isNotEmpty(queryParameters)) {
       // get reference to the dasextension element in feed
       ExtensibleElement dasExt =
           feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
       if (NullChecker.isNotEmpty(dasExt)) {
         List<Element> queryParametersEntries = queryParameters.getElements();
         if (NullChecker.isNotEmpty(queryParametersEntries)) {
           // get or create the new dasextension::path::parameters Element
           ExtensibleElement queryParametersFeed = this.getQueryParameters(dasExt);
           // add in the dasextension::path::parameters::entry Elements
           for (Element curQueryParameterEntry : queryParametersEntries) {
             queryParametersFeed.addExtension(curQueryParameterEntry);
           }
         }
       }
     }
   }
   return feed;
 }
コード例 #15
0
  /**
   * Places the org.osehra.integration.http.uri.UriInfo uriInfo instance's query parameter values
   * into the DAS dasextension Atom Feed at feed::dasextension::query::parameters. Notes: The feed
   * parameter must contain a constructed DAS dasextension Atom Feed. This method will remove any
   * existing feed::dasextension::query::parameters::entry elements before adding the new entries
   * from uriInfo.
   *
   * @param feed -mandatory - must contain a valid feed::dasextension Element
   * @param uriInfo - mandatory
   * @return
   */
  public Feed addQueryParameters(Feed feed, final javax.ws.rs.core.UriInfo uriInfo) {
    if (NullChecker.isNotEmpty(feed)) {
      // get reference to the dasextension element in feed
      ExtensibleElement dasExt =
          feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
      if (NullChecker.isNotEmpty(dasExt)) {
        // check for a UriInfo to input
        if (NullChecker.isNotEmpty(uriInfo) && !(uriInfo.getQueryParameters().isEmpty())) {
          // get or create reference to the dasextension::query::parameters element in feed
          ExtensibleElement parameters = this.getQueryParameters(dasExt);

          // discard any existing path dasextension::path::parameter::entry elements
          List<Element> queryParameterEntries = parameters.getElements();
          if (NullChecker.isNotEmpty(queryParameterEntries)) {
            for (Element curQueryParameterEntry : queryParameterEntries) {
              curQueryParameterEntry.discard();
            }
          }

          // add the dasextension::query::parameters::entry elements from uriInfo
          QName entryQname = new QName(this.dasextensionNamespace, "entry");
          QName keyQname = new QName(this.dasextensionNamespace, "key");
          QName valueQname = new QName(this.dasextensionNamespace, "value");

          MultivaluedMap<String, String> queryParametersExt = uriInfo.getQueryParameters();
          Set<Map.Entry<String, List<String>>> queryParamsEntries = queryParametersExt.entrySet();
          for (Map.Entry<String, List<String>> queryParameterEntry : queryParamsEntries) {
            ExtensibleElement entry = parameters.addExtension(entryQname);
            ExtensibleElement key = entry.addExtension(keyQname);
            key.setText(queryParameterEntry.getKey());
            for (String entryValue : queryParameterEntry.getValue()) {
              ExtensibleElement value = entry.addExtension(valueQname);
              value.setText(entryValue);
            }
          }
        }
      }
    }
    return feed;
  }
コード例 #16
0
 public Map<QName, String> getExtensions(final Document document) {
   final Map<QName, String> extensions = new LinkedHashMap<QName, String>();
   if (NullChecker.isNotEmpty(this.extensionExpressions)) {
     try {
       for (final Entry<QName, XPathExpression> entry : this.extensionExpressions.entrySet()) {
         extensions.put(entry.getKey(), entry.getValue().evaluate(document));
       }
     } catch (final XPathExpressionException ex) {
       throw new RuntimeException(ex);
     }
   }
   return extensions;
 }
コード例 #17
0
  @Override
  public Object transform(final Object src) throws TransformerException {
    if (NullChecker.isEmpty(this.transformers)) {
      return src;
    }

    Object value = src;
    for (final Transformer<Object, Object> transformer : this.transformers) {
      value = transformer.transform(value);
    }

    return value;
  }
コード例 #18
0
 private List<String> evaluteExpressions(
     final Document document, final List<XPathExpression> expressions) {
   final List<String> results = new ArrayList<String>();
   if (NullChecker.isNotEmpty(expressions)) {
     try {
       for (final XPathExpression expression : expressions) {
         results.add(expression.evaluate(document));
       }
     } catch (final XPathExpressionException ex) {
       throw new RuntimeException(ex);
     }
   }
   return results;
 }
コード例 #19
0
  /**
   * Find the current dasextension::path::parameters element or create a new one in the proper place
   * in the given dasextension element.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  private ExtensibleElement getPathParameters(ExtensibleElement dasExt) {

    QName parametersQname = new QName(this.dasextensionNamespace, "parameters");
    ExtensibleElement parameters = null;

    ExtensibleElement path = this.getPath(dasExt);
    ExtensibleElement pathFirstChild = path.getFirstChild();
    if (NullChecker.isNotEmpty(pathFirstChild)) {
      // already have a parameters
      parameters = pathFirstChild;
    } else {
      // no parameters, so add one
      parameters = path.addExtension(parametersQname);
    }

    return parameters;
  }
コード例 #20
0
  @Override
  public final boolean validate(final Document message) throws ValidatorException {

    Assert.assertNotEmpty(message, "Message cannot be null!");

    try {
      for (final XPathExpression expression : this.xPathExpressions) {
        final java.lang.Boolean booleanValue =
            (java.lang.Boolean) expression.evaluate(message, XPathConstants.BOOLEAN);
        if (NullChecker.isEmpty(booleanValue) || !booleanValue) {
          return false;
        }
      }
      return true;
    } catch (final XPathException e) {
      throw new ValidatorException(e);
    }
  }
コード例 #21
0
  /**
   * Adds a new dasextension element in the given feed parameter, which contains the given siteName,
   * siteId, and an HTTP success code of "200" for this site in the
   * feed::dasextension::query::sites::site Element.
   *
   * @param feed - mandatory - must contain a valid Atom feed
   * @param siteName - mandatory
   * @param siteId - optional
   * @param requestUriInfo - optional
   * @return
   */
  public Feed addSuccessDasExtension(
      Feed feed,
      final String siteName,
      final String siteId,
      final javax.ws.rs.core.UriInfo requestUriInfo) {
    if (NullChecker.isNotEmpty(feed)) {
      // add on the base dasextension
      feed = this.addEmptyDasExtension(feed);

      // add on the path parameters
      feed = this.addPathParameters(feed, requestUriInfo);

      // add on the query parameters
      feed = this.addQueryParameters(feed, requestUriInfo);

      // add on the site element
      final int successHttpStatus = 200; // SUCCESS Http Status code
      feed = this.addSite(feed, siteName, siteId, successHttpStatus, "", "", "");
    }
    return feed;
  }
コード例 #22
0
 @Override
 public String transform(final Feed feed) throws TransformerException {
   try {
     if (NullChecker.isNotEmpty(feed)) {
       // TODO: Cleanup - Fix this using DOM or research why XMLNS is being
       // added to entry baseURI
       String feedString = feed.toString();
       feedString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + feedString;
       feedString =
           feedString.replaceAll(
               EscapeChars.forRegex("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\""), "");
       feedString =
           feedString.replaceAll(
               EscapeChars.forRegex("xmlns=\"http://www.w3.org/XML/1998/namespace\""), "");
       return feedString;
     }
     return null;
   } catch (PatternSyntaxException ex) {
     throw new TransformerException(ex);
   }
 }
コード例 #23
0
  /**
   * Find the current dasextension::path element or create a new one in the proper place in the
   * given dasextension element.
   *
   * @param dasExt - must be a valid dasextension Element
   * @return
   */
  private ExtensibleElement getPath(ExtensibleElement dasExt) {

    // get or create a reference to the dasextension::path element in feed
    QName pathQname = new QName(this.dasextensionNamespace, "path");
    ExtensibleElement path = null;
    ExtensibleElement firstChild = (ExtensibleElement) dasExt.getFirstChild();
    if (NullChecker.isNotEmpty(firstChild)) {
      QName fCQname = firstChild.getQName();
      if ("path".equals(fCQname.getLocalPart())) {
        // path is the firstChild
        path = firstChild;
      } else {
        // no path, so add it before firstChild
        path = dasExt.addExtension(pathQname, fCQname);
      }
    } else {
      // no children, so create a "path" element
      path = dasExt.addExtension(pathQname);
    }

    return path;
  }
コード例 #24
0
  /**
   * Find the current dasextension::query::parameters element or create a new one in the proper
   * place in the given dasextension element.
   *
   * @param dasExt - mandatory - must be a valid dasextension Element
   * @return
   */
  private ExtensibleElement getQueryParameters(ExtensibleElement dasExt) {

    QName parametersQname = new QName(this.dasextensionNamespace, "parameters");
    ExtensibleElement parameters = null;

    ExtensibleElement query = this.getQuery(dasExt);
    ExtensibleElement queryFirstChild = query.getFirstChild();
    if (NullChecker.isEmpty(queryFirstChild)) {
      // no children in query, so just query::parameters
      parameters = query.addExtension(parametersQname);

    } else {

      QName fCQname = queryFirstChild.getQName();
      if ("parameters".equals(fCQname.getLocalPart())) {
        // already have a query::parameters
        parameters = queryFirstChild;
      } else {
        // firstQueryChild is not parameters, so add query::parameters before it
        parameters = query.addExtension(parametersQname, fCQname);
      }
    }
    return parameters;
  }
コード例 #25
0
  /**
   * Adds a single error element into the DAS dasextension Atom Feed, i.e. adds one of the following
   * inside of feed::dasextension::query::errors: <error> <errorSeverity></errorSeverity>
   * <errorCode></errorCode> <errorValue></errorValue> <errorLocation></errorLocation> </error>
   * Note: The feed parameter must contain a constructed DAS dasextension Atom Feed.
   *
   * @param feed - mandatory - must contain a valid feed::dasextension Element
   * @param errorSeverity - optional
   * @param errorCode - optional
   * @param errorValue - optional
   * @param errorLocation - optional
   * @return
   */
  public Feed addError(
      Feed feed,
      final String errorSeverity,
      final String errorCode,
      final String errorValue,
      final String errorLocation) {
    if (NullChecker.isNotEmpty(feed)) {
      // get reference to the dasextension element in feed
      ExtensibleElement dasExt =
          feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
      if (NullChecker.isNotEmpty(dasExt)) {
        // get reference to the dasextension::query::errors element in feed
        // -- if errors doesn't exist, this method will add it
        ExtensibleElement errors = this.getErrors(dasExt);

        // add the dasextension::query::errors::error element
        QName errorQname = new QName(this.dasextensionNamespace, "error");
        ExtensibleElement errorsError = errors.addExtension(errorQname);
        if (NullChecker.isNotEmpty(errorSeverity)) {
          QName errorSeverityQname = new QName(this.dasextensionNamespace, "errorSeverity");
          ExtensibleElement errorSeverityElement = errorsError.addExtension(errorSeverityQname);
          errorSeverityElement.setText(errorSeverity);
        }
        if (NullChecker.isNotEmpty(errorCode)) {
          QName errorCodeQname = new QName(this.dasextensionNamespace, "errorCode");
          ExtensibleElement errorCodeElement = errorsError.addExtension(errorCodeQname);
          errorCodeElement.setText(errorCode);
        }
        if (NullChecker.isNotEmpty(errorValue)) {
          QName errorValueQname = new QName(this.dasextensionNamespace, "errorValue");
          ExtensibleElement errorValueElement = errorsError.addExtension(errorValueQname);
          errorValueElement.setText(errorValue);
        }
        if (NullChecker.isNotEmpty(errorLocation)) {
          QName errorLocationQname = new QName(this.dasextensionNamespace, "errorLocation");
          ExtensibleElement errorLocationElement = errorsError.addExtension(errorLocationQname);
          errorLocationElement.setText(errorLocation);
        }
      }
    }
    return feed;
  }
コード例 #26
0
  public org.apache.abdera.model.Entry transform(
      final Document document, final org.apache.abdera.model.Entry entry)
      throws TransformerException {
    final List<String> categories = this.getCategories(document);
    for (final String category : categories) {
      entry.addCategory(category);
    }
    final String title = this.getTitle(document);
    if (NullChecker.isNotEmpty(title)) {
      entry.setTitle(title, Text.Type.TEXT);
    }
    final String editedDate = this.getEditedDate(document);
    if (NullChecker.isNotEmpty(editedDate)) {
      final Date date = this.parseDate(editedDate);
      entry.setEdited(date);
    }

    final String id = this.getId(document);
    if (NullChecker.isNotEmpty(id)) {
      entry.setId(id);
    }

    final String published = this.getPublished(document);
    if (NullChecker.isNotEmpty(published)) {
      final Date date = this.parseDate(published);
      entry.setPublished(date);
    }

    final String rights = this.getRights(document);
    if (NullChecker.isNotEmpty(rights)) {
      entry.setRights(rights);
    }

    final String summary = this.getSummary(document);
    if (NullChecker.isNotEmpty(summary)) {
      entry.setSummaryAsHtml(summary);
    }

    final String updated = this.getUpdated(document);
    if (NullChecker.isNotEmpty(updated)) {
      final Date date = this.parseDate(updated);
      entry.setUpdated(date);
    }

    final String author = this.getAuthor(document);
    if (NullChecker.isNotEmpty(author)) {
      entry.addAuthor(author);
    }

    final String comment = this.getComment(document);
    if (NullChecker.isNotEmpty(comment)) {
      entry.addComment(comment);
    }

    final String contributor = this.getContributor(document);
    if (NullChecker.isNotEmpty(contributor)) {
      entry.addContributor(contributor);
    }

    final Map<QName, String> extensions = this.getExtensions(document);
    for (final java.util.Map.Entry<QName, String> extension : extensions.entrySet()) {
      final QName extensionQName = extension.getKey();
      final String text = extension.getValue();
      final Element element = entry.addExtension(extensionQName);
      element.setText(text);
    }
    final String content = this.xmlToString.transform(document);
    entry.setContent(content, MediaType.APPLICATION_XML);

    return entry;
  }
コード例 #27
0
  /**
   * Adds a single site element into the DAS dasextension Atom Feed. i.e. adds one of the following
   * inside of feed::dasextension::query::sites: <site> <id></id> <name></name>
   * <expectedCount></expectedCount> <retrievedCount></retrievedCount> <status></status>
   * <error></error> </site> Notes: The feed parameter must contain a constructed DAS dasextension
   * Atom Feed. An existing site element with the same site::name value as the given siteName value
   * will be removed before the new site element is added.
   *
   * @param feed - mandatory - must contain a valid feed::dasextension Element
   * @param siteName - mandatory
   * @param siteId - optional
   * @param siteHttpStatus - mandatory
   * @param expectedCount - optional
   * @param retrievedCount - optional
   * @param siteErrorMessage - optional
   * @return
   */
  public Feed addSite(
      Feed feed,
      final String siteName,
      final String siteId,
      final int siteHttpStatus,
      final String expectedCount,
      final String retrievedCount,
      final String siteErrorMessage) {
    if (NullChecker.isNotEmpty(feed)) {
      // get reference to the dasextension element in feed
      ExtensibleElement dasExt =
          feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));
      if (NullChecker.isNotEmpty(dasExt)) {
        // get reference to the dasextension::query::sites element in feed
        ExtensibleElement sites = this.getSites(dasExt);

        // search for any existing site children by site::name value with
        // the new siteName, and if one is found, remove it
        List<Element> siteElements = sites.getElements();
        for (Element curSiteElement : siteElements) {
          List<Element> siteChildElements = curSiteElement.getElements();
          for (Element curSiteChildElement : siteChildElements) {
            if ("name".equals(curSiteChildElement.getQName().getLocalPart())) {
              if (siteName.equals(curSiteChildElement.getText())) {
                curSiteElement.discard();
              }
            }
          }
        }

        // add the dasextension::query::sites::site element
        QName siteQname = new QName(this.dasextensionNamespace, "site");
        ExtensibleElement site = sites.addExtension(siteQname);
        if (NullChecker.isNotEmpty(siteId)) {
          QName idQname = new QName(this.dasextensionNamespace, "id");
          ExtensibleElement idElement = site.addExtension(idQname);
          idElement.setText(siteId);
        }
        QName nameQname = new QName(this.dasextensionNamespace, "name");
        ExtensibleElement nameElement = site.addExtension(nameQname);
        nameElement.setText(siteName);
        if (NullChecker.isNotEmpty(expectedCount)) {
          QName expectedCountQname = new QName(this.dasextensionNamespace, "expectedCount");
          ExtensibleElement expectedCountElement = site.addExtension(expectedCountQname);
          expectedCountElement.setText(expectedCount);
        }
        if (NullChecker.isNotEmpty(retrievedCount)) {
          QName retrievedCountQname = new QName(this.dasextensionNamespace, "retrievedCount");
          ExtensibleElement retrievedCountElement = site.addExtension(retrievedCountQname);
          retrievedCountElement.setText(retrievedCount);
        }
        QName statusQname = new QName(this.dasextensionNamespace, "status");
        ExtensibleElement statusElement = site.addExtension(statusQname);
        String siteStatus = new Integer(siteHttpStatus).toString();
        statusElement.setText(siteStatus);
        if (NullChecker.isNotEmpty(siteErrorMessage)) {
          QName errorQname = new QName(this.dasextensionNamespace, "error");
          ExtensibleElement siteErrorElement = site.addExtension(errorQname);
          siteErrorElement.setText(siteErrorMessage);
        }
      }
    }
    return feed;
  }
コード例 #28
0
  /**
   * Merge the elements in the given dasextensionToMerge Element into the feed::dasextension element
   * in the given feed. Note: The dasextension::path::parameters and dasextension::query::parameters
   * values in the given dasextensionToMerge Element will only be merged into the given feed if the
   * given feed does not already have these Elements.
   *
   * @param feed - mandatory - must contain a valid feed::dasextension Element
   * @param extensionToMerge - mandatory - must contain a valid dasextension Element
   * @return
   */
  public Feed mergeDasExtension(Feed feed, final Element dasextensionToMerge) {

    if (NullChecker.isNotEmpty(feed)) {
      if (NullChecker.isNotEmpty(dasextensionToMerge)) {

        QName mergeExtQname = dasextensionToMerge.getQName();
        String mergeExtTagName = mergeExtQname.getLocalPart();

        // if dasextensionToMerge isn't a dasextension, ignore it
        if ("dasextension".equals(mergeExtTagName)) {
          ExtensibleElement feedDasExt =
              feed.getExtension(new QName(this.dasextensionNamespace, "dasextension"));

          if (NullChecker.isNotEmpty(feedDasExt)) {
            // feed contains an existing dasextension, so merge other dasextensionToMerge with it:

            // merge dasextension::path::parameters if none are already in feed
            boolean feedPathParametersExists = this.pathParametersExists(feedDasExt);
            boolean mergePathParametersExists =
                this.pathParametersExists((ExtensibleElement) dasextensionToMerge);
            if (false == feedPathParametersExists) {
              if (mergePathParametersExists) {
                ExtensibleElement mergePathParameters =
                    this.getPathParameters((ExtensibleElement) dasextensionToMerge);
                feed = this.addPathParameters(feed, mergePathParameters);
              }
            }

            // merge dasextension::query::parameters if none are already in feed
            boolean feedQueryParametersExists = this.queryParametersExists(feedDasExt);
            boolean mergeQueryParametersExists =
                this.queryParametersExists((ExtensibleElement) dasextensionToMerge);
            if (false == feedQueryParametersExists) {
              if (mergeQueryParametersExists) {
                ExtensibleElement mergeQueryParameters =
                    this.getQueryParameters((ExtensibleElement) dasextensionToMerge);
                feed = this.addQueryParameters(feed, mergeQueryParameters);
              }
            }

            // collect all of the current dasextension sites::site elements
            List<Element> siteElements = new ArrayList<Element>();
            ExtensibleElement mergeSites = this.getSites((ExtensibleElement) dasextensionToMerge);
            if (NullChecker.isNotEmpty(mergeSites)) {
              siteElements.addAll(mergeSites.getElements());
            }

            // add in the site elements into the feed's dasextension
            for (final Element siteElement : siteElements) {
              feed = this.addSite(feed, (ExtensibleElement) siteElement);
            }

            // collect all of the merge dasextension errors::error elements
            List<Element> errorElements = new ArrayList<Element>();
            ExtensibleElement mergeErrors = this.getErrors((ExtensibleElement) dasextensionToMerge);
            if (NullChecker.isNotEmpty(mergeErrors)) {
              errorElements.addAll(mergeErrors.getElements());
            }

            // add in the error elements into the feed's dasextension
            for (final Element errorElement : errorElements) {
              feed = this.addError(feed, (ExtensibleElement) errorElement);
            }

          } else {
            // feed has no existing dasextension element, so add in dasextensionToMerge
            feed.addExtension(dasextensionToMerge);
          }
        }
      }
    }
    return feed;
  }