X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2FBaseClass.java;h=42d4b0dd7f57090a056870f13280f573e6d2146c;hb=f04a32e97c847d7e2551037a4d5f6a070879215c;hp=1dd76442324ca845d2f603e5dd04c532bd7bdd32;hpb=5ad0e17e7fea1c602cb2638a006424af9c7e33e8;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/BaseClass.java b/src/be/nikiroo/jvcard/BaseClass.java index 1dd7644..42d4b0d 100644 --- a/src/be/nikiroo/jvcard/BaseClass.java +++ b/src/be/nikiroo/jvcard/BaseClass.java @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.List; import java.util.ListIterator; -import be.nikiroo.jvcard.resources.StringUtils; +import be.nikiroo.utils.StringUtils; /** * This class is basically a List with a parent and a "dirty" state check. It @@ -30,7 +30,7 @@ import be.nikiroo.jvcard.resources.StringUtils; *

* * @author niki - * + * * @param * the type of the child elements */ @@ -275,7 +275,7 @@ public abstract class BaseClass> implements List { public String getContentState(boolean self) { StringBuilder builder = new StringBuilder(); buildContentStateRaw(builder, self); - return StringUtils.getHash(builder.toString()); + return StringUtils.getMd5Hash(builder.toString()); } /** @@ -307,7 +307,7 @@ public abstract class BaseClass> implements List { * * @param depth * the depth into which to descend (0 = only this object, not its - * children) + * children, negative value for infinite depth) * * @return the debug {@link String} */ @@ -333,7 +333,7 @@ public abstract class BaseClass> implements List { * *

* Not that this state is lossy. You cannot retrieve the data from - * the state, it can only be used as an ID to check if thw data are + * the state, it can only be used as an ID to check if the data are * identical. *

* @@ -346,7 +346,7 @@ public abstract class BaseClass> implements List { * Get the recursive state of the current object, i.e., its children * included. It represents the full state information about this object's * children. - * + *

* It is not hashed. * * @param builder @@ -372,7 +372,7 @@ public abstract class BaseClass> implements List { * * @param depth * the depth into which to descend (0 = only this object, not its - * children) + * children, negative value for infinite depth) * * @param tab * the current tabulation increment @@ -382,16 +382,16 @@ public abstract class BaseClass> implements List { builder.append(" "); builder.append(getContentState(false) + " " + getId()); - if (depth > 0) + if (depth != 0) builder.append(": ["); - if (depth > 0) { + if (depth != 0) { for (E child : this) { builder.append("\n"); child.getDebugInfo(builder, depth - 1, tab + 1); } } - if (depth > 0) { + if (depth != 0) { builder.append("\n"); for (int i = 0; i < tab; i++) builder.append(" "); @@ -400,7 +400,8 @@ public abstract class BaseClass> implements List { } /** - * Notify that this element has unsaved changes. + * Notify that this element and all its parent elements has unsaved + * changes. */ void setDirty() { dirty = true; @@ -421,7 +422,10 @@ public abstract class BaseClass> implements List { } /** - * Set the parent of this element and all its descendants. + * Set the parent of this element. + *

+ * Will also check and fix if needed the parent (this) of all its + * descendants (recursively). * * @param parent * the new parent @@ -433,6 +437,38 @@ public abstract class BaseClass> implements List { } } + /** + * Escape the given value to VCF standard. + * + * @param value + * the value to escape + * + * @return the escaped value + */ + protected String escape(String value) { + if (value == null) + return null; + + return value.replaceAll(",", "\\\\,").replaceAll(";", "\\\\;") + .replaceAll("\n", "\\\\n"); + } + + /** + * Unescape the given value from the VCF standard. + * + * @param value + * the value to unescape + * + * @return the unescaped value + */ + protected String unescape(String value) { + if (value == null) + return null; + + return value.replaceAll("\\\\,", ",").replaceAll("\\\\;", ";") + .replaceAll("\\\\n", "\n"); + } + /** * Each element that leaves the parent will pass trough here. *