use of org.dom4j.tree.DefaultElement in project Openfire by igniterealtime.
the class DiscoIQRegisteredProcessor method process.
@Override
public void process(Packet packet, final String subdomain, String to, String from) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQRegisteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) {
Log.debug("Spark extension is deactivated. Won't change the disco#info");
return;
}
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (!processed && incoming) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element packetElement = iqPacket.getChildElement();
if (packetElement == null)
return;
String ns = iqPacket.getChildElement().getNamespace().getURI();
if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") && iqPacket.getFrom().toString().equals(subdomain)) {
// Check if we are already registered
setRegistered(iqPacket.toString().contains("<registered/>"));
throw new PacketRejectedException();
} else if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("http://jabber.org/protocol/disco#info") && iqPacket.getFrom().toString().equals(subdomain)) {
/*
* This is the answer of the disco#info from spark
* to our component. add the jabber:iq:register
* feature if we are registered
*/
if (isRegistered()) {
Log.debug("Modifying disco#info packge to send registered iq feature to Spark user " + iqPacket.getTo().toString());
Attribute attribut = new DefaultAttribute("var", "jabber:iq:registered");
iqPacket.getChildElement().addElement("feature").add(attribut);
}
}
}
}
}
};
Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
interceptorManager.addInterceptor(interceptor);
IQ askComponent = new IQ();
askComponent.setTo(to);
askComponent.setFrom(from);
askComponent.setType(IQ.Type.get);
Element query = new DefaultElement(QName.get("query", "jabber:iq:register"));
askComponent.setChildElement(query);
// Remove the package intercepter in 1sec
TimerTask removeInterceptorTask = new TimerTask() {
@Override
public void run() {
Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
interceptorManager.removeInterceptor(interceptor);
}
};
Timer timer = new Timer();
timer.schedule(removeInterceptorTask, 1000);
// Send the register query to component
dispatchPacket(askComponent);
}
use of org.dom4j.tree.DefaultElement in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method sendRosterToComponent.
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(subdomain);
Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
for (RosterItem i : items) {
String jid = i.getJid().toString();
if (!jid.equals(subdomain) && jid.contains(subdomain)) {
Log.debug("Roster exchange for external component " + subdomain + ". Sending user " + i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
item.add(new DefaultAttribute("name", i.getNickname()));
item.add(new DefaultAttribute("subscription", "both"));
for (String s : i.getGroups()) {
Element group = new DefaultElement("group");
group.setText(s);
item.add(group);
}
query.add(item);
}
}
response.setChildElement(query);
dispatchPacket(response);
}
use of org.dom4j.tree.DefaultElement in project Openfire by igniterealtime.
the class IQRosterPayloadProcessor method sendEmptyRoster.
private void sendEmptyRoster(Packet requestPacket, String subdomain) {
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
response.setTo(subdomain);
Element query = new DefaultElement(QName.get("query", "jabber:iq:roster"));
response.setChildElement(query);
dispatchPacket(response);
}
use of org.dom4j.tree.DefaultElement in project hibernate-orm by hibernate.
the class IdMetadataGenerator method addId.
@SuppressWarnings({ "unchecked" })
IdMappingData addId(PersistentClass pc, boolean audited) {
// Xml mapping which will be used for relations
final Element relIdMapping = new DefaultElement("properties");
// Xml mapping which will be used for the primary key of the versions table
final Element origIdMapping = new DefaultElement("composite-id");
final Property idProp = pc.getIdentifierProperty();
final Component idMapper = pc.getIdentifierMapper();
// Checking if the id mapping is supported
if (idMapper == null && idProp == null) {
return null;
}
SimpleIdMapperBuilder mapper;
if (idMapper != null) {
// Multiple id
final Class componentClass = ReflectionTools.loadClass(((Component) pc.getIdentifier()).getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new MultipleIdMapper(componentClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), null, true, audited)) {
return null;
}
} else if (idProp.isComposite()) {
// Embedded id
final Component idComponent = (Component) idProp.getValue();
final Class embeddableClass = ReflectionTools.loadClass(idComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new EmbeddedIdMapper(getIdPropertyData(idProp), embeddableClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), null, true, audited)) {
return null;
}
} else {
// Single id
mapper = new SingleIdMapper(pc.getServiceRegistry());
// Last but one parameter: ids are always insertable
mainGenerator.getBasicMetadataGenerator().addBasic(relIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), mapper, true, false);
// null mapper - the mapping where already added the first time, now we only want to generate the xml
mainGenerator.getBasicMetadataGenerator().addBasic(origIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), null, true, true);
}
origIdMapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
// Adding a relation to the revision entity (effectively: the "revision number" property)
mainGenerator.addRevisionInfoRelation(origIdMapping);
return new IdMappingData(mapper, origIdMapping, relIdMapping);
}
use of org.dom4j.tree.DefaultElement in project tesb-studio-se by Talend.
the class AddSpringConfigurationPropertyMigrationTask method addIgnoreExchangeEventProperty.
private void addIgnoreExchangeEventProperty(CamelProcessItem item) throws PersistenceException, DocumentException {
String springContent = item.getSpringContent();
if (null != springContent && !springContent.isEmpty()) {
Document document = DocumentHelper.parseText(springContent);
QName qname = QName.get("bean", SPRING_BEANS_NAMESPACE);
List<Element> beans = document.getRootElement().elements(qname);
for (Element bean : beans) {
if ("jmxEventNotifier".equals(bean.attributeValue("id")) && "org.apache.camel.management.JmxNotificationEventNotifier".equals(bean.attributeValue("class"))) {
List<Element> properties = bean.elements(QName.get("property", SPRING_BEANS_NAMESPACE));
boolean hasIgnore = false;
for (Element property : properties) {
List<Attribute> propertyAttributes = property.attributes();
for (Attribute propertyAttribute : propertyAttributes) {
if (propertyAttribute.getValue().equals(IGNORE_EXCHANGE_EVENTS)) {
hasIgnore = true;
break;
}
}
}
if (!hasIgnore) {
DefaultElement ignoreExchangeElement = new DefaultElement("property", bean.getNamespace());
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "name", IGNORE_EXCHANGE_EVENTS));
ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "value", "true"));
bean.add(ignoreExchangeElement);
item.setSpringContent(document.asXML());
saveItem(item);
}
break;
}
}
}
}
Aggregations