Ejemplo n.º 1
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();
    }
  }
  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 String doExport(Definition definition) {
    try {
      Document document = SAXReaderUtil.createDocument();

      Element workflowDefinitionElement = document.addElement("workflow-definition");

      workflowDefinitionElement.addAttribute(
          "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      workflowDefinitionElement.addAttribute(
          "xsi:schemaLocation",
          "urn:liferay.com:liferay-workflow_"
              + _version
              + " http://www.liferay.com/dtd/liferay-workflow-definition_"
              + _schemaVersion
              + ".xsd");
      workflowDefinitionElement.addNamespace("", "urn:liferay.com:liferay-workflow_" + _version);

      Element nameElement = workflowDefinitionElement.addElement("name", _namespace);

      nameElement.addText(definition.getName());

      if (Validator.isNotNull(definition.getDescription())) {
        Element descriptionElement =
            workflowDefinitionElement.addElement("description", _namespace);

        descriptionElement.addText(definition.getDescription());
      }

      Element versionElement = workflowDefinitionElement.addElement("version", _namespace);

      versionElement.addText(String.valueOf(definition.getVersion()));

      Collection<Node> nodes = definition.getNodes();

      for (Node node : nodes) {
        NodeExporter nodeExporter = NodeExporterRegistry.getNodeExporter(node.getNodeType());

        nodeExporter.exportNode(node, workflowDefinitionElement, _namespace);
      }

      return document.formattedString();
    } catch (IOException ioe) {
      throw new SystemException("Unable to export definition", ioe);
    }
  }
  protected void addMetadataEntry(Map<String, String> entryMap, Element metadataElement) {

    for (Map.Entry<String, String> entry : entryMap.entrySet()) {
      Element entryElement = metadataElement.addElement("entry");

      entryElement.addAttribute("name", entry.getKey());

      entryElement.addText(entry.getValue());
    }
  }
  protected void exportLayoutIconImage(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    Image image = _imageLocalService.getImage(layout.getIconImageId());

    if (image != null) {
      String iconPath =
          ExportImportPathUtil.getModelPath(
              portletDataContext.getScopeGroupId(), Image.class.getName(), image.getImageId());

      Element iconImagePathElement = layoutElement.addElement("icon-image-path");

      iconImagePathElement.addText(iconPath);

      portletDataContext.addZipEntry(iconPath, image.getTextObj());
    }
  }
  protected void upgradeToAssetEntryUuidElement(Element rootElement) throws Exception {

    Element assetEntryIdElement = rootElement.element("assetEntryId");

    long assetEntryId = GetterUtil.getLong(assetEntryIdElement.getText());

    try (PreparedStatement ps =
        connection.prepareStatement("select classUuid from AssetEntry where entryId = ?")) {

      ps.setLong(1, assetEntryId);

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

          Element assetEntryUuidElement = rootElement.addElement("assetEntryUuid");

          assetEntryUuidElement.addText(classUuid);

          rootElement.remove(assetEntryIdElement);
        }
      }
    }
  }
Ejemplo n.º 7
0
  protected void addURLElement(
      Element element,
      String url,
      UnicodeProperties typeSettingsProperties,
      Date modifiedDate,
      String canonicalURL,
      Map<Locale, String> alternateURLs) {

    Element urlElement = element.addElement("url");

    Element locElement = urlElement.addElement("loc");

    locElement.addText(encodeXML(url));

    if (typeSettingsProperties == null) {
      if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
      }

      if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
      }
    } else {
      String changefreq = typeSettingsProperties.getProperty("sitemap-changefreq");

      if (Validator.isNotNull(changefreq)) {
        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(changefreq);
      } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
      }

      String priority = typeSettingsProperties.getProperty("sitemap-priority");

      if (Validator.isNotNull(priority)) {
        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(priority);
      } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
      }
    }

    if (modifiedDate != null) {
      Element modifiedDateElement = urlElement.addElement("lastmod");

      DateFormat iso8601DateFormat = DateUtil.getISO8601Format();

      modifiedDateElement.addText(iso8601DateFormat.format(modifiedDate));
    }

    if (alternateURLs != null) {
      for (Map.Entry<Locale, String> entry : alternateURLs.entrySet()) {
        Locale locale = entry.getKey();
        String href = entry.getValue();

        Element alternateURLElement =
            urlElement.addElement("xhtml:link", "http://www.w3.org/1999/xhtml");

        alternateURLElement.addAttribute("href", href);
        alternateURLElement.addAttribute("hreflang", LocaleUtil.toW3cLanguageId(locale));
        alternateURLElement.addAttribute("rel", "alternate");
      }

      Element alternateURLElement =
          urlElement.addElement("xhtml:link", "http://www.w3.org/1999/xhtml");

      alternateURLElement.addAttribute("rel", "alternate");
      alternateURLElement.addAttribute("hreflang", "x-default");
      alternateURLElement.addAttribute("href", canonicalURL);
    }
  }