Example #1
0
  /**
   * Gets the albums' list.
   *
   * @param element
   * @return Albums
   */
  protected GalleryAlbums getAlbums(Element element) {
    GalleryAlbums galleryAlbums = new GalleryAlbums();

    String galleryName =
        element.getElementsByTagName("galleryName").item(0).getFirstChild().getNodeValue();
    String galleryHomePage =
        element.getElementsByTagName("homePage").item(0).getFirstChild().getNodeValue();

    String[] tags = null;

    NodeList albums = element.getElementsByTagName("album");
    int albumsCount = albums.getLength();
    AlbumBean[] photoAlbums = new AlbumBean[albumsCount];

    for (int i = 0; i < albumsCount; i++) {
      Element elAlbum = (Element) albums.item(i);

      String allCategories = elAlbum.getAttribute("tags");
      tags = allCategories.split(JcsPhotoGalleryConstants.ALBUM_SEPARATOR);
      photoAlbums[i] =
          new AlbumBean(
              elAlbum.getAttribute("img"),
              elAlbum.getAttribute("folderName"),
              elAlbum.getAttribute("name"),
              tags,
              i);
      photoAlbums[i].setParent(galleryAlbums);
    }

    galleryAlbums.setGalleryName(galleryName);
    galleryAlbums.setGalleryHomePage(galleryHomePage);
    galleryAlbums.setAlbums(photoAlbums);

    return galleryAlbums;
  }
Example #2
0
  protected void getAlbumsElements(Document doc, GalleryAlbums gallery) {
    Element galleryNameElement = doc.createElement("galleryName");
    galleryNameElement.appendChild(doc.createTextNode(gallery.getGalleryName()));

    Element homePageElement = doc.createElement("homePage");
    homePageElement.appendChild(doc.createTextNode(gallery.getGalleryHomePage()));

    Element root = doc.getDocumentElement();

    root.appendChild(galleryNameElement);
    root.appendChild(homePageElement);

    Element albumsElement = doc.createElement("albums");

    AlbumBean[] albums = gallery.getAllAlbums();
    for (AlbumBean album : albums) {

      Element albumElement = doc.createElement("album");

      albumElement.setAttribute("img", album.getImgThumbnail());
      albumElement.setAttribute("folderName", album.getFolderName());
      albumElement.setAttribute("name", album.getName());
      albumElement.setAttribute("tags", album.getTagsInOneLine());

      albumsElement.appendChild(albumElement);
    }
    root.appendChild(albumsElement);
  }