Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

In this page you can find the example usage for org.dom4j Element addText.

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:lost.tok.html.DiscussionPage.java

License:Open Source License

/**
 * Returns a paragraph Element linking to the selected source
 * @param src the source to link to// w  w  w .  j  a  v a 2 s .c om
 * @return a p element which can be added to the page
 */
private Element getLinkSrcElm(Source src) {
    Element cite = DocumentHelper.createElement("cite"); //$NON-NLS-1$

    Element srcLink = cite.addElement("a"); //$NON-NLS-1$
    srcLink.addAttribute("href", getPathToSrc(src)); //$NON-NLS-1$
    srcLink.addText(src.getTitle());

    cite.addText(Messages.getString("DiscussionPage.by")); //$NON-NLS-1$
    cite.addElement("em").addText(src.getAuthor()); //$NON-NLS-1$

    return cite;
}

From source file:lost.tok.html.IndexPage.java

License:Open Source License

/**
 * Returns a list of either sources or roots as an html elements
 * If the list is empty, returns an empty div element instead
 * @param isRoot true if the list should be of roots
 * @return an html div element containing the entire list
 *//*ww  w . j  a va 2 s  .c o  m*/
public Element getSourcesElement(boolean genRoot) {
    Element main = DocumentHelper.createElement("div"); //$NON-NLS-1$
    String listTitle = genRoot ? Messages.getString("IndexPage.Roots") //$NON-NLS-1$
            : Messages.getString("IndexPage.Sources"); //$NON-NLS-1$

    main.addElement("h2").addText(listTitle); //$NON-NLS-1$

    int numItems = 0; // the number of items in the list

    Element rootsList = main.addElement("ul"); //$NON-NLS-1$
    for (Source src : sources) {
        if (src.isRoot() != genRoot)
            continue;

        Element item = rootsList.addElement("li"); //$NON-NLS-1$

        String srcPath = src.getFile().getProjectRelativePath().toString();

        Element a = item.addElement("a"); //$NON-NLS-1$
        SourcePage sPage = srcPathToPage.get(srcPath);
        a.addAttribute("href", getPathTo(sPage)); //$NON-NLS-1$
        // a.addAttribute("tooltip", value)
        a.addText(src.getTitle());

        item.addText(Messages.getString("IndexPage.by")); //$NON-NLS-1$
        item.addElement("em").addText(src.getAuthor()); //$NON-NLS-1$
        item.addText(" (" + srcPath + ")"); //$NON-NLS-1$ //$NON-NLS-2$

        numItems++;
    }

    if (numItems > 0)
        return main;
    // else, we return an empty div
    return DocumentHelper.createElement("div"); //$NON-NLS-1$
}

From source file:lost.tok.html.IndexPage.java

License:Open Source License

/**
 * Returns a list of links to discussions, or empty div if no discussions exist
 * @return an html div element containing the entire list
 *///from  w  ww. j  av  a 2 s  .  co m
