private DefaultTreeModel createJTreeModelFromConfluencePages()

in src/main/java/com/atlassian/uwc/ui/organizer/OrganizerTree.java [100:168]


    private DefaultTreeModel createJTreeModelFromConfluencePages(ConfluenceServerSettings confServerSettings, String space) {
        DefaultMutableTreeNode pageNode = new DefaultMutableTreeNode("space", true);
        Map<String, DefaultMutableTreeNode> pageNodeMapById = new HashMap<String, DefaultMutableTreeNode>();
        // first pass - iterate through the pages, create the tree nodes
        //   and stick them into a map
        RemoteWikiBroker rwb = RemoteWikiBroker.getInstance();
        Collection<PageForXmlRpc> pages = null;
		try {
			pages = rwb.getAllServerPageSummaries(confServerSettings, space);
		} catch (IOException e1) {
			e1.printStackTrace();
		} catch (XmlRpcException e1) {
			e1.printStackTrace();
		}
        for (PageForXmlRpc page : pages) {
            pageNode = new DefaultMutableTreeNode(page, true);
            pageNodeMapById.put(page.getId(), pageNode);
        }

        // create place for pages with no parent
        DefaultMutableTreeNode noParentNode = new DefaultMutableTreeNode("no parent", true);

        // create the model and add the root
        String homePageId = null;
		try {
			homePageId = rwb.getSpaceHomePageId(confServerSettings, space);
		} catch (IOException e1) {
			e1.printStackTrace();
		} catch (XmlRpcException e1) {
			e1.printStackTrace();
		}
        DefaultMutableTreeNode root = pageNodeMapById.get(homePageId);
        if (root==null) {
            log.error("=================");
            log.error("No root node found!!!");
            log.error("=================");
            return null;
        }
        root.add(noParentNode);

        // second pass, connect all the nodes together into their
        //   child parent relationships
        for (PageForXmlRpc page : pages) {
            List children = null;
			try {
				children = rwb.getPageChildrenIds(confServerSettings, page.getId());
			} catch (IOException e1) {
				e1.printStackTrace();
			} catch (XmlRpcException e1) {
				e1.printStackTrace();
			}
            pageNode = pageNodeMapById.get(page.getId());
            for (Object aChildren : children) {
                String childId = (String) aChildren;
                pageNode.add(pageNodeMapById.get(childId));
                log.debug("adding to node: "+page.getTitle()+ "   child:  "+pageNodeMapById.get(childId).toString());
            }
            // add pages with no parent to the no parent group
            if (page.getParentId()==null||page.getParentId().equals("0")) {
                try {
                    noParentNode.add(pageNode);
                } catch (IllegalArgumentException e) {
                    log.debug(page.toString()+"  - probably the root node");
                }
            }
        }
        DefaultTreeModel model = new DefaultTreeModel(root);
        return model;  //To change body of created methods use File | Settings | File Templates.
    }