/* (non-Javadoc) * @see org.alfresco.repo.dictionary.ModelQuery#getDataType(java.lang.Class) */ public DataTypeDefinition getDataType(Class javaClass) { for (DataTypeDefinition dataTypeDef : dataTypes.values()) { if (dataTypeDef.getJavaClassName().equals(javaClass.getName())) { return dataTypeDef; } } return null; }
/* (non-Javadoc) * @see org.alfresco.service.cmr.view.Exporter#value(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.Serializable) */ public void value(NodeRef nodeRef, QName property, Object value, int index) { try { // determine data type of value QName valueDataType = null; PropertyDefinition propDef = dictionaryService.getProperty(property); DataTypeDefinition dataTypeDef = (propDef == null) ? null : propDef.getDataType(); if (dataTypeDef == null || dataTypeDef.getName().equals(DataTypeDefinition.ANY)) { dataTypeDef = (value == null) ? null : dictionaryService.getDataType(value.getClass()); if (dataTypeDef != null) { valueDataType = dataTypeDef.getName(); } } // convert node references to paths if (value instanceof NodeRef && referenceType.equals(ReferenceType.PATHREF)) { NodeRef valueNodeRef = (NodeRef) value; if (nodeRef.getStoreRef().equals(valueNodeRef.getStoreRef())) { Path nodeRefPath = createPath(context.getExportOf(), nodeRef, valueNodeRef); value = (nodeRefPath == null) ? null : nodeRefPath.toPrefixString(namespaceService); } } // output value wrapper if value is null or property data type is ANY or value is part of // collection if (value == null || valueDataType != null || index != -1) { AttributesImpl attrs = new AttributesImpl(); if (value == null) { attrs.addAttribute( NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, ISNULL_QNAME.toPrefixString(), null, "true"); } if (valueDataType != null) { attrs.addAttribute( NamespaceService.REPOSITORY_VIEW_PREFIX, DATATYPE_LOCALNAME, DATATYPE_QNAME.toPrefixString(), null, toPrefixString(valueDataType)); } contentHandler.startElement( NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME), attrs); } // output value String strValue = (String) DefaultTypeConverter.INSTANCE.convert(String.class, value); if (strValue != null) { for (int i = 0; i < strValue.length(); i++) { char[] temp = new char[] {strValue.charAt(i)}; contentHandler.characters(temp, 0, 1); } } // output value wrapper if property data type is any if (value == null || valueDataType != null || index != -1) { contentHandler.endElement( NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, toPrefixString(VALUE_QNAME)); } } catch (SAXException e) { throw new ExporterException( "Failed to process value event - nodeRef " + nodeRef + "; property " + toPrefixString(property) + "; value " + value, e); } }
/* * (non-Javadoc) * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { try { // construct qname for element QName elementName = decodeQName(QName.createQName(qName, importResolver)); // setup parent context ParentContext parentContext = null; if (contextStack.empty()) { // create root parent context parentContext = new ParentContext(elementName, dictionaryService, importer); } else { // create parent context NodeContext parentNode = (NodeContext) contextStack.peek(); parentContext = new ParentContext(elementName, parentNode); } // create node context NodeContext node = new NodeContext(elementName, parentContext, null); node.setChildName(elementName.toPrefixString(importResolver)); contextStack.push(node); // process node properties for (int i = 0; i < atts.getLength(); i++) { QName propName = decodeQName(QName.createQName(atts.getURI(i), atts.getLocalName(i))); String value = atts.getValue(i); // // process "well-known" properties // if (propName.equals(JCRPrimaryTypeProperty.PROPERTY_NAME)) { // primary type QName primaryTypeQName = QName.createQName(value, importResolver); TypeDefinition typeDef = dictionaryService.getType(primaryTypeQName); if (typeDef == null) { throw new InvalidTypeException(primaryTypeQName); } node.setTypeDefinition(typeDef); } else if (propName.equals(JCRMixinTypesProperty.PROPERTY_NAME)) { // aspects String[] aspects = value.split(" "); for (String aspect : aspects) { // ignore JCR specific aspects QName aspectQName = QName.createQName(aspect, importResolver); if (!(JCRNamespace.JCR_URI.equals(aspectQName.getNamespaceURI()) || JCRNamespace.MIX_URI.equals(aspectQName.getNamespaceURI()))) { AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName); if (aspectDef == null) { throw new InvalidTypeException(aspectQName); } node.addAspect(aspectDef); } } } else if (JCRUUIDProperty.PROPERTY_NAME.equals(propName)) { node.setUUID(value); } // // Note: ignore JCR specific properties // else if (JCRNamespace.JCR_URI.equals(propName.getNamespaceURI())) { } // // process all other properties // else { // determine type of property PropertyDefinition propDef = dictionaryService.getProperty(propName); if (propDef == null) { throw new ImporterException( "Property " + propName + " is not known to the repository data dictionary"); } DataTypeDefinition dataTypeDef = propDef.getDataType(); // extract values from node xml attribute String[] propValues = null; PropertyContext propertyContext = new PropertyContext(elementName, node, propName, dataTypeDef.getName()); if (dataTypeDef.getName().equals(DataTypeDefinition.CONTENT)) { // Note: we only support single valued content properties propValues = new String[] {value}; } else { // attempt to split multi-value properties propValues = value.split(" "); } // extract values appropriately for (String propValue : propValues) { propertyContext.startValue(); propertyContext.appendCharacters(propValue.toCharArray(), 0, propValue.length()); propertyContext.endValue(); } // add each value to the node if (propertyContext.isMultiValue()) { node.addPropertyCollection(propName); } List<StringBuffer> nodeValues = propertyContext.getValues(); for (StringBuffer nodeValue : nodeValues) { // first, cast value to appropriate type (using JCR converters) Serializable objVal = (Serializable) session.getTypeConverter().convert(dataTypeDef, nodeValue.toString()); String strValue = DefaultTypeConverter.INSTANCE.convert(String.class, objVal); node.addProperty(propName, strValue); } } } // import node NodeRef nodeRef = node.getImporter().importNode(node); node.setNodeRef(nodeRef); } catch (Exception e) { throw new SAXException("Failed to process element " + qName, e); } }