Пример #1
0
 public static void browseFolders(String who, DrawAccumulator out) {
   for (Element e :
       Reg.doc(MediaConfig.MEDIA_CONFIG).xpl("/config/storage/host[@name='" + who + "']/media")) {
     String dir = e.getAttribute("localdir");
     String t = e.hasAttribute("type") ? e.getAttribute("type") : "Movie";
     AssetKey ref = new AssetKey("Folder", dir, AssetLocation.mutantEnv(who, ""));
     JUpnpContainer f = new JUpnpContainer(dir, ref, byFolder.ref.toUrlEncodedString(), 1, t);
     parentCache.put(ref, byFolder.ref.toUrlEncodedString());
     out.write(f);
   }
 }
Пример #2
0
  @SuppressWarnings("rawtypes")
  public SoaResponse BrowseImpl(
      String ObjectID,
      String BrowseFlag,
      String Filter,
      String StartingIndex,
      String RequestedCount,
      razie.assets.Affordance aff)
      throws IOException {
    SoaResponse result = new SoaResponse();

    int count =
        RequestedCount == null
            ? 0
            : (RequestedCount.length() > 0 ? Integer.parseInt(RequestedCount) : 0);
    int start =
        StartingIndex == null
            ? 0
            : (StartingIndex.length() > 0 ? Integer.parseInt(StartingIndex) : 0);

    boolean browseMeta = BrowseFlag.equals("BrowseMetadata");

    DIDLDrawStream out = new DIDLDrawStream();

    if (browseMeta && ObjectID.equals("0")) {
      // browse the root
      out.write(root.toUpnpXml("0"));
    } else if (ObjectID.equals("0")) {
      // browse the root

      byFolder.childCount =
          Reg.doc(MediaConfig.MEDIA_CONFIG)
              .xpl("/config/storage/host[@name='" + Agents.getMyHostName() + "']/media")
              .size();

      writesection(out, rootKids, start, count);
    } else if (ObjectID.equals(byCategory.ref.toUrlEncodedString())) {
      // browse below the root, return folders or categories???
    } else if (ObjectID.equals(byFolder.ref.toUrlEncodedString())) {
      // browse below the root, return folders or categories???
      if (browseMeta) {
        byFolder.childCount =
            Reg.doc(MediaConfig.MEDIA_CONFIG)
                .xpl("/config/storage/host[@name='" + Agents.getMyHostName() + "']/media")
                .size();
        out.write(byFolder);
      } else browseFolders(Agents.getMyHostName(), out);
    } else {
      // the object ID must be aref
      AssetKey ref = AssetKey.fromString(HttpUtils.fromUrlEncodedString(ObjectID));

      if (browseMeta) {
        if ("Folder".equals(ref.getType())) {
          JUpnpContainer c = browseFolder(null, ref, out, "Movie", true); // will only
          // count children
          // UpnpContainer c = new UpnpContainer(ref.getId(), ref, "-1", 1,
          // "movie");
          // c.parentID = parentCache.get(ref) == null ? "-1" :
          // parentCache.get(ref);
          out.write(c);
        } else {
          AssetBrief b = JavaAssetMgr.getBrief(ref);
          b.setParentID(parentCache.get(ref) == null ? "-1" : parentCache.get(ref));
          if (b != null) {
            out.write(b);
          } else {
          }
        }
      } else {
        if ("Folder".equals(ref.getType())) {
          JUpnpContainer c = browseFolder(null, ref, out, "Movie", false);
          List l = new ArrayList();
          l.addAll(c.getContainers());
          l.addAll(c.getItems());

          writesection(out, l.toArray(), start, count);
        } else {
          // can't be...
        }
      }
    }

    out.close();
    result.setAttr("NumberReturned", String.valueOf(out.size()));
    String res = out.toString();

    result.setAttr("Result", res);
    result.setAttr("TotalMatches", result.getAttr("NumberReturned"));
    result.setAttr("UpdateID", "10");

    Log.logThis((String) result.getAttr("Result"));
    return result;
  }