Search in sources :

Example 1 with Node

use of org.dom4j.Node in project Openfire by igniterealtime.

the class ClientToComponentUpdateProcessor method process.

@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    Log.debug("Processing packet in ClientToComponentUpdateProcessor: " + packet.toString());
    Element query = ((IQ) packet).getChildElement();
    List<Node> nodes = findNodesInDocument(query.getDocument(), "//roster:item");
    if (nodes.size() > 0) {
        // against our valid subdomains.
        for (Node n : nodes) {
            String jid = n.valueOf("@jid");
            // TODO: We ignore remove iq packets for now. There might be
            // conflicts
            // when we remove our legacy network registration.
            String found_subdomain = searchJIDforSubdomain(jid);
            if (found_subdomain.length() > 0 && !n.valueOf("@subscription").equals("remove")) {
                Log.debug("Mirroring packet from local network to legacy component " + found_subdomain);
                IQ forward = (IQ) packet.createCopy();
                forward.setTo(found_subdomain);
                dispatchPacket(forward);
            }
        }
    }
}
Also used : Element(org.dom4j.Element) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ)

Example 2 with Node

use of org.dom4j.Node in project Openfire by igniterealtime.

the class IQRosterPayloadProcessor method handleIQset.

private void handleIQset(IQ myPacket, final String subdomain, final String username) throws PacketRejectedException {
    IQ response = IQ.createResultIQ(myPacket);
    List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
    for (Node n : nodes) {
        Roster roster;
        String jid = n.valueOf("@jid");
        String name = n.valueOf("@name");
        String subvalue = n.valueOf("@subscription");
        // causing trouble on register:remove
        if (JiveGlobals.getBooleanProperty("plugin.remoteroster.ignoreSubdomains", true) && jid.equals(subdomain) && subvalue.equals("both"))
            throw new PacketRejectedException();
        if (subvalue.equals("both")) {
            try {
                roster = _rosterManager.getRoster(username);
                List<String> grouplist = new ArrayList<String>();
                List<Node> groupnodes = findNodesInDocument(n.getDocument(), "//roster:group");
                for (Node ne : groupnodes) {
                    String groupName = ne.getText();
                    grouplist.add(groupName);
                }
                boolean rosterPersistent = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
                Log.debug("Adding/Updating Contact " + jid + " to roster of " + username);
                try {
                    RosterItem item = roster.getRosterItem(new JID(jid));
                    item.setGroups(grouplist);
                    roster.updateRosterItem(item);
                    // dont send iq-result if just updating user
                    continue;
                } catch (UserNotFoundException exc) {
                // Then we should add him!
                }
                RosterItem item = roster.createRosterItem(new JID(jid), name, grouplist, false, rosterPersistent);
                item.setSubStatus(RosterItem.SUB_BOTH);
                roster.updateRosterItem(item);
            } catch (Exception e) {
                Log.info("Could not add user to Roster although no entry should exist..." + username, e);
            }
            dispatchPacket(response);
        } else if (subvalue.equals("remove")) {
            // we dont need to do this when persistent = false because they will get deleted as soon as gateway is unavailable
            if (JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && jid.equals(subdomain)) {
                deleteSubdomainItemsFromRoster(username, subdomain);
            }
            // to handle it
            throw new PacketRejectedException();
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Roster(org.jivesoftware.openfire.roster.Roster) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 3 with Node

use of org.dom4j.Node in project Openfire by igniterealtime.

the class MucFilterProcessor method process.

/**
	 * At this Point we know: MucBlock = true, !incoming, !processed Package is
	 * IQ with Namespace disco#info, from equals the watched subdomain given
	 * through subdomain
	 */
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    IQ iqPacket = (IQ) packet;
    if (iqPacket.getType().equals(IQ.Type.result) && to.length() > 0) {
        Element root = iqPacket.getChildElement();
        List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//disco:feature");
        for (Node node : nodes) {
            String var = node.valueOf("@var");
            if (var.equals("http://jabber.org/protocol/muc"))
                root.remove(node);
        }
    }
}
Also used : Element(org.dom4j.Element) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ)

Example 4 with Node

use of org.dom4j.Node in project Openfire by igniterealtime.

the class WhitelistProcessor method process.

/**
	 * If this is valid disco#items package for this Use-Case we iterate through
	 * the nodes and check if we have to remove nodes, this way they are not
	 * shown to the user receiving this disco#items.
	 * 
	 * @param subdomain
	 *            not the actual Subdomain here, as we have to use our set.
	 */
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
    IQ myPacket = (IQ) packet;
    if (myPacket.getType().equals(IQ.Type.result) && (from.length() == 0 || from.equals(_server.getServerInfo().getXMPPDomain()))) {
        Log.debug("Processing packet in Whitelistprocessor for " + to + "Packet: " + packet.toString());
        Element root = myPacket.getChildElement();
        List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoitems:item");
        for (Node node : nodes) {
            String node_domain = node.valueOf("@jid");
            if (watchedSubdomains.contains(node_domain)) {
                if (_permissions.isGatewayLimited(node_domain) && !_permissions.allowedForUser(node_domain, myPacket.getTo()))
                    root.remove(node);
            }
        }
    }
}
Also used : Element(org.dom4j.Element) Node(org.dom4j.Node) IQ(org.xmpp.packet.IQ)

