/**
  * 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;
 }
 /**
  * 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;
 }
  /**
   * 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;
  }
  /**
   * 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;
  }
  /**
   * 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;
  }
  /**
   * 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;
  }
 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;
 }
 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);
   }
 }
 /**
  * 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;
 }
  /**
   * 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;
  }
 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;
 }
 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;
 }
  /**
   * 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;
  }
  /**
   * 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;
  }
 @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);
   }
 }
  /**
   * 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;
  }
  /**
   * 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;
  }
  /**
   * 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;
  }
  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;
  }
  /**
   * 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;
  }