KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > xml > CmsXmlAddDEHelpSearchIndex


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/xml/CmsXmlAddDEHelpSearchIndex.java,v $
3  * Date : $Date: 2006/03/27 14:52:44 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.setup.xml;
33
34 import org.opencms.configuration.CmsConfigurationManager;
35 import org.opencms.configuration.CmsSearchConfiguration;
36 import org.opencms.configuration.I_CmsXmlConfiguration;
37 import org.opencms.file.CmsProject;
38 import org.opencms.file.types.CmsResourceTypeXmlPage;
39 import org.opencms.search.CmsVfsIndexer;
40 import org.opencms.workplace.CmsWorkplace;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.dom4j.Document;
46 import org.dom4j.Node;
47
48 /**
49  * Adds the german help search index.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.2 $
54  *
55  * @since 6.1.8
56  */

57 public class CmsXmlAddDEHelpSearchIndex extends A_CmsSetupXmlUpdate {
58
59     /** List of xpaths to update. */
60     private List JavaDoc m_xpaths;
61
62     /**
63      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
64      */

65     public String JavaDoc getName() {
66
67         return "Add German Help search index";
68     }
69
70     /**
71      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getXmlFilename()
72      */

73     public String JavaDoc getXmlFilename() {
74
75         return CmsSearchConfiguration.DEFAULT_XML_FILE_NAME;
76     }
77
78     /**
79      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
80      */

81     protected boolean executeUpdate(Document document, String JavaDoc xpath) {
82
83         Node node = document.selectSingleNode(xpath);
84         if (node == null) {
85             if (xpath.equals(getXPathsToUpdate().get(0))) {
86                 CmsSetupXmlHelper.setValue(document, xpath + "/" + I_CmsXmlConfiguration.N_NAME, "German online help");
87                 CmsSetupXmlHelper.setValue(document, xpath + "/" + CmsSearchConfiguration.N_REBUILD, "auto");
88                 CmsSetupXmlHelper.setValue(
89                     document,
90                     xpath + "/" + CmsSearchConfiguration.N_PROJECT,
91                     CmsProject.ONLINE_PROJECT_NAME);
92                 CmsSetupXmlHelper.setValue(document, xpath + "/" + CmsSearchConfiguration.N_LOCALE, "de");
93                 CmsSetupXmlHelper.setValue(document, xpath
94                     + "/"
95                     + CmsSearchConfiguration.N_SOURCES
96                     + "/"
97                     + CmsSearchConfiguration.N_SOURCE, "source2");
98             } else if (xpath.equals(getXPathsToUpdate().get(1))) {
99                 CmsSetupXmlHelper.setValue(document, xpath + "/" + I_CmsXmlConfiguration.N_NAME, "source2");
100                 CmsSetupXmlHelper.setValue(document, xpath
101                     + "/"
102                     + CmsSearchConfiguration.N_INDEXER
103                     + "/@"
104                     + I_CmsXmlConfiguration.A_CLASS, CmsVfsIndexer.class.getName());
105                 CmsSetupXmlHelper.setValue(document, xpath
106                     + "/"
107                     + CmsSearchConfiguration.N_RESOURCES
108                     + "/"
109                     + I_CmsXmlConfiguration.N_RESOURCE, CmsWorkplace.VFS_PATH_LOCALES);
110                 CmsSetupXmlHelper.setValue(document, xpath
111                     + "/"
112                     + CmsSearchConfiguration.N_DOCUMENTTYPES_INDEXED
113                     + "/"
114                     + I_CmsXmlConfiguration.N_NAME, CmsResourceTypeXmlPage.getStaticTypeName());
115             }
116             return true;
117         }
118         return false;
119     }
120
121     /**
122      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
123      */

124     protected String JavaDoc getCommonPath() {
125
126         // /opencms/search
127
return new StringBuffer JavaDoc("/").append(CmsConfigurationManager.N_ROOT).append("/").append(
128             CmsSearchConfiguration.N_SEARCH).toString();
129     }
130
131     /**
132      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
133      */

134     protected List JavaDoc getXPathsToUpdate() {
135
136         if (m_xpaths == null) {
137             // /opencms/search/indexes/index[name='German online help']
138
StringBuffer JavaDoc xp = new StringBuffer JavaDoc(256);
139             xp.append("/");
140             xp.append(CmsConfigurationManager.N_ROOT);
141             xp.append("/");
142             xp.append(CmsSearchConfiguration.N_SEARCH);
143             xp.append("/");
144             xp.append(CmsSearchConfiguration.N_INDEXES);
145             xp.append("/");
146             xp.append(CmsSearchConfiguration.N_INDEX);
147             xp.append("[");
148             xp.append(I_CmsXmlConfiguration.N_NAME);
149             xp.append("='German online help']");
150             m_xpaths = new ArrayList JavaDoc();
151             m_xpaths.add(xp.toString());
152             // /opencms/search/indexsources/indexsource[name='source2']
153
xp = new StringBuffer JavaDoc(256);
154             xp.append("/");
155             xp.append(CmsConfigurationManager.N_ROOT);
156             xp.append("/");
157             xp.append(CmsSearchConfiguration.N_SEARCH);
158             xp.append("/");
159             xp.append(CmsSearchConfiguration.N_INDEXSOURCES);
160             xp.append("/");
161             xp.append(CmsSearchConfiguration.N_INDEXSOURCE);
162             xp.append("[");
163             xp.append(I_CmsXmlConfiguration.N_NAME);
164             xp.append("='source2']");
165             m_xpaths.add(xp.toString());
166         }
167         return m_xpaths;
168     }
169
170 }
Popular Tags