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);
    }
  }
Пример #4
0
  public static Namespace createNamespace(String prefix, String uri) {
    Namespace namespace = null;

    if (uri.equals(WebDAVUtil.DAV_URI.getURI())) {
      namespace = WebDAVUtil.DAV_URI;
    } else if (Validator.isNull(prefix)) {
      namespace = SAXReaderUtil.createNamespace(uri);
    } else {
      namespace = SAXReaderUtil.createNamespace(prefix, uri);
    }

    return namespace;
  }
  protected void exportAssetCategories(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("categories-hierarchy");

    Element assetVocabulariesElement = rootElement.addElement("vocabularies");

    List<AssetVocabulary> assetVocabularies =
        AssetVocabularyLocalServiceUtil.getGroupVocabularies(portletDataContext.getGroupId());

    for (AssetVocabulary assetVocabulary : assetVocabularies) {
      _portletExporter.exportAssetVocabulary(
          portletDataContext, assetVocabulariesElement, assetVocabulary);
    }

    Element categoriesElement = rootElement.addElement("categories");

    List<AssetCategory> assetCategories =
        AssetCategoryUtil.findByGroupId(portletDataContext.getGroupId());

    for (AssetCategory assetCategory : assetCategories) {
      _portletExporter.exportAssetCategory(
          portletDataContext, assetVocabulariesElement, categoriesElement, assetCategory);
    }

    _portletExporter.exportAssetCategories(portletDataContext, rootElement);

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/categories-hierarchy.xml", document.formattedString());
  }
  protected void exportLocks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("locks");

    Map<String, Lock> locksMap = portletDataContext.getLocks();

    for (Map.Entry<String, Lock> entry : locksMap.entrySet()) {
      Lock lock = entry.getValue();

      String entryKey = entry.getKey();

      int pos = entryKey.indexOf(CharPool.POUND);

      String className = entryKey.substring(0, pos);
      String key = entryKey.substring(pos + 1);

      String path = getLockPath(portletDataContext, className, key, lock);

      Element assetElement = rootElement.addElement("asset");

      assetElement.addAttribute("path", path);
      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("key", key);

      portletDataContext.addZipEntry(path, lock);
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/locks.xml",
        document.formattedString());
  }
  protected String formatContent(String content) throws Exception {
    String oldCompanyId = (String) _companyIdColumn.getOldValue();
    Long newCompanyId = (Long) _companyIdColumn.getNewValue();
    Long groupId = (Long) _groupIdColumn.getNewValue();
    String articleId = (String) _articleIdColumn.getNewValue();
    Double version = (Double) _versionColumn.getNewValue();

    try {
      Document doc = SAXReaderUtil.read(content);

      Element root = doc.getRootElement();

      format(
          oldCompanyId,
          newCompanyId.longValue(),
          groupId.longValue(),
          articleId,
          version.doubleValue(),
          root);

      content = JournalUtil.formatXML(doc);
    } catch (Exception e) {
      _log.error(
          "Unable to format content for {articleId="
              + articleId
              + ",version="
              + version
              + "}: "
              + e.getMessage());
    }

    return content;
  }
Пример #8
0
  protected void read(ClassLoader classLoader, String source) throws Exception {

    InputStream is = classLoader.getResourceAsStream(source);

    if (is == null) {
      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Loading " + source);
    }

    Document document = SAXReaderUtil.read(is);

    Element rootElement = document.getRootElement();

    for (Element sqlElement : rootElement.elements("sql")) {
      String file = sqlElement.attributeValue("file");

      if (Validator.isNotNull(file)) {
        read(classLoader, file);
      } else {
        String id = sqlElement.attributeValue("id");
        String content = transform(sqlElement.getText());

        content = replaceIsNull(content);

        _sqlPool.put(id, content);
      }
    }
  }
  protected void exportAssetLinks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("links");

    Element exportDataRootElement = portletDataContext.getExportDataRootElement();

    try {
      portletDataContext.setExportDataRootElement(rootElement);

      ActionableDynamicQuery linkActionableDynamicQuery =
          _assetLinkLocalService.getExportActionbleDynamicQuery(portletDataContext);

      linkActionableDynamicQuery.performActions();

      for (long linkId : portletDataContext.getAssetLinkIds()) {
        AssetLink assetLink = _assetLinkLocalService.getAssetLink(linkId);

        StagedAssetLink stagedAssetLink =
            ModelAdapterUtil.adapt(assetLink, AssetLink.class, StagedAssetLink.class);

        portletDataContext.addClassedModel(
            portletDataContext.getExportDataElement(stagedAssetLink),
            ExportImportPathUtil.getModelPath(stagedAssetLink),
            stagedAssetLink);
      }
    } finally {
      portletDataContext.setExportDataRootElement(exportDataRootElement);
    }

    portletDataContext.addZipEntry(
        ExportImportPathUtil.getRootPath(portletDataContext) + "/links.xml",
        document.formattedString());
  }
