KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > edit > CatalogToHtml


1 /*
2  * Created on Dec 22, 2004
3  */

4 package com.openedit.store.edit;
5
6 import java.util.Iterator JavaDoc;
7
8 import com.openedit.store.Category;
9 import com.openedit.store.StoreException;
10
11 /**
12  * @author cburkey
13  *
14  */

15 public class CatalogToHtml
16 {
17     protected Category fieldRootCatalog;
18     
19     public Category getRootCatalog()
20     {
21         return fieldRootCatalog;
22     }
23     public void setRootCatalog(Category inRootCatalog)
24     {
25         fieldRootCatalog = inRootCatalog;
26     }
27     public String JavaDoc getCatalogsAsHtml(String JavaDoc inSelectedCatalogId) throws StoreException
28     {
29         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
30         appendCatalogsAsHtml(sb, getRootCatalog(), 0, inSelectedCatalogId);
31         return sb.toString();
32     }
33
34     protected void appendCatalogsAsHtml(StringBuffer JavaDoc inBuffer, Category inCatalog, int inLevel,
35         String JavaDoc inSelectedCatalogId)
36     {
37         if (inCatalog == null)
38         {
39             return;
40         }
41         inBuffer.append("<option value=\"");
42         inBuffer.append(inCatalog.getId());
43         inBuffer.append('\"');
44         if (inCatalog.getId() != null && inCatalog.getId().equals(inSelectedCatalogId))
45         {
46             inBuffer.append(" selected");
47         }
48         inBuffer.append('>');
49         if (inLevel > 0)
50         {
51             for (int n = 0; n < inLevel; n++)
52             {
53                 inBuffer.append("&nbsp;&nbsp;&nbsp;");
54             }
55             inBuffer.append("- ");
56         }
57         inBuffer.append(inCatalog.getName());
58         inBuffer.append("</option>");
59
60         for (Iterator JavaDoc it = inCatalog.getChildren().iterator(); it.hasNext();)
61         {
62             Category child = (Category) it.next();
63             appendCatalogsAsHtml(inBuffer, child, inLevel + 1, inSelectedCatalogId);
64         }
65     }
66 }
67
Popular Tags