コード例 #1
0
ファイル: Serializer.java プロジェクト: razie/razmutant
  public static AssetMap assetsFromJson(String json) throws JSONException {
    JSONArray read = new JSONArray(json);
    AssetMap newbriefs = new AssetMap();
    for (int i = 0; i < read.length(); i++) {
      AssetBrief b = AssetBrief$.MODULE$.fromJson(read.getJSONObject(i));
      newbriefs.put(b.getKey(), b);
    }

    return newbriefs;
  }
コード例 #2
0
  /** @return a (parent) container with containers and items (sub-folders and items) */
  public static JUpnpContainer browseFolder(
      JUpnpContainer parent, AssetKey ref, DrawStream out, String mediaType, boolean countonly) {
    if (parent == null) parent = new JUpnpContainer(ref.getId(), ref, "", 0, mediaType);
    parent.parentID = parentCache.get(ref) == null ? "-1" : parentCache.get(ref);

    int count = 0;

    String dir = ref.getId();
    String lp = ref.getLocation().getLocalPath();
    if (lp != null && lp.length() > 0) {
      dir = lp + (lp.endsWith("/") || lp.endsWith("\\") ? "" : "/") + dir;
    }

    String parentID = ref.toUrlEncodedString();

    File f = new File(dir);
    File[] entries = f.listFiles();
    if (entries != null) {
      for (File entry : entries) {
        if (entry.isDirectory()) {
          count++;
          String d = entry.getName();
          AssetKey myref =
              new AssetKey("Folder", d, AssetLocation.mutantEnv(Agents.getMyHostName(), dir));
          JUpnpContainer cont = new JUpnpContainer(d, myref, parentID, 1, mediaType);
          parentCache.put(myref, parentID);
          out.write(cont);
          if (!countonly) parent.addContainer(cont);
        }
      }
    }

    // now list files...

    AssetLocation env = AssetLocation.mutantEnv(dir);
    AssetMap assets = null;
    if ("Movie".equals(mediaType)) assets = JavaAssetMgr.find("Movie", env, false);
    else if ("Music".equals(mediaType)) assets = JavaAssetMgr.find("Music", env, false);
    else if ("Photo".equals(mediaType)) assets = JavaAssetMgr.find("Photo", env, false);
    else assets = JavaAssetMgr.find("Movie", env, false);

    for (AssetBrief movie : assets.jvalues()) {
      movie.setParentID(parentID);
      parentCache.put(movie.getKey(), parentID);
      // res.add(movie.toUpnpItem(parentID));
      if (!countonly) parent.addItem(movie);
    }

    parent.childCount = count;

    return parent;
  }
コード例 #3
0
ファイル: Serializer.java プロジェクト: razie/razmutant
 public static String assetsToJson(AssetMap briefs) throws JSONException {
   JSONArray write = new JSONArray(briefs.values());
   String json = write.toString(2);
   return json;
 }