The Custom XML parser now properly handles element names which are a
truncation of another element's name.
Change-Id: I5bbf7d4832976fc75d8e60a9ebc0e09d1463bd51
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/27771
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
(cherry picked from commit
33937d3c8a9f55f7f1505a6617cf978536a933ee)
Reviewed-on: https://git.eclipse.org/r/27853
} else if (location.getLocationInfo() instanceof Long) {
fFile.seek((Long) location.getLocationInfo());
}
} else if (location.getLocationInfo() instanceof Long) {
fFile.seek((Long) location.getLocationInfo());
}
- final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$
long rawPos = fFile.getFilePointer();
String line = fFile.getNextLine();
while (line != null) {
long rawPos = fFile.getFilePointer();
String line = fFile.getNextLine();
while (line != null) {
- final int idx = line.indexOf(recordElementStart);
+ final int idx = indexOfElement(fRecordInputElement.elementName, line, 0);
if (idx != -1) {
context.setLocation(new TmfLongLocation(rawPos + idx));
return context;
if (idx != -1) {
context.setLocation(new TmfLongLocation(rawPos + idx));
return context;
event = extractEvent(element, fRecordInputElement);
((StringBuffer) event.getContent().getValue()).append(elementBuffer);
event = extractEvent(element, fRecordInputElement);
((StringBuffer) event.getContent().getValue()).append(elementBuffer);
-
- final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$
long rawPos = fFile.getFilePointer();
String line = fFile.getNextLine();
while (line != null) {
long rawPos = fFile.getFilePointer();
String line = fFile.getNextLine();
while (line != null) {
- final int idx = line.indexOf(recordElementStart);
+ final int idx = indexOfElement(fRecordInputElement.elementName, line, 0);
if (idx != -1) {
context.setLocation(new TmfLongLocation(rawPos + idx));
return event;
if (idx != -1) {
context.setLocation(new TmfLongLocation(rawPos + idx));
return event;
+ private static int indexOfElement(String elementName, String line, int fromIndex) {
+ final String recordElementStart = '<' + elementName;
+ int index = line.indexOf(recordElementStart, fromIndex);
+ if (index == -1) {
+ return index;
+ }
+ int nextCharIndex = index + recordElementStart.length();
+ if (nextCharIndex < line.length()) {
+ char c = line.charAt(nextCharIndex);
+ // Check that the match is not just a substring of another element
+ if (Character.isLetterOrDigit(c)) {
+ return indexOfElement(elementName, line, nextCharIndex);
+ }
+ }
+ return index;
+ }
+
private void readElement(final StringBuffer buffer, final RandomAccessFile raFile) {
try {
int numRead = 0;
private void readElement(final StringBuffer buffer, final RandomAccessFile raFile) {
try {
int numRead = 0;
}
try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
int lineCount = 0;
}
try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
int lineCount = 0;
- final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$
long rawPos = 0;
String line = rafile.getNextLine();
while ((line != null) && (lineCount++ < MAX_LINES)) {
long rawPos = 0;
String line = rafile.getNextLine();
while ((line != null) && (lineCount++ < MAX_LINES)) {
- final int idx = line.indexOf(recordElementStart);
+ final int idx = indexOfElement(fRecordInputElement.elementName, line, 0);
if (idx != -1) {
rafile.seek(rawPos + idx + 1); // +1 is for the <
final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$
if (idx != -1) {
rafile.seek(rawPos + idx + 1); // +1 is for the <
final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$