protected boolean isValidStructureField(long groupId, String structureId, String contentField) {

    if (contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)
        || contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {

      return true;
    }

    try {
      DDMStructure ddmStructure =
          ddmStructureLocalService.getStructure(
              groupId, classNameLocalService.getClassNameId(JournalArticle.class), structureId);

      Document document = SAXReaderUtil.read(ddmStructure.getXsd());

      contentField = HtmlUtil.escapeXPathAttribute(contentField);

      XPath xPathSelector =
          SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

      Node node = xPathSelector.selectSingleNode(document);

      if (node != null) {
        return true;
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  protected List<Node> getElementsByName(Document document, String name) {
    name = HtmlUtil.escapeXPathAttribute(name);

    XPath xPathSelector =
        SAXReaderUtil.createXPath("//dynamic-element[@name=".concat(name).concat("]"));

    return xPathSelector.selectNodes(document);
  }
  private Map<String, String> _getField(Element element, String locale) {
    Map<String, String> field = new HashMap<String, String>();

    List<String> availableLocales = getAvailableLanguageIds();

    if ((locale != null) && !availableLocales.contains(locale)) {
      locale = getDefaultLanguageId();
    }

    locale = HtmlUtil.escapeXPathAttribute(locale);

    String xPathExpression = "meta-data[@locale=".concat(locale).concat("]");

    XPath xPathSelector = SAXReaderUtil.createXPath(xPathExpression);

    Node node = xPathSelector.selectSingleNode(element);

    Element metaDataElement = (Element) node.asXPathResult(node.getParent());

    if (metaDataElement != null) {
      List<Element> childMetaDataElements = metaDataElement.elements();

      for (Element childMetaDataElement : childMetaDataElements) {
        String name = childMetaDataElement.attributeValue("name");
        String value = childMetaDataElement.getText();

        field.put(name, value);
      }
    }

    for (Attribute attribute : element.attributes()) {
      field.put(attribute.getName(), attribute.getValue());
    }

    Element parentElement = element.getParent();

    if (parentElement != null) {
      String parentName = parentElement.attributeValue("name");

      if (Validator.isNotNull(parentName)) {
        field.put(_getPrivateAttributeKey("parentName"), parentName);
      }
    }

    return field;
  }
  protected void processStructure(
      com.liferay.portal.kernel.xml.Document structureDocument,
      Document document,
      Element rootElement)
      throws Exception {

    LinkedList<Element> queue = new LinkedList<Element>(rootElement.elements());

    Element element = null;

    while ((element = queue.poll()) != null) {
      String elName = element.attributeValue("name", StringPool.BLANK);
      String elType = element.attributeValue("type", StringPool.BLANK);
      String elIndexType = element.attributeValue("index-type", StringPool.BLANK);

      if (structureDocument != null) {
        String path = element.getPath();

        path = path.concat("[@name=").concat(HtmlUtil.escapeXPathAttribute(elName)).concat("]");

        Node structureNode = structureDocument.selectSingleNode(path);

        if (structureNode != null) {
          Element structureElement = (Element) structureNode;

          elType = structureElement.attributeValue("type", StringPool.BLANK);
          elIndexType = structureElement.attributeValue("index-type", StringPool.BLANK);
        }
      }

      if (Validator.isNotNull(elType)) {
        indexField(document, element, elType, elIndexType);
      }

      queue.addAll(element.elements());
    }
  }
  protected String processContent(
      JournalFeed feed,
      JournalArticle article,
      String languageId,
      ThemeDisplay themeDisplay,
      SyndEntry syndEntry,
      SyndContent syndContent)
      throws Exception {

    String content = article.getDescription(languageId);

    String contentField = feed.getContentField();

    if (contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {
      String rendererTemplateId = article.getTemplateId();

      if (Validator.isNotNull(feed.getRendererTemplateId())) {
        rendererTemplateId = feed.getRendererTemplateId();
      }

      JournalArticleDisplay articleDisplay =
          JournalContentUtil.getDisplay(
              feed.getGroupId(),
              article.getArticleId(),
              rendererTemplateId,
              null,
              languageId,
              themeDisplay,
              1,
              _XML_REQUUEST);

      if (articleDisplay != null) {
        content = articleDisplay.getContent();
      }
    } else if (!contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)) {

      Document document = SAXReaderUtil.read(article.getContentByLocale(languageId));

      contentField = HtmlUtil.escapeXPathAttribute(contentField);

      XPath xPathSelector =
          SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

      List<Node> results = xPathSelector.selectNodes(document);

      if (results.size() == 0) {
        return content;
      }

      Element element = (Element) results.get(0);

      String elType = element.attributeValue("type");

      if (elType.equals("document_library")) {
        String url = element.elementText("dynamic-content");

        url = processURL(feed, url, themeDisplay, syndEntry);
      } else if (elType.equals("image") || elType.equals("image_gallery")) {
        String url = element.elementText("dynamic-content");

        url = processURL(feed, url, themeDisplay, syndEntry);

        content =
            content + "<br /><br /><img alt='' src='" + themeDisplay.getURLPortal() + url + "' />";
      } else if (elType.equals("text_box")) {
        syndContent.setType("text");

        content = element.elementText("dynamic-content");
      } else {
        content = element.elementText("dynamic-content");
      }
    }

    return content;
  }