Search in sources :

Example 1 with DbProperties

use of org.jivesoftware.xmpp.workgroup.DbProperties in project Openfire by igniterealtime.

the class FormManager method saveDataForm.

private void saveDataForm(Workgroup workgroup) {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    WorkgroupForm form = getWebForm(workgroup);
    if (form.getTitle() != null) {
        dataForm.setTitle(form.getTitle());
    }
    if (form.getDescription() != null) {
        dataForm.addInstruction(form.getDescription());
    }
    List<FormElement> elems = new ArrayList<FormElement>();
    // Add normal elems
    int size = form.getFormElements().size();
    for (int j = 0; j < size; j++) {
        elems.add(form.getFormElementAt(j));
    }
    size = form.getHiddenVars().size();
    for (int k = 0; k < size; k++) {
        elems.add(form.getHiddenVars().get(k));
    }
    size = elems.size();
    for (int i = 0; i < size; i++) {
        FormElement elem = elems.get(i);
        FormField field = dataForm.addField();
        field.setLabel(elem.getLabel());
        field.setVariable(elem.getVariable());
        field.setRequired(elem.isRequired());
        if (elem.getDescription() != null) {
            field.setDescription(elem.getDescription());
        }
        if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
            field.setType(FormField.Type.text_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
            field.setType(FormField.Type.text_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
            field.setType(FormField.Type.boolean_type);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
            field.setType(FormField.Type.list_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
            field.setType(FormField.Type.list_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
            field.setType(FormField.Type.hidden);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
            field.setType(FormField.Type.text_private);
        }
        if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
            for (String item : elem.getAnswers()) {
                field.addOption(item, item);
            }
        } else if (elem.getAnswers().size() > 0) {
            // Add hidden element values.
            for (String item : elem.getAnswers()) {
                field.addValue(item);
            }
        }
    }
    XStream xstream = new XStream();
    String xmlToSave = xstream.toXML(dataForm);
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    try {
        props.deleteProperty(context);
        props.setProperty(context, xmlToSave);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) FormField(org.xmpp.forms.FormField)

Example 2 with DbProperties

use of org.jivesoftware.xmpp.workgroup.DbProperties in project Openfire by igniterealtime.

the class FormManager method loadWebForms.

private void loadWebForms() {
    final WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
        DbProperties props = workgroup.getProperties();
        String context = "jive.webform.wg";
        String form = props.getProperty(context);
        if (form != null) {
            XStream xstream = new XStream();
            xstream.setClassLoader(this.getClass().getClassLoader());
            try {
                Object object = xstream.fromXML(form);
                WorkgroupForm workgroupForm = (WorkgroupForm) object;
                if (workgroupForm != null) {
                    addWorkgroupForm(workgroup, workgroupForm);
                }
            } catch (Exception e) {
                Log.error(e.getMessage(), e);
            }
        } else {
            // Create a default Web Form
            createGenericForm(workgroup);
        }
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException)

Example 3 with DbProperties

use of org.jivesoftware.xmpp.workgroup.DbProperties in project Openfire by igniterealtime.

the class FormManager method getDataForm.

public DataForm getDataForm(Workgroup workgroup) {
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    String form = props.getProperty(context);
    if (form != null) {
        XStream xstream = new XStream();
        xstream.setClassLoader(this.getClass().getClassLoader());
        try {
            return (DataForm) xstream.fromXML(form);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException)

Example 4 with DbProperties

use of org.jivesoftware.xmpp.workgroup.DbProperties in project Openfire by igniterealtime.

the class FormManager method saveWorkgroupForm.

public void saveWorkgroupForm(Workgroup workgroup) {
    // Save Web Form for editing
    WorkgroupForm workgroupForm = getWebForm(workgroup);
    if (workgroupForm != null) {
        XStream xstream = new XStream();
        String xmlToSave = xstream.toXML(workgroupForm);
        DbProperties props = workgroup.getProperties();
        String context = "jive.webform.wg";
        try {
            props.deleteProperty(context);
            props.setProperty(context, xmlToSave);
        } catch (UnauthorizedException e) {
            Log.error(e.getMessage(), e);
        }
    }
    // Save DataForm for usage
    saveDataForm(workgroup);
}
Also used : XStream(com.thoughtworks.xstream.XStream) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Example 5 with DbProperties

use of org.jivesoftware.xmpp.workgroup.DbProperties in project Openfire by igniterealtime.

the class MacroProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply;
    Element iq = packet.getChildElement();
    String personalMacro = iq.element("personalMacro").getTextTrim();
    try {
        // Verify that an agent is requesting this information.
        Agent agent = workgroup.getAgentManager().getAgent(packet.getFrom());
        DbProperties props = agent.getProperties();
        XStream xstream = new XStream();
        xstream.alias("macro", Macro.class);
        xstream.alias("macrogroup", MacroGroup.class);
        MacroGroup group = (MacroGroup) xstream.fromXML(personalMacro);
        String saveString = xstream.toXML(group);
        try {
            props.deleteProperty("personal.macro");
            props.setProperty("personal.macro", saveString);
        } catch (UnauthorizedException e) {
            Log.error(e.getMessage(), e);
        }
        reply = IQ.createResultIQ(packet);
    } catch (AgentNotFoundException e) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }
    workgroup.send(reply);
}
Also used : Agent(org.jivesoftware.xmpp.workgroup.Agent) XStream(com.thoughtworks.xstream.XStream) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) AgentNotFoundException(org.jivesoftware.xmpp.workgroup.AgentNotFoundException) PacketError(org.xmpp.packet.PacketError) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties)

Aggregations

DbProperties (org.jivesoftware.xmpp.workgroup.DbProperties)9 UnauthorizedException (org.jivesoftware.xmpp.workgroup.UnauthorizedException)6 XStream (com.thoughtworks.xstream.XStream)5 Element (org.dom4j.Element)2 Agent (org.jivesoftware.xmpp.workgroup.Agent)2 AgentNotFoundException (org.jivesoftware.xmpp.workgroup.AgentNotFoundException)2 DataForm (org.xmpp.forms.DataForm)2 IQ (org.xmpp.packet.IQ)2 PacketError (org.xmpp.packet.PacketError)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)1 WorkgroupManager (org.jivesoftware.xmpp.workgroup.WorkgroupManager)1 FormField (org.xmpp.forms.FormField)1