protected void setProperty(Node node, Property property, boolean isMultiValued) throws RepositoryException { Name name = property.getName(); if (name.equals(JcrLexicon.PRIMARY_TYPE)) return; if (name.equals(ModeShapeIntLexicon.NODE_DEFINITON)) return; if (name.equals(ModeShapeIntLexicon.MULTI_VALUED_PROPERTIES)) return; if (name.equals(JcrLexicon.MIXIN_TYPES)) { for (Object mixinVvalue : property.getValuesAsArray()) { String mixinTypeName = stringFor(mixinVvalue); node.addMixin(mixinTypeName); } return; } // Otherwise, just set the normal property. First determine the expected type ... String propertyName = stringFor(name); if (isMultiValued) { Value[] values = new Value[property.size()]; int index = 0; PropertyType propertyType = null; for (Object value : property) { if (value == null) continue; if (propertyType == null) propertyType = PropertyType.discoverType(value); values[index] = convertToJcrValue(propertyType, value); ++index; } node.setProperty(propertyName, values); } else { Object firstValue = property.getFirstValue(); PropertyType propertyType = PropertyType.discoverType(firstValue); Value value = convertToJcrValue(propertyType, firstValue); node.setProperty(propertyName, value); } }
protected void write(Property property, Writer stream, ValueFactory<String> strings) throws IOException { String name = strings.create(property.getName()); stream.append(encoder.encode(name)); if (property.isEmpty()) return; stream.append(" ("); PropertyType type = PropertyType.discoverType(property.getFirstValue()); stream.append(type.getName().toLowerCase()); stream.append(") "); if (property.isMultiple()) { stream.append('['); } boolean first = true; boolean quote = type == PropertyType.STRING; for (Object value : property) { if (first) first = false; else stream.append(", "); String str = null; if (value instanceof Binary) { str = StringUtil.getHexString(((Binary) value).getBytes()); } else { str = strings.create(value); } if (quote) { stream.append('"'); stream.append(quoter.encode(str)); stream.append('"'); } else { stream.append(str); } } if (property.isMultiple()) { stream.append(']'); } stream.append('\n'); stream.flush(); }