/* (non-Javadoc) * @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef) */ public void startNode(NodeRef nodeRef) { try { AttributesImpl attrs = new AttributesImpl(); Path path = nodeService.getPath(nodeRef); if (path.size() > 1) { // a child name does not exist for root Path.ChildAssocElement pathElement = (Path.ChildAssocElement) path.last(); QName childQName = pathElement.getRef().getQName(); attrs.addAttribute( NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME, CHILDNAME_QNAME.toPrefixString(), null, toPrefixString(childQName)); } QName type = nodeService.getType(nodeRef); contentHandler.startElement( type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs); } catch (SAXException e) { throw new ExporterException( "Failed to process start node event - node ref " + nodeRef.toString(), e); } }
/** * Return relative path between from and to references within export root * * @param fromRef from reference * @param toRef to reference * @return path */ private Path createPath(NodeRef rootRef, NodeRef fromRef, NodeRef toRef) { // Check that item exists first if (!nodeService.exists(toRef)) { // return null path return null; } // Check whether item is the root node of the store // If so, always return absolute path if (toRef.equals(nodeService.getRootNode(toRef.getStoreRef()))) { return nodeService.getPath(toRef); } // construct relative path Path rootPath = createIndexedPath(rootRef, nodeService.getPath(rootRef)); Path fromPath = createIndexedPath(fromRef, nodeService.getPath(fromRef)); Path toPath = createIndexedPath(toRef, nodeService.getPath(toRef)); Path relativePath = null; try { // Determine if 'to path' is a category // TODO: This needs to be resolved in a more appropriate manner - special support is // required for categories. for (int i = 0; i < toPath.size(); i++) { Path.Element pathElement = toPath.get(i); if (pathElement.getPrefixedString(namespaceService).equals("cm:categoryRoot")) { Path.ChildAssocElement childPath = (Path.ChildAssocElement) pathElement; relativePath = new Path(); relativePath.append( new Path.ChildAssocElement( new ChildAssociationRef(null, null, null, childPath.getRef().getParentRef()))); relativePath.append(toPath.subPath(i + 1, toPath.size() - 1)); break; } } if (relativePath == null) { // Determine if from node is relative to export tree int i = 0; while (i < rootPath.size() && i < fromPath.size() && rootPath.get(i).equals(fromPath.get(i))) { i++; } if (i == rootPath.size()) { // Determine if to node is relative to export tree i = 0; while (i < rootPath.size() && i < toPath.size() && rootPath.get(i).equals(toPath.get(i))) { i++; } if (i == rootPath.size()) { // build relative path between from and to relativePath = new Path(); for (int p = 0; p < fromPath.size() - i; p++) { relativePath.append(new Path.ParentElement()); } if (i < toPath.size()) { relativePath.append(toPath.subPath(i, toPath.size() - 1)); } } } } if (relativePath == null) { // default to absolute path relativePath = toPath; } } catch (Throwable e) { String msg = "Failed to determine relative path: root path=" + rootPath + "; from path=" + fromPath + "; to path=" + toPath; throw new ExporterException(msg, e); } return relativePath; }
private CategoryPaths getCategoryPaths( NodeRef nodeRef, Set<QName> aspects, Map<QName, Serializable> properties) { ArrayList<Pair<Path, QName>> categoryPaths = new ArrayList<Pair<Path, QName>>(); ArrayList<ChildAssociationRef> categoryParents = new ArrayList<ChildAssociationRef>(); nodeDAO.setCheckNodeConsistency(); for (QName classRef : aspects) { AspectDefinition aspDef = dictionaryService.getAspect(classRef); if (!isCategorised(aspDef)) { continue; } LinkedList<Pair<Path, QName>> aspectPaths = new LinkedList<Pair<Path, QName>>(); for (PropertyDefinition propDef : aspDef.getProperties().values()) { if (!propDef.getDataType().getName().equals(DataTypeDefinition.CATEGORY)) { // The property is not a category continue; } // Don't try to iterate if the property is null Serializable propVal = properties.get(propDef.getName()); if (propVal == null) { continue; } for (NodeRef catRef : DefaultTypeConverter.INSTANCE.getCollection(NodeRef.class, propVal)) { if (catRef == null) { continue; } // can be running in context of System user, hence use input nodeRef catRef = tenantService.getName(nodeRef, catRef); try { Pair<Long, NodeRef> pair = nodeDAO.getNodePair(catRef); if (pair != null) { for (Path path : nodeDAO.getPaths(pair, false)) { aspectPaths.add(new Pair<Path, QName>(path, aspDef.getName())); } } } catch (InvalidNodeRefException e) { // If the category does not exists we move on the next } } } categoryPaths.addAll(aspectPaths); } // Add member final element for (Pair<Path, QName> pair : categoryPaths) { if (pair.getFirst().last() instanceof Path.ChildAssocElement) { Path.ChildAssocElement cae = (Path.ChildAssocElement) pair.getFirst().last(); ChildAssociationRef assocRef = cae.getRef(); ChildAssociationRef categoryParentRef = new ChildAssociationRef( assocRef.getTypeQName(), assocRef.getChildRef(), QName.createQName("member"), nodeRef); pair.getFirst().append(new Path.ChildAssocElement(categoryParentRef)); categoryParents.add(categoryParentRef); } } return new CategoryPaths(categoryPaths, categoryParents); }