Source Code Cross Referenced for LiusConfigBuilder.java in  » Search-Engine » Lius-0.4 » ca » ulaval » bibl » lius » 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 » Lius 0.4 » ca.ulaval.bibl.lius.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:
0003:         * LIUS - Lucene Index Update and Search
0004:         * http://sourceforge.net/projects/lius/
0005:         *
0006:         * Copyright (c) 2005, Laval University Library.  All rights reserved.
0007:         * 
0008:         * This library is free software; you can redistribute it and/or
0009:         * modify it under the terms of the GNU Lesser General Public
0010:         * License as published by the Free Software Foundation; either
0011:         * version 2.1 of the License, or (at your option) any later version.
0012:         * 
0013:         * This library is distributed in the hope that it will be useful,
0014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016:         * Lesser General Public License for more details.
0017:         * 
0018:         * You should have received a copy of the GNU Lesser General Public
0019:         * License along with this library; if not, write to the Free Software
0020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0021:         */
0022:
0023:        package ca.ulaval.bibl.lius.config;
0024:
0025:        import java.io.File;
0026:        import java.io.IOException;
0027:        import java.util.ArrayList;
0028:        import java.util.Collection;
0029:        import java.util.HashMap;
0030:        import java.util.Iterator;
0031:        import java.util.List;
0032:        import java.util.Map;
0033:        import java.util.Vector;
0034:
0035:        import org.apache.log4j.Logger;
0036:        import org.jdom.Attribute;
0037:        import org.jdom.Document;
0038:        import org.jdom.Element;
0039:        import org.jdom.JDOMException;
0040:        import org.jdom.input.SAXBuilder;
0041:        import org.jdom.xpath.XPath;
0042:
0043:        /**
0044:         * 
0045:         * Classe permettant de parser le fichier de configuration. <br/><br/>Class for
0046:         * 
0047:         * parsing configuration file.
0048:         * 
0049:         * 
0050:         * 
0051:         * Changelog:
0052:         * 
0053:         * 2005/06/02: added support for VCardIndexer and TexIndexer (jf)
0054:         * 
0055:         * 2005/06/03: added support for FontIndexer (jf)
0056:         * 
0057:         * 
0058:         * 
0059:         * 
0060:         * 
0061:         * @author Rida Benjelloun (rida.benjelloun@bibl.ulaval.ca)
0062:         *  
0063:         */
0064:
0065:        public class LiusConfigBuilder {
0066:
0067:            static Logger logger = Logger.getRootLogger();
0068:
0069:            private LiusConfig xc = null;
0070:
0071:            private String oldFile = null;
0072:
0073:            private static LiusConfigBuilder liusConfigBuilder;
0074:
0075:            private HashMap configsCach = new HashMap();
0076:
0077:            private LiusConfigBuilder() {
0078:            }
0079:
0080:            public static LiusConfigBuilder getSingletonInstance() {
0081:
0082:                if (liusConfigBuilder == null)
0083:
0084:                    liusConfigBuilder = new LiusConfigBuilder();
0085:
0086:                return liusConfigBuilder;
0087:
0088:            }
0089:
0090:            protected Document parse(String file) {
0091:
0092:                org.jdom.Document xmlDoc = new org.jdom.Document();
0093:
0094:                try {
0095:
0096:                    SAXBuilder builder = new SAXBuilder();
0097:
0098:                    xmlDoc = builder.build(new File(file));
0099:
0100:                } catch (JDOMException e) {
0101:
0102:                    logger.error(e.getMessage());
0103:
0104:                } catch (IOException e) {
0105:
0106:                    logger.error(e.getMessage());
0107:
0108:                }
0109:
0110:                return xmlDoc;
0111:
0112:            }
0113:
0114:            /**
0115:             * 
0116:             * Méthode permettant de parser le fichier de configuration et de retourner
0117:             * 
0118:             * un objet de type LiusConfig. <br/><br/>Method for parsing the
0119:             * 
0120:             * configuration file, returns a LiusConfig object.
0121:             *  
0122:             */
0123:
0124:            public LiusConfig getLiusConfig(String xmlConfigFile) {
0125:
0126:                if (configsCach.get(xmlConfigFile) != null) {
0127:
0128:                    return (LiusConfig) configsCach.get(xmlConfigFile);
0129:
0130:                } else {
0131:
0132:                    Document doc = parse(xmlConfigFile);
0133:
0134:                    xc = new LiusConfig();
0135:
0136:                    populateLiusConfig(doc, xc);
0137:
0138:                    configsCach.put(xmlConfigFile, xc);
0139:
0140:                }
0141:
0142:                return xc;
0143:
0144:            }
0145:
0146:            private void populateLiusConfig(Document doc, LiusConfig xc) {
0147:
0148:                xc.setAnalyzer(getAnlyzerClassString(doc));
0149:
0150:                xc.setStopWord(getStopWordValue(doc));
0151:
0152:                xc.setValueCreateIndex(getCreateIndexValue(doc));
0153:
0154:                xc.setMergeFactor(getMergeFactorValue(doc));
0155:
0156:                xc.setMaxMergeDocs(getMaxMergeDocs(doc));
0157:
0158:                xc.setOptimizeValue(getOptimizeValue(doc));
0159:
0160:                xc.setXmlFileFields(getXmlFileFields(doc));
0161:
0162:                xc.setXmlNodesFields(getXmlNodesFields(doc));
0163:
0164:                xc.setDisplayFields(getDisplayFields(doc));
0165:
0166:                xc.setElemSearch(getQueryType(doc, xc));
0167:
0168:                xc.setJavaBeansFields(getJavaBeansFields(doc));
0169:
0170:                xc.setPdfFields(getPdfFields(doc));
0171:
0172:                xc.setMsWordFields(getMsWordFields(doc));
0173:
0174:                xc.setHtmlFields(getHtmlFields(doc));
0175:
0176:                xc.setMixteIndexingElements(getMixteIndexingElements(doc));
0177:
0178:                xc.setRtfFields(getRtfFields(doc));
0179:
0180:                xc.setExcelFields(getExcelFields(doc));
0181:
0182:                xc.setTxtFields(getTxtFields(doc));
0183:
0184:                xc.setOOFields(getOOFields(doc));
0185:
0186:                xc.setPPTFields(getPPTFields(doc));
0187:
0188:                xc.setMP3Fields(getMP3Fields(doc));
0189:
0190:                xc.setTexFields(getTexFields(doc));
0191:
0192:                xc.setVCardFields(getVCardFields(doc));
0193:
0194:                xc.setFontFields(getFontFields(doc));
0195:
0196:                xc.setHighlighter(getHighlighter(doc));
0197:
0198:            }
0199:
0200:            /**
0201:             * 
0202:             * Méthode permettant de récupérer l'analyseur à partir du fichier XML.
0203:             * 
0204:             * <br/><br/>Method for getting the analyser from XML file.
0205:             *  
0206:             */
0207:
0208:            public String getAnlyzerClassString(Document doc) {
0209:
0210:                String className = null;
0211:
0212:                try {
0213:
0214:                    Attribute classN = (Attribute) XPath.selectSingleNode(doc,
0215:
0216:                    "//properties/analyzer/@class");
0217:
0218:                    if (classN != null)
0219:
0220:                        className = classN.getValue();
0221:
0222:                } catch (JDOMException e) {
0223:
0224:                    logger.error(e.getMessage());
0225:
0226:                }
0227:
0228:                return className;
0229:
0230:            }
0231:
0232:            public boolean getHighlighter(Document doc) {
0233:
0234:                String highlightValue = null;
0235:
0236:                boolean highlight = false;
0237:
0238:                try {
0239:
0240:                    Attribute highlightAttr = (Attribute) XPath
0241:                            .selectSingleNode(doc,
0242:
0243:                            "//fieldsToDisplay/@setHighlighter");
0244:
0245:                    if (highlightAttr != null) {
0246:
0247:                        highlightValue = highlightAttr.getValue();
0248:
0249:                        if (highlightValue.equalsIgnoreCase("true"))
0250:
0251:                            highlight = true;
0252:
0253:                    }
0254:
0255:                } catch (JDOMException e) {
0256:
0257:                    logger.error(e.getMessage());
0258:
0259:                }
0260:
0261:                return highlight;
0262:
0263:            }
0264:
0265:            /**
0266:             * 
0267:             * Méthode permettant de récupérer la valeur de création de l'index (true,
0268:             * 
0269:             * false ou auto) dans le fichier de configuration. <br/><br/>Method for
0270:             * 
0271:             * getting the creation value of index (true, false, auto) in the
0272:             * 
0273:             * configuration file.
0274:             *  
0275:             */
0276:
0277:            public String getCreateIndexValue(Document doc) {
0278:
0279:                String createIndexValue = null;
0280:
0281:                try {
0282:
0283:                    Attribute createIndexV = (Attribute) XPath
0284:                            .selectSingleNode(doc,
0285:
0286:                            "//properties/createIndex/@value");
0287:
0288:                    createIndexValue = createIndexV.getValue();
0289:
0290:                } catch (JDOMException e) {
0291:
0292:                    logger.error(e.getMessage());
0293:
0294:                }
0295:
0296:                return createIndexValue;
0297:
0298:            }
0299:
0300:            /**
0301:             * 
0302:             * Méthode permettant de récupérer la valeur du mergeFactor dans le fichier
0303:             * 
0304:             * de configuration. <br/><br/>Method for getting mergeFactor value in
0305:             * 
0306:             * configuration file.
0307:             *  
0308:             */
0309:
0310:            public String getMergeFactorValue(Document doc) {
0311:
0312:                String mergeFactorValue = "";
0313:
0314:                try {
0315:
0316:                    Attribute mergeFactor = (Attribute) XPath.selectSingleNode(
0317:                            doc,
0318:
0319:                            "//indexWriterProperty/@mergeFactor");
0320:
0321:                    if (mergeFactor != null)
0322:
0323:                        mergeFactorValue = mergeFactor.getValue();
0324:
0325:                    else
0326:
0327:                        return mergeFactorValue = null;
0328:
0329:                } catch (JDOMException e) {
0330:
0331:                    logger.error(e.getMessage());
0332:
0333:                }
0334:
0335:                return mergeFactorValue;
0336:
0337:            }
0338:
0339:            /**
0340:             * 
0341:             * Méthode permettant de récupérer la valeur du maxMergeDocs dans le fichier
0342:             * 
0343:             * de configuration. <br/><br/>Method for getting the maxMergeDocs value in
0344:             * 
0345:             * the configuration file.
0346:             *  
0347:             */
0348:
0349:            public String getMaxMergeDocs(Document doc) {
0350:
0351:                String maxMergeDocsValue = "";
0352:
0353:                try {
0354:
0355:                    Attribute maxMergeDocs = (Attribute) XPath
0356:                            .selectSingleNode(doc,
0357:
0358:                            "//indexWriterProperty/@maxMergeDocs");
0359:
0360:                    if (maxMergeDocs != null)
0361:
0362:                        maxMergeDocsValue = maxMergeDocs.getValue();
0363:
0364:                    else
0365:
0366:                        return maxMergeDocsValue = null;
0367:
0368:                } catch (JDOMException e) {
0369:
0370:                    logger.error(e.getMessage());
0371:
0372:                }
0373:
0374:                return maxMergeDocsValue;
0375:
0376:            }
0377:
0378:            public String[] getSortField(Document doc) {
0379:
0380:                String[] sortFields = null;
0381:
0382:                try {
0383:
0384:                    Attribute searchSort = (Attribute) XPath.selectSingleNode(
0385:                            doc,
0386:
0387:                            "//searchResult/@sortBy");
0388:
0389:                    if (searchSort != null) {
0390:
0391:                        String attrContent = searchSort.getValue().trim();
0392:
0393:                        sortFields = attrContent.split(",");
0394:
0395:                    }
0396:
0397:                } catch (JDOMException e) {
0398:
0399:                    logger.error(e.getMessage());
0400:
0401:                }
0402:
0403:                return sortFields;
0404:
0405:            }
0406:
0407:            /**
0408:             * 
0409:             * Méthode permettant de récupérer la valeur d'optimize dans le fichier de
0410:             * 
0411:             * configuration. <br/><br/>Method for getting the optimize value in the
0412:             * 
0413:             * configuration file.
0414:             *  
0415:             */
0416:
0417:            public String getOptimizeValue(Document doc) {
0418:
0419:                String optimizeValue = "";
0420:
0421:                try {
0422:
0423:                    Attribute optimize = (Attribute) XPath.selectSingleNode(
0424:                            doc,
0425:
0426:                            "//indexWriterProperty/@optimize");
0427:
0428:                    if (optimize != null)
0429:
0430:                        optimizeValue = optimize.getValue();
0431:
0432:                    else
0433:
0434:                        return optimizeValue = null;
0435:
0436:                } catch (JDOMException e) {
0437:
0438:                    logger.error(e.getMessage());
0439:
0440:                }
0441:
0442:                return optimizeValue;
0443:
0444:            }
0445:
0446:            /**
0447:             * 
0448:             * Méthode permettant de retourner une collection d'objets LiusField à
0449:             * 
0450:             * partir du fichier XML si l'élément "xmlFile" existe. <br/><br/>Method
0451:             * 
0452:             * returning a Collection of LiusField objects from the XML file if the
0453:             * 
0454:             * element xmlFile exists.
0455:             *  
0456:             */
0457:
0458:            private Collection getXmlFileFields(Document doc) {
0459:
0460:                Collection res = new ArrayList();
0461:
0462:                HashMap hm = new HashMap();
0463:
0464:                try {
0465:
0466:                    List ls = XPath.selectNodes(doc, "//xmlFile");
0467:
0468:                    Iterator i = ls.iterator();
0469:
0470:                    while (i.hasNext()) {
0471:
0472:                        Collection coll = new ArrayList();
0473:
0474:                        Element elemNode = (Element) i.next();
0475:
0476:                        List fieldList = XPath.selectNodes(elemNode,
0477:                                "luceneField");
0478:
0479:                        for (int j = 0; j < fieldList.size(); j++) {
0480:
0481:                            Element elem = (Element) fieldList.get(j);
0482:
0483:                            LiusField lf = buildLiusField(elem);
0484:
0485:                            coll.add(lf);
0486:
0487:                        }
0488:
0489:                        if (elemNode.getAttributeValue("setBoost") != null) {
0490:
0491:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
0492:
0493:                            ldp
0494:                                    .setBoost(elemNode
0495:                                            .getAttributeValue("setBoost"));
0496:
0497:                            coll.add(ldp);
0498:
0499:                        }
0500:
0501:                        hm.put(elemNode.getAttributeValue("ns"), coll);
0502:
0503:                    }
0504:
0505:                } catch (JDOMException e) {
0506:
0507:                    logger.error(e.getMessage());
0508:
0509:                }
0510:
0511:                res.add(hm);
0512:
0513:                return res;
0514:
0515:            }
0516:
0517:            /**
0518:             * 
0519:             * Méthode permettant de retourner un HashMap contenant comme clé
0520:             * 
0521:             * l'expression XPATH du noeud à indexer, et comme valeur une collection
0522:             * 
0523:             * d'objets de type LiusField. <br/><br/>Method returning an HashMap which
0524:             * 
0525:             * key containing the XPath expression for the node to index and for value a
0526:             * 
0527:             * Collection of LiusField objects.
0528:             *  
0529:             */
0530:
0531:            private HashMap getXmlNodesFields(Document doc) {
0532:
0533:                HashMap hm = new HashMap();
0534:
0535:                try {
0536:
0537:                    List ls = XPath.selectNodes(doc, "//node");
0538:
0539:                    Iterator i = ls.iterator();
0540:
0541:                    while (i.hasNext()) {
0542:
0543:                        Collection coll = new ArrayList();
0544:
0545:                        Element elemNode = (Element) i.next();
0546:
0547:                        List fieldList = XPath.selectNodes(elemNode,
0548:                                "luceneField");
0549:
0550:                        for (int j = 0; j < fieldList.size(); j++) {
0551:
0552:                            Element elem = (Element) fieldList.get(j);
0553:
0554:                            LiusField lf = buildLiusField(elem);
0555:
0556:                            coll.add(lf);
0557:
0558:                        }
0559:
0560:                        if (elemNode.getAttributeValue("setBoost") != null) {
0561:
0562:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
0563:
0564:                            ldp
0565:                                    .setBoost(elemNode
0566:                                            .getAttributeValue("setBoost"));
0567:
0568:                            coll.add(ldp);
0569:
0570:                        }
0571:
0572:                        hm.put(elemNode.getAttributeValue("select"), coll);
0573:
0574:                    }
0575:
0576:                } catch (JDOMException e) {
0577:
0578:                    logger.error(e.getMessage());
0579:
0580:                }
0581:
0582:                return hm;
0583:
0584:            }
0585:
0586:            /**
0587:             * 
0588:             * Méthode permettant de retourner un tableau de mots vides à partir de
0589:             * 
0590:             * l'élément "stopWord". <br/><br/>Method that returns an array of stop
0591:             * 
0592:             * words from the element "stopWord".
0593:             *  
0594:             */
0595:
0596:            public String[] getStopWordValue(Document doc) {
0597:
0598:                String[] stopWords = null;
0599:
0600:                String stopWordsString = null;
0601:
0602:                String sep = null;
0603:
0604:                try {
0605:
0606:                    Element elem = (Element) XPath.selectSingleNode(doc,
0607:                            "//stopWord");
0608:
0609:                    if (elem != null) {
0610:
0611:                        stopWordsString = elem.getText().trim();
0612:
0613:                        Attribute att = (Attribute) XPath.selectSingleNode(doc,
0614:
0615:                        "//stopWord/@sep");
0616:
0617:                        sep = att.getValue();
0618:
0619:                        if (sep == null)
0620:
0621:                            sep = ",";
0622:
0623:                        stopWords = stopWordsString.split(sep);
0624:
0625:                    }
0626:
0627:                } catch (JDOMException e) {
0628:
0629:                    logger.error(e.getMessage());
0630:
0631:                }
0632:
0633:                return stopWords;
0634:
0635:            }
0636:
0637:            /**
0638:             * 
0639:             * Permet de retourner un tableau d'éléments sur lesquels la recherche va
0640:             * 
0641:             * être effectuée. Ce dernier sera passé comme argument au constructeur
0642:             * 
0643:             * "MultiFieldQueryParser". <br/><br/>Returns an array of elements which
0644:             * 
0645:             * will be searched. It will be passed as parameter for the constructor
0646:             * 
0647:             * "MultiFieldQueryParser".
0648:             *  
0649:             */
0650:
0651:            public String[] getSearchFieldsValue(String text, String sep) {
0652:
0653:                String[] champsRecherche = text.split(sep);
0654:
0655:                return champsRecherche;
0656:
0657:            }
0658:
0659:            /**
0660:             * 
0661:             * Méthode retournant un tableau qui va contenir la liste des champs à
0662:             * 
0663:             * afficher dans le résultat de recherche. <br/><br/>Method that returns an
0664:             * 
0665:             * array containing the list of fields to show in the search result.
0666:             *  
0667:             */
0668:
0669:            public Vector getDisplayFields(Document doc) {
0670:
0671:                Vector displayFields = new Vector();
0672:
0673:                try {
0674:
0675:                    List elems = XPath.selectNodes(doc,
0676:
0677:                    "//searchResult/fieldsToDisplay/luceneField");
0678:
0679:                    for (int i = 0; i < elems.size(); i++) {
0680:
0681:                        Element elem = (Element) elems.get(i);
0682:
0683:                        LiusField lf = buildLiusField(elem);
0684:
0685:                        displayFields.add(lf);
0686:
0687:                    }
0688:
0689:                } catch (JDOMException e) {
0690:
0691:                    logger.error(e.getMessage());
0692:
0693:                }
0694:
0695:                return displayFields;
0696:
0697:            }
0698:
0699:            /**
0700:             * 
0701:             * Méthode utilisée pour la recherche. La construction de LiusQuery se base
0702:             * 
0703:             * sur l'élément trouvé dans le fichier de configuration pour constuire
0704:             * 
0705:             * l'objet. <br/><br/>Method used for search. The construction of LiusQuery
0706:             * 
0707:             * is based on the element found in the configuration file for constructing
0708:             * 
0709:             * the object.
0710:             *  
0711:             */
0712:
0713:            public String getQueryType(Document doc, LiusConfig xc) {
0714:
0715:                String nomElem = "";
0716:
0717:                String[] xpathExp = { "//search/queryTerm",
0718:                        "//search/queryParser",
0719:
0720:                        "//search/multiFieldQueryParser", "//search/rangeQuery" };
0721:
0722:                try {
0723:
0724:                    for (int i = 0; i < xpathExp.length; i++) {
0725:
0726:                        Element testElem = (Element) XPath.selectSingleNode(
0727:                                doc,
0728:
0729:                                xpathExp[i]);
0730:
0731:                        if (testElem != null) {
0732:
0733:                            if (i == 0) {
0734:
0735:                                xc.setQueryTermClass(testElem
0736:
0737:                                .getAttributeValue("class"));
0738:
0739:                                xc.setTermFiled(testElem.getChild("term")
0740:
0741:                                .getAttributeValue("field"));
0742:
0743:                                return nomElem = "queryTerm";
0744:
0745:                            }
0746:
0747:                            else if (i == 1) {
0748:
0749:                                xc.setDefaultSearchField(testElem.getChild(
0750:
0751:                                "defaultSearchField").getAttributeValue(
0752:
0753:                                "value"));
0754:
0755:                                return nomElem = "queryParser";
0756:
0757:                            } else if (i == 2) {
0758:
0759:                                xc.setSearchFields(getSearchFieldsValue(
0760:                                        testElem
0761:
0762:                                        .getChild("searchFields").getText(),
0763:                                        testElem
0764:
0765:                                        .getChild("searchFields")
0766:                                                .getAttributeValue(
0767:
0768:                                                "sep")));
0769:
0770:                                return nomElem = "multiFieldQueryParser";
0771:
0772:                            } else if (i == 3) {
0773:
0774:                                String[] vals = new String[2];
0775:
0776:                                vals[0] = testElem.getChild("term")
0777:
0778:                                .getAttributeValue("field");
0779:
0780:                                vals[1] = testElem.getChild("booleanInclusive")
0781:
0782:                                .getAttributeValue("value");
0783:
0784:                                xc.setRangeQueryFileds(vals);
0785:
0786:                                return nomElem = "rangeQuery";
0787:
0788:                            }
0789:
0790:                        }
0791:
0792:                    }
0793:
0794:                } catch (JDOMException e) {
0795:
0796:                    logger.error(e.getMessage());
0797:
0798:                }
0799:
0800:                return nomElem;
0801:
0802:            }
0803:
0804:            /**
0805:             * 
0806:             * Méthode retournant un Map qui va contenir les informations pour
0807:             * 
0808:             * l'indexation. <br/><br/>Method returning a Map containing the
0809:             * 
0810:             * information for indexation.
0811:             *  
0812:             */
0813:
0814:            public Map getJavaBeansFields(Document doc) {
0815:
0816:                Collection coll = null;
0817:
0818:                Map javaBeansMap = new HashMap();
0819:
0820:                try {
0821:
0822:                    List javaBeans = XPath.selectNodes(doc, "//JavaBeans/Bean");
0823:
0824:                    for (int i = 0; i < javaBeans.size(); i++) {
0825:
0826:                        coll = new ArrayList();
0827:
0828:                        Element beanC = (Element) javaBeans.get(i);
0829:
0830:                        List bean = beanC.getChildren("luceneField");
0831:
0832:                        for (int j = 0; j < bean.size(); j++) {
0833:
0834:                            LiusField lf = buildLiusField((Element) bean.get(j));
0835:
0836:                            coll.add(lf);
0837:
0838:                        }
0839:
0840:                        if (beanC.getAttributeValue("setBoost") != null) {
0841:
0842:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
0843:
0844:                            ldp.setBoost(beanC.getAttributeValue("setBoost"));
0845:
0846:                            coll.add(ldp);
0847:
0848:                        }
0849:
0850:                        javaBeansMap
0851:                                .put(beanC.getAttributeValue("class"), coll);
0852:
0853:                    }
0854:
0855:                } catch (JDOMException e) {
0856:
0857:                    logger.error(e.getMessage());
0858:
0859:                }
0860:
0861:                return javaBeansMap;
0862:
0863:            }
0864:
0865:            /**
0866:             * 
0867:             * Méthode retournant une collection contenant les propriétés à utiliser
0868:             * 
0869:             * pour l'indexation du PDF à partir du fichier de configuration de Lius.
0870:             * 
0871:             * <br/><br/>Method returning a collection containing the properties to use
0872:             * 
0873:             * for indexing PDF files from the Lius configuration file.
0874:             *  
0875:             */
0876:
0877:            public Collection getPdfFields(Document doc) {
0878:
0879:                Collection coll = new ArrayList();
0880:
0881:                try {
0882:
0883:                    List pdfLs = XPath.selectNodes(doc, "//pdf/luceneField");
0884:
0885:                    if (pdfLs != null) {
0886:
0887:                        for (int i = 0; i < pdfLs.size(); i++) {
0888:
0889:                            LiusField lf = buildLiusField((Element) pdfLs
0890:                                    .get(i));
0891:
0892:                            coll.add(lf);
0893:
0894:                        }
0895:
0896:                        Attribute boost = (Attribute) XPath.selectSingleNode(
0897:                                doc,
0898:
0899:                                "//pdf/@setBoost");
0900:
0901:                        if (boost != null) {
0902:
0903:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
0904:
0905:                            ldp.setBoost(boost.getValue());
0906:
0907:                            coll.add(ldp);
0908:
0909:                        }
0910:
0911:                    }
0912:
0913:                } catch (JDOMException e) {
0914:
0915:                    logger.error(e.getMessage());
0916:
0917:                }
0918:
0919:                return coll;
0920:
0921:            }
0922:
0923:            /**
0924:             * 
0925:             * Méthode retournant une collection contenant les propriétés à utiliser
0926:             * 
0927:             * pour l'indexation du Excel à partir du fichier de configuration de Lius.
0928:             * 
0929:             * <br/><br/>Method returning a collection containing the properties to use
0930:             * 
0931:             * for indexing Excel files for Lius configuration file.
0932:             *  
0933:             */
0934:
0935:            public Collection getExcelFields(Document doc) {
0936:
0937:                Collection coll = new ArrayList();
0938:
0939:                try {
0940:
0941:                    List excelLs = XPath.selectNodes(doc,
0942:                            "//msExcel/luceneField");
0943:
0944:                    if (excelLs.size() > 0) {
0945:
0946:                        for (int i = 0; i < excelLs.size(); i++) {
0947:
0948:                            LiusField lf = buildLiusField((Element) excelLs
0949:                                    .get(i));
0950:
0951:                            coll.add(lf);
0952:
0953:                        }
0954:
0955:                        Attribute boost = (Attribute) XPath.selectSingleNode(
0956:                                doc,
0957:
0958:                                "//msExcel/@setBoost");
0959:
0960:                        if (boost != null) {
0961:
0962:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
0963:
0964:                            ldp.setBoost(boost.getValue());
0965:
0966:                            coll.add(ldp);
0967:
0968:                        }
0969:
0970:                    }
0971:
0972:                } catch (JDOMException e) {
0973:
0974:                    logger.error(e.getMessage());
0975:
0976:                }
0977:
0978:                return coll;
0979:
0980:            }
0981:
0982:            /**
0983:             * 
0984:             * Méthode retournant une collection contenant les propriétés à utiliser
0985:             * 
0986:             * pour l'indexation du MS WORD à partir du fichier de configuration de
0987:             * 
0988:             * Lius. <br/><br/>Method returning a collection containing the properties
0989:             * 
0990:             * to use for indexing MS WORD files for Lius configuration file.
0991:             *  
0992:             */
0993:
0994:            public Collection getMsWordFields(Document doc) {
0995:
0996:                Collection coll = new ArrayList();
0997:
0998:                try {
0999:
1000:                    List wordLs = XPath
1001:                            .selectNodes(doc, "//msWord/luceneField");
1002:
1003:                    if (wordLs.size() > 0) {
1004:
1005:                        for (int i = 0; i < wordLs.size(); i++) {
1006:
1007:                            LiusField lf = buildLiusField((Element) wordLs
1008:                                    .get(i));
1009:
1010:                            coll.add(lf);
1011:
1012:                        }
1013:
1014:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1015:                                doc,
1016:
1017:                                "//msWord/@setBoost");
1018:
1019:                        if (boost != null) {
1020:
1021:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1022:
1023:                            ldp.setBoost(boost.getValue());
1024:
1025:                            coll.add(ldp);
1026:
1027:                        }
1028:
1029:                    }
1030:
1031:                } catch (JDOMException e) {
1032:
1033:                    logger.error(e.getMessage());
1034:
1035:                }
1036:
1037:                return coll;
1038:
1039:            }
1040:
1041:            /**
1042:             * 
1043:             * Méthode retournant une collection contenant les propriétés à utiliser
1044:             * 
1045:             * pour l'indexation du XHTML à partir du fichier de configuration de Lius.
1046:             * 
1047:             * <br/><br/>Method returning a collection containing the properties to use
1048:             * 
1049:             * for indexing XHTML files for Lius configuration file.
1050:             *  
1051:             */
1052:
1053:            public Collection getHtmlFields(Document doc) {
1054:
1055:                Collection coll = new ArrayList();
1056:
1057:                try {
1058:
1059:                    List listeElem = XPath.selectNodes(doc,
1060:                            "//html/luceneField");
1061:
1062:                    for (int i = 0; i < listeElem.size(); i++) {
1063:
1064:                        LiusField lf = buildLiusField((Element) listeElem
1065:                                .get(i));
1066:
1067:                        coll.add(lf);
1068:
1069:                    }
1070:
1071:                    Attribute boost = (Attribute) XPath.selectSingleNode(doc,
1072:
1073:                    "//html/@setBoost");
1074:
1075:                    if (boost != null) {
1076:
1077:                        LiusDocumentProperty ldp = new LiusDocumentProperty();
1078:
1079:                        ldp.setBoost(boost.getValue());
1080:
1081:                        coll.add(ldp);
1082:
1083:                    }
1084:
1085:                } catch (JDOMException e) {
1086:
1087:                    logger.error(e.getMessage());
1088:
1089:                }
1090:
1091:                return coll;
1092:
1093:            }
1094:
1095:            /**
1096:             * 
1097:             * Méthode retournant une collection contenant les propriétés à utiliser
1098:             * 
1099:             * pour l'indexation du RTF à partir du fichier de configuration de Lius.
1100:             * 
1101:             * <br/><br/>Method returning a collection containing the properties to use
1102:             * 
1103:             * for indexing RTF files for Lius configuration file.
1104:             *  
1105:             */
1106:
1107:            public Collection getRtfFields(Document doc) {
1108:
1109:                Collection coll = new ArrayList();
1110:
1111:                try {
1112:
1113:                    List rtfLs = XPath.selectNodes(doc, "//rtf/luceneField");
1114:
1115:                    if (rtfLs.size() > 0) {
1116:
1117:                        for (int i = 0; i < rtfLs.size(); i++) {
1118:
1119:                            LiusField lf = buildLiusField((Element) rtfLs
1120:                                    .get(i));
1121:
1122:                            coll.add(lf);
1123:
1124:                        }
1125:
1126:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1127:                                doc,
1128:
1129:                                "//rtf/@setBoost");
1130:
1131:                        if (boost != null) {
1132:
1133:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1134:
1135:                            ldp.setBoost(boost.getValue());
1136:
1137:                            coll.add(ldp);
1138:
1139:                        }
1140:
1141:                    }
1142:
1143:                } catch (JDOMException e) {
1144:
1145:                    logger.error(e.getMessage());
1146:
1147:                }
1148:
1149:                return coll;
1150:
1151:            }
1152:
1153:            public Collection getTxtFields(Document doc) {
1154:
1155:                Collection coll = new ArrayList();
1156:
1157:                try {
1158:
1159:                    List rtfLs = XPath.selectNodes(doc, "//txt/luceneField");
1160:
1161:                    if (rtfLs.size() > 0) {
1162:
1163:                        for (int i = 0; i < rtfLs.size(); i++) {
1164:
1165:                            LiusField lf = buildLiusField((Element) rtfLs
1166:                                    .get(i));
1167:
1168:                            coll.add(lf);
1169:
1170:                        }
1171:
1172:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1173:                                doc,
1174:
1175:                                "//txt/@setBoost");
1176:
1177:                        if (boost != null) {
1178:
1179:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1180:
1181:                            ldp.setBoost(boost.getValue());
1182:
1183:                            coll.add(ldp);
1184:
1185:                        }
1186:
1187:                    }
1188:
1189:                } catch (JDOMException e) {
1190:
1191:                    logger.error(e.getMessage());
1192:
1193:                }
1194:
1195:                return coll;
1196:
1197:            }
1198:
1199:            public Collection getPPTFields(Document doc) {
1200:
1201:                Collection coll = new ArrayList();
1202:
1203:                try {
1204:
1205:                    List rtfLs = XPath.selectNodes(doc,
1206:                            "//msPowerPoint/luceneField");
1207:
1208:                    if (rtfLs.size() > 0) {
1209:
1210:                        for (int i = 0; i < rtfLs.size(); i++) {
1211:
1212:                            LiusField lf = buildLiusField((Element) rtfLs
1213:                                    .get(i));
1214:
1215:                            coll.add(lf);
1216:
1217:                        }
1218:
1219:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1220:                                doc,
1221:
1222:                                "//msPowerPoint/@setBoost");
1223:
1224:                        if (boost != null) {
1225:
1226:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1227:
1228:                            ldp.setBoost(boost.getValue());
1229:
1230:                            coll.add(ldp);
1231:
1232:                        }
1233:
1234:                    }
1235:
1236:                } catch (JDOMException e) {
1237:
1238:                    logger.error(e.getMessage());
1239:
1240:                }
1241:
1242:                return coll;
1243:
1244:            }
1245:
1246:            public Collection getOOFields(Document doc) {
1247:
1248:                Collection col = new ArrayList();
1249:
1250:                try {
1251:
1252:                    List listeElem = XPath
1253:
1254:                    .selectNodes(doc, "//openOffice/luceneField");
1255:
1256:                    if (listeElem.size() == 0) {
1257:
1258:                        return col = null;
1259:
1260:                    } else {
1261:
1262:                        for (int i = 0; i < listeElem.size(); i++) {
1263:
1264:                            LiusField lf = buildLiusField((Element) listeElem
1265:                                    .get(i));
1266:
1267:                            col.add(lf);
1268:
1269:                        }
1270:
1271:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1272:                                doc,
1273:
1274:                                "//openOffice/@setBoost");
1275:
1276:                        if (boost != null) {
1277:
1278:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1279:
1280:                            ldp.setBoost(boost.getValue());
1281:
1282:                            col.add(ldp);
1283:
1284:                        }
1285:
1286:                    }
1287:
1288:                }
1289:
1290:                catch (JDOMException e) {
1291:
1292:                    logger.error(e.getMessage());
1293:
1294:                }
1295:
1296:                return col;
1297:
1298:            }
1299:
1300:            /**
1301:             * 
1302:             * Méthode retournant une collection contenant les propriétés à utiliser
1303:             * 
1304:             * pour l'indexation mixte à partir du fichier de configuration de Lius.
1305:             * 
1306:             * <br/><br/>Method returning a collection containing the properties to use
1307:             * 
1308:             * for mixed indexing for Lius configuration file.
1309:             *  
1310:             */
1311:
1312:            public List getMixteIndexingElements(Document doc) {
1313:
1314:                List lsToIndex = new ArrayList();
1315:
1316:                try {
1317:
1318:                    Element mixteIndexing = (Element) XPath.selectSingleNode(
1319:                            doc,
1320:
1321:                            "//mixteIndexing");
1322:
1323:                    if (mixteIndexing != null) {
1324:
1325:                        List children = mixteIndexing.getChildren();
1326:
1327:                        for (int i = 0; i < children.size(); i++) {
1328:
1329:                            if (((Element) children.get(i)).getText()
1330:
1331:                            .equalsIgnoreCase("true")) {
1332:
1333:                                lsToIndex.add(((Element) children.get(i))
1334:
1335:                                .getName().toLowerCase());
1336:
1337:                            }
1338:
1339:                        }
1340:
1341:                    }
1342:
1343:                } catch (JDOMException e) {
1344:
1345:                    logger.error(e.getMessage());
1346:
1347:                }
1348:
1349:                return lsToIndex;
1350:
1351:            }
1352:
1353:            public Collection getMP3Fields(Document doc) {
1354:
1355:                Collection coll = new ArrayList();
1356:
1357:                try {
1358:
1359:                    List mp3Ls = XPath.selectNodes(doc, "//mp3/luceneField");
1360:
1361:                    if (mp3Ls != null) {
1362:
1363:                        for (int i = 0; i < mp3Ls.size(); i++) {
1364:
1365:                            LiusField lf = buildLiusField((Element) mp3Ls
1366:                                    .get(i));
1367:
1368:                            coll.add(lf);
1369:
1370:                        }
1371:
1372:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1373:                                doc,
1374:
1375:                                "//mp3/@setBoost");
1376:
1377:                        if (boost != null) {
1378:
1379:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1380:
1381:                            ldp.setBoost(boost.getValue());
1382:
1383:                            coll.add(ldp);
1384:
1385:                        }
1386:
1387:                    }
1388:
1389:                } catch (JDOMException e) {
1390:
1391:                    logger.error(e.getMessage());
1392:
1393:                }
1394:
1395:                return coll;
1396:
1397:            }
1398:
1399:            public Collection getTexFields(Document doc) {
1400:
1401:                Collection coll = new ArrayList();
1402:
1403:                try {
1404:
1405:                    List texLs = XPath.selectNodes(doc, "//tex/luceneField");
1406:
1407:                    if (texLs != null) {
1408:
1409:                        for (int i = 0; i < texLs.size(); i++) {
1410:
1411:                            LiusField lf = buildLiusField((Element) texLs
1412:                                    .get(i));
1413:
1414:                            coll.add(lf);
1415:
1416:                        }
1417:
1418:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1419:                                doc,
1420:
1421:                                "//tex/@setBoost");
1422:
1423:                        if (boost != null) {
1424:
1425:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1426:
1427:                            ldp.setBoost(boost.getValue());
1428:
1429:                            coll.add(ldp);
1430:
1431:                        }
1432:
1433:                    }
1434:
1435:                } catch (JDOMException e) {
1436:
1437:                    logger.error(e.getMessage());
1438:
1439:                }
1440:
1441:                return coll;
1442:
1443:            }
1444:
1445:            public Collection getVCardFields(Document doc) {
1446:
1447:                Collection coll = new ArrayList();
1448:
1449:                try {
1450:
1451:                    List vcardLs = XPath
1452:                            .selectNodes(doc, "//vcard/luceneField");
1453:
1454:                    if (vcardLs != null) {
1455:
1456:                        for (int i = 0; i < vcardLs.size(); i++) {
1457:
1458:                            LiusField lf = buildLiusField((Element) vcardLs
1459:                                    .get(i));
1460:
1461:                            coll.add(lf);
1462:
1463:                        }
1464:
1465:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1466:                                doc,
1467:
1468:                                "//vcard/@setBoost");
1469:
1470:                        if (boost != null) {
1471:
1472:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1473:
1474:                            ldp.setBoost(boost.getValue());
1475:
1476:                            coll.add(ldp);
1477:
1478:                        }
1479:
1480:                    }
1481:
1482:                } catch (JDOMException e) {
1483:
1484:                    logger.error(e.getMessage());
1485:
1486:                }
1487:
1488:                return coll;
1489:
1490:            }
1491:
1492:            public Collection getFontFields(Document doc) {
1493:
1494:                Collection coll = new ArrayList();
1495:
1496:                try {
1497:
1498:                    List fontLs = XPath.selectNodes(doc, "//font/luceneField");
1499:
1500:                    if (fontLs != null) {
1501:
1502:                        for (int i = 0; i < fontLs.size(); i++) {
1503:
1504:                            LiusField lf = buildLiusField((Element) fontLs
1505:                                    .get(i));
1506:
1507:                            coll.add(lf);
1508:
1509:                        }
1510:
1511:                        Attribute boost = (Attribute) XPath.selectSingleNode(
1512:                                doc,
1513:
1514:                                "//font/@setBoost");
1515:
1516:                        if (boost != null) {
1517:
1518:                            LiusDocumentProperty ldp = new LiusDocumentProperty();
1519:
1520:                            ldp.setBoost(boost.getValue());
1521:
1522:                            coll.add(ldp);
1523:
1524:                        }
1525:
1526:                    }
1527:
1528:                } catch (JDOMException e) {
1529:
1530:                    logger.error(e.getMessage());
1531:
1532:                }
1533:
1534:                return coll;
1535:
1536:            }
1537:
1538:            private LiusField buildLiusField(Element elem) {
1539:
1540:                LiusField lf = new LiusField();
1541:
1542:                if (elem.getAttribute("name") != null)
1543:
1544:                    lf.setName(elem.getAttributeValue("name"));
1545:
1546:                if (elem.getAttribute("xpathSelect") != null)
1547:
1548:                    lf.setXpathSelect(elem.getAttributeValue("xpathSelect"));
1549:
1550:                if (elem.getAttribute("type") != null)
1551:
1552:                    lf.setType(elem.getAttributeValue("type"));
1553:
1554:                if (elem.getAttribute("ocurSep") != null)
1555:
1556:                    lf.setOcurSep(elem.getAttributeValue("ocurSep"));
1557:
1558:                if (elem.getAttribute("dateFormat") != null)
1559:
1560:                    lf.setDateFormat(elem.getAttributeValue("dateFormat"));
1561:
1562:                if (elem.getAttribute("label") != null)
1563:
1564:                    lf.setLabel(elem.getAttributeValue("label"));
1565:
1566:                if (elem.getAttribute("getMethod") != null)
1567:
1568:                    lf.setGetMethod(elem.getAttributeValue("getMethod"));
1569:
1570:                if (elem.getAttribute("get") != null)
1571:
1572:                    lf.setGet(elem.getAttributeValue("get"));
1573:
1574:                if (elem.getAttribute("setFragmenter") != null)
1575:
1576:                    lf.setFragmenter(elem.getAttributeValue("setFragmenter"));
1577:
1578:                if (elem.getAttribute("setBoost") != null) {
1579:
1580:                    Float f = new Float(elem.getAttributeValue("setBoost"));
1581:
1582:                    lf.setBoost(f.floatValue());
1583:
1584:                    lf.setIsBoosted(true);
1585:
1586:                }
1587:
1588:                return lf;
1589:
1590:            }
1591:
1592:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.