1 4 package com.openedit.archive.cumulus; 5 6 import java.util.Iterator ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import com.canto.cumulus.CumulusException; 12 import com.canto.cumulus.Field; 13 import com.canto.cumulus.Fields; 14 import com.canto.cumulus.ServerCatalogs; 15 import com.openedit.OpenEditRuntimeException; 16 import com.openedit.config.Configuration; 17 import com.openedit.page.manage.PageManager; 18 import com.openedit.store.CatalogConverter; 19 20 public abstract class BaseCumulusConvert extends CatalogConverter 21 { 22 private static final Log log = LogFactory.getLog(BaseCumulusConvert.class); 23 protected PageManager fieldPageManager; 24 25 public PageManager getPageManager() 26 { 27 return fieldPageManager; 28 } 29 public void setPageManager(PageManager inPageManager) 30 { 31 fieldPageManager = inPageManager; 32 } 33 34 protected CumulusConnectionPool fieldCumulusConnectionPool; 35 36 protected Configuration openSettings(String inCatId, Configuration inConfig) 37 { 38 for (Iterator iter = inConfig.getChildIterator("catalog"); iter.hasNext();) 39 { 40 Configuration config = (Configuration) iter.next(); 41 if ( inCatId.equals( config.getAttribute("id")) ) 42 { 43 return config; 44 } 45 } 46 Configuration catconfig = inConfig.addChild("catalog"); 47 catconfig.setAttribute("id",inCatId); 48 49 return catconfig; 50 } 51 protected String extractId( String inName) 52 { 53 StringBuffer out = new StringBuffer (inName.length()); 54 for (int i = 0; i < inName.length(); i++) 55 { 56 char c = inName.charAt(i); 57 if( Character.isLetterOrDigit(c)) 58 { 59 out.append(c); 60 } 61 } 62 String result = out.toString().toLowerCase(); 63 return result; 64 } 65 public String extractProductId(String name, String inId) 66 { 67 name = name.replaceAll(" ","sp"); 68 name = name.replaceAll("&","amp"); 69 name = name.replaceAll("\\(","lp"); 70 name = name.replaceAll("\\)","rp"); 71 name = name.replaceAll("\\.","dot"); 72 name = name.replaceAll("_","und"); 73 name = name.replaceAll("\\+","plus"); 74 name = name.replaceAll("\\-","min"); 75 name = extractId(name) + inId; 76 return name; 77 } 78 79 public ServerCatalogs getServerCatalogs() throws Exception 80 { 81 return getCumulusConnectionPool().getServerCatalogs(); 82 } 83 84 public String getValue( Field inField) 85 { 86 if ( inField==null || !inField.hasValue()) 87 { 88 return null; 89 } 90 Object val; 91 try 92 { 93 val = inField.getValue(); 94 if( val instanceof String ) 95 { 96 String scrub = scrubChars((String )val); 97 return scrub; 98 } 99 } 100 catch (CumulusException ex) 101 { 102 log.error( ex ); 103 throw new OpenEditRuntimeException(ex); 104 } 105 if ( val == null) 106 { 107 return null; 108 } 109 return val.toString(); 110 } 111 protected String scrubChars(String inVal) 112 { 113 StringBuffer done = new StringBuffer (inVal.length()); 114 for (int i = 0; i < inVal.length(); i++) 115 { 116 char c = inVal.charAt(i); 117 switch (c) 118 { 119 case '\t': 120 case '\n': 121 case '\r': 122 done.append(c); break; 124 default: 125 { 126 if (c > 31) { 128 done.append(c); 129 } 130 } 131 } 132 } 133 return done.toString(); 134 } 135 public CumulusConnectionPool getCumulusConnectionPool() 136 { 137 return fieldCumulusConnectionPool; 138 } 139 public void setCumulusConnectionPool(CumulusConnectionPool inCumulusConnectionPool) 140 { 141 fieldCumulusConnectionPool = inCumulusConnectionPool; 142 } 143 144 145 protected void dump(String type , com.canto.cumulus.Category inCat) throws Exception 146 { 147 log.info("category: "+ type + "|" + inCat.getName()); 149 dumpFields( type + "|" + inCat.getName(), inCat.getFields()); 150 for (int i = 0; i < inCat.getSubCategories().countCategories(); i++) 151 { 152 dump(type + "|" + inCat.getName(), inCat.getSubCategories().getCategory(i)); 153 } 154 } 155 protected void dumpFields(String type , Fields inFields) throws Exception 156 { 157 for (int i = 0; i < inFields.countFields(); i++) 159 { 160 Field field = inFields.getField(i); 161 log.info("field:" + type + ":" + field.getFieldDefinition().getName()); 162 if (field.getFieldDefinition().getName().equals("Live Filtering Record Query")) 163 { 164 log.info("field:" + type + ":" + field.getFieldDefinition().getName()); 165 if( field.hasValue() ) { 166 log.info("value:" + type + ":" + String.valueOf( field.getValue() )); 167 } 168 } 169 } 170 } 171 172 } 173 | Popular Tags |