Пример #10
0
  /*
   *  Reads 'resource-bundle' property from portlet.xml
   * */
  private static boolean readPortletXML(
      String xml, ServletContext servletContext, String bundleName) throws DocumentException {

    boolean resourceBundleSpecified = false;

    Document document = SAXReaderUtil.read(xml, true);

    Element rootElement = document.getRootElement();

    for (Element portletElement : rootElement.elements("portlet")) {

      String resourceBundleString = portletElement.elementText("resource-bundle");
      if (StringUtils.isNotBlank(resourceBundleString)) {
        String resourceBundleName = portletElement.elementText("resource-bundle").replace('.', '/');

        if (resourceBundleName != null) {

          resourceBundleSpecified = true;
          processBundle(resourceBundleName, servletContext, bundleName);
        }
      }
    }

    return resourceBundleSpecified;
  }
Пример #11
0
  protected void exportAssetTags(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("tags");

    Map<String, String[]> assetTagNamesMap = portletDataContext.getAssetTagNamesMap();

    for (Map.Entry<String, String[]> entry : assetTagNamesMap.entrySet()) {
      String[] assetTagNameParts = StringUtil.split(entry.getKey(), CharPool.POUND);

      String className = assetTagNameParts[0];
      String classPK = assetTagNameParts[1];

      Element assetElement = rootElement.addElement("asset");

      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("class-pk", classPK);
      assetElement.addAttribute("tags", StringUtil.merge(entry.getValue()));
    }

    List<AssetTag> assetTags =
        AssetTagServiceUtil.getGroupTags(portletDataContext.getScopeGroupId());

    for (AssetTag assetTag : assetTags) {
      exportAssetTag(portletDataContext, assetTag, rootElement);
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/tags.xml", document.formattedString());
  }
Пример #12
0
  protected Set<String> getArticleFieldNames(long articleId) throws Exception {

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

    try (LoggingTimer loggingTimer = new LoggingTimer()) {
      String sql =
          "select JournalArticle.content from JournalArticle where " + "JournalArticle.id_ = ?";

      try (PreparedStatement ps = connection.prepareStatement(sql)) {
        ps.setLong(1, articleId);

        try (ResultSet rs = ps.executeQuery()) {
          if (rs.next()) {
            String content = rs.getString("content");

            Document document = SAXReaderUtil.read(content);

            Element rootElement = document.getRootElement();

            articleFieldNames = getArticleDynamicElements(rootElement);
          }
        }
      }
    }

    return articleFieldNames;
  }
  @Override
  protected PortletPreferences doImportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences,
      String data)
      throws Exception {

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-producers")) {

      Element wsrpProducersElement = rootElement.element("wsrp-producers");

      importWSRPProducers(portletDataContext, wsrpProducersElement);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-consumers")) {

      Element wsrpConsumersElement = rootElement.element("wsrp-consumers");

      importWSRPConsumers(portletDataContext, wsrpConsumersElement);
    }

    return null;
  }
Пример #14
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 (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);
    }
  }
