List<NodeTypeData> nodeTypes = new ArrayList<NodeTypeData>();
HashMap<InternalQName, String> propertiesMap = new HashMap<InternalQName, String>();
List<InternalQName> mixinNodeTypes = new ArrayList<InternalQName>();
InternalQName jcrName = locationFactory.parseJCRName(nodeName).getInternalName();
parseAttr(atts, nodeTypes, mixinNodeTypes, propertiesMap, jcrName);
ImportNodeData nodeData = createNode(nodeTypes, propertiesMap, mixinNodeTypes, jcrName);
NodeData parentNodeData = getParent();
changesLog.add(new ItemState(nodeData, ItemState.ADDED, true, getAncestorToSave()));
tree.push(nodeData);
if (log.isDebugEnabled())
{
log.debug("Node " + ": " + nodeData.getQPath().getAsString());
}
Iterator<InternalQName> keys = propertiesMap.keySet().iterator();
PropertyData newProperty;
while (keys.hasNext())
{
newProperty = null;
InternalQName propName = keys.next();
if (log.isDebugEnabled())
{
log.debug("Property NAME: " + propName + "=" + propertiesMap.get(propName));
}
if (propName.equals(Constants.JCR_PRIMARYTYPE))
{
InternalQName childName =
locationFactory.parseJCRName(propertiesMap.get(Constants.JCR_PRIMARYTYPE)).getInternalName();
if (!nodeTypeDataManager.isChildNodePrimaryTypeAllowed(childName, parentNodeData.getPrimaryTypeName(),
parentNodeData.getMixinTypeNames()))
{
throw new ConstraintViolationException("Can't add node " + nodeData.getQName().getAsString() + " to "
+ parentNodeData.getQPath().getAsString() + " node type "
+ propertiesMap.get(Constants.JCR_PRIMARYTYPE)
+ " is not allowed as child's node type for parent node type "
+ parentNodeData.getPrimaryTypeName().getAsString());
}
newProperty = endPrimaryType(nodeData.getPrimaryTypeName());
}
else if (propName.equals(Constants.JCR_MIXINTYPES))
{
newProperty = endMixinTypes(mixinNodeTypes, propName);
}
else if (nodeData.isMixReferenceable() && propName.equals(Constants.JCR_UUID))
{
newProperty = endUuid(nodeData, propName, propertiesMap.get(Constants.JCR_UUID));
}
else
{
PropertyDefinitionData pDef;
PropertyDefinitionDatas defs;
InternalQName[] nTypes = mixinNodeTypes.toArray(new InternalQName[mixinNodeTypes.size() + 1]);
nTypes[nTypes.length - 1] = nodeData.getPrimaryTypeName();
defs = nodeTypeDataManager.getPropertyDefinitions(propName, nTypes);
if (defs == null || defs.getAnyDefinition() == null)
{
if (!((Boolean)context.get(ContentImporter.RESPECT_PROPERTY_DEFINITIONS_CONSTRAINTS)))
{
log.warn("Property definition not found for " + propName.getAsString());
continue;
}
throw new RepositoryException("Property definition not found for " + propName.getAsString());
}
pDef = defs.getAnyDefinition();
if ((pDef == null) || (defs == null))
{
throw new RepositoryException("no propertyDefinition found");
}
if (pDef.getRequiredType() == PropertyType.BINARY)
{
newProperty = endBinary(propertiesMap, newProperty, propName);
}
else
{
StringTokenizer spaceTokenizer = new StringTokenizer(propertiesMap.get(propName));
List<ValueData> values = new ArrayList<ValueData>();
int pType = pDef.getRequiredType() > 0 ? pDef.getRequiredType() : PropertyType.STRING;
if (defs.getAnyDefinition().isResidualSet())
{
if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
{
if (nodeData.getPrimaryTypeName().equals(Constants.NT_FROZENNODE))
{
// get primaryType
InternalQName fptName = locationFactory.parseJCRName(atts.get("jcr:frozenPrimaryType")).getInternalName();
// get mixin types
List<JCRName> mtNames = getJCRNames(atts.get("jcr:frozenMixinTypes"));
InternalQName fmtName[] = new InternalQName[mtNames.size()];
for (int i = 0; i < mtNames.size(); i++)
{
fmtName[i] = new InternalQName(mtNames.get(i).getNamespace(), mtNames.get(i).getName());
}
PropertyDefinitionDatas ptVhdefs = nodeTypeDataManager.getPropertyDefinitions(propName, fptName, fmtName);
if (ptVhdefs != null)
{
pType = (ptVhdefs.getAnyDefinition().getRequiredType() > 0 ? ptVhdefs.getAnyDefinition()
.getRequiredType() : PropertyType.STRING);
}
}
}
}
if ("".equals(propertiesMap.get(propName)))
{
// Skip empty non string values
if (pType != PropertyType.STRING)
{
continue;
}
String denormalizeString = StringConverter.denormalizeString(propertiesMap.get(propName));
Value value = valueFactory.createValue(denormalizeString, pType);
values.add(((BaseValue)value).getInternalData());
if (Constants.EXO_OWNER.equals(propName))
{
nodeData.setExoOwner(denormalizeString);
}
}
else
{
List<String> denormalizeStrings = new ArrayList<String>();
while (spaceTokenizer.hasMoreTokens())
{
String elem = spaceTokenizer.nextToken();
String denormalizeString = StringConverter.denormalizeString(elem);
denormalizeStrings.add(denormalizeString);
Value value = valueFactory.createValue(denormalizeString, pType);
if (log.isDebugEnabled())
{
String valueAsString = null;
try
{
valueAsString = value.getString();
}
catch (Exception e)
{
log.error("Can't present value as string. " + e.getMessage());
valueAsString = "[Can't present value as string]";
}
log.debug("Property " + ExtendedPropertyType.nameFromValue(pType) + ": " + propName + "="
+ valueAsString);
}
values.add(((BaseValue)value).getInternalData());
}
if (pType == ExtendedPropertyType.PERMISSION)
{
nodeData.setExoPrivileges(denormalizeStrings);
}
else if (Constants.EXO_OWNER.equals(propName))
{
nodeData.setExoOwner(denormalizeStrings.get(0));
}
}
boolean isMultivalue = true;
// determinating is property multivalue;
if (values.size() == 1)
{
PropertyDefinitionDatas vhdefs = null;
if (defs.getAnyDefinition().isResidualSet())
{
if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
{
if (nodeData.getPrimaryTypeName().equals(Constants.NT_FROZENNODE))
{
// get primaryType
InternalQName fptName =
locationFactory.parseJCRName(atts.get("jcr:frozenPrimaryType")).getInternalName();
// get mixin types
List<JCRName> mtNames = getJCRNames(atts.get("jcr:frozenMixinTypes"));
InternalQName fmtName[] = new InternalQName[mtNames.size()];
for (int i = 0; i < mtNames.size(); i++)
{
fmtName[i] = new InternalQName(mtNames.get(i).getNamespace(), mtNames.get(i).getName());
}
vhdefs = nodeTypeDataManager.getPropertyDefinitions(propName, fptName, fmtName);
if (vhdefs != null)