KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > archive > cumulus > BaseCumulusConvert


1 /*
2  * Created on Mar 24, 2006
3  */

4 package com.openedit.archive.cumulus;
5
6 import java.util.Iterator JavaDoc;
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 JavaDoc inCatId, Configuration inConfig)
37     {
38         for (Iterator JavaDoc 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 JavaDoc extractId( String JavaDoc inName)
52     {
53         StringBuffer JavaDoc out = new StringBuffer JavaDoc(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 JavaDoc result = out.toString().toLowerCase();
63         return result;
64     }
65     public String JavaDoc extractProductId(String JavaDoc name, String JavaDoc 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 JavaDoc
80     {
81         return getCumulusConnectionPool().getServerCatalogs();
82     }
83
84     public String JavaDoc getValue( Field inField)
85     {
86         if ( inField==null || !inField.hasValue())
87         {
88             return null;
89         }
90         Object JavaDoc val;
91         try
92         {
93             val = inField.getValue();
94             if( val instanceof String JavaDoc)
95             {
96                 String JavaDoc scrub = scrubChars((String JavaDoc)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 JavaDoc scrubChars(String JavaDoc inVal)
112     {
113         StringBuffer JavaDoc done = new StringBuffer JavaDoc(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); //these are safe
123
break;
124                  default:
125                  {
126                     if (c > 31) //other skip unless over 31
127
{
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 JavaDoc type , com.canto.cumulus.Category inCat) throws Exception JavaDoc
146     {
147         // TODO Auto-generated method stub
148
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 JavaDoc type , Fields inFields) throws Exception JavaDoc
156     {
157         // TODO Auto-generated method stub
158
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