Пример #15
0
  public EARBuilder(String originalApplicationXML, String[] pluginFileNames) {
    try {
      Document document = SAXReaderUtil.read(new File(originalApplicationXML));

      Element rootElement = document.getRootElement();

      for (String pluginFileName : pluginFileNames) {
        Element moduleElement = rootElement.addElement("module");

        Element webElement = moduleElement.addElement("web");

        Element webURIElement = webElement.addElement("web-uri");

        webURIElement.addText(pluginFileName);

        Element contextRootElement = webElement.addElement("context-root");

        String contextRoot = _getContextRoot(pluginFileName);

        contextRootElement.addText(contextRoot);
      }

      FileUtil.write(originalApplicationXML, document.formattedString(), true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public void read(String servletContextName, InputStream inputStream) throws Exception {

    Document document = SAXReaderUtil.read(inputStream, true);

    read(servletContextName, document);
  }
Пример #17
0
  public static String getUserPreference(
      long userId, long plid, String portletId, String preferenceName) {
    String _preference = StringPool.BLANK;

    PortletPreferences preferences = null;
    try {
      preferences =
          PortletPreferencesLocalServiceUtil.getPortletPreferences(
              userId, PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletId);
    } catch (PortalException e) {
      // ignore
    } catch (SystemException e) {
      // ignore
    }

    if (Validator.isNull(preferences)) return _preference;

    Document document = null;
    try {
      document = SAXReaderUtil.read(preferences.getPreferences());
    } catch (DocumentException e) {
      e.printStackTrace();
    }

    for (Iterator<Element> itr = document.getRootElement().elementIterator("preference");
        itr.hasNext(); ) {
      Element preference = (Element) itr.next();

      if (preference.element("name").getText().equalsIgnoreCase(preferenceName)) {
        _preference = preference.element("value").getText();
      }
    }

    return _preference;
  }
  @Override
  public void removeAndStoreSelection(
      List<String> assetEntryUuids, PortletPreferences portletPreferences) throws Exception {

    if (assetEntryUuids.size() == 0) {
      return;
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
      String assetEntryXml = itr.next();

      Document document = SAXReaderUtil.read(assetEntryXml);

      Element rootElement = document.getRootElement();

      String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

      if (assetEntryUuids.contains(assetEntryUuid)) {
        itr.remove();
      }
    }

    portletPreferences.setValues(
        "assetEntryXml", assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
  }
Пример #19
0
  @Override
  public String getXML(Document document, Fields fields) {
    Element rootElement = null;

    try {
      if (document != null) {
        rootElement = document.getRootElement();
      } else {
        document = SAXReaderUtil.createDocument();

        rootElement = document.addElement("root");
      }

      Iterator<Field> itr = fields.iterator(true);

      while (itr.hasNext()) {
        Field field = itr.next();

        List<Node> nodes = getElementsByName(document, field.getName());

        for (Node node : nodes) {
          document.remove(node);
        }

        appendField(rootElement, field);
      }

      return document.formattedString();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
Пример #20
0
  protected void exportAssetLinks(PortletDataContext portletDataContext) throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("links");

    Map<String, String[]> assetLinkUuidsMap = portletDataContext.getAssetLinkUuidsMap();

    for (Map.Entry<String, String[]> entry : assetLinkUuidsMap.entrySet()) {
      String[] assetLinkNameParts = StringUtil.split(entry.getKey(), CharPool.POUND);
      String[] targetAssetEntryUuids = entry.getValue();

      String sourceAssetEntryUuid = assetLinkNameParts[0];
      String assetLinkType = assetLinkNameParts[1];

      Element assetElement = rootElement.addElement("asset-link");

      assetElement.addAttribute("source-uuid", sourceAssetEntryUuid);
      assetElement.addAttribute("target-uuids", StringUtil.merge(targetAssetEntryUuids));
      assetElement.addAttribute("type", assetLinkType);
    }

    portletDataContext.addZipEntry(
        portletDataContext.getRootPath() + "/links.xml", document.formattedString());
  }
  @Override
  protected PortletPreferences doImportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences,
      String data)
      throws Exception {

    portletDataContext.importPermissions(
        "com.liferay.portlet.calendar",
        portletDataContext.getSourceGroupId(),
        portletDataContext.getScopeGroupId());

    Document document = SAXReaderUtil.read(data);

    Element rootElement = document.getRootElement();

    for (Element eventElement : rootElement.elements("event")) {
      String path = eventElement.attributeValue("path");

      if (!portletDataContext.isPathNotProcessed(path)) {
        continue;
      }

      CalEvent event = (CalEvent) portletDataContext.getZipEntryAsObject(path);

      importEvent(portletDataContext, eventElement, event);
    }

    return null;
  }
  private String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) {

    String xml = null;

    try {
      Document document = SAXReaderUtil.createDocument(StringPool.UTF8);

      Element assetEntryElement = document.addElement("asset-entry");

      Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type");

      assetEntryTypeElement.addText(assetEntryType);

      Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid");

      assetEntryUuidElement.addText(assetEntryUuid);

      xml = document.formattedString(StringPool.BLANK);
    } catch (IOException ioe) {
      if (_log.isWarnEnabled()) {
        _log.warn(ioe);
      }
    }

    return xml;
  }
  protected void readExpandoTables(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/expando-tables.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> expandoTableElements = rootElement.elements("expando-table");

    for (Element expandoTableElement : expandoTableElements) {
      String className = expandoTableElement.attributeValue("class-name");

      ExpandoTable expandoTable = null;

      try {
        expandoTable =
            _expandoTableLocalService.getDefaultTable(portletDataContext.getCompanyId(), className);
      } catch (NoSuchTableException nste) {
        expandoTable =
            _expandoTableLocalService.addDefaultTable(portletDataContext.getCompanyId(), className);
      }

      List<Element> expandoColumnElements = expandoTableElement.elements("expando-column");

      for (Element expandoColumnElement : expandoColumnElements) {
        long columnId = GetterUtil.getLong(expandoColumnElement.attributeValue("column-id"));
        String name = expandoColumnElement.attributeValue("name");
        int type = GetterUtil.getInteger(expandoColumnElement.attributeValue("type"));
        String defaultData = expandoColumnElement.elementText("default-data");
        String typeSettings = expandoColumnElement.elementText("type-settings");

        Serializable defaultDataObject =
            ExpandoConverterUtil.getAttributeFromString(type, defaultData);

        ExpandoColumn expandoColumn =
            _expandoColumnLocalService.getColumn(expandoTable.getTableId(), name);

        if (expandoColumn != null) {
          _expandoColumnLocalService.updateColumn(
              expandoColumn.getColumnId(), name, type, defaultDataObject);
        } else {
          expandoColumn =
              _expandoColumnLocalService.addColumn(
                  expandoTable.getTableId(), name, type, defaultDataObject);
        }

        _expandoColumnLocalService.updateTypeSettings(expandoColumn.getColumnId(), typeSettings);

        portletDataContext.importPermissions(
            ExpandoColumn.class, columnId, expandoColumn.getColumnId());
      }
    }
  }
  protected void importAssetLinks(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/links.xml");

    if (xml == null) {
      return;
    }

    Element importDataRootElement = portletDataContext.getImportDataRootElement();

    try {
      Document document = SAXReaderUtil.read(xml);

      Element rootElement = document.getRootElement();

      portletDataContext.setImportDataRootElement(rootElement);

      Element linksElement = portletDataContext.getImportDataGroupElement(StagedAssetLink.class);

      List<Element> linkElements = linksElement.elements();

      for (Element linkElement : linkElements) {
        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, linkElement);
      }
    } finally {
      portletDataContext.setImportDataRootElement(importDataRootElement);
    }
  }
  protected void importSQL() throws Exception {
    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    InputStream inputStream = classLoader.getResourceAsStream("/resources/data/sql.xml");

    String xml = new String(FileUtil.getBytes(inputStream));

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

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

    for (Element batchElement : batchElements) {
      String testSQL = batchElement.elementText("test-sql");

      int count = getCount(testSQL);

      if (count > 0) {
        continue;
      }

      String[] importSQLs =
          StringUtil.split(batchElement.elementText("import-sql"), StringPool.SEMICOLON);

      runSQL(importSQLs);
    }
  }
  protected void readLocks(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            ExportImportPathUtil.getSourceRootPath(portletDataContext) + "/locks.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

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

    for (Element assetElement : assetElements) {
      String path = assetElement.attributeValue("path");
      String className = assetElement.attributeValue("class-name");
      String key = assetElement.attributeValue("key");

      Lock lock = (Lock) portletDataContext.getZipEntryAsObject(path);

      if (lock != null) {
        portletDataContext.addLocks(className, key, lock);
      }
    }
  }
  @Override
  protected void validateExport(
      PortletDataContext portletDataContext,
      StagedModel stagedModel,
      Map<String, List<StagedModel>> dependentStagedModelsMap)
      throws Exception {

    ManifestSummary manifestSummary = portletDataContext.getManifestSummary();

    Map<String, LongWrapper> modelAdditionCounters = manifestSummary.getModelAdditionCounters();

    Assert.assertEquals(4, modelAdditionCounters.size());
    Assert.assertEquals(
        1, manifestSummary.getModelAdditionCount(DDMStructure.class, JournalArticle.class));
    Assert.assertEquals(
        1, manifestSummary.getModelAdditionCount(DDMTemplate.class, DDMStructure.class));
    Assert.assertEquals(1, manifestSummary.getModelAdditionCount(JournalArticle.class));
    Assert.assertEquals(1, manifestSummary.getModelAdditionCount(JournalFolder.class));

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    Element headerElement = rootElement.addElement("header");

    _exportDate = new Date();

    headerElement.addAttribute("export-date", Time.getRFC822(_exportDate));

    ExportImportHelperUtil.writeManifestSummary(document, manifestSummary);

    zipWriter.addEntry("/manifest.xml", document.asXML());
  }
  protected void validate(String name, String description, String xsd) throws PortalException {

    if (Validator.isNull(name)) {
      throw new StructureNameException();
    } else if (Validator.isNull(description)) {
      throw new StructureDescriptionException();
    }

    if (Validator.isNull(xsd)) {
      throw new StructureXsdException();
    } else {
      try {
        Document doc = SAXReaderUtil.read(xsd);

        Element root = doc.getRootElement();

        List<Element> children = root.elements();

        if (children.size() == 0) {
          throw new StructureXsdException();
        }

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

        validate(children, elNames);
      } catch (Exception e) {
        throw new StructureXsdException();
      }
    }
  }
Пример #29
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);
  }
 @Override
 public void setEvaluationModel(Course course, JSONObject model)
     throws PortalException, SystemException, DocumentException, IOException {
   Document document = SAXReaderUtil.createDocument();
   Element rootElement = document.addElement("eval");
   rootElement.addElement("courseEval").setText(PonderatedCourseEval.class.getName());
   course.setCourseExtraData(document.formattedString());
 }