19 package org.turro.contacts.mydata;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.string.ObjectString;
28 import org.turro.string.Strings;
29 import org.jdom.Document;
30 import org.jdom.Element;
31 import org.jdom.JDOMException;
32 import org.jdom.input.SAXBuilder;
33 import org.turro.elephant.context.ElephantContext;
34 import org.turro.plugin.contacts.IContact;
35 import org.zkoss.zul.impl.InputElement;
46 this.contact = contact;
54 if(Strings.isBlank(contact.
getName()))
return false;
56 if(Strings.isBlank(contact.
getGlobalId()))
return false;
68 if(!Strings.isBlank(item.
getValue())) {
77 if(!Strings.isBlank(password)) {
86 private void readItems() {
88 if(confFile.exists()) {
91 SAXBuilder builder =
new SAXBuilder();
93 doc = builder.build(confFile);
94 conf = doc.getRootElement();
96 addItems(conf.getChild(
"my-data"));
98 }
catch (JDOMException | IOException ex) {
99 Logger.getLogger(
MyDataList.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
104 private void addItems(Element myData) {
106 for(Element item : (List<Element>) myData.getChildren()) {
107 MyDataItemType mdit = MyDataItemType.getMyDataType(item.getName());
109 MyDataItem mdi =
new MyDataItem(mdit);
110 mdi.setRequired(item.getAttributeValue(
"required",
"false").equals(
"true"));
111 mdi.setReadonly(item.getAttributeValue(
"readonly",
"false").equals(
"true"));
112 mdi.setName(item.getAttributeValue(
"name"));
113 if(mdit.equals(MyDataItemType.MYDATA_NAME)) {
114 mdi.setLabel(item.getAttributeValue(
"label",
"Full name"));
115 }
else if(mdit.equals(MyDataItemType.MYDATA_GIF)) {
116 mdi.setLabel(item.getAttributeValue(
"label",
"Global identifier"));
117 }
else if(mdit.equals(MyDataItemType.MYDATA_PASSWORD)) {
118 mdi.setLabel(item.getAttributeValue(
"label",
"New password"));
119 mdi.setRequired(
false);
120 }
else if(mdit.equals(MyDataItemType.MYDATA_CONNECTOR)) {
121 mdi.setLabel(item.getAttributeValue(
"label"));
122 }
else if(mdit.equals(MyDataItemType.MYDATA_IMAGE)) {
123 mdi.setLabel(item.getAttributeValue(
"label"));
124 mdi.setValue(item.getAttributeValue(
"value"));
126 mdi.setCols((
int) ObjectString.parseNativeString(item.getAttributeValue(
"cols"), Integer.class,
true));
127 mdi.fillValue(contact);
134 private void formToFields() {
135 for(MyDataItem item :
this) {
136 if(item.getInput() instanceof InputElement) {
137 item.setValue(item.getInput().getText());
static String getRealPath(String path)