List of usage examples for org.apache.commons.vfs2 UserAuthenticationData.Type toString
public String toString()
From source file:pl.otros.vfs.browser.auth.AuthStoreUtils.java
public void save(AuthStore authStore, OutputStream out) throws IOException { Collection<UserAuthenticationInfo> all = authStore.getAll(); for (UserAuthenticationInfo userAuthenticationInfo : all) { UserAuthenticationData userAuthenticationData = authStore .getUserAuthenticationData(userAuthenticationInfo); }/* www .j a v a 2 s .c o m*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element root = document.createElement("root"); document.appendChild(root); for (UserAuthenticationInfo userAuthenticationInfo : all) { UserAuthenticationDataWrapper userAuthenticationData = authStore .getUserAuthenticationData(userAuthenticationInfo); Element entry = document.createElement(ENTRY); entry.setAttribute(PROTOCOL, userAuthenticationInfo.getProtocol()); entry.setAttribute(HOST, userAuthenticationInfo.getHost()); entry.setAttribute(USER, userAuthenticationInfo.getUser()); Map<UserAuthenticationData.Type, char[]> addedTypes = userAuthenticationData.getAddedTypes(); for (UserAuthenticationData.Type type : addedTypes.keySet()) { Element elementUserAuthenticationData = document.createElement(USER_AUTHENTICATION_DATA); char[] data = userAuthenticationData.getData(type); String value; // if (UserAuthenticationData.PASSWORD.equals(type)) { // if (password == null){ // password = passwordProvider.getPassword("Enter password for password store"); // } // if (password == null || password.length==0){ // throw new IOException("Password for password store not entered"); // } // value = saltAndEncrypt(data); // } else { // value = new String(data); // } value = new String(data); Element elementType = document.createElement(TYPE); elementType.setTextContent(type.toString()); Element elementData = document.createElement(DATA); elementData.setTextContent(value); elementUserAuthenticationData.appendChild(elementType); elementUserAuthenticationData.appendChild(elementData); entry.appendChild(elementUserAuthenticationData); } root.appendChild(entry); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (Exception e) { throw new IOException(e); } }