public static ContentTree createDataSourceTree(
      ApplicationManager appManager, Application app, long flags)
      throws ParserConfigurationException, SAXException, IOException, ParseException {
    ContentTree tree = new ContentTree();
    tree.id = "1";
    ArrayList<ContentTreeItem> result = new ArrayList<ContentTreeItem>();
    tree.setItems(result);

    ArrayList<DataSourceBase> datasources = app.getDataSources();

    ContentTreeItem rootItem = new ContentTreeItem();
    rootItem.name = "Data Sources";
    rootItem.label = "Data Sources";
    rootItem.id = "9898989";
    rootItem.children = new ArrayList<Reference>();
    // result.add(rootItem);
    tree.items.add(rootItem);
    rootItem.type = "top";
    rootItem.contentType =
        "" + ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.Unknown);

    for (int i = 0; i < datasources.size(); i++) {
      DataSourceBase ds = datasources.get(i);
      String dsType = ds.getType();
      Boolean isValid =
          dsType.equals("Youtube")
              || dsType.equals("Picassa")
              || dsType.equals("Calendar")
              || dsType.equals("Documents");
      if (!isValid) continue;

      ContentTreeItem item = new ContentTreeItem();
      item.name = GoogleTreeFactory.getDataSourceLabel(ds);
      item.id = "" + ds.getUid();
      item.dataSourceUID = ds.uid;
      item.contentType =
          "" + ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.DataSourceItem);
      /*
      item.children = new ArrayList<Reference>();
      Reference ref0 = new Reference();
      ref0._reference="" + "asdasd";
      item.addChild(ref0);
      */
      Reference ref = new Reference();
      ref._reference = "" + item.id;
      rootItem.addChild(ref);
      result.add(item);
      item.type = ds.getType();

      if (dsType.equals("Picassa")
          && BitUtils.hasFlag(
              flags,
              ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.GooglePicassaAlbum))) {
        ArrayList<ContentTreeItem> albumItems =
            GoogleTreeFactory.addAlbums(appManager, app, ds, item, tree, flags);
        if (albumItems != null) {
          tree.items.addAll(albumItems);
        }
      }

      if (dsType.equals("Calendar")
          && BitUtils.hasFlag(
              flags,
              ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.GoogleCalendar))) {
        ArrayList<ContentTreeItem> albumItems =
            GoogleTreeFactory.addCalendars(appManager, app, ds, item, tree, flags);
        if (albumItems != null) {
          tree.items.addAll(albumItems);
        }
      }

      Boolean docs =
          BitUtils.hasFlag(
              flags,
              ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.GoogleDocumentFolder));
      if (dsType.equals("Documents")
          && BitUtils.hasFlag(
              flags,
              ECMContentSourceTypeTools.TypeToInteger(ECMContentSourceType.GoogleDocumentFolder))) {
        ArrayList<ContentTreeItem> albumItems =
            GoogleTreeFactory.addDocFolders(appManager, app, ds, item, tree, flags);
        if (albumItems != null) {
          tree.items.addAll(albumItems);
        }
      }
    }
    // tree.setItems(result);

    return tree;
  }