18 package org.turro.configuration;
21 import java.io.IOException;
22 import java.io.OutputStreamWriter;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.jdom.Document;
27 import org.jdom.Element;
28 import org.jdom.JDOMException;
29 import org.jdom.input.SAXBuilder;
30 import org.jdom.output.Format;
31 import org.jdom.output.XMLOutputter;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.impl.util.FileUtil;
41 private static final String
42 CONFIGURATION_FOLDER =
"/WEB-INF/_zul-site/conf";
43 private final String confKey;
47 this.confKey = confKey;
56 }
catch (JDOMException ex) {
67 }
catch (JDOMException ex) {
78 }
catch (JDOMException ex) {
88 }
catch (JDOMException ex) {
99 }
catch (JDOMException ex) {
110 }
catch (JDOMException ex) {
126 private void saveSet() {
129 if(!folder.exists()) folder.mkdirs();
132 Format fm = Format.getPrettyFormat();
134 XMLOutputter xo =
new XMLOutputter(fm);
137 }
catch (IOException ex) {
138 Logger.getLogger(
ConfigurationSet.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
142 private void loadSet() {
143 SAXBuilder builder =
new SAXBuilder();
145 File confFile =
new File(ElephantContext.getRealPath(CONFIGURATION_FOLDER +
"/" + convertName(confKey) +
".xml"));
146 if(confFile.exists()) {
147 doc = builder.build(confFile);
149 doc =
new Document(
new Element(
"elephant-configuration"));
151 }
catch (IOException | JDOMException ex) {
152 Logger.getLogger(
ConfigurationSet.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
156 private String convertName(String confKey) {
157 return confKey.replaceAll(
"[^A-Za-z0-9]",
"");
List< String > getChildrenValue(Path path, String element, String name)
void setChildrenValue(Path path, String element, String name, List< String > values)
String getNodeValue(Path path, String name)
ConfigurationSet(String confKey)
void setNodeValue(Path path, String name, String value)
List< String[]> getChildrenValues(Path path, String element, String names[])
void setChildrenValues(Path path, String element, String name[], List< String[]> values)
void setDocument(Document doc)
List< String[]> getChildrenValues(String element, String names[])
List< String > getChildrenValue(String element, String name)
void setChildrenValue(String element, String name, List< String > values)
void setChildrenValues(String element, String names[], List< String[]> values)
String getNodeValue(String name)
void setDoc(Document doc)
void setNodeValue(String name, String value)
static String getRealPath(String path)
static String logMsg(String msg)
static String getEncoding()
static OutputStreamWriter getFileWriter(String folder, String file)