use of org.dom4j.Document in project hibernate-orm by hibernate.
the class RevisionInfoConfiguration method generateRevisionInfoRelationMapping.
private Element generateRevisionInfoRelationMapping() {
final Document document = globalCfg.getEnversService().getXmlHelper().getDocumentFactory().createDocument();
final Element revRelMapping = document.addElement("key-many-to-one");
revRelMapping.addAttribute("type", revisionPropType);
revRelMapping.addAttribute("class", revisionInfoEntityName);
if (revisionPropSqlType != null) {
// Putting a fake name to make Hibernate happy. It will be replaced later anyway.
MetadataTools.addColumn(revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false);
}
return revRelMapping;
}
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 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.Document in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterChatMessage.
@Test
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
String chatXML = "<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" + "<body>fox</body>" + "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" + "<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" + "</html>" + "<x xmlns=\"jabber:x:event\">" + "<composing/>" + "</x>" + "</message>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(chatXML));
Message m = new Message(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = chatXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(m);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, m.toXML());
}
Aggregations