Esempio n. 1
0
  protected void validate(Document document) throws Exception {
    XPath xPathSelector = _saxReader.createXPath("//dynamic-element");

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

    Set<String> elementNames = new HashSet<>();

    for (Node node : nodes) {
      Element element = (Element) node;

      String name = StringUtil.toLowerCase(element.attributeValue("name"));

      if (Validator.isNull(name)) {
        throw new StructureDefinitionException(
            "Element must have a name attribute " + element.formattedString());
      }

      if (name.startsWith(DDMStructureConstants.XSD_NAME_RESERVED)) {
        throw new StructureDefinitionException("Element name " + name + " is reserved");
      }

      if (elementNames.contains(name)) {
        throw new StructureDuplicateElementException(
            "Element with name " + name + " already exists");
      }

      elementNames.add(name);
    }
  }
Esempio n. 2
0
  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 void _indexFieldsMap(String locale) throws PortalException, SystemException {

    Map<String, Map<String, String>> fieldsMap = _localizedFieldsMap.get(locale);
    Map<String, Map<String, String>> transientFieldsMap = _localizedTransientFieldsMap.get(locale);

    if (fieldsMap != null) {
      return;
    }

    if (getParentStructureId() > 0) {
      DDMStructure parentStructure =
          DDMStructureLocalServiceUtil.getStructure(getParentStructureId());

      fieldsMap = parentStructure.getFieldsMap(locale);
      transientFieldsMap = parentStructure.getTransientFieldsMap(locale);
    } else {
      fieldsMap = new LinkedHashMap<String, Map<String, String>>();
      transientFieldsMap = new LinkedHashMap<String, Map<String, String>>();
    }

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

    List<Node> nodes = xPathSelector.selectNodes(getDocument());

    for (Node node : nodes) {
      Element element = (Element) node;

      String name = element.attributeValue("name");

      if (Validator.isNotNull(element.attributeValue("dataType"))) {
        fieldsMap.put(name, _getField(element, locale));
      } else {
        transientFieldsMap.put(name, _getField(element, locale));
      }
    }

    String[] privateFieldNames = PropsValues.DYNAMIC_DATA_MAPPING_STRUCTURE_PRIVATE_FIELD_NAMES;

    for (String privateFieldName : privateFieldNames) {
      Map<String, String> privateField = _getPrivateField(privateFieldName);

      fieldsMap.put(privateFieldName, privateField);
    }

    _localizedFieldsMap.put(locale, fieldsMap);
    _localizedTransientFieldsMap.put(locale, transientFieldsMap);
  }
Esempio n. 4
0
  protected void validate(Document document) throws Exception {
    XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element");

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

    Set<String> elementNames = new HashSet<>();

    for (Node node : nodes) {
      Element element = (Element) node;

      String name = StringUtil.toLowerCase(element.attributeValue("name"));

      if (name.startsWith(DDMStructureConstants.XSD_NAME_RESERVED)) {
        throw new StructureDefinitionException();
      }

      if (elementNames.contains(name)) {
        throw new StructureDuplicateElementException();
      }

      elementNames.add(name);
    }
  }
Esempio n. 5
0
  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;
  }