Hi all !!
I’m working in a plugin to export some users information and I would like to know if its possible to retrive all the key from PrivateStorage.
i.e:
Let say we have:
bookmarks under: “storage” key
Foods likes and dislikes under: “foodProfile” key
Movies profile under: “moviesProfile” key
With this code:
Element element = userElement.addElement(“storage”, “storage:bookmarks”);
Element result = privateStorage.get(userName, element); <- this statement will retrive all the bookmarks stored under the key “storage” but what if I don’t know all the keys ?
I was trying to retrive from an higher level:
Element element = userElement.addElement(“query”, “jabber:iq:private”)
Element result = privateStorage.get(userName, element);
But I got an empty elemnt.
There is a way to achive that ?
Exist any method like:
KeySet key = privateStorage.getkey(userName);
Thanks
Santiago
Hey guys!
I did some changes in yours PrivateStorage.java source file, in order to add a method to get all private stored info. (XEP-0049)
...
private static final String LOAD_ALL_PRIVATE = "SELECT privateData FROM ofPrivate WHERE username=?";
... public Element getAll(String username) {
QName qName = new QName("", new Namespace("","jabber:iq:private"), "query");
Element data = DocumentHelper.createElement(qName);
if (enabled) {
Connection con = null;
PreparedStatement pstmt = null;
SAXReader xmlReader = null;
try {
// Get a sax reader from the pool
xmlReader = xmlReaders.take();
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_ALL_PRIVATE);
pstmt.setString(1, username);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
String result = rs.getString(1).trim();
Document doc = xmlReader.read(new StringReader(result));
data.add(doc.getRootElement());
}
rs.close();
} catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
} finally {
// Return the sax reader to the pool
if (xmlReader != null) {
xmlReaders.add(xmlReader);
}
try {
if (pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
Log.error(e);
}
}
}
return data;
}
Also I attached the PrivateStorage.java source with those change.
If this code make sense for you and there is not another way to retrive it, would you mind to add it in your nexts releases.
If there is another way, can you show me ? please.
Best regards
Santiago
PrivateStorage.java.zip (2598 Bytes)