use of org.dom4j.Document in project hibernate-orm by hibernate.
the class RevisionInfoConfiguration method configure.
public RevisionInfoConfigurationResult configure(MetadataImplementor metadata, ReflectionManager reflectionManager) {
boolean revisionEntityFound = false;
RevisionInfoGenerator revisionInfoGenerator = null;
Class<?> revisionInfoClass = null;
for (PersistentClass persistentClass : metadata.getEntityBindings()) {
// Ensure we're in POJO, not dynamic model, mapping.
if (persistentClass.getClassName() != null) {
XClass clazz;
try {
clazz = reflectionManager.classForName(persistentClass.getClassName());
} catch (ClassLoadingException e) {
throw new MappingException(e);
}
final RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
if (revisionEntity != null) {
if (revisionEntityFound) {
throw new MappingException("Only one entity may be annotated with @RevisionEntity!");
}
// Checking if custom revision entity isn't audited
if (clazz.getAnnotation(Audited.class) != null) {
throw new MappingException("An entity annotated with @RevisionEntity cannot be audited!");
}
revisionEntityFound = true;
final MutableBoolean revisionNumberFound = new MutableBoolean();
final MutableBoolean revisionTimestampFound = new MutableBoolean();
final MutableBoolean modifiedEntityNamesFound = new MutableBoolean();
searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound, modifiedEntityNamesFound);
if (!revisionNumberFound.isSet()) {
throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " + "with @RevisionNumber!");
}
if (!revisionTimestampFound.isSet()) {
throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " + "with @RevisionTimestamp!");
}
revisionInfoEntityName = persistentClass.getEntityName();
revisionInfoClass = persistentClass.getMappedClass();
final Class<? extends RevisionListener> revisionListenerClass = getRevisionListenerClass(revisionEntity.value());
revisionInfoTimestampType = persistentClass.getProperty(revisionInfoTimestampData.getName()).getType();
if (globalCfg.isTrackEntitiesChangedInRevision() || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass)) || (!globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass)) || modifiedEntityNamesFound.isSet()) {
// If tracking modified entities parameter is enabled, custom revision info entity is a subtype
// of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used.
revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry());
globalCfg.setTrackEntitiesChangedInRevision(true);
} else {
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), metadata.getMetadataBuildingOptions().getServiceRegistry());
}
}
}
}
// In case of a custom revision info generator, the mapping will be null.
Document revisionInfoXmlMapping = null;
final Class<? extends RevisionListener> revisionListenerClass = getRevisionListenerClass(RevisionListener.class);
if (revisionInfoGenerator == null) {
if (globalCfg.isTrackEntitiesChangedInRevision()) {
revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultTrackingModifiedEntitiesRevisionEntity.class : SequenceIdTrackingModifiedEntitiesRevisionEntity.class;
revisionInfoEntityName = revisionInfoClass.getName();
revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry());
} else {
revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultRevisionEntity.class : SequenceIdRevisionEntity.class;
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), metadata.getMetadataBuildingOptions().getServiceRegistry());
}
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
}
return new RevisionInfoConfigurationResult(revisionInfoGenerator, revisionInfoXmlMapping, new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(), revisionInfoTimestampData.getName(), isTimestampAsDate()), generateRevisionInfoRelationMapping(), new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData, metadata.getMetadataBuildingOptions().getServiceRegistry()), globalCfg.isTrackEntitiesChangedInRevision() ? new ModifiedEntityNamesReader(revisionInfoClass, modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry()) : null, revisionInfoEntityName, revisionInfoClass, revisionInfoTimestampData);
}
use of org.dom4j.Document in project Openfire by igniterealtime.
the class ConfigManager method saveSettings.
/**
* Saves settings from options screen.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @param options Options passed from options form.
*/
public void saveSettings(String transportName, HashMap<String, String> options) {
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
Element leftPanel = optConfig.getRootElement().element("leftpanel");
if (leftPanel != null && leftPanel.nodeCount() > 0) {
for (Object nodeObj : leftPanel.elements("item")) {
Element node = (Element) nodeObj;
saveOptionSetting(node, options);
}
}
Element rightPanel = optConfig.getRootElement().element("rightpanel");
if (rightPanel != null && rightPanel.nodeCount() > 0) {
for (Object nodeObj : rightPanel.elements("item")) {
Element node = (Element) nodeObj;
saveOptionSetting(node, options);
}
}
Element bottomPanel = optConfig.getRootElement().element("bottompanel");
if (bottomPanel != null && bottomPanel.nodeCount() > 0) {
for (Object nodeObj : bottomPanel.elements("item")) {
Element node = (Element) nodeObj;
saveOptionSetting(node, options);
}
}
}
use of org.dom4j.Document in project Openfire by igniterealtime.
the class PluginCacheConfigurator method configure.
public void configure(String pluginName) {
try {
SAXReader saxReader = new SAXReader();
saxReader.setEncoding("UTF-8");
Document cacheXml = saxReader.read(configDataStream);
List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping");
for (Node mapping : mappings) {
registerCache(pluginName, mapping);
}
} catch (DocumentException e) {
Log.error(e.getMessage(), e);
}
}
use of org.dom4j.Document in project Openfire by igniterealtime.
the class UpdateManager method loadLatestServerInfo.
private void loadLatestServerInfo() {
Document xmlResponse;
File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "server-update.xml");
if (!file.exists()) {
return;
}
// Check read privs.
if (!file.canRead()) {
Log.warn("Cannot retrieve server updates. File must be readable: " + file.getName());
return;
}
try (FileReader reader = new FileReader(file)) {
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlResponse = xmlReader.read(reader);
} catch (Exception e) {
Log.error("Error reading server-update.xml", e);
return;
}
// Parse info and recreate update information (if still required)
Element openfire = xmlResponse.getRootElement().element("openfire");
if (openfire != null) {
Version latestVersion = new Version(openfire.attributeValue("latest"));
String changelog = openfire.attributeValue("changelog");
String url = openfire.attributeValue("url");
// Check if current server version is correct
Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
if (latestVersion.isNewerThan(currentServerVersion)) {
serverUpdate = new Update("Openfire", latestVersion.getVersionString(), changelog, url);
}
}
}
use of org.dom4j.Document 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();
}
Aggregations