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 boolean isValidStructureField(long groupId, String structureId, String contentField) {

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

      return true;
    } else {
      try {
        JournalStructure structure = journalStructurePersistence.findByG_S(groupId, structureId);

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

        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;
  }
  @Test
  public void testGetFieldsFromContentWithDocumentLibraryElement() throws Exception {

    Fields expectedFields = new Fields();

    ServiceContext serviceContext =
        ServiceContextTestUtil.getServiceContext(group.getGroupId(), TestPropsValues.getUserId());

    FileEntry fileEntry =
        DLAppLocalServiceUtil.addFileEntry(
            TestPropsValues.getUserId(),
            group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Test 1.txt",
            ContentTypes.TEXT_PLAIN,
            RandomTestUtil.randomBytes(),
            serviceContext);

    Field documentLibraryField = getDocumentLibraryField(fileEntry, _ddmStructure.getStructureId());

    expectedFields.put(documentLibraryField);

    Field fieldsDisplayField =
        getFieldsDisplayField(_ddmStructure.getStructureId(), "document_library_INSTANCE_4aGOvP3N");

    expectedFields.put(fieldsDisplayField);

    String content = read("test-journal-content-doc-library-field.xml");

    XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-content");

    Document document = SAXReaderUtil.read(content);

    Element element = (Element) xPathSelector.selectSingleNode(document);

    String[] previewURLs = new String[2];

    previewURLs[0] =
        DLUtil.getPreviewURL(
            fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, true, true);
    previewURLs[1] =
        DLUtil.getPreviewURL(
            fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, false);

    for (int i = 0; i < previewURLs.length; i++) {
      element.addCDATA(previewURLs[i]);

      Fields actualFields = JournalConverterUtil.getDDMFields(_ddmStructure, document.asXML());

      Assert.assertEquals(expectedFields, actualFields);
    }
  }
  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;
  }