Source Code Cross Referenced for SchemaModel.java in  » Portal » Open-Portal » com » sun » portal » search » admin » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.search.admin.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.search.admin.model;
007:
008:        import java.lang.*;
009:        import java.util.*;
010:        import java.util.logging.Logger;
011:        import java.util.logging.Level;
012:        import java.util.logging.LogRecord;
013:        import java.io.*;
014:
015:        import javax.servlet.http.HttpServletRequest;
016:
017:        import com.iplanet.jato.view.*;
018:        import com.iplanet.jato.view.html.*;
019:        import com.iplanet.jato.model.*;
020:        import com.iplanet.jato.util.*;
021:
022:        import com.sun.portal.search.soif.*;
023:        import com.sun.portal.search.rdm.*;
024:        import com.sun.portal.search.rdmserver.*;
025:        import com.sun.portal.search.util.SearchConfig;
026:        import com.sun.portal.search.admin.CSConfig;
027:
028:        import com.sun.portal.search.admin.model.*;
029:        import com.sun.portal.log.common.PortalLogger;
030:
031:        public class SchemaModel extends DefaultModel {
032:            private String name = "";
033:            private String oldName = "";
034:            private String description = "";
035:            private String multiplier = null;
036:            private String aliases = "";
037:            private boolean editable = false;
038:            private boolean indexable = false;
039:            private String dataType = "";
040:            private static RDMSchema schema;
041:            private String edit = "";
042:            private String index = "";
043:            private String schfn = "";
044:            private String errMsg = null;
045:            public final String DEFAULT_TYPE = "string";
046:            public static final String[] DATA_TYPES = { "blob", "date", "int",
047:                    "string" };
048:
049:            // Create a Logger for this class
050:            private static Logger debugLogger = PortalLogger
051:                    .getLogger(SchemaModel.class);
052:
053:            public SchemaModel() {
054:                super ();
055:                loadSchema();
056:                this .name = "New";
057:            }
058:
059:            public SchemaModel(String name) {
060:                super (name);
061:                loadSchema();
062:                this .name = name;
063:                oldName = name;
064:            }
065:
066:            public String getErrorMessage() {
067:                return errMsg;
068:            }
069:
070:            public void initializeValues() {
071:                /*
072:                 * Sample arr list would be
073:                 * Author : Classification : Expires : ReadACL :
074:                 * gV-Discussion-Id : gV-Last-Modified : gV-Rating :
075:                 * gV-Reference-Id : Keywords : Last-Modified :
076:                 * RD-Expires : RD-Last-Modified : Title : URL
077:                 */
078:
079:                String[] arr = schema.schema_nonInternal_attrs();
080:                if (arr.length > 0)
081:                    name = arr[0];
082:            }
083:
084:            public boolean doAdd() {
085:                int col = schema.getColumnNumber(name);
086:                // if the schema field does not already exist
087:                if (col == -1) {
088:                    int num = schema.getNumEntriesInt();
089:                    col = schema.getMaxIndex() + 1;
090:                    schema.setSOIFAttribute(col, name);
091:                    schema.setColumnName(col, name);
092:                    schema.setSysColumnName(col, name);
093:                    schema.setTableName(col, "Documents");
094:                    schema.setSysTableName(col, "doctbl");
095:                    schema.setDescription(col, description);
096:                    schema.setAliases(col, aliases);
097:                    schema.setEditAttribute(col, edit);
098:                    schema.setIndexAttribute(col, index);
099:                    schema.setNumEntries(String.valueOf(num + 1));
100:                    if (multiplier != null) {
101:                        schema.setValue(name, RDM.A_RDM_SCORE_MULTIPLIER,
102:                                multiplier);
103:                    }
104:
105:                    debugLogger.log(Level.FINER, "PSSH_CSPSAM0043",
106:                            new String[] { Integer.toString(col), name,
107:                                    description, aliases, edit, index });
108:
109:                    saveSchema();
110:                    return true;
111:                }
112:                errMsg = "schema.error.duplicate";
113:                return false;
114:            }
115:
116:            public boolean validateSchema() {
117:                if (name.trim().equals("")) {
118:                    errMsg = "schema.error.emptyname";
119:                    return false;
120:                }
121:
122:                for (int i = 0; i < name.length(); i++) {
123:                    char c = name.charAt(i);
124:                    if ((!Character.isLetterOrDigit(c)) && (c != '.')
125:                            && (c != '_') && (c != '-')) {
126:
127:                        errMsg = "schema.error.invalidcharinname";
128:                        return false;
129:                    }
130:                }
131:                if (indexable && multiplier != null) {
132:                    try {
133:                        Float f = new Float(multiplier);
134:                        if (f.doubleValue() < 0.0) {
135:                            errMsg = "schema.error.negativemultiplier";
136:                            return false;
137:                        }
138:                    } catch (NumberFormatException e) {
139:                        errMsg = "schema.error.invalidmultiplier";
140:                        return false;
141:                    }
142:                }
143:
144:                return true;
145:            }
146:
147:            public boolean doUpdate() {
148:
149:                debugLogger.log(Level.FINER, "PSSH_CSPSAM0044", new String[] {
150:                        name, description, aliases, edit, index });
151:                if (!validateSchema()) {
152:                    return false;
153:                }
154:
155:                try {
156:                    int col = schema.getColumnNumber(oldName);
157:                    if (col == -1) {
158:                        return this .doAdd();
159:                    } else {
160:                        int newcol = schema.getColumnNumber(name);
161:                        if (oldName.equals(name) || newcol == -1) {
162:                            schema.setSOIFAttribute(col, name);
163:                            schema.setColumnName(col, name);
164:                            schema.setSysColumnName(col, name);
165:                            schema.setDescription(col, description);
166:                            schema.setAliases(col, aliases);
167:                            schema.setEditAttribute(col, edit);
168:                            schema.setIndexAttribute(col, index);
169:                            schema.setDataType(col, dataType);
170:                            schema.setValue(name, RDM.A_RDM_SCORE_MULTIPLIER,
171:                                    multiplier);
172:                            saveSchema();
173:                            debugLogger.log(Level.FINER, "PSSH_CSPSAM0045",
174:                                    new String[] { oldName, name });
175:                            return true;
176:                        }
177:                        errMsg = "schema.error.duplicate";
178:                        return false;
179:                    }
180:                } catch (Exception e) {
181:                    return false;
182:                }
183:            }
184:
185:            public void doDelete() {
186:
187:                debugLogger.log(Level.FINER, "PSSH_CSPSAM0044", new String[] {
188:                        name, description, aliases, edit, index });
189:                schema.deleteColumn(name);
190:                saveSchema();
191:            }
192:
193:            /*public OptionList getSchemaLst() {
194:            String[] arr = schema.schema_nonInternal_attrs();
195:            try {
196:                Arrays.sort(arr);
197:            } catch (ClassCastException e) {
198:               CSDebug.logln("Error in sorting schema");
199:
200:            }
201:            schemaLst = new OptionList(arr, arr);
202:            return schemaLst;
203:            }
204:             */
205:            /*    public void setSchemaLst(OptionList sch) {
206:             this.schemaLst = sch;
207:             }
208:             */
209:            public String getName() {
210:                return name;
211:            }
212:
213:            public void setName(String n) {
214:                this .name = n;
215:            }
216:
217:            public String getDescription() {
218:                if (name.equals(""))
219:                    return "";
220:                description = schema.getValue(name, RDM.A_RDM_DESC_ATTR);
221:                return (description == null ? "" : description);
222:            }
223:
224:            public String getMultiplier() {
225:                if (name.equals(""))
226:                    return "";
227:                multiplier = schema.getValue(name, RDM.A_RDM_SCORE_MULTIPLIER);
228:                return (multiplier == null ? "" : multiplier);
229:            }
230:
231:            public String getAliases() {
232:                if (name.equals(""))
233:                    return "";
234:                aliases = schema.getValue(name, RDM.A_RDM_ALIASES);
235:                return (aliases == null ? "" : aliases);
236:            }
237:
238:            public void setDescription(String desc) {
239:                this .description = desc;
240:            }
241:
242:            public void setMultiplier(String multip) {
243:                if (multip.trim().length() > 0) {
244:                    multiplier = multip;
245:                }
246:            }
247:
248:            public void setAliases(String desc) {
249:                this .aliases = desc;
250:            }
251:
252:            public boolean getEditable() {
253:                if (name.equals(""))
254:                    return false;
255:                edit = schema.getValue(name, RDM.A_RDM_EDIT_ATTR);
256:                if (edit != null) {
257:                    if (edit.equals("1"))
258:                        return true;
259:                }
260:                return false;
261:            }
262:
263:            public void setEditable(boolean b) {
264:                this .editable = b;
265:                if (editable)
266:                    edit = "1";
267:                else
268:                    edit = "0";
269:            }
270:
271:            public boolean getIndexable() {
272:                if (name.equals(""))
273:                    return false;
274:                index = schema.getValue(name, RDM.A_RDM_INDEX_ATTR);
275:                if (index != null) {
276:                    if (index.equals("1"))
277:                        return true;
278:                }
279:                return false;
280:            }
281:
282:            public void setIndexable(boolean b) {
283:                this .indexable = b;
284:                if (indexable)
285:                    index = "1";
286:                else
287:                    index = "0";
288:            }
289:
290:            public String getDataType() {
291:                String type = schema.getValue(name, RDM.A_RDM_DATA_TYPE);
292:                if (type != null) {
293:                    return type;
294:                }
295:                return DEFAULT_TYPE;
296:            }
297:
298:            public void setDataType(String type) {
299:                dataType = type;
300:            }
301:
302:            public void saveSchema() {
303:                try {
304:                    SOIFOutputStream ss = new SOIFOutputStream(schfn);
305:                    ss.write(schema.getSOIF());
306:                } catch (Exception e) {
307:                    if (debugLogger.isLoggable(Level.INFO)) {
308:                        LogRecord logRecord = new LogRecord(Level.INFO,
309:                                "PSSH_CSPSAM0046");
310:                        logRecord.setParameters(new String[] { schfn });
311:                        logRecord.setThrown(e);
312:                        logRecord.setLoggerName(debugLogger.getName());
313:                        debugLogger.log(logRecord);
314:                    }
315:                }
316:            }
317:
318:            public void loadSchema() {
319:                String csidfn = CSConfig.getServerRoot() + File.separator
320:                        + SearchConfig.CONFDIR + File.separator
321:                        + SearchConfig.SEARCH_CONF;
322:                try {
323:                    SearchConfig.init(csidfn);
324:                } catch (Exception e) {
325:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0047", csidfn);
326:                }
327:
328:                if ((schfn = SearchConfig.getValue(SearchConfig.SCHEMA)) == null) {
329:                    debugLogger.finer("PSSH_CSPSAM0048");
330:                }
331:
332:                // Load the schema
333:                debugLogger.log(Level.FINER, "PSSH_CSPSAM0041", schfn);
334:                SOIFInputStream ss = null;
335:                try {
336:                    ss = new SOIFInputStream(schfn);
337:                } catch (Exception e) {
338:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0042", schfn);
339:                }
340:
341:                try {
342:                    schema = new RDMSchema(ss.readSOIF());
343:                } catch (Exception e) {
344:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0049", schfn);
345:                }
346:
347:                //printSchema();
348:            }
349:
350:            public static void printSchema() {
351:                String[] arr = schema.schema_nonInternal_attrs();
352:
353:                for (int i = 0; i < arr.length; i++) {
354:                    String s = arr[i];
355:                    int col = schema.getColumnNumber(s);
356:                    String d = schema.getDescription(col);
357:                    String aliases = schema.getAliases(col);
358:                    String edit = schema.getEditAttribute(col);
359:                    String index = schema.getIndexAttribute(col);
360:                    debugLogger.log(Level.FINER, "PSSH_CSPSAM0043",
361:                            new String[] { Integer.toString(col), s, d,
362:                                    aliases, edit, index });
363:                }
364:            }
365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.