Package org.teleal.cling.support.model.container

Examples of org.teleal.cling.support.model.container.Container


      smdObjectID = null;
    }else {
      smdObjectID = objectID;
    }

    Container upnpContainer = new Container()
    upnpContainer.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.container"));
    upnpContainer.setRestricted(true);
    didl.addContainer(upnpContainer);

    if(smdObjectID == null) {
      upnpContainer.setTitle("Root Container");
      upnpContainer.setParentID("-1");
      upnpContainer.setId("0");
    } else if (smdObjectID.matches("^Folder:([^/]+)$") ) {
      java.util.regex.Pattern folderRx = java.util.regex.Pattern.compile("^Folder:([^/]+)$");
      java.util.regex.Matcher matcher = folderRx.matcher(smdObjectID);
      matcher.find();
      upnpContainer.setTitle(matcher.group(1));
      upnpContainer.setParentID("0");
      upnpContainer.setId(smdObjectID);
     
    }
   
    return new BrowseResult(new DIDLParser().generate(didl), 1, 1);
    }
View Full Code Here


    Result<Object> browsedContent = browseService.findChildren("upnp", smdObjectID, (int)firstResult, smdMaxItems, false);
   
    // Memo: DIDL object mandatory elements:
    // id, parentID, title, class, restricted (for 'object' base class)
   
    Container upnpContainer = null;
    Item upnpItem = null;
   
    for(ResultItem<?> browsedItem: browsedContent.getItems()) {
     
      // nullify container to prevent a bug if browsedItem type is unknown
      // unless nullified, the same object will be added twice in didl document
      upnpContainer = null;
     
      if(browsedItem.getType().equals("Folder") || browsedItem.getType().equals("ImageFolder") ) {
       
       
        // found item is a Folder (could be root elements, LastFM Image, etc.
        upnpContainer = new SmdFolder( (ResultItem<String>)browsedItem);

        // create object ID (parentId/itemID)
        if(smdObjectID != null) {
          upnpContainer.setId(smdObjectID+"/"+browsedItem.getId());
        }
        // before r839: upnpContainer.setChildCount(browseService.findChildren(browsedItem.getId(), null, null, false).getCount().intValue());
                // after  r839: upnpContainer.setChildCount(browseService.findChildren("upnp", browsedItem.getId(), null, null, false).getCount().intValue());

      } else if (browsedItem.getType().equals("Artist") ) {
       
        // SMD Item is considered as an artist, create corresponding UPnP container
       
        ResultItem<ArtistEntity> artistItem = (ResultItem<ArtistEntity>) browsedItem;
       
        org.teleal.cling.support.model.container.MusicArtist upnpMusicArtist = new org.teleal.cling.support.model.container.MusicArtist();
       
        upnpContainer = upnpMusicArtist;
        upnpMusicArtist.setId(objectID+"/"+artistItem.getId())
          .setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.container.person.musicArtist"))
          .setTitle(artistItem.getItem().getName());
        System.err.println("CurrentArtist: "+upnpMusicArtist.getTitle());
        // TODO: Artist can have "artistDiscographyURI"
        // upnpMusicArtist.setGenres( new String[] {"Unknown"} );
       
        // findChildren seems to require parent path concatenation now
        //upnpContainer.setChildCount(browseService.findChildren(artistItem.getId(), null, null, false).getCount().intValue());
        // upnpContainer.setChildCount(browseService.findChildren(objectID+"/"+artistItem.getId(), null, null, false).getCount().intValue());
       
        // search for artist genre
        // TODO: activate again when performance problem is gone
//        List<String> artistGenres = new ArrayList<String>();
//        for(ResultItem<ClassificationEntity> classificationResult: classificationBrowseService.findChildren(Arrays.asList(artistItem.getId()), null, 0, null, false).getItems() ) {
//          ClassificationEntity classification = classificationResult.getItem();
//          if(classification.getType().equals("genre")) {
//            artistGenres.add(classification.getName());
//          }
//        }
//        if(artistGenres.size()>0) {
//          upnpMusicArtist.setGenres(artistGenres.toArray(new String[0]));
//        }

      } else if (browsedItem.getType().equals("Release") ) {
        ResultItem<ReleaseEntity> releaseItem = (ResultItem<ReleaseEntity>) browsedItem;
        MusicAlbum upnpAlbum = new MusicAlbum();
        upnpContainer = upnpAlbum;
        List<PersonWithRole> contributors =  new ArrayList<PersonWithRole>();
       
//        try {

        Collection<ResultItem<ArtistEntity>> artists =
          artistBrowseService.findChildren(Arrays.asList(releaseItem.getId()), null, 0, null, false).getItems();
       
        for(ResultItem<ArtistEntity> artist : artists) {
          // TODO: replace hard coded "performer" by SMD role
           contributors.add(new PersonWithRole(artist.getItem().getName(), "Performer"));
        }
       
        upnpAlbum.setArtists(contributors.toArray(new PersonWithRole[0] ));
// TODO: check what happens if there's no artist (should be handled below by contributors.size test)
//        } catch(java.util.NoSuchElementException Ex) {
//          // ignore this exception, it means there's no artist for that album
//        }
       
        upnpAlbum.setId(objectID+"/"+releaseItem.getId());
        upnpAlbum.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.container.album.musicAlbum"));
       
        if(contributors.size()>0) {
          upnpAlbum.setCreator(contributors.get(0).getName());
        } else {
          upnpAlbum.setCreator("unknown");
        }
       
        upnpAlbum.setTitle(releaseItem.getItem().getName());
        upnpAlbum.addProperty(new DIDLObject.Property.UPNP.ALBUM(upnpAlbum.getTitle()) );
        upnpAlbum.setDescription("aze");
        // <albumArtUri dlna:profileID="PNG_TN">
        // <albumArtUri dlna:profileID="JPEG_TN">
       
        upnpAlbum.setAlbumArtURIs(new URI[] { new URI(releaseItem.getImage().getUrl())} );
        Property<URI>[] albumArtUriProperties = upnpAlbum.getProperties(UPNP.ALBUM_ART_URI.class);
        for(Property<URI> uriProperty : albumArtUriProperties) {
          //DIDLObject.Property.DLNA.PROFILE_ID toto = new DIDLObject.Property.DLNA.PROFILE_ID();
          //toto.getValue().
          //DIDLAttribute tutu = new DIDLAttribute(DIDLObject.Property.DLNA, "dlna", "zeazé")
         
          // value for dlna:profileID attribute of upnp:albumArtURI element
          String upnpProfileID;
         
            if(uriProperty.getValue().toString().endsWith(".png")) {
              upnpProfileID = "PNG_TN";
            } else {
              // if extension isn't png, suppose it's JPEG (may be a bad guess)
              upnpProfileID = "JPEG_TN";
              // TODO: improve image entity to contain image type or enhance this code
              // to detect image format
            }
           
          uriProperty.addAttribute(
              new DIDLObject.Property.DLNA.PROFILE_ID(
                  new DIDLAttribute(
                  DIDLObject.Property.DLNA.NAMESPACE.URI,
                  "dlna",
                  upnpProfileID)
              ) 
          );         
        }
       
        // search for album genre
// commented for performance reason, should be uncommented or changed
// when performance problem is solved
//        List<String> albumGenres = new ArrayList<String>();
//        for(ResultItem<ClassificationEntity> classificationResult: classificationBrowseService.findChildren(Arrays.asList(releaseItem.getId()), null, 0, null, false).getItems() ) {
//          ClassificationEntity classification = classificationResult.getItem();
//          if(classification.getType().equals("genre")) {
//            albumGenres.add(classification.getName());
//          }
//        }

       
        // construct album genres from genre, style and moods classifications
        List<String> albumGenres = new ArrayList<String>();
        for(ResultItem<ClassificationEntity> classificationResult:
                classificationBrowseService.findChildren(
                  Arrays.asList(releaseItem.getId(),"Classification.genre"),
                    null, 0, null, false).getItems()
        ) {
          StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
          while(sk.hasMoreTokens() ) {
            String genre = sk.nextToken().trim();
            if(!albumGenres.contains(genre))
              albumGenres.add(genre);
          }
        }

        for(ResultItem<ClassificationEntity> classificationResult:
          classificationBrowseService.findChildren(
            Arrays.asList(releaseItem.getId(),"Classification.style"),
              null, 0, null, false).getItems()
        ) {
//            albumGenres.addAll( Arrays.asList(classificationResult.getItem().getName().split(" ")) );
          StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
          while(sk.hasMoreTokens() ) {
            String genre = sk.nextToken().trim();
            if(!albumGenres.contains(genre))
              albumGenres.add(genre);
          }
        }

        for(ResultItem<ClassificationEntity> classificationResult:
          classificationBrowseService.findChildren(
            Arrays.asList(releaseItem.getId(),"Classification.mood"),
              null, 0, null, false).getItems()
        ) {
//            albumGenres.add(classificationResult.getItem().getName());
            StringTokenizer sk = new StringTokenizer(classificationResult.getItem().getName(), ",");
            while(sk.hasMoreTokens() ) {
              String genre = sk.nextToken().trim();
              if(!albumGenres.contains(genre))
                albumGenres.add(genre);
            }           
        }
         
        if(albumGenres.size()>0) {
          upnpAlbum.setGenres(albumGenres.toArray(new String[0]));
        }
       
        // TODO: add childcount is asked for by the client parameters
        // before r839: upnpContainer.setChildCount(browseService.findChildren(objectID+"/"+releaseItem.getId(), null, null, false).getCount().intValue());
        // after  r839: upnpContainer.setChildCount(browseService.findChildren("upnp", artistItem.getId(), null, null, false).getCount().intValue());

      } else if (browsedItem.getType().equals("Classification") ) {
        ResultItem<ClassificationEntity> classificationItem = (ResultItem<ClassificationEntity>) browsedItem;
        upnpContainer = new org.teleal.cling.support.model.container.MusicArtist();
        upnpContainer.setId(objectID+"/"+classificationItem.getId())
          .setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.container.genre.musicGenre"))
          .setTitle(classificationItem.getItem().getName());
        upnpContainer.setChildCount(browseService.findChildren("upnp", classificationItem.getId(), null, null, false).getCount().intValue());
       
      } else if (browsedItem.getType().equals("Track") ) {
       
        upnpItem = getUpnpMusicTrackFromSmdTrackEntity((ResultItem<TrackEntity>)browsedItem, objectID, filters);
       
      } else if (browsedItem.getType().equals("LastFMImage") ) {
        ResultItemImage smdImage = browsedItem.getImage();    
        Photo upnpPhoto = new Photo();
          upnpItem = upnpPhoto;
         
        // Mandatory elements:
          upnpPhoto.setTitle("unknown");
          upnpPhoto.setAlbum("unknown");
          upnpPhoto.setWriteStatus(WriteStatus.NOT_WRITABLE);
          upnpPhoto.setCreator("LastFM");
          upnpPhoto.setId(objectID+"/"+browsedItem.getId());
          upnpPhoto.setClazz(new org.teleal.cling.support.model.DIDLObject.Class("object.item.imageItem.photo"));
          Res url = new Res();
          upnpPhoto.addResource(url);
          url.setValue(smdImage.getUrl());
          if(url.getValue().endsWith(".png")) {
            url.setProtocolInfo(new ProtocolInfo("http-get:*:image/png:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS="));
          } else if(url.getValue().endsWith(".jpg")) {
            url.setProtocolInfo(new ProtocolInfo("http-get:*:image/jpeg:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS="));
          }

      } else {
        System.err.println("TYPE: "+browsedItem.getType());
      }
     
      if(upnpContainer != null) {
        upnpContainer.setRestricted(true);
        upnpContainer.setParentID(objectID);
       
        if(upnpContainer.getCreator() == null) {
          upnpContainer.setCreator("SMD");
        }
       
        didl.addContainer(upnpContainer);
      }
      if(upnpItem != null) {
View Full Code Here

TOP

Related Classes of org.teleal.cling.support.model.container.Container

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.