+
+ /**
+ * Replace the media tags in the given XML string
+ * @param inSource source XML for point
+ * @param inValue value for the current point
+ * @return modified String, or null if not possible
+ */
+ private static String replaceMediaLinks(String inSource, String inValue)
+ {
+ if (inSource == null) {return null;}
+ // Note that this method is very similar to replaceGpxTags except there can be multiple link tags
+ // and the tags must have attributes. So either one heavily parameterized method or two.
+ // Look for start and end tags within source
+ final String STARTTEXT = "<link";
+ final String ENDTEXT = "</link>";
+ final int startPos = inSource.indexOf(STARTTEXT);
+ final int endPos = inSource.lastIndexOf(ENDTEXT);
+ if (startPos > 0 && endPos > 0)
+ {
+ String origValue = inSource.substring(startPos, endPos + ENDTEXT.length());
+ if (inValue != null && origValue.equals(inValue)) {
+ // Value unchanged
+ return inSource;
+ }
+ else if (inValue == null || inValue.equals("")) {
+ // Need to delete value
+ return inSource.substring(0, startPos) + inSource.substring(endPos + ENDTEXT.length());
+ }
+ else {
+ // Need to replace value
+ return inSource.substring(0, startPos) + inValue + inSource.substring(endPos + ENDTEXT.length());
+ }
+ }
+ // Value not found for this field in original source
+ if (inValue == null || inValue.equals("")) {return inSource;}
+ return null;
+ }
+
+