* @param items the items to retrieve from response
* @return a string array containing the values of items
*/
public static String[] retrieveCommunication(String path, ServerPrimitives primitive, String... items) {
String [] returnValues = new String[items.length];
WebdavFileObject response = null;
FileSystemManager vfsManager = WebDAVClientManager.getVFSManager();
try {
//control if .response arrive..
while((response == null || !response.exists())){
LOGGER.debug("webdav path: " + path.replace("dav", "webdav") + "/.response");
if(response == null) LOGGER.debug("response == null");
LOGGER.debug("path: " + path);
if(vfsManager == null) LOGGER.debug("vfsManager == null");
response = (WebdavFileObject) vfsManager.resolveFile(path.replace("dav", "webdav") + "/.response");
}
} catch (FileSystemException fsException) {
LOGGER.error(fsException.getMessage());
}
try {
if(response != null && response.exists()){
//retrieve WebDAV resource
LOGGER.debug("webdav path: " + path.replace("dav", "webdav") + "/.request");
//process .response
ServerPrimitives primitiveReceived = ResponseManager.manageResponse(response);
LOGGER.debug("primitive received: " + primitiveReceived);
if(primitive == ServerPrimitives.OE_SUCCESSFUL){
String[] returnTrue = {"true"};
response.delete();
return returnTrue;
} else if(ServerPrimitives.OE_ERROR == primitiveReceived){
OverEncryptClient.showError(FileSystemUtils.getArgFromFile(response, "reason"));
System.exit(0);
} else if(ServerPrimitives.OE_FORBIDDEN == primitiveReceived) {
JOptionPane.showMessageDialog(null, "User's session expired. Login again.", "Session error.", JOptionPane.ERROR_MESSAGE);
System.exit(0);
} else if(primitive == primitiveReceived) {
for(int i = 0; i < items.length; i++) {
returnValues[i] = FileSystemUtils.getArgFromFile(response, items[i]);
LOGGER.debug("ReturnValue: " + returnValues[i]);
}
} else {
JOptionPane.showMessageDialog(null, "Communication error", "Retrieve server information failed.", JOptionPane.ERROR_MESSAGE);
}
response.delete();
}
} catch (HeadlessException e) {
LOGGER.error(e.getMessage());
} catch (FileSystemException e) {
LOGGER.error(e.getMessage());