use of org.dom4j.DocumentException in project Openfire by igniterealtime.
the class ChatTranscriptManager method getTextTranscriptFromSessionID.
/**
* Return the plain text version of a chat transcript.
*
* @param sessionID the sessionID of the <code>ChatSession</code>
* @return the plain text version of a chat transcript.
*/
public static String getTextTranscriptFromSessionID(String sessionID) {
String transcript = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_SESSION_TRANSCRIPT);
pstmt.setString(1, sessionID);
rs = pstmt.executeQuery();
if (rs.next()) {
transcript = DbConnectionManager.getLargeTextField(rs, 1);
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
if (transcript == null || "".equals(transcript)) {
return "";
}
// Define time zone used in the transcript.
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();
// 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);
}
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("[").append(formattedDate).append("] ").append(message).append("\n");
} else {
buf.append("[").append(formattedDate).append("] ").append(from).append(": ").append(message).append("\n");
}
} catch (ParseException e) {
Log.error(e.getMessage(), e);
}
}
}
}
return buf.toString();
}
use of org.dom4j.DocumentException in project tdi-studio-se by Talend.
the class AlfrescoOutputModelManager method addModel.
/**
* Adds an Alfresco model definition file.
*
* @param newModelFilePath
* @throws AlfrescoOutputException if already added or error reading it
*/
public void addModel(String newModelFilePath) throws AlfrescoOutputException {
if (this.availableModels.contains(newModelFilePath)) {
//$NON-NLS-1$
throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.alreadyAdded"));
}
this.availableModels.add(newModelFilePath);
// parsing the model
org.dom4j.Document modelDoc = null;
try {
modelDoc = new SAXReader().read(new File(newModelFilePath));
} catch (DocumentException dex) {
throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + newModelFilePath, dex);
}
Element modelElt = modelDoc.getRootElement();
//$NON-NLS-1$
Element namespacesElt = modelElt.element("namespaces");
if (namespacesElt != null) {
//$NON-NLS-1$
List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
HashMap<String, String> availablePrefixToNamespaceMapTmp = new HashMap<String, String>(3);
for (Element namespace : namespaces) {
//$NON-NLS-1$
String namespacePrefix = namespace.attributeValue("prefix");
if (this.availablePrefixToNamespaceMap.containsKey(namespacePrefix)) {
throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("AlfrescoOutputModelManager.prefixConflict") + " " + namespacePrefix + " " + //$NON-NLS-1$
this.availablePrefixToNamespaceMap.get(namespacePrefix));
}
//$NON-NLS-1$
String namespaceUri = namespace.attributeValue("uri");
availablePrefixToNamespaceMapTmp.put(namespacePrefix, namespaceUri);
}
this.availablePrefixToNamespaceMap.putAll(availablePrefixToNamespaceMapTmp);
}
//$NON-NLS-1$
Element typesElt = modelElt.element("types");
if (typesElt != null) {
//$NON-NLS-1$
List<Element> types = (List<Element>) typesElt.elements("type");
this.availableTypes.addAllAlfrescoModelElement(types);
}
//$NON-NLS-1$
Element aspectsElt = modelElt.element("aspects");
if (aspectsElt != null) {
//$NON-NLS-1$
List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
this.availableAspects.addAllAlfrescoModelElement(aspects);
}
}
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 Openfire by igniterealtime.
the class KrakenPlugin method getOptionsConfig.
/**
* Returns the web options config for the given transport, if it exists.
*
* @param type type of the transport we want the options config for.
* @return XML document with the options config.
*/
public Document getOptionsConfig(TransportType type) {
// Load any custom-defined servlets.
File optConf = new File(this.pluginDirectory, "web" + File.separator + "WEB-INF" + File.separator + "options" + File.separator + type.toString() + ".xml");
Document optConfXML;
try {
FileReader reader = new FileReader(optConf);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
optConfXML = xmlReader.read(reader);
} catch (FileNotFoundException e) {
// Non-existent: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
} catch (DocumentException e) {
// Bad config: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
}
return optConfXML;
}
use of org.dom4j.DocumentException in project cubrid-manager by CUBRID.
the class FormatXMLAction method run.
/**
* Format XML strings.
*/
public void run() {
//format editor.
try {
ByteArrayOutputStream sw = new ByteArrayOutputStream();
writeTo(sw, editor.getDocument().get(), "utf-8");
String string = new String(sw.toByteArray(), "utf-8");
editor.getDocument().set(string);
sw.close();
} catch (UnsupportedEncodingException e) {
showErrorMessage();
} catch (IOException e) {
showErrorMessage();
} catch (DocumentException e) {
showErrorMessage();
}
}
Aggregations