1 4 package com.openedit.store.edit; 5 6 import java.util.Iterator ; 7 8 import com.openedit.store.Category; 9 import com.openedit.store.StoreException; 10 11 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 getCatalogsAsHtml(String inSelectedCatalogId) throws StoreException 28 { 29 StringBuffer sb = new StringBuffer (); 30 appendCatalogsAsHtml(sb, getRootCatalog(), 0, inSelectedCatalogId); 31 return sb.toString(); 32 } 33 34 protected void appendCatalogsAsHtml(StringBuffer inBuffer, Category inCatalog, int inLevel, 35 String 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(" "); 54 } 55 inBuffer.append("- "); 56 } 57 inBuffer.append(inCatalog.getName()); 58 inBuffer.append("</option>"); 59 60 for (Iterator 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 |