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);
}
}
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);
}
}
}
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;
}
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);
}
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);
}
Aggregations