Source Code Cross Referenced for XmlSearchConfig.java in  » Search-Engine » regain » net » sf » regain » search » config » 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 » Search Engine » regain » net.sf.regain.search.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CVS information:
003:         *  $RCSfile$
004:         *   $Source$
005:         *     $Date: 2005-08-18 10:01:39 +0200 (Do, 18 Aug 2005) $
006:         *   $Author: til132 $
007:         * $Revision: 172 $
008:         */
009:        package net.sf.regain.search.config;
010:
011:        import java.io.File;
012:        import java.util.ArrayList;
013:        import java.util.HashMap;
014:        import java.util.Properties;
015:
016:        import net.sf.regain.RegainException;
017:        import net.sf.regain.XmlToolkit;
018:
019:        import org.w3c.dom.Document;
020:        import org.w3c.dom.Element;
021:        import org.w3c.dom.Node;
022:
023:        /**
024:         * 
025:         * @author Tilman Schneider, STZ-IDA an der FH Karlsruhe
026:         */
027:        public class XmlSearchConfig implements  SearchConfig {
028:
029:            /** All configured indexes. */
030:            private HashMap mIndexHash;
031:
032:            /** The names of the default indexes. */
033:            private String[] mDefaultIndexNameArr;
034:
035:            /**
036:             * Creates a new instance of XmlSearchConfig.
037:             * 
038:             * @param xmlFile The XML file to read the config from.
039:             * @throws RegainException If reading the config failed.
040:             */
041:            public XmlSearchConfig(File xmlFile) throws RegainException {
042:                Document doc = XmlToolkit.loadXmlDocument(xmlFile);
043:                Element config = doc.getDocumentElement();
044:
045:                readIndexList(config);
046:            }
047:
048:            /**
049:             * Reads the search indexes from the config.
050:             *
051:             * @param config The configuration to read from.
052:             * @throws RegainException If the configration has errors.
053:             */
054:            private void readIndexList(Element config) throws RegainException {
055:                Node node;
056:
057:                Node listNode = XmlToolkit.getChild(config, "indexList", true);
058:
059:                // Get the node that holds the default settings for all indexes
060:                Node defaultNode = XmlToolkit.getChild(listNode,
061:                        "defaultSettings");
062:
063:                // Get the index nodes
064:                mIndexHash = new HashMap();
065:                ArrayList defaultIndexNameList = new ArrayList();
066:                Node[] nodeArr = XmlToolkit.getChildArr(listNode, "index");
067:                for (int indexIdx = 0; indexIdx < nodeArr.length; indexIdx++) {
068:                    Node indexNode = nodeArr[indexIdx];
069:
070:                    String indexName = XmlToolkit.getAttribute(indexNode,
071:                            "name", true);
072:                    String directory = XmlToolkit.getChildText(indexNode,
073:                            "dir", true);
074:
075:                    // Read the openInNewWindowRegex
076:                    node = XmlToolkit.getCascadedChild(indexNode, defaultNode,
077:                            "openInNewWindowRegex", true);
078:                    String openInNewWindowRegex = XmlToolkit
079:                            .getText(node, true);
080:
081:                    // Read the useFileToHttpBridge
082:                    node = XmlToolkit.getCascadedChild(indexNode, defaultNode,
083:                            "useFileToHttpBridge");
084:                    boolean useFileToHttpBridge = true;
085:                    if (node != null) {
086:                        useFileToHttpBridge = XmlToolkit.getTextAsBoolean(node);
087:                    }
088:
089:                    // Read the search field list
090:                    node = XmlToolkit.getCascadedChild(indexNode, defaultNode,
091:                            "searchFieldList");
092:                    String[] searchFieldList = null;
093:                    if (node != null) {
094:                        searchFieldList = XmlToolkit.getTextAsWordList(node,
095:                                true);
096:                    }
097:
098:                    // Read the rewrite rules
099:                    node = XmlToolkit.getCascadedChild(indexNode, defaultNode,
100:                            "rewriteRules");
101:                    String[][] rewriteRules = readRewriteRules(node);
102:
103:                    // Read the SearchAccessController
104:                    String searchAccessControllerClass = null;
105:                    String searchAccessControllerJar = null;
106:                    Properties searchAccessControllerConfig = null;
107:                    node = XmlToolkit.getCascadedChild(indexNode, defaultNode,
108:                            "searchAccessController");
109:                    if (node != null) {
110:                        Node classNode = XmlToolkit.getChild(node, "class",
111:                                true);
112:                        searchAccessControllerClass = XmlToolkit.getText(
113:                                classNode, true);
114:                        searchAccessControllerJar = XmlToolkit.getAttribute(
115:                                classNode, "jar");
116:
117:                        Node configNode = XmlToolkit.getChild(node, "config");
118:                        if (configNode != null) {
119:                            searchAccessControllerConfig = new Properties();
120:                            Node[] paramNodeArr = XmlToolkit.getChildArr(
121:                                    configNode, "param");
122:                            for (int i = 0; i < paramNodeArr.length; i++) {
123:                                String name = XmlToolkit.getAttribute(
124:                                        paramNodeArr[i], "name", true);
125:                                String value = XmlToolkit.getText(
126:                                        paramNodeArr[i], true);
127:                                searchAccessControllerConfig.setProperty(name,
128:                                        value);
129:                            }
130:                        }
131:                    }
132:
133:                    // Create the index config
134:                    IndexConfig indexConfig = new IndexConfig(indexName,
135:                            directory, openInNewWindowRegex,
136:                            useFileToHttpBridge, searchFieldList, rewriteRules,
137:                            searchAccessControllerClass,
138:                            searchAccessControllerJar,
139:                            searchAccessControllerConfig);
140:                    mIndexHash.put(indexName, indexConfig);
141:
142:                    // Check whether this index is default
143:                    boolean isDefault = XmlToolkit.getAttributeAsBoolean(
144:                            indexNode, "default", false);
145:                    if (isDefault) {
146:                        defaultIndexNameList.add(indexName);
147:                    }
148:                }
149:
150:                // Store the default indexes into an array
151:                mDefaultIndexNameArr = new String[defaultIndexNameList.size()];
152:                defaultIndexNameList.toArray(mDefaultIndexNameArr);
153:            }
154:
155:            /**
156:             * Reads the URL rewrite rules from a node
157:             * 
158:             * @param node The node to read from.
159:             * @return The rewrite rules. May be null.
160:             * @throws RegainException If the configration has errors.
161:             */
162:            private String[][] readRewriteRules(Node node)
163:                    throws RegainException {
164:                if (node == null) {
165:                    return null;
166:                }
167:
168:                Node[] ruleNodeArr = XmlToolkit.getChildArr(node, "rule");
169:                String[][] rewriteRules = new String[ruleNodeArr.length][];
170:                for (int i = 0; i < ruleNodeArr.length; i++) {
171:                    String prefix = XmlToolkit.getAttribute(ruleNodeArr[i],
172:                            "prefix", true);
173:                    String replacement = XmlToolkit.getAttribute(
174:                            ruleNodeArr[i], "replacement", true);
175:
176:                    // Add this rule
177:                    rewriteRules[i] = new String[] { prefix, replacement };
178:                }
179:
180:                return rewriteRules;
181:            }
182:
183:            /**
184:             * Gets the configuration for an index.
185:             * 
186:             * @param indexName The name of the index to get the config for.
187:             * @return The configuration for the wanted index or <code>null</code> if
188:             *         there is no such index configured.
189:             */
190:            public IndexConfig getIndexConfig(String indexName) {
191:                return (IndexConfig) mIndexHash.get(indexName);
192:            }
193:
194:            /**
195:             * Gets the names of the default indexes.
196:             * 
197:             * @return The names of the default indexes or an empty array if no default
198:             *         index was specified.
199:             */
200:            public String[] getDefaultIndexNameArr() {
201:                return mDefaultIndexNameArr;
202:            }
203:
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.