Example 5 with Node

use of org.dom4j.Node in project atlas by alibaba.

the class ManifestFileUtils method updatePreProcessManifestFile.

/**
     * 更新libManifest文件
     *
     * @param libManifestFile
     * @param mainManifestFileObject param updateSdkVersion
     */
public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject, boolean updateSdkVersion) throws IOException, DocumentException {
    if (!libManifestFile.exists()) {
        return;
    }
    File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml");
    if (orgManifestFile.exists()) {
        return;
    }
    libManifestFile.renameTo(orgManifestFile);
    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    // 设置XML文件的编码格式
    format.setEncoding("UTF-8");
    // 读取XML文件
    Document document = reader.read(orgManifestFile);
    // 得到根节点
    Element root = document.getRootElement();
    if (updateSdkVersion) {
        Element useSdkElement = root.element("uses-sdk");
        if (null == useSdkElement) {
            useSdkElement = root.addElement("uses-sdk");
        }
        if (null != useSdkElement) {
            updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties());
        }
    }
    // 先人工处理一下tools:remove和tools:replace规则,发现有些通过ManifestMerge不一定可以
    Element applicationElement = root.element("application");
    Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute();
    List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute();
    if (null != applicationElement) {
        // 去除lib项目里的tools属性
        List<Attribute> toRomoved = new ArrayList<Attribute>();
        for (Attribute attribute : applicationElement.attributes()) {
            if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) {
                // applicationElement.remove(attribute);
                // applicationElement.attributes().remove(attribute);
                toRomoved.add(attribute);
            }
        }
        if (toRomoved.size() > 0) {
            for (Attribute attribute : toRomoved) {
                applicationElement.remove(attribute);
            }
        }
        updateApplicationElement(applicationElement, replaceAttrs, removeAttrs);
    }
    //处理packageName TODO
    String packageName = root.attributeValue("package");
    if (StringUtils.isEmpty(packageName)) {
        packageName = ManifestFileUtils.getPackage(orgManifestFile);
    }
    List<? extends Node> applicatNodes = root.selectNodes("//application");
    for (Node node : applicatNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (!attribute.getValue().startsWith(packageName)) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }
    fillFullClazzName(root, packageName, "activity");
    fillFullClazzName(root, packageName, "provider");
    fillFullClazzName(root, packageName, "receiver");
    fillFullClazzName(root, packageName, "service");
    saveFile(document, format, libManifestFile);
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) File(java.io.File)

Aggregations

Node (org.dom4j.Node)253 Document (org.dom4j.Document)83 Element (org.dom4j.Element)61 ArrayList (java.util.ArrayList)56 List (java.util.List)54 Test (org.junit.Test)40 SAXReader (org.dom4j.io.SAXReader)28 File (java.io.File)25 Iterator (java.util.Iterator)18 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)18 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)18 HashMap (java.util.HashMap)16 URL (java.net.URL)15 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)15 InputStream (java.io.InputStream)14 Attribute (org.dom4j.Attribute)14 Image (java.awt.Image)12 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)11 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10