Skip to content

Commit 6b2ea3b

Browse files
committed
Added some XML update actions to the updater.
1 parent 4aa2a8d commit 6b2ea3b

File tree

3 files changed

+77
-26
lines changed

3 files changed

+77
-26
lines changed

src-setup/org/opencms/setup/xml/CmsSetupXmlManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public void initialize(int detectedVersion) {
198198
m_plugins.add(new org.opencms.setup.xml.v8.CmsXmlAddResourceTypeParams());
199199
m_plugins.add(new org.opencms.setup.xml.v8.CmsXmlAddWidgets());
200200
m_plugins.add(new org.opencms.setup.xml.v8.CmsXmlAddCollectors());
201+
m_plugins.add(new org.opencms.setup.xml.v8.CmsXmlAddTypeMappings());
201202
//m_plugins.add(new org.opencms.setup.xml.v8.CmsXmlUpdateSchemaTypes());
202203

203204
// workplace

src-setup/org/opencms/setup/xml/v8/CmsXmlAddADESearch.java

+50
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ protected void removeTypes(Node node) {
164164
}
165165
}
166166

167+
class ElementReplaceAction extends CmsXmlUpdateAction {
168+
169+
private String m_replacementXml;
170+
171+
private String m_xpath;
172+
173+
public ElementReplaceAction(String xpath, String replacementXml) {
174+
175+
m_xpath = xpath;
176+
m_replacementXml = replacementXml;
177+
}
178+
179+
@Override
180+
public boolean executeUpdate(Document doc, String xpath, boolean forReal) {
181+
182+
if (!forReal) {
183+
return true;
184+
}
185+
Node node = doc.selectSingleNode(m_xpath);
186+
if (node != null) {
187+
Element parent = node.getParent();
188+
node.detach();
189+
try {
190+
Element element = createElementFromXml(m_replacementXml);
191+
parent.add(element);
192+
return true;
193+
} catch (DocumentException e) {
194+
e.printStackTrace(System.out);
195+
return false;
196+
}
197+
} else {
198+
return false;
199+
}
200+
}
201+
}
202+
167203
/** A map from xpaths to XML update actions.<p> */
168204
private Map<String, CmsXmlUpdateAction> m_actions;
169205

@@ -795,5 +831,19 @@ public boolean executeUpdate(Document document, String xpath, boolean forReal) {
795831
buildXpathForIndexedDocumentType("source1", "containerpage"),
796832
createIndexedTypeAction("containerpage"));
797833

834+
//=============================================================================================================
835+
836+
String analyzerEnPath = "/opencms/search/analyzers/analyzer[class='org.apache.lucene.analysis.standard.StandardAnalyzer'][locale='en']";
837+
m_actions.put(analyzerEnPath, new ElementReplaceAction(analyzerEnPath, "<analyzer>\n"
838+
+ " <class>org.apache.lucene.analysis.en.EnglishAnalyzer</class>\n"
839+
+ " <locale>en</locale>\n"
840+
+ " </analyzer>"));
841+
842+
String analyzerItPath = "/opencms/search/analyzers/analyzer[class='org.apache.lucene.analysis.snowball.SnowballAnalyzer'][stemmer='Italian']";
843+
m_actions.put(analyzerItPath, new ElementReplaceAction(analyzerItPath, "<analyzer>\n"
844+
+ " <class>org.apache.lucene.analysis.it.ItalianAnalyzer</class>\n"
845+
+ " <locale>it</locale>\n"
846+
+ " </analyzer>"));
847+
798848
}
799849
}

src-setup/org/opencms/setup/xml/v8/CmsXmlAddTypeMappings.java

+26-26
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
*/
4848
public class CmsXmlAddTypeMappings extends A_CmsXmlVfs {
4949

50-
/** List of xpaths to update. */
51-
private List<String> m_xpaths;
52-
5350
/**
5451
* The new widget definition data.<p>
5552
*/
56-
private String[] m_suffixes = {".flv", ".swf"};
53+
private String[] m_suffixes = {".flv", ".swf", ".docx", ".xlsx", ".pptx"};
54+
55+
/** List of xpaths to update. */
56+
private List<String> m_xpaths;
5757

5858
/**
5959
* @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
@@ -78,16 +78,16 @@ public boolean validate(CmsSetupBean setupBean) throws Exception {
7878
@Override
7979
protected boolean executeUpdate(Document document, String xpath, boolean forReal) {
8080

81+
boolean result = false;
8182
for (int i = 0; i < m_suffixes.length; i++) {
8283
if (xpath.equals(getXPathsToUpdate().get(i))) {
83-
if (document.selectSingleNode(xpath) != null) {
84-
return false;
84+
if (document.selectSingleNode(xpath) == null) {
85+
CmsSetupXmlHelper.setValue(document, xpath, "");
86+
result = true;
8587
}
86-
CmsSetupXmlHelper.setValue(document, xpath, "");
87-
return true;
8888
}
8989
}
90-
return false;
90+
return result;
9191
}
9292

9393
/**
@@ -114,23 +114,6 @@ protected List<String> getXPathsToUpdate() {
114114
return m_xpaths;
115115
}
116116

117-
/**
118-
* Returns the xpath for a the resourcetypes node.<p>
119-
*
120-
* @return the xpath for the resourcetypes node
121-
*/
122-
protected String xpathForTypes() {
123-
124-
return "/"
125-
+ CmsConfigurationManager.N_ROOT
126-
+ "/"
127-
+ CmsVfsConfiguration.N_VFS
128-
+ "/"
129-
+ CmsVfsConfiguration.N_RESOURCES
130-
+ "/"
131-
+ CmsVfsConfiguration.N_RESOURCETYPES;
132-
}
133-
134117
/**
135118
* Returns the xpath for the type node with a given type name.<p>
136119
*
@@ -171,4 +154,21 @@ protected String xpathForTypeMapping(String type, String suffix) {
171154
+ "']";
172155
}
173156

157+
/**
158+
* Returns the xpath for a the resourcetypes node.<p>
159+
*
160+
* @return the xpath for the resourcetypes node
161+
*/
162+
protected String xpathForTypes() {
163+
164+
return "/"
165+
+ CmsConfigurationManager.N_ROOT
166+
+ "/"
167+
+ CmsVfsConfiguration.N_VFS
168+
+ "/"
169+
+ CmsVfsConfiguration.N_RESOURCES
170+
+ "/"
171+
+ CmsVfsConfiguration.N_RESOURCETYPES;
172+
}
173+
174174
}

0 commit comments

Comments
 (0)