/** * Convenience method for getting an attribute value, substituting an empty * string for a null attribute. * * @param document document to get from * @param element element to get from * @param attributeName name of attribute to get * * @return value of attribute, or empty string if the value is null */ private String getNonNullAttribute(ObservableMutableDocument<? super E, E, ?> document, E element, String attributeName) { String attribute = document.getAttribute(element, attributeName); return attribute == null ? "" : attribute; } }
private String valueOf(E element) { return getDocument().getAttribute(element, WaveletBasedSupplement.ID_ATTR); }
/** * Gets the key of an entry. * * @param entry * @return the key of an entry. */ private K keyOf(E entry) { String keyString = getDocument().getAttribute(entry, keyAttrName); return keySerializer.fromString(keyString); }
private WaveletId valueOf(E element) { String waveletIdStr = getDocument().getAttribute(element, WaveletBasedSupplement.ID_ATTR); return WaveletBasedConversation.widFor(waveletIdStr); }
/** * Gets the value of an entry. * * @param element entry to evaluate * @return the value embedded in the element. */ private T valueOf(E element) { return serializer.fromString(getDocument().getAttribute(element, valueAttrName)); } }
/** * Gets the value of an entry. * * @param entry * @return the value of an entry. */ private V valueOf(E entry) { String valueString = getDocument().getAttribute(entry, valueAttrName); return valueString != null ? valueSerializer.fromString(valueString) : null; }
/** * Gets the value of an entry. * * @param entry * @return the value of an entry. */ private C valueOf(E entry) { return serializer.fromString(getDocument().getAttribute(entry, valueAttrName)); }
private WaveletId valueOf(E element) { String waveletIdStr = getDocument().getAttribute(element, WaveletBasedSupplement.ID_ATTR); return WaveletBasedConversation.widFor(waveletIdStr); }
@Override public Integer adapt(DocumentEventRouter<? super E, E, ?> router, E element) { String valueStr = router.getDocument().getAttribute(element, attributeName); return Integer.parseInt(valueStr); }
@Override public Integer adapt(DocumentEventRouter<? super E, E, ?> router, E element) { String valueStr = router.getDocument().getAttribute(element, attributeName); return Integer.parseInt(valueStr); }
@Override public WantedEvaluation adapt(DocumentEventRouter<? super E, E, ?> router, E element) { // We can do the conversion once at adapt() time because WantedEvaluations // are immutable. This also means we don't need a DocumentBased // implementation of WantedEvaluation. // TODO(user): work out what to do if wavelet id is missing. ObservableMutableDocument<? super E, E, ?> document = router.getDocument(); WaveletId waveletId = WaveletIdSerializer.INSTANCE.fromString(document.getAttribute(element, WAVELET_ID_ATTR)); boolean wanted = Serializer.BOOLEAN.fromString(document.getAttribute(element, WANTED_ATTR), false); double certainty = Serializer.DOUBLE.fromString(document.getAttribute(element, CERTAINTY_ATTR), 0.0); long timestamp = Serializer.LONG.fromString(document.getAttribute(element, TIMESTAMP_ATTR), 0L); boolean ignored = Serializer.BOOLEAN.fromString(document.getAttribute(element, IGNORED_ATTR), false); String agentIdentity = getNonNullAttribute(document, element, AGENT_ATTR); String comment = getNonNullAttribute(document, element, COMMENT_ATTR); String adderAddress = getNonNullAttribute(document, element, ADDER_ATTR); return new SimpleWantedEvaluation(waveletId, adderAddress, wanted, certainty, timestamp, agentIdentity, ignored, comment); }
private void changeValue(E newElement) { Boolean oldValue = get(); if (newElement != null) { valueElement = newElement; // It's a positive element if it has the right tagname and does not have // value = false. Note, absence of attributes is interpreted as a positive // element. value = !FALSE.equals(getDocument().getAttribute(valueElement, valueAttr)); } else { valueElement = null; value = null; } Boolean newValue = get(); maybeTriggerOnValueChanged(oldValue, newValue); }
void removeEntries(K key) { N curChild = context.doc.getFirstChild(context.container); String keyString = keySerializer.toString(key); E e = DocHelper.getFirstChildElement(context.doc, context.container); while (e != null) { if (ENTRY_TAG.equals(context.doc.getTagName(e)) && keyString.equals(context.doc.getAttribute(e, KEY_ATTR))) { context.doc.deleteNode(e); } e = DocHelper.getNextSiblingElement(context.doc, e); } }
void removeEntries(K key) { N curChild = context.doc.getFirstChild(context.container); String keyString = keySerializer.toString(key); E e = DocHelper.getFirstChildElement(context.doc, context.container); while (e != null) { if (ENTRY_TAG.equals(context.doc.getTagName(e)) && keyString.equals(context.doc.getAttribute(e, KEY_ATTR))) { context.doc.deleteNode(e); } e = DocHelper.getNextSiblingElement(context.doc, e); } }