Search in sources :

Example 16 with Element

use of org.dom4j.Element in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method createJoins.

@SuppressWarnings({ "unchecked" })
private void createJoins(PersistentClass pc, Element parent, ClassAuditingData auditingData) {
    final Iterator<Join> joins = pc.getJoinIterator();
    final Map<Join, Element> joinElements = new HashMap<>();
    entitiesJoins.put(pc.getEntityName(), joinElements);
    while (joins.hasNext()) {
        Join join = joins.next();
        // Checking if all of the join properties are audited
        if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
            continue;
        }
        // Determining the table name. If there is no entry in the dictionary, just constructing the table name
        // as if it was an entity (by appending/prepending configured strings).
        final String originalTableName = join.getTable().getName();
        String auditTableName = auditingData.getSecondaryTableDictionary().get(originalTableName);
        if (auditTableName == null) {
            auditTableName = verEntCfg.getAuditEntityName(originalTableName);
        }
        final String schema = getSchema(auditingData.getAuditTable().schema(), join.getTable());
        final String catalog = getCatalog(auditingData.getAuditTable().catalog(), join.getTable());
        final Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
        joinElements.put(join, joinElement);
        // HHH-8305 - Fix case when join is considered optional.
        if (join.isOptional()) {
            joinElement.addAttribute("optional", "true");
        }
        // HHH-8305 - Fix case when join is the inverse side of a mapping.
        if (join.isInverse()) {
            joinElement.addAttribute("inverse", "true");
        }
        final Element joinKey = joinElement.addElement("key");
        MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
        MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null);
    }
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) Join(org.hibernate.mapping.Join)

Example 17 with Element

use of org.dom4j.Element in project hibernate-orm by hibernate.

the class AuditMetadataGenerator method addEndRevision.

private void addEndRevision(Element anyMapping) {
    // Add the end-revision field, if the appropriate strategy is used.
    if (auditStrategy instanceof ValidityAuditStrategy) {
        final Element endRevMapping = (Element) revisionInfoRelationMapping.clone();
        endRevMapping.setName("many-to-one");
        endRevMapping.addAttribute("name", verEntCfg.getRevisionEndFieldName());
        MetadataTools.addOrModifyColumn(endRevMapping, verEntCfg.getRevisionEndFieldName());
        anyMapping.add(endRevMapping);
        if (verEntCfg.isRevisionEndTimestampEnabled()) {
            // add a column for the timestamp of the end revision
            final String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName();
            final Element timestampProperty = MetadataTools.addProperty(anyMapping, verEntCfg.getRevisionEndTimestampFieldName(), revisionInfoTimestampSqlType, true, true, false);
            MetadataTools.addColumn(timestampProperty, verEntCfg.getRevisionEndTimestampFieldName(), null, null, null, null, null, null);
        }
    }
}
Also used : Element(org.dom4j.Element) ValidityAuditStrategy(org.hibernate.envers.strategy.ValidityAuditStrategy)

Example 18 with Element

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

the class BookmarkInterceptor method conferenceExists.

/**
     * Checks if the conference bookmark has already been defined in the users private storage.
     *
     * @param element  the private storage element.
     * @param roomJID the JID of the room to find.
     * @return true if the bookmark exists.
     */
private Element conferenceExists(Element element, String roomJID) {
    // Iterate through current elements to see if the conference bookmark
    // already exists.
    final Iterator<Element> conferences = element.elementIterator("conference");
    while (conferences.hasNext()) {
        final Element conferenceElement = conferences.next();
        String jidValue = conferenceElement.attributeValue("jid");
        if (jidValue != null && roomJID != null && jidValue.equalsIgnoreCase(roomJID)) {
            return conferenceElement;
        }
    }
    return null;
}
Also used : Element(org.dom4j.Element)

Example 19 with Element

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

the class IRCListener method updateCommand.

