コード例 #1
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);
    }
  }
コード例 #2
0
 private static DateFormat _getDateFormat() {
   return DateUtil.getISO8601Format();
 }