if (line.length() == 0) return null; // blank line
char firstChar = line.charAt(0);
if (firstChar == '#') return null; // comment line
if (firstChar == ' ') return null; // ignore line
Matcher matcher = PROPERTY_PATTERN.matcher(line);
NameFactory nameFactory = factories.getNameFactory();
if (!matcher.matches()) {
// It should be an empty multi-valued property, and the line consists only of the name ...
Name name = nameFactory.create(decoder.decode(line));
return propertyFactory.create(name);
}
String nameString = decoder.decode(matcher.group(1));
String typeString = matcher.group(2);
String valuesString = matcher.group(4);
Name name = null;
try {
name = factories.getNameFactory().create(nameString);
} catch (ValueFormatException e) {
// See MODE-1281. Earlier versions would write out an empty property without the trailing line feed,
// so we need to consider this case now. About the only thing we can do is look for two namespace-prefixed names
// ...
if (nameString.indexOf(':') < nameString.lastIndexOf(':')) {
// This is likely two names smashed together. Use the namespace prefixes to look for where we can break this
// ...
Set<String> prefixes = new LinkedHashSet<String>();
prefixes.add(JcrLexicon.Namespace.PREFIX);
for (String prefix : registry.getPrefixes()) {
prefixes.add(prefix);
}
for (String prefix : prefixes) {
int index = nameString.lastIndexOf(prefix + ":");
if (index <= 0) continue;
// Otherwise, we found a match. Parse the first property name, and create an empty property ...
name = nameFactory.create(nameString.substring(0, index));
result.put(name, propertyFactory.create(name));
// Now parse the name of the next property and continue ...
name = nameFactory.create(nameString.substring(index));
break;
}
} else {
throw e;
}