public Element getDiscussionElement() {
    Element main = DocumentHelper.createElement("div"); //$NON-NLS-1$

    if (discussions.length == 0)
        return main; // empty div

    main.addElement("h2").addText(Messages.getString("IndexPage.Discussions")); //$NON-NLS-1$ //$NON-NLS-2$

    Element rootsList = main.addElement("ul"); //$NON-NLS-1$
    for (Discussion disc : discussions) {
        Element item = rootsList.addElement("li"); //$NON-NLS-1$

        Element a = item.addElement("a"); //$NON-NLS-1$
        DiscussionPage dPage = discNameToPage.get(disc.getDiscName());
        a.addAttribute("href", getPathTo(dPage)); //$NON-NLS-1$
        // TODO(Shay, low): Add a normal tooltip in the index page
        //   a.addAttribute("tooltip", disc.getLinkType() );
        a.addText(disc.getDiscName());

        item.addText(Messages.getString("IndexPage.by")); //$NON-NLS-1$
        item.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$
        item.addText(" (" + disc.getDiscFileName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    return main;
}

From source file:mesquite.lib.PhoneHomeUtil.java

License:Open Source License

public static void writePhoneRecords(String path, ListableVector phoneRecords) {
    if (StringUtil.blank(path))
        return;/*  w w  w.  j  ava2  s. com*/
    Element mesquiteElement = DocumentHelper.createElement("mesquite");
    Document doc = DocumentHelper.createDocument(mesquiteElement);
    Element phoneRecordElement = DocumentHelper.createElement("phoneRecords");
    mesquiteElement.add(phoneRecordElement);
    Element versionElement = DocumentHelper.createElement("version");
    versionElement.addText("1");
    phoneRecordElement.add(versionElement);

    for (int i = 0; i < phoneRecords.size(); i++) {
        Element recordElement = DocumentHelper.createElement("record");
        phoneRecordElement.add(recordElement);
        PhoneHomeRecord phoneRecord = (PhoneHomeRecord) phoneRecords.elementAt(i);
        Element element = DocumentHelper.createElement("module");
        element.add(DocumentHelper.createCDATA(phoneRecord.getModuleName()));
        recordElement.add(element);
        MesquiteModuleInfo mmi = MesquiteTrunk.mesquiteModulesInfoVector.findModule(MesquiteModule.class,
                phoneRecord.getModuleName());
        XMLUtil.addFilledElement(recordElement, "lastVersionUsed",
                MesquiteInteger.toString(phoneRecord.getLastVersionUsed()));
        XMLUtil.addFilledElement(recordElement, "lastNotice",
                MesquiteInteger.toString(phoneRecord.getLastNotice()));
        XMLUtil.addFilledElement(recordElement, "lastNoticeForMyVersion",
                MesquiteInteger.toString(phoneRecord.getLastNoticeForMyVersion()));
        XMLUtil.addFilledElement(recordElement, "lastVersionNoticed",
                MesquiteInteger.toString(phoneRecord.getLastVersionNoticed()));
        XMLUtil.addFilledElement(recordElement, "lastNewerVersionReported",
                MesquiteInteger.toString(phoneRecord.getLastNewerVersionReported()));
    }
    String xml = XMLUtil.getDocumentAsXMLString(doc);
    if (!StringUtil.blank(xml))
        MesquiteFile.putFileContents(path, xml, true);

}

From source file:mesquite.lib.XMLUtil.java

License:Open Source License

public static Element addFilledElement(Element containingElement, String name, String content) {
    if (content == null || name == null)
        return null;
    Element element = DocumentHelper.createElement(name);
    element.addText(content);
    containingElement.add(element);//from  ww w . j  a  v  a  2  s . c o  m
    return element;
}

From source file:net.sf.kraken.protocols.irc.IRCListener.java

License:Open Source License

@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);
            }//from   ww  w. j  a va2s .c  o m
        }
    } 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());

    }
}

From source file:net.unicon.academus.apps.briefcase.migrate.BriefcaseMigrator.java

License:Open Source License

