@Override public String read(InputNode node) throws Exception { InputNode encryptedAttribute = node.getAttribute("encrypted"); if (encryptedAttribute != null && encryptedAttribute.getValue().equals(Boolean.TRUE.toString())) { return TransferSettings.decrypt(node.getValue()); } return node.getValue(); }
@Override public PartialFileHistory.FileHistoryId read(InputNode node) throws Exception { return PartialFileHistory.FileHistoryId.parseFileId(node.getValue()); }
@Override public FileContent.FileChecksum read(InputNode node) throws Exception { return FileContent.FileChecksum.parseFileChecksum(node.getValue()); }
@Override public VectorClock read(InputNode node) throws Exception { return VectorClock.parseVectorClock(node.getValue()); }
public SaltedSecretKey read(InputNode node) throws Exception { byte[] saltBytes = StringUtil.fromHex(node.getAttribute("salt").getValue()); byte[] keyBytes = StringUtil.fromHex(node.getAttribute("key").getValue()); return new SaltedSecretKey(new SecretKeySpec(keyBytes, CipherParams.MASTER_KEY_DERIVATION_FUNCTION), saltBytes); }
@Override public String read(InputNode inputNode) throws Exception { String value = inputNode.getValue(); return value == null ? "": value; }
@Override public String read(final InputNode node) throws Exception { return StringUtils.defaultIfBlank(node.getValue(), StringUtils.EMPTY); }
@Override public String read(final InputNode node) throws Exception { return StringUtils.defaultIfBlank(node.getValue(), StringUtils.EMPTY); }
@Override public Color read(InputNode node) throws Exception { int r = Integer.parseInt(node.getAttribute("r").getValue()); int g = Integer.parseInt(node.getAttribute("g").getValue()); int b = Integer.parseInt(node.getAttribute("b").getValue()); int a = Integer.parseInt(node.getAttribute("a").getValue()); return new Color(r, g, b, a); }
private boolean isProtected(InputNode node) throws Exception { InputNode isProtectedNode = node.getAttribute("Protected"); if (isProtectedNode == null) { return false; } String value = isProtectedNode.getValue(); return value.equalsIgnoreCase("true"); }
@Override public Date read(InputNode inputNode) throws Exception { String value = inputNode.getValue(); if (value.equals("${creationDate}")) { return new Date(); } return Helpers.toDate(value); }
@Override public UUID read(InputNode inputNode) throws Exception { String value = inputNode.getValue(); if (value == null || value.equals("")) { return UUID.randomUUID(); } return Helpers.uuidFromBase64(value); }
public class ByteArrayConverter implements Converter<ByteArrayWrapper> { @Override public ByteArrayWrapper read(InputNode node) throws Exception { InputNode nextnode = node.getNext(); return new ByteArrayWrapper(Base64.decode(nextnode.getValue())); } public void write(OutputNode node, ByteArrayWrapper byteArray) throws Exception { OutputNode byteArrayNode = node.getChild("byteArray"); byteArrayNode.setValue(Base64.encode(byteArray.getByteArray(), false)); } }
@Override public Boolean read(InputNode inputNode) throws Exception { return Helpers.toBoolean(inputNode.getValue()); }
@Override public KeePassFile.ByteArray read(InputNode inputNode) throws Exception { String input = inputNode.getValue(); byte[] value = input == null? new byte[0] : input.getBytes(); return new KeePassFile.ByteArray(Helpers.decodeBase64Content(value, false)); }
public static String get(InputNode input, String attribute) { InputNode node = input.getAttribute(attribute); String value = null; if (node != null) { try { value = node.getValue(); } catch (Exception exception) { throw new XmlPersisterException(format("Can't get value of %s", node), exception); } } return value; }
static Map<String, String> getParameters(InputNode inputNode) throws ParseException { Map<String, String> parameters = Maps.newHashMap(); try { for (String name : inputNode.getAttributes()) { String value = inputNode.getAttribute(name).getValue(); parameters.put(name, value); } } catch (Exception e) { throw new ParseException(e.getMessage(), e); } return parameters; } }
@Override public Object read(InputNode input, Class type, XmlReadContext context) { try { return transformer.read(input.getValue(), type); } catch (Exception exception) { throw new XmlPersisterException(exception); } }
public static Element read(InputNode node) throws Exception { QName qname = new QName(node.getReference(), node.getName(), node.getPrefix()); org.w3c.dom.Element element = SardineUtil.createElement(qname); element.setTextContent(node.getValue()); return element; }
@Override public PropertyValue read(InputNode node) throws Exception { String value = node.getValue(); if (value == null) { return new PropertyValue(false, ""); } if (isProtected(node)) { String rawValue = strategy.apply(value); return new PropertyValue(true, rawValue); } return new PropertyValue(false, value); }