use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class MailPort method postModify.
@Override
public void postModify(CallbackContext context, String attrName, Entry entry) {
super.postModify(context, attrName, entry);
if (entry instanceof Server) {
Server localServer = null;
try {
localServer = Provisioning.getInstance().getLocalServer();
if (entry == localServer) {
String port = localServer.getAttr(attrName);
LocalConfig lc = new LocalConfig(null);
lc.set(LC.zimbra_mail_service_port.key(), port);
lc.save();
}
} catch (ServiceException | DocumentException | ConfigException | NumberFormatException | IOException e) {
ZimbraLog.misc.warn("Unable to update LC.zimbra_mail_port due to Exception", e);
}
}
}
use of org.dom4j.DocumentException in project cubrid-manager by CUBRID.
the class SqlMapCondition method getIncludedStatement.
public String getIncludedStatement() {
if (this.includedStatement == null) {
if (this.statement == null) {
throw new NullPointerException("The statement field couldn't be a null.");
}
SAXReader reader = new SAXReader(false);
Document document = null;
try {
InputSource source = new InputSource(new StringReader(this.statement));
document = reader.read(source);
} catch (DocumentException e) {
ExceptionUtils.printRootCauseStackTrace(e);
throw new IllegalArgumentException("fail to parse condition", e);
}
// include 처리용 statement 저장
Element copiedElement = document.getRootElement().createCopy();
copiedElement.clearContent();
copiedElement.setText(this.modifiedStatement);
this.includedStatement = copiedElement.asXML();
}
return includedStatement;
}
use of org.dom4j.DocumentException in project ats-framework by Axway.
the class XmlText method init.
private void init(String xmlText) throws XMLException {
Document document = null;
try {
document = new SAXReader().read(new StringReader(xmlText));
} catch (DocumentException e) {
throw new XMLException("Error parsing XML text:\n" + xmlText, e);
}
this.root = document.getRootElement();
}
use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class LocalConfigCLI method exec.
private void exec(String[] args) {
CommandLine cl = null;
CommandLineParser parser = new GnuParser();
try {
cl = parser.parse(mOptions, args);
} catch (ParseException pe) {
Logging.error("Failed to parse command line: " + pe);
System.exit(1);
}
if (cl.hasOption("q")) {
Logging.setQuietMode(true);
}
if (cl.hasOption("h")) {
usage();
}
// Load known keys from BackupLC if available
loadExtensionLC("com.zimbra.cs.backup.BackupLC");
// Load known keys from ZimbraOpenOfficeExt if available
loadExtensionLC("com.zimbra.openoffice.config.OpenOfficeLC");
// Load known keys from ZimbraVoice if available
loadExtensionLC("com.zimbra.cs.voice.VoiceLC");
// info/docs for supported keys
if (cl.hasOption("i")) {
checkCompatibleOptions("i", "q", cl);
LocalConfig.printDoc(System.out, cl.getArgs(), false);
return;
}
// info/docs for all keys (hidden option)
if (cl.hasOption("all")) {
checkCompatibleOptions("all", "q", cl);
LocalConfig.printDoc(System.out, cl.getArgs(), true);
return;
}
LocalConfig lc = null;
try {
lc = new LocalConfig(cl.getOptionValue("c"));
} catch (DocumentException de) {
error("failed when reading config file", de);
} catch (ConfigException ce) {
error("failed with error in config file", ce);
}
// edit
if (cl.hasOption("e")) {
checkNotRoot("-e");
checkCompatibleOptions("e", "qfrc", cl);
String[] av = cl.getArgs();
if (av == null || av.length == 0) {
error("insufficient arguments", null);
}
for (int i = 0; i < av.length; i++) {
String key = null;
String value = null;
if (cl.hasOption("r")) {
key = av[i];
value = RandomPassword.generate();
} else {
int eqidx = av[i].indexOf("=");
if (eqidx <= 0) {
// <= 0 also catches first char being =, ie no key specified
error("argument '" + av[i] + "' not in key=value form", null);
}
key = av[i].substring(0, eqidx);
value = av[i].substring(eqidx + 1, av[i].length());
}
if (KnownKey.needForceToEdit(key) && !cl.hasOption("f")) {
error("can not edit key " + key, null);
}
lc.set(key, value);
}
try {
lc.save();
} catch (Exception e) {
error("save to " + lc.getConfigFile() + " failed", e);
}
return;
}
// unset
if (cl.hasOption("u")) {
checkNotRoot("-u");
checkCompatibleOptions("u", "qfc", cl);
String[] av = cl.getArgs();
if (av == null || av.length == 0) {
error("insufficient arguments", null);
}
for (int i = 0; i < av.length; i++) {
String key = av[i];
if (!lc.isSet(key)) {
error("key " + key + " is not set", null);
}
lc.remove(key);
}
try {
lc.save();
} catch (Exception e) {
error("save to " + lc.getConfigFile() + " failed", e);
}
return;
}
// show path
if (cl.hasOption("p")) {
checkCompatibleOptions("p", "qc", cl);
System.out.println(lc.getConfigFile());
return;
}
if (cl.hasOption("l")) {
// reset logging and run native lib load
CliUtil.toolSetup("WARN");
try {
reload();
} catch (ServiceException e) {
if (e.getCause() instanceof ConnectException) {
error("'" + Provisioning.SERVICE_MAILBOX + "' service is not running", null);
} else {
error(e.getMessage(), e);
}
}
return;
}
// print values
String format = cl.getOptionValue("m");
ConfigWriter cwriter = null;
try {
cwriter = ConfigWriter.getInstance(format, cl.hasOption("x"), !cl.hasOption("s"));
} catch (ConfigException iae) {
error("failed to create writer " + format, iae);
}
try {
// changed
if (cl.hasOption("n")) {
checkCompatibleOptions("n", "qscmx", cl);
lc.printChanged(System.out, cwriter, cl.getArgs());
return;
}
// default
if (cl.hasOption("d")) {
checkCompatibleOptions("d", "qscmx", cl);
lc.printDefaults(System.out, cwriter, cl.getArgs());
return;
}
// current
checkCompatibleOptions("", "qscmx", cl);
lc.print(System.out, cwriter, cl.getArgs());
} catch (Exception e) {
error("exception occurred when printing", e);
}
}
use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.
the class ReloadLocalConfig method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
try {
LC.reload();
} catch (DocumentException e) {
ZimbraLog.misc.error("Failed to reload LocalConfig", e);
throw AdminServiceException.FAILURE("Failed to reload LocalConfig", e);
} catch (ConfigException e) {
ZimbraLog.misc.error("Failed to reload LocalConfig", e);
throw AdminServiceException.FAILURE("Failed to reload LocalConfig", e);
}
ZimbraLog.misc.info("LocalConfig reloaded");
ZimbraSoapContext zsc = getZimbraSoapContext(context);
return zsc.jaxbToElement(new ReloadLocalConfigResponse());
}
Aggregations