Search in sources :

Example 1 with DefaultElement

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);
}
Also used : Packet(org.xmpp.packet.Packet) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Attribute(org.dom4j.Attribute) DefaultElement(org.dom4j.tree.DefaultElement) InterceptorManager(org.jivesoftware.openfire.interceptor.InterceptorManager) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) TimerTask(java.util.TimerTask) Timer(java.util.Timer) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) DefaultAttribute(org.dom4j.tree.DefaultAttribute) Session(org.jivesoftware.openfire.session.Session)

Example 2 with DefaultElement

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);
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DefaultAttribute(org.dom4j.tree.DefaultAttribute)

Example 3 with DefaultElement

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);
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 4 with DefaultElement

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);
}
Also used : SingleIdMapper(org.hibernate.envers.internal.entities.mapper.id.SingleIdMapper) DefaultElement(org.dom4j.tree.DefaultElement) SimpleIdMapperBuilder(org.hibernate.envers.internal.entities.mapper.id.SimpleIdMapperBuilder) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Iterator(java.util.Iterator) PersistentClass(org.hibernate.mapping.PersistentClass) Component(org.hibernate.mapping.Component) EmbeddedIdMapper(org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper) Property(org.hibernate.mapping.Property) MultipleIdMapper(org.hibernate.envers.internal.entities.mapper.id.MultipleIdMapper) IdMappingData(org.hibernate.envers.internal.entities.IdMappingData)

Example 5 with DefaultElement

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;
            }
        }
    }
}
Also used : Attribute(org.dom4j.Attribute) DefaultElement(org.dom4j.tree.DefaultElement) QName(org.dom4j.QName) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Document(org.dom4j.Document)

Aggregations

DefaultElement (org.dom4j.tree.DefaultElement)9 Element (org.dom4j.Element)8 IQ (org.xmpp.packet.IQ)3 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 DefaultAttribute (org.dom4j.tree.DefaultAttribute)2 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)1 Modifications (com.thoughtworks.go.domain.materials.Modifications)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 QName (org.dom4j.QName)1 SAXReader (org.dom4j.io.SAXReader)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 IdMappingData (org.hibernate.envers.internal.entities.IdMappingData)1 EmbeddedIdMapper (org.hibernate.envers.internal.entities.mapper.id.EmbeddedIdMapper)1