@Override
@SuppressWarnings("unchecked")
protected void updateCommand(InCommand inCommand) {
    Log.debug("IRC: Received incoming command:" + inCommand);
    if (inCommand instanceof CtcpMessage) {
        CtcpMessage cm = (CtcpMessage) inCommand;
        if (cm.getAction().equals("VERSION")) {
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "VERSION", "IMGateway" + getSession().getTransport().getVersionString() + ":Java:-"));
        } else if (cm.getAction().equals("PING")) {
            String timestamp = cm.getMessage();
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "PING", timestamp));
        } else if (cm.getAction().equals("TIME")) {
            Date current = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZZ");
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "TIME", format.format(current)));
        } else if (cm.getAction().equals("ACTION")) {
            if (cm.isPrivateToUs(getSession().getConnection().getClientState())) {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(cm.getSource().getNick()), "/me " + cm.getMessage());
            } else {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(cm.getDest(), cm.getSource().getNick()), "/me " + cm.getMessage(), Message.Type.groupchat);
            }
        }
    } else if (inCommand instanceof MessageCommand) {
        MessageCommand mc = (MessageCommand) inCommand;
        if (mc.isPrivateToUs(getSession().getConnection().getClientState())) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()));
        } else {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mc.getDest(), mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()), Message.Type.groupchat);
        }
    } else if (inCommand instanceof NoticeCommand) {
        NoticeCommand nc = (NoticeCommand) inCommand;
        if (nc.getFrom() != null) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(nc.getFrom().getNick()), IRCStringUtils.stripControlChars(nc.getNotice()));
        }
    } else if (inCommand instanceof JoinCommand) {
        JoinCommand jc = (JoinCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(jc.getChannel());
            mucSession.getContacts().add(jc.getUser().getNick());
            Presence p = new Presence();
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(jc.getChannel(), jc.getUser().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "member");
            item.addAttribute("role", "participant");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof PartCommand) {
        PartCommand pc = (PartCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(pc.getChannel());
            mucSession.getContacts().remove(pc.getUser().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(pc.getChannel(), pc.getUser().getNick()));
            p.setTo(getSession().getJID());
            if (pc.getReason() != null && !pc.getReason().equals("")) {
                p.setStatus(pc.getReason());
            }
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof QuitCommand) {
        QuitCommand qc = (QuitCommand) inCommand;
        for (MUCTransportSession session : getSession().getMUCSessionManager().getSessions()) {
            if (((IRCMUCSession) session).getContacts().contains(qc.getUser().getNick())) {
                ((IRCMUCSession) session).getContacts().remove(qc.getUser().getNick());
                Presence p = new Presence();
                p.setType(Presence.Type.unavailable);
                p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(((IRCMUCSession) session).roomname, qc.getUser().getNick()));
                p.setTo(getSession().getJID());
                if (qc.getReason() != null && !qc.getReason().equals("")) {
                    p.setStatus(qc.getReason());
                }
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                item.addAttribute("affiliation", "none");
                item.addAttribute("role", "none");
                getSession().getTransport().sendPacket(p);
            }
        }
    } else if (inCommand instanceof InviteCommand) {
        InviteCommand ic = (InviteCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        Message m = new Message();
        m.setTo(getSession().getJID());
        m.setFrom(mucTransport.convertIDToJID(ic.getChannel(), null));
        Element x = m.addChildElement("x", "http://jabber.org/protocol/muc#user");
        Element invite = x.addElement("invite");
        invite.addAttribute("from", getSession().getTransport().convertIDToJID(ic.getSourceString()).toBareJID());
        getSession().getTransport().sendPacket(m);
    } else if (inCommand instanceof KickCommand) {
        KickCommand kc = (KickCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(kc.getChannel());
            mucSession.getContacts().add(kc.getKicked().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(mucTransport.convertIDToJID(kc.getChannel(), kc.getKicked().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            Element actor = item.addElement("actor");
            actor.addAttribute("jid", getSession().getTransport().convertIDToJID(kc.getKicker().getNick()).toBareJID());
            Element reason = item.addElement("reason");
            reason.addText(kc.getComment());
            Element status = elem.addElement("status");
            status.addAttribute("code", "307");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
        if (kc.kickedUs(getSession().getConnection().getClientState())) {
            getSession().getMUCSessionManager().removeSession(kc.getChannel());
        }
    } else if (inCommand instanceof ChannelModeCommand) {
    //ChannelModeCommand cmc = (ChannelModeCommand)inCommand;
    // TODO: Fix up martyr to handle this then handle it here
    } else if (inCommand instanceof NickCommand) {
    //NickCommand nc = (NickCommand)inCommand;
    // TODO: Map to MUC event  (someone's nick just changed)
    } else if (inCommand instanceof ModeCommand) {
    //ModeCommand mc = (ModeCommand)inCommand;
    // TODO: Map to MUC event  (your mode just changed)
    } else if (inCommand instanceof TopicCommand) {
        TopicCommand tc = (TopicCommand) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tc.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof TopicInfoReply) {
        TopicInfoReply tir = (TopicInfoReply) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tir.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof NamesReply) {
        NamesReply nr = (NamesReply) inCommand;
        String channelName = nr.getChannel();
        List<MUCTransportRoomMember> members = new ArrayList<MUCTransportRoomMember>();
        for (String nick : nr.getNames()) {
            members.add(new MUCTransportRoomMember(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, nick)));
        }
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomMembers(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(channelName, null), members);
    } else if (inCommand instanceof NamesEndReply) {
        NamesEndReply ner = (NamesEndReply) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(ner.getChannel());
            mucSession.getContacts().clear();
            Member myMember = null;
            Channel channel = getSession().getConnection().getClientState().getChannel(ner.getChannel());
            if (channel != null) {
                Enumeration members = channel.getMembers();
                while (members.hasMoreElements()) {
                    Member member = (Member) members.nextElement();
                    if (member.getNick().getNick().equals(mucSession.getNickname()) || member.getNick().getNick().equals(getSession().getRegistration().getNickname())) {
                        // Aha, this is us, save for the end.
                        myMember = member;
                        continue;
                    }
                    Presence p = new Presence();
                    p.setTo(getSession().getJID());
                    if (member.hasOps()) {
                        // Moderator.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "admin");
                        item.addAttribute("role", "moderator");
                    } else {
                        // Regular participant.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "member");
                        item.addAttribute("role", "participant");
                    }
                    mucTransport.sendPacket(p);
                }
            }
            if (myMember != null) {
                Presence p = new Presence();
                p.setTo(getSession().getJID());
                p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), mucSession.getNickname()));
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                if (myMember.hasOps()) {
                    item.addAttribute("affiliation", "admin");
                    item.addAttribute("role", "moderator");
                } else {
                    item.addAttribute("affiliation", "member");
                    item.addAttribute("role", "participant");
                }
                Element status = elem.addElement("status");
                status.addAttribute("code", "110");
                mucTransport.sendPacket(p);
            }
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof ListStartReply) {
    // Do nothing.
    } else if (inCommand instanceof ListReply) {
        ListReply lr = (ListReply) inCommand;
        String channelName = lr.getChannel();
        MUCTransportRoom mucRoom = getSession().getTransport().getMUCTransport().getCachedRoom(channelName);
        if (mucRoom == null) {
            mucRoom = new MUCTransportRoom(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, ""), channelName);
        }
        mucRoom.setTopic(lr.getTopic());
        mucRoom.setOccupant_count(lr.getMemberCount());
        getSession().getTransport().getMUCTransport().cacheRoom(mucRoom);
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomInfo(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mucRoom.getName(), null), mucRoom);
    } else if (inCommand instanceof ListEndReply) {
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRooms(getSession().getJID(), getSession().getTransport().getMUCTransport().getCachedRooms());
    } else if (inCommand instanceof IsonCommand) {
        IsonCommand ic = (IsonCommand) inCommand;
        List<String> newNicks = new ArrayList<String>();
        for (String nick : ic.getNicks()) {
            newNicks.add(nick.toLowerCase());
        }
        Log.debug("IRC: Got ISON for " + ic.getDest() + " of: " + ic.getNicks());
        for (TransportBuddy buddy : getSession().getBuddyManager().getBuddies()) {
            if (!newNicks.contains(buddy.getName())) {
                // Previously online nick went offline
                buddy.setPresence(PresenceType.unavailable);
            } else {
                // Previously online nick is still online
                buddy.setPresence(PresenceType.available);
            }
        }
    } else if (inCommand instanceof UnAwayReply) {
        getSession().setPresence(PresenceType.available);
    } else if (inCommand instanceof NowAwayReply) {
        getSession().setPresence(PresenceType.away);
    } else if (inCommand instanceof AwayReply) {
        AwayReply ar = (AwayReply) inCommand;
        getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(ar.getNick()), LocaleUtils.getLocalizedString("gateway.irc.autoreply", "kraken") + " " + ar.getMessage());
    }
}
Also used : CtcpNotice(f00f.net.irc.martyr.commands.CtcpNotice) Message(org.xmpp.packet.Message) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) JoinCommand(f00f.net.irc.martyr.commands.JoinCommand) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) NickCommand(f00f.net.irc.martyr.commands.NickCommand) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) AwayReply(f00f.net.irc.martyr.replies.AwayReply) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) InviteCommand(f00f.net.irc.martyr.commands.InviteCommand) TopicInfoReply(f00f.net.irc.martyr.replies.TopicInfoReply) PartCommand(f00f.net.irc.martyr.commands.PartCommand) ListStartReply(f00f.net.irc.martyr.replies.ListStartReply) NamesReply(f00f.net.irc.martyr.replies.NamesReply) KickCommand(f00f.net.irc.martyr.commands.KickCommand) Presence(org.xmpp.packet.Presence) ModeCommand(f00f.net.irc.martyr.commands.ModeCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) ArrayList(java.util.ArrayList) List(java.util.List) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) Member(f00f.net.irc.martyr.clientstate.Member) NamesEndReply(f00f.net.irc.martyr.replies.NamesEndReply) BaseMUCTransport(net.sf.kraken.muc.BaseMUCTransport) IsonCommand(f00f.net.irc.martyr.commands.IsonCommand) MUCTransportSession(net.sf.kraken.muc.MUCTransportSession) Enumeration(java.util.Enumeration) TopicCommand(f00f.net.irc.martyr.commands.TopicCommand) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) MessageCommand(f00f.net.irc.martyr.commands.MessageCommand) Channel(f00f.net.irc.martyr.clientstate.Channel) TransportBuddy(net.sf.kraken.roster.TransportBuddy) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) NoticeCommand(f00f.net.irc.martyr.commands.NoticeCommand) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) ListEndReply(f00f.net.irc.martyr.replies.ListEndReply) Date(java.util.Date) ListReply(f00f.net.irc.martyr.replies.ListReply) MUCTransportRoom(net.sf.kraken.muc.MUCTransportRoom) QuitCommand(f00f.net.irc.martyr.commands.QuitCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with Element

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

the class BaseMUCTransport method sendRooms.

/**
     * Sends a list of rooms as a response to a service discovery request.
     *
     * @param to JID we will be sending the response to.
     * @param rooms List of MUCTransportRoom objects to send as a response.
     */
public void sendRooms(JID to, Collection<MUCTransportRoom> rooms) {
    IQ request = getPendingRequest(to, this.getJID(), NameSpace.DISCO_ITEMS);
    if (request != null) {
        IQ result = IQ.createResultIQ(request);
        Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_ITEMS));
        for (MUCTransportRoom room : rooms) {
            Element item = response.addElement("item");
            item.addAttribute("jid", room.getJid().toBareJID());
            item.addAttribute("name", room.getName());
        }
        result.setChildElement(response);
        this.sendPacket(result);
    }
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64