final PropertyIterator stringMap = currentNode.getProperties();
JSONObject jsonObject = new JSONObject();
// Map<String,Object> map = new HashMap<String, Object>();
Set<String> matchingProperties = new HashSet<String>();
while (stringMap.hasNext()) {
JCRPropertyWrapper propertyWrapper = (JCRPropertyWrapper) stringMap.next();
final int type = propertyWrapper.getType();
final String name = escapeColon ? propertyWrapper.getName().replace(":", "_") : propertyWrapper.getName();
if (type == PropertyType.BINARY) {
continue;
}
if (type == PropertyType.WEAKREFERENCE || type == PropertyType.REFERENCE) {
if (!propertyWrapper.isMultiple()) {
jsonObject.put(name, ((JCRNodeWrapper) propertyWrapper.getNode()).getUrl());
}
} else {
if (!propertyWrapper.isMultiple()) {
jsonObject.put(name, propertyWrapper.getValue().getString());
// @todo this code is duplicated for multiple values, we need to clean this up.
if (propertyMatchRegexp != null && propertyMatchRegexp.matcher(propertyWrapper.getValue().getString()).matches()) {
if (alreadyIncludedPropertyValues != null) {
String nodeIdentifier = alreadyIncludedPropertyValues.get(propertyWrapper.getValue().getString());
if (nodeIdentifier != null) {
if (!nodeIdentifier.equals(currentNode.getIdentifier())) {
// This property value already exists and comes from another node.
return null;
}
} else {
alreadyIncludedPropertyValues.put(propertyWrapper.getValue().getString(), currentNode.getIdentifier());
}
}
// property starts with the propertyMatchRegexp, let's add it to the list of matching properties.
matchingProperties.add(name);
}
} else {
JSONArray jsonArray = new JSONArray();
Value[] propValues = propertyWrapper.getValues();
for (Value propValue : propValues) {
jsonArray.put(propValue.getString());
if (propertyMatchRegexp != null && propertyMatchRegexp.matcher(propValue.getString()).matches()) {
if (alreadyIncludedPropertyValues != null) {
String nodeIdentifier = alreadyIncludedPropertyValues.get(propValue.getString());