public static void main(String[] args) {

    System.out.println("Starting Briefcase portlet migration of data from Academus 1.5 " + " to Academus 1.6");

    if (args.length == 2) {
        try {// w ww .  ja va2s .  c o  m
            DataSource ds = new SimpleDataSource();

            SAXReader reader = new SAXReader();

            // replace the old urls with the new classpaths
            System.out.println("Updating the resource urls.");
            updateUrl(ds);
            updateSharedResourceUrls(ds);

            // replace the OWNER access type.
            System.out.println("Updating the accessTypes.");
            updateAccessType(ds);

            // set the uni_sequence table for the RdbmsAccessBroker Counter
            // and the FSA_Kernel_Sequencer
            updateSequencers(ds);

            // read the old config file
            // and correct the classpaths for all the access brokers.  
            Document oldDoc = reader.read(args[0]);

            DOMDocumentFactory dFac = new DOMDocumentFactory();

            // Get all access brokers
            List brokers = oldDoc.selectNodes("//access-broker");
            Element broker = null;

            // Change access brokers to point to alchemist instead of academus
            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                String implValue = broker.attributeValue("impl").replaceFirst("academus", "alchemist");
                broker.addAttribute("impl", implValue);
            }

            // Get the Access Broker under the personal Drive, and make sure it's a JIT broker
            Element targetsJitAccessBroker = (Element) ((Element) oldDoc.selectNodes(
                    "/briefcase/drive[@handle='personal']/access-broker[@impl='net.unicon.alchemist.access.jit.JitAccessBroker']")
                    .get(0)).detach();

            // Only enter this code if the personal drive section was successful selected
            if (targetsJitAccessBroker != null) {

                // Create new permissions element, mirroring targets element
                Element permissionsJitAccessBroker = (Element) targetsJitAccessBroker.clone();

                // Change handles
                targetsJitAccessBroker.addAttribute("handle", "personal-resourses-t");
                permissionsJitAccessBroker.addAttribute("handle", "personal-resourses-p");

                // Create new permissions access-broker
                Element permAccessBroker = dFac.createElement(new QName("access-broker"), 2);
                permAccessBroker.addAttribute("handle", "personal-jit");
                permAccessBroker.addAttribute("impl", PermissionsAccessBroker.class.getName());

                // Create new access element and add it to permAccessBroker
                Element permAccess = dFac.createElement(new QName("access"), 1);
                permAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permAccessBroker.add(permAccess);

                // Create targets and permissions elements and add to the new permissions access-broker
                Element targets = permAccessBroker.addElement("targets");
                targets.add(targetsJitAccessBroker);

                Element permissions = permAccessBroker.addElement("permissions");
                permissions.add(permissionsJitAccessBroker);

                // Add new permissions access broker to the drive
                Element curDrive = (Element) oldDoc.selectNodes("/briefcase/drive[@handle='personal']").get(0);
                curDrive.add(permAccessBroker);

                //
                // Change targets internals
                //

                List targetsAccess = targets.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < targetsAccess.size(); i++) {

                    // Add impl attribute with value of fully-qualified class name
                    ((Element) targetsAccess.get(i)).addAttribute("impl", DummyAccessType.class.getName());

                    // Get all child type elements and remove them
                    List types = ((Element) targetsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        ((Element) types.get(j)).detach();
                    }

                    // Add a single dummy element
                    Element eType = dFac.createElement(new QName("type"), 2);
                    eType.addAttribute("value", "GRANT");
                    eType.addAttribute("handle", "DUMMY");

                    ((Element) targetsAccess.get(i)).add(eType);

                }

                // Add internal access broker's access element
                Element targetsIAccessBroker = (Element) (targets.selectNodes("access-broker/access-broker")
                        .get(0));
                Element targetsIAccess = dFac.createElement(new QName("access"), 1);
                targetsIAccess.addAttribute("impl", DummyAccessType.class.getName());
                targetsIAccessBroker.add(targetsIAccess);

                //
                // Change permissions internals
                //

                List permissionsAccess = permissions.selectNodes("access-broker/jit-rule/behavior/access");
                for (int i = 0; i < permissionsAccess.size(); i++) {
                    // Add impl attribute with value of fully-qualified class name
                    ((Element) permissionsAccess.get(i)).addAttribute("impl",
                            BriefcaseAccessType.class.getName());

                    // Get all child type elements and replace them
                    List types = ((Element) permissionsAccess.get(i)).elements();
                    for (int j = 0; j < types.size(); j++) {
                        Attribute value = ((Element) types.get(j)).attribute("value");
                        String text = value.getValue();
                        value.setValue("GRANT");

                        if (text.equals("0")) {
                            BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                            ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                            for (int k = 1; k < aTypes.length; k++) {
                                Element eType = dFac.createElement(new QName("type"), 2);
                                eType.addAttribute("value", "GRANT");
                                eType.addAttribute("handle", aTypes[k].getName());
                                ((Element) permissionsAccess.get(i)).add(eType);
                            }
                        } else {
                            ((Element) types.get(j)).addAttribute("handle",
                                    BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                        }
                    }

                }

                // Change other elements in the permissions section
                List permissionsBehavior = permissions.selectNodes("access-broker/jit-rule/behavior");
                for (int i = 0; i < permissionsBehavior.size(); i++) {
                    Element trigger = (Element) ((Element) permissionsBehavior.get(i)).elements("trigger")
                            .get(0);
                    Element target = (Element) ((Element) permissionsBehavior.get(i)).elements("target").get(0);
                    Element creator = (Element) ((Element) permissionsBehavior.get(i)).elements("creator")
                            .get(0);

                    // Insert trigger text into target
                    target.addAttribute("type", "GROUP");
                    target.addText(trigger.getText());

                    // Remove current creator element
                    creator.detach();

                    // Add new current creator element
                    Element eCreator = dFac.createElement(new QName("creator"), 1);
                    eCreator.addAttribute("impl", DummyCreator.class.getName());
                    ((Element) permissionsBehavior.get(i)).add(eCreator);
                }

                // Change internal access broker's name
                Element permissionsIAccessBroker = (Element) (permissions
                        .selectNodes("access-broker/access-broker").get(0));
                permissionsIAccessBroker.addAttribute("handle", "personal-resources-p-i");

                // Add internal access broker's access element
                Element permissionsIAccess = dFac.createElement(new QName("access"), 1);
                permissionsIAccess.addAttribute("impl", BriefcaseAccessType.class.getName());
                permissionsIAccessBroker.add(permissionsIAccess);

            }

            List access = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access");
            for (int i = 0; i < access.size(); i++) {

                // Add impl attribute with value of fully-qualified class name
                ((Element) access.get(i)).addAttribute("impl", BriefcaseAccessType.class.getName());

                List types = ((Element) access.get(i)).elements();
                for (int j = 0; j < types.size(); j++) {
                    Attribute value = ((Element) types.get(j)).attribute("value");
                    String text = value.getValue();
                    value.setValue("GRANT");

                    if (text.equals("0")) {
                        BriefcaseAccessType[] aTypes = BriefcaseAccessType.getInstances();
                        ((Element) types.get(j)).addAttribute("handle", aTypes[0].getName());

                        for (int k = 1; k < aTypes.length; k++) {
                            Element eType = dFac.createElement(new QName("type"), 2);
                            eType.addAttribute("value", "GRANT");
                            eType.addAttribute("handle", aTypes[k].getName());
                            ((Element) access.get(i)).add(eType);
                        }
                    } else {
                        ((Element) types.get(j)).addAttribute("handle",
                                BriefcaseAccessType.getAccessType(Integer.parseInt(text)).getName());
                    }
                }
            }

            // add impl attribute to specify the UserDirectory impl to user-attribute element
            List userAttr = oldDoc.selectNodes("//user-attribute");
            for (int i = 0; i < userAttr.size(); i++) {
                ((Element) userAttr.get(i)).addAttribute("impl",
                        "net.unicon.academus.apps.briefcase.UserAttributeDirectory");
            }

            //replace the resource factory urls  
            List entries = oldDoc
                    .selectNodes("/briefcase/drive[@handle!='personal']//access-broker/entry[@target!='']");
            for (int i = 0; i < entries.size(); i++) {
                ((Element) entries.get(i)).addAttribute("target", ((Element) entries.get(i))
                        .attributeValue("target").replaceAll("academus.resource.factory", "demetrius.fac"));
            }

            // add access element to specify the AccessType to the RdbmsAccessBroker
            brokers = oldDoc.selectNodes("/briefcase/drive[@handle!='personal']//access-broker[@impl='"
                    + RdbmsAccessBroker.class.getName() + "']");

            for (int i = 0; i < brokers.size(); i++) {
                broker = (Element) brokers.get(i);
                Element eType = dFac.createElement(new QName("access"), 1);
                eType.addAttribute("impl", BriefcaseAccessType.class.getName());
                broker.add(eType);
            }

            // add the civis address book information.
            Element drive = (Element) oldDoc.selectSingleNode("briefcase");
            drive.addComment("Civis implementation to be used to resolve usernames and group paths"
                    + " to academus users and groups. This should not require"
                    + " modification, as it utilized the Academus framework for gathering this"
                    + " information.");

            Element civis = dFac.createElement("civis");
            civis.addAttribute("id", "addressBook");
            civis.addAttribute("impl", "net.unicon.civis.fac.academus.AcademusCivisFactory");

            Element restrictor = dFac.createElement("restrictor");
            restrictor.addAttribute("impl", "net.unicon.civis.grouprestrictor.AcademusGroupRestrictor");
            civis.add(restrictor);

            drive.add(civis);

            File f = new File(args[1]);
            PrintWriter pw = new PrintWriter(new FileOutputStream(f));
            pw.write(oldDoc.asXML());
            pw.flush();
            pw.close();

            System.out.println(
                    "Done. Enjoy !! \n Remember to the use the migrated config file with the 1.6 deploy.");

        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        usage();
    }

}

