@SuppressWarnings("unchecked")
 private void traverseTaxonTree(StringBuffer buff, MappedNode curr) {
   if (curr != null) {
     boolean emptyOrInternal = StringUtils.notEmpty(curr.getName());
     if (emptyOrInternal) {
       buff.append("<li>" + curr.getName());
     }
     List children = curr.getChildren();
     if (!children.isEmpty()) {
       if (emptyOrInternal) {
         buff.append("<ul>");
       }
       for (Iterator itr = children.iterator(); itr.hasNext(); ) {
         MappedNode child = (MappedNode) itr.next();
         traverseTaxonTree(buff, child);
       }
       if (emptyOrInternal) {
         buff.append("</ul>");
       }
     }
     if (emptyOrInternal) {
       buff.append("</li>");
     }
   }
 }
 @SuppressWarnings("unchecked")
 private String getCopyrightOwnersIdString(Collection contributors) {
   ArrayList names = new ArrayList();
   Iterator it = contributors.iterator();
   while (it.hasNext()) {
     PageContributor contr = (PageContributor) it.next();
     if (contr.getIsCopyOwner()) {
       names.add(contr.getContributor().getId());
     }
   }
   return StringUtils.returnCommaJoinedString(names);
 }
  @SuppressWarnings("unchecked")
  public void processContent() {

    Element page = new Element(PageContentElements.PAGE, ContentPreparer.NS);
    page.addAttribute(new Attribute(PageContentAttributes.ID, "" + getMappedPage().getPageId()));

    String pageNodeNameUrl = getMappedPage().getMappedNode().getName();
    try {
      pageNodeNameUrl = URLEncoder.encode(pageNodeNameUrl, "UTF-8");
    } catch (Exception e) {
      e.printStackTrace();
    }
    String nodeIdString = "" + getMappedPage().getMappedNode().getId();
    pageNodeNameUrl =
        StringUtils.notEmpty(pageNodeNameUrl) ? pageNodeNameUrl + "/" + nodeIdString : nodeIdString;
    String pageUrl = "http://tolweb.org/" + pageNodeNameUrl;
    page.addAttribute(new Attribute(PageContentAttributes.PAGE_URL, pageUrl));
    page.addAttribute(
        new Attribute(PageContentAttributes.PAGE_STATUS, getMappedPage().getStatus()));
    page.addAttribute(
        new Attribute(
            PageContentAttributes.DATE_CREATED,
            getSafeString(getMappedPage().getFirstOnlineString())));
    page.addAttribute(
        new Attribute(
            PageContentAttributes.DATE_CHANGED,
            safeToString(getMappedPage().getContentChangedDate())));

    Element group = new Element(PageContentElements.GROUP, ContentPreparer.NS);
    page.appendChild(group);

    group.addAttribute(
        new Attribute(PageContentAttributes.NODE, "" + getMappedPage().getMappedNode().getId()));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.EXTINCT,
            (getMappedPage().getMappedNode().getExtinct() == 2) ? "true" : "false"));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.PHYLESIS,
            getPhylesisString(getMappedPage().getMappedNode().getPhylesis())));
    group.addAttribute(
        new Attribute(
            PageContentAttributes.LEAF,
            getMappedPage().getMappedNode().getIsLeaf() ? "true" : "false"));

    Element groupDesc = new Element(PageContentElements.GROUP_DESCRIPTION, ContentPreparer.NS);
    String groupDescText = getMappedPage().getMappedNode().getDescription();
    groupDesc.appendChild(new Text(groupDescText));

    if (StringUtils.notEmpty(groupDescText)) {
      group.appendChild(groupDesc);
    }

    Element groupCmt = new Element(PageContentElements.GROUP_COMMENT, ContentPreparer.NS);
    String groupCmtText = getMappedPage().getLeadText();
    groupCmt.appendChild(new Text(groupCmtText));

    if (StringUtils.notEmpty(groupCmtText)) {
      group.appendChild(groupCmt);
    }

    Element names = new Element(PageContentElements.NAMES, ContentPreparer.NS);
    page.appendChild(names);

    Element name = new Element(PageContentElements.NAME, ContentPreparer.NS);
    names.appendChild(name);

    name.appendChild(new Text(getMappedPage().getMappedNode().getName()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.ITALICIZE_NAME,
            Boolean.valueOf(getMappedPage().getMappedNode().getItalicizeName()).toString()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.AUTHORITY,
            getSafeString(getMappedPage().getMappedNode().getNameAuthority())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.AUTH_DATE,
            safeToString(getMappedPage().getMappedNode().getAuthorityDate())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.NAME_COMMENT,
            getSafeString(getMappedPage().getMappedNode().getNameComment())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.NEW_COMBINATION,
            Boolean.valueOf(getMappedPage().getMappedNode().getIsNewCombination()).toString()));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.COMBINATION_AUTHOR,
            getSafeString(getMappedPage().getMappedNode().getCombinationAuthor())));
    name.addAttribute(
        new Attribute(
            PageContentAttributes.COMBINATION_DATE,
            safeToString(getMappedPage().getMappedNode().getCombinationDate())));

    Element othernames = new Element(PageContentElements.OTHERNAMES, ContentPreparer.NS);

    SortedSet otherNamesSet = getMappedPage().getMappedNode().getSynonyms();

    for (Iterator itr = otherNamesSet.iterator(); itr.hasNext(); ) {
      MappedOtherName moname = (MappedOtherName) itr.next();
      Element othername = new Element(PageContentElements.OTHERNAME, ContentPreparer.NS);
      othername.addAttribute(new Attribute(PageContentAttributes.ID, "" + moname.getId()));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.ITALICIZE_NAME,
              Boolean.valueOf(moname.getItalicize()).toString()));
      othername.addAttribute(
          new Attribute(PageContentAttributes.AUTHORITY, getSafeString(moname.getAuthority())));
      othername.addAttribute(
          new Attribute(PageContentAttributes.AUTH_DATE, safeToString(moname.getAuthorityYear())));
      othername.addAttribute(
          new Attribute(PageContentAttributes.NAME_COMMENT, getSafeString(moname.getComment())));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.IS_IMPORTANT,
              Boolean.valueOf(moname.getIsImportant()).toString()));
      othername.addAttribute(
          new Attribute(
              PageContentAttributes.IS_PREFERRED,
              Boolean.valueOf(moname.getIsPreferred()).toString()));
      othername.addAttribute(
          new Attribute(PageContentAttributes.SEQUENCE, safeToString(moname.getOrder())));
    }

    if (!otherNamesSet.isEmpty()) {
      names.appendChild(othernames);
    }

    List children = getMappedPage().getMappedNode().getChildren();
    boolean isTerminal = children != null && children.isEmpty();

    // add this if not a leaf or writeaslist is false... or is terminal (e.g. no children)
    if (getMappedPage().getMappedNode().getIsLeaf() && !isTerminal) {
      Element subgroups = new Element(PageContentElements.SUBGROUPS, ContentPreparer.NS);
      page.appendChild(subgroups);

      if (!getMappedPage().getWriteAsList()) {
        Element treeimage = new Element(PageContentElements.TREEIMAGE, ContentPreparer.NS);
        ContributorLicenseInfo currDefault =
            new ContributorLicenseInfo(ContributorLicenseInfo.TREE_IMAGE_LICENSE);
        treeimage.addAttribute(
            new Attribute(PageContentAttributes.LICENSE, currDefault.toShortString()));
        String treeImageName = getMappedPage().getGroupName().replaceAll("\\s", "_");
        treeimage.appendChild(
            new Text("http://www.tolweb.org/Public/treeImages/" + treeImageName + ".png"));
        subgroups.appendChild(treeimage);
      }

      Element newicktree = new Element(PageContentElements.NEWICKTREE, ContentPreparer.NS);
      subgroups.appendChild(newicktree);

      Element taxonlist = new Element(PageContentElements.TAXON_LIST, ContentPreparer.NS);
      taxonlist.appendChild(new Text(StringEscapeUtils.escapeXml(getTaxonListAsHTML())));
      subgroups.appendChild(taxonlist);

      Element treecomment = new Element(PageContentElements.TREE_COMMENT, ContentPreparer.NS);
      subgroups.appendChild(treecomment);
      treecomment.appendChild(
          new Text(StringEscapeUtils.escapeXml(getMappedPage().getPostTreeText())));
    }

    Element sections = new Element(PageContentElements.SECTIONS, ContentPreparer.NS);
    page.appendChild(sections);

    SortedSet textSections = getMappedPage().getTextSections();
    for (Iterator itr = textSections.iterator(); itr.hasNext(); ) {
      MappedTextSection mtxt = (MappedTextSection) itr.next();
      Element section = new Element(PageContentElements.SECTION, ContentPreparer.NS);
      section.addAttribute(new Attribute(PageContentAttributes.ID, "" + mtxt.getTextSectionId()));
      section.addAttribute(new Attribute(PageContentAttributes.SECTION_TITLE, mtxt.getHeading()));
      section.addAttribute(
          new Attribute(PageContentAttributes.PAGE_ORDER, safeToString(mtxt.getOrder())));
      section.addAttribute(
          new Attribute(PageContentAttributes.COPYRIGHT_DATE, getMappedPage().getCopyrightDate()));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.LICENSE,
              getLicenseShortName(getMappedPage().getUsePermission())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.AUTHORS,
              getAuthorsIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.CORRESPONDENTS,
              getCorrespondentsIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.COPYRIGHT_OWNERS,
              getCopyrightOwnersIdString(getMappedPage().getContributors())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.OTHER_COPYRIGHT,
              getSafeString(getMappedPage().getCopyrightHolder())));
      section.addAttribute(
          new Attribute(
              PageContentAttributes.CONTENT_CHANGED,
              safeToString(getMappedPage().getContentChangedDate())));

      // add the section-text text element
      Element sectionText = new Element(PageContentElements.SECTION_TEXT, ContentPreparer.NS);
      sectionText.appendChild(new Text(processSectionText(mtxt.getText(), pageUrl)));
      section.appendChild(sectionText);

      Element sectionMedia = new Element(PageContentElements.SECTION_MEDIA, ContentPreparer.NS);
      processSectionMedia(sectionMedia);
      section.appendChild(sectionMedia);

      // add the section-source element
      Element sectionSource = new Element(PageContentElements.SECTION_SOURCE, ContentPreparer.NS);
      // TODO add attribute data to section-source
      section.appendChild(sectionSource);

      String sectionAnchor = mtxt.getHeadingNoSpaces();
      sectionSource.addAttribute(new Attribute(PageContentAttributes.SOURCE_COLLECTION, "0"));
      sectionSource.addAttribute(
          new Attribute(PageContentAttributes.SOURCE_TITLE, mtxt.getHeading()));
      sectionSource.addAttribute(
          new Attribute(
              PageContentAttributes.SOURCE_URL,
              "http://tolweb.org/" + pageNodeNameUrl + "#" + sectionAnchor));
      sectionSource.addAttribute(new Attribute(PageContentAttributes.MORE_SOURCE, "[future-use]"));

      sections.appendChild(section);
    }

    Element refs = new Element(PageContentElements.REFERENCES, ContentPreparer.NS);
    page.appendChild(refs);
    TextPreparer txtPrep = new TextPreparer();
    List refsList = txtPrep.getNewlineSeparatedList(getMappedPage().getReferences());
    for (Iterator itr = refsList.iterator(); itr.hasNext(); ) {
      String ref = (String) itr.next();
      // only add the reference element if it's not empty
      if (StringUtils.notEmpty(ref)) {
        Element refEl = new Element(PageContentElements.REFERENCE, ContentPreparer.NS);
        refEl.appendChild(new Text(StringEscapeUtils.escapeXml(ref)));
        refs.appendChild(refEl);
      }
    }

    Element internetInfo = new Element(PageContentElements.INTERNET_INFO, ContentPreparer.NS);
    page.appendChild(internetInfo);
    internetInfo.appendChild(
        new Text(StringEscapeUtils.escapeXml(getMappedPage().getInternetInfo())));

    getElement().appendChild(page);
  }
Exemple #4
0
 public boolean getHasImage2() {
   return StringUtils.notEmpty(getImageFilename2());
 }