use of org.dom4j.DocumentException in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerSettings.
private void registerSettings(IPlatformPlugin plugin, ClassLoader loader) {
IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
InputStream stream = resLoader.getResourceAsStream(loader, "settings.xml");
if (stream == null) {
// No settings.xml is fine
return;
}
Properties properties = new Properties();
try {
Document docFromStream = XmlDom4JHelper.getDocFromStream(stream);
for (Object element : docFromStream.getRootElement().elements()) {
Element ele = (Element) element;
String name = ele.getName();
String value = ele.getText();
properties.put("settings/" + name, value);
}
} catch (DocumentException | IOException e) {
logger.error("Error parsing settings.xml for plugin: " + plugin.getId(), e);
}
try {
systemConfig.registerConfiguration(new PropertiesFileConfiguration(plugin.getId(), properties));
} catch (IOException e) {
logger.error("Error registering settings.xml for plugin: " + plugin.getId(), e);
}
}
use of org.dom4j.DocumentException in project pentaho-platform by pentaho.
the class PentahoObjectsConfig method setDocument.
public void setDocument(Document doc) throws DocumentException {
Element rootElement = doc.getRootElement();
if ((rootElement != null) && !doc.getRootElement().getName().equals(ROOT)) {
throw new DocumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"PentahoObjectsConfig.ERROR_0001_INVALID_ROOT_ELEMENT"));
}
document = doc;
}
use of org.dom4j.DocumentException in project pentaho-platform by pentaho.
the class EmailConfigurationXml method loadFromConfigurationDocument.
private void loadFromConfigurationDocument(final Document doc) throws DocumentException {
final Element rootElement = doc.getRootElement();
if ((rootElement != null) && !doc.getRootElement().getName().equals(ROOT_ELEMENT)) {
// $NON-NLS-1$
throw new DocumentException(messages.getErrorString("EmailConfigurationXml.ERROR_0002_INVALID_ROOT_ELEMENT"));
}
setSmtpHost(getStringValue(doc, SMTP_HOST_XPATH));
setSmtpPort(getIntegerPortValue(doc, SMTP_PORT_XPATH));
setSmtpProtocol(getStringValue(doc, SMTP_PROTOCOL_XPATH));
setUseStartTls(getBooleanValue(doc, USE_START_TLS_XPATH));
setAuthenticate(getBooleanValue(doc, AUTHENTICATE_XPATH));
setUseSsl(getBooleanValue(doc, USE_SSL_XPATH));
setDebug(getBooleanValue(doc, DEBUG_XPATH));
setSmtpQuitWait(getBooleanValue(doc, SMTP_QUIT_WAIT_XPATH));
setDefaultFrom(getStringValue(doc, DEFAULT_FROM_XPATH));
setFromName(getStringValue(doc, FROM_NAME_XPATH));
setUserId(getStringValue(doc, USER_ID_XPATH));
setPassword(Encr.decryptPasswordOptionallyEncrypted(getStringValue(doc, PASSWORD_XPATH)));
}
use of org.dom4j.DocumentException in project alfresco-repository by Alfresco.
the class QueryRegisterComponentImpl method loadQueryCollection.
public void loadQueryCollection(String location) {
try {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
SAXReader reader = SAXReader.createDefault();
Document document = reader.read(is);
is.close();
QueryCollection collection = QueryCollectionImpl.createQueryCollection(document.getRootElement(), dictionaryService, namespaceService);
collections.put(location, collection);
} catch (DocumentException de) {
throw new AlfrescoRuntimeException("Error reading XML", de);
} catch (IOException e) {
throw new AlfrescoRuntimeException("IO Error reading XML", e);
}
}
use of org.dom4j.DocumentException in project Openfire by igniterealtime.
the class ChatTranscriptManager method formatTranscript.
/**
* Formats a given XML Chat Transcript.
*
* @param transcript the XMP ChatTranscript.
* @return the pretty-version of a transcript.
*/
public static String formatTranscript(String transcript) {
if (transcript == null || "".equals(transcript)) {
return "";
}
final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat(XMPPDateTimeFormat.XMPP_DELAY_DATETIME_FORMAT);
UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
Document element = null;
try {
element = DocumentHelper.parseText(transcript);
} catch (DocumentException e) {
Log.error(e.getMessage(), e);
}
StringBuilder buf = new StringBuilder();
String conv1 = null;
// Add the Messages and Presences contained in the retrieved transcript element
for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext(); ) {
Element packet = it.next();
String name = packet.getName();
String message = "";
String from = "";
if ("presence".equals(name)) {
String type = packet.attributeValue("type");
from = new JID(packet.attributeValue("from")).getResource();
if (type == null) {
message = from + " has joined the room";
} else {
message = from + " has left the room";
}
} else if ("message".equals(name)) {
from = new JID(packet.attributeValue("from")).getResource();
message = packet.elementText("body");
message = StringUtils.escapeHTMLTags(message);
if (conv1 == null) {
conv1 = from;
}
}
List<Element> el = packet.elements("x");
for (Element ele : el) {
if ("jabber:x:delay".equals(ele.getNamespaceURI())) {
String stamp = ele.attributeValue("stamp");
try {
String formattedDate;
synchronized (UTC_FORMAT) {
Date d = UTC_FORMAT.parse(stamp);
formattedDate = formatter.format(d);
}
if ("presence".equals(name)) {
buf.append("<tr valign=\"top\"><td class=\"notification-label\" colspan=2 nowrap>[").append(formattedDate).append("] ").append(message).append("</td></tr>");
} else {
String cssClass = conv1.equals(from) ? "conversation-label1" : "conversation-label2";
buf.append("<tr valign=\"top\"><td width=1% class=\"" + cssClass + "\" nowrap>[").append(formattedDate).append("] ").append(from).append(":</td><td class=\"conversation-body\">").append(message).append("</td></tr>");
}
} catch (ParseException e) {
Log.error(e.getMessage(), e);
}
}
}
}
return buf.toString();
}
Aggregations