From source file:nl.ru.cmbi.vase.parse.VASEXMLParser.java

License:Apache License

private static void table2xml(TableData tableData, Element root) {

    Element table = root.addElement("data_table");

    for (ColumnInfo ci : tableData.getColumnInfos()) {

        Element column = table.addElement("column");
        column.addAttribute("id", ci.getId());

        if (!ci.getTitle().isEmpty())
            column.addAttribute("title", ci.getTitle());

        column.addAttribute("hidden", new Boolean(ci.isHidden()).toString());
        column.addAttribute("mouseover", new Boolean(ci.isMouseOver()).toString());
    }/*from ww w. j a v a 2  s . c o m*/

    for (int i = 0; i < tableData.getNumberOfRows(); i++) {

        Element row = table.addElement("row");

        Map<String, Object> rowData = tableData.getRowValues(i);

        for (ColumnInfo ci : tableData.getColumnInfos()) {

            Element value = row.addElement("value");
            value.addText(rowData.get(ci.getId()).toString());
        }
    }
}

From source file:nl.tue.gale.ae.impl.DefaultLoginHandler.java

License:Open Source License

@Override
public void addLoginPage(String method, Element page, Map<String, String[]> parameters) {
    if ("register".equals(method))
        addRegisterPage(page, parameters);
    if (!LoginManager.LOGINMETHOD.equals(method))
        return;//from   w w  w  .  j a  va 2 s .c  om
    Element div = page.element("body").addElement("div");
    Element p = div.addElement("p");
    p.addText("Leave empty if you want to log in anonymously");
    p.addElement("br");
    p.addElement("a").addAttribute("href", "?method=register").addText("Register here");
    Element table = div.addElement("form").addAttribute("action", "?method=default")
            .addAttribute("method", "POST").addElement("table");
    Element tr;
    tr = table.addElement("tr");
    tr.addElement("td").addText("Username:");
    tr.addElement("td").addElement("input").addAttribute("id", "focusfield").addAttribute("name", "username")
            .addAttribute("type", "text").addAttribute("size", "30");
    tr = table.addElement("tr");
    tr.addElement("td").addText("Password:");
    tr.addElement("td").addElement("input").addAttribute("name", "password").addAttribute("type", "password")
            .addAttribute("size", "30");
    tr = table.addElement("tr");
    tr.addElement("td");
    tr.addElement("td").addElement("input").addAttribute("name", "submit").addAttribute("type", "submit")
            .addAttribute("value", "Login");
}

