KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > links > XmlCatalogLinkLoader


1 package com.openedit.store.links;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.dom4j.Element;
6 import org.openedit.links.Link;
7 import org.openedit.links.XmlLinkLoader;
8
9 import com.openedit.OpenEditException;
10 import com.openedit.page.Page;
11 import com.openedit.store.Category;
12 import com.openedit.store.Store;
13 import com.openedit.store.StoreException;
14 import com.openedit.util.PathUtilities;
15
16 public class XmlCatalogLinkLoader extends XmlLinkLoader
17 {
18     protected Store fieldStore;
19
20     public Store getStore()
21     {
22         return fieldStore;
23     }
24
25     public void setStore(Store inStore)
26     {
27         fieldStore = inStore;
28     }
29     
30     //TODO: Replace with a different method call (store.getStoreHome()?)
31
public String JavaDoc catalogRoot()
32     {
33         return getStore().getStoreHome() + "/categories/";
34     }
35     //Overrride this parent method
36
protected void checkLink(Element inElement, Link inLink) throws OpenEditException
37     {
38         if (inLink.getUrl() != null && inLink.getUrl().startsWith(catalogRoot()))
39         {
40             addCatalogLinks(inLink);
41         }
42     }
43     
44     private void addCatalogLinks(Link inLink) throws StoreException
45     {
46         String JavaDoc catId = PathUtilities.extractPageName(inLink.getUrl());
47         Category parent;
48         parent = getStore().getCatalog(catId);
49         if (parent != null)
50         {
51             for (Iterator JavaDoc iter = parent.getChildren().iterator(); iter.hasNext();)
52             {
53                 Category child = (Category) iter.next();
54                 Link childLink = makeCatalogLink(child);
55                 inLink.addChild(childLink);
56             }
57         }
58     }
59     
60     private Link makeCatalogLink(Category inCatalog)
61     {
62         Link link = new Link();
63         link.setId(inCatalog.getId());
64         link.setText(inCatalog.getName());
65         link.setPath(catalogRoot() + inCatalog.getId() + ".html");
66         
67         for (Iterator JavaDoc iter = inCatalog.getChildren().iterator(); iter.hasNext();)
68         {
69             Category childCat = (Category) iter.next();
70             Link childLink = makeCatalogLink(childCat);
71             link.addChild(childLink);
72         }
73         return link;
74     }
75     
76 }
77
Popular Tags