Пример #1
0
  public static Tuple getElements(String xml, String className, int inactiveGroupsCount) {

    List<Element> resultRows = new ArrayList<>();
    int totalRows = 0;

    try {
      xml = XMLUtil.stripInvalidChars(xml);

      Document document = SAXReaderUtil.read(xml);

      Element rootElement = document.getRootElement();

      List<Element> elements = rootElement.elements("entry");

      totalRows =
          GetterUtil.getInteger(
              rootElement.elementText(
                  OpenSearchUtil.getQName("totalResults", OpenSearchUtil.OS_NAMESPACE)));

      for (Element element : elements) {
        try {
          long entryScopeGroupId =
              GetterUtil.getLong(
                  element.elementText(
                      OpenSearchUtil.getQName("scopeGroupId", OpenSearchUtil.LIFERAY_NAMESPACE)));

          if ((entryScopeGroupId != 0) && (inactiveGroupsCount > 0)) {
            Group entryGroup = GroupServiceUtil.getGroup(entryScopeGroupId);

            if (entryGroup.isLayout()) {
              entryGroup = GroupLocalServiceUtil.getGroup(entryGroup.getParentGroupId());
            }

            if (!entryGroup.isActive()) {
              totalRows--;

              continue;
            }
          }

          resultRows.add(element);
        } catch (Exception e) {
          _log.error("Unable to retrieve individual search result for " + className, e);

          totalRows--;
        }
      }
    } catch (Exception e) {
      _log.error("Unable to display content for " + className, e);
    }

    return new Tuple(resultRows, totalRows);
  }
Пример #2
0
  protected String transformDateFieldValues(String content) throws Exception {
    if (!containsDateFieldType(content)) {
      return content;
    }

    Document document = SAXReaderUtil.read(content);

    Element rootElement = document.getRootElement();

    List<Element> dynamicElementElements = rootElement.elements("dynamic-element");

    transformDateFieldValues(dynamicElementElements);

    return XMLUtil.formatXML(document);
  }
Пример #3
0
  protected String convertStaticContentToDynamic(String content) throws Exception {

    Document document = SAXReaderUtil.read(content);

    Document newDocument = SAXReaderUtil.createDocument();

    Element rootElement = document.getRootElement();

    String availableLocales = rootElement.attributeValue("available-locales");
    String defaultLocale = rootElement.attributeValue("default-locale");

    Element newRootElement = SAXReaderUtil.createElement("root");

    newRootElement.addAttribute("available-locales", availableLocales);
    newRootElement.addAttribute("default-locale", defaultLocale);

    newDocument.add(newRootElement);

    Element dynamicElementElement = SAXReaderUtil.createElement("dynamic-element");

    dynamicElementElement.addAttribute("name", "content");
    dynamicElementElement.addAttribute("type", "text_area");
    dynamicElementElement.addAttribute("index-type", "keyword");
    dynamicElementElement.addAttribute("index", String.valueOf(0));

    newRootElement.add(dynamicElementElement);

    List<Element> staticContentElements = rootElement.elements("static-content");

    for (Element staticContentElement : staticContentElements) {
      String languageId = staticContentElement.attributeValue("language-id");
      String text = staticContentElement.getText();

      Element dynamicContentElement = SAXReaderUtil.createElement("dynamic-content");

      dynamicContentElement.addAttribute("language-id", languageId);
      dynamicContentElement.addCDATA(text);

      dynamicElementElement.add(dynamicContentElement);
    }

    return XMLUtil.formatXML(newDocument);
  }