From source file:nl.tue.gale.ae.impl.OpenIdLoginHandler.java

License:Open Source License

@Override
public void addLoginPage(String method, Element page, Map<String, String[]> parameters) {
    if (!LoginManager.LOGINMETHOD.equals(method))
        return;//w w  w. j a va 2s . c o m
    Element div = page.element("body").addElement("div");
    Element p = div.addElement("p");
    p.addText("Login using your ");
    p.addElement("a").addAttribute("href", "http://www.openid.net").addText("OpenID");
    /*
     * p.addElement("br"); p.add(createOpenIdLink("Facebook"));
     * p.addText(" | "); p.add(createOpenIdLink("Twitter"));
     * p.addText(" | "); p.add(createOpenIdLink("LinkedIn"));
     * p.addText(" | "); p.add(createOpenIdLink("Windows Live",
     * "live.anyopenid.com")); p.addText(" | ");
     * p.add(createOpenIdLink("MySpace"));
     */
    Element table = div.addElement("form").addAttribute("action", "?method=openid")
            .addAttribute("method", "POST").addElement("table");
    Element tr;
    tr = table.addElement("tr");
    tr.addElement("td").addText("OpenID:");
    tr.addElement("td").addElement("input").addAttribute("id", "openidlogo").addAttribute("name", "openidurl")
            .addAttribute("type", "text").addAttribute("size", "30");
    tr = table.addElement("tr");
    tr.addElement("td");
    tr.addElement("td").addElement("input").addAttribute("name", "submit").addAttribute("type", "submit")
            .addAttribute("value", "Login");
}