1 17 package org.alfresco.util.debug; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.Map ; 22 23 import org.alfresco.service.cmr.repository.ChildAssociationRef; 24 import org.alfresco.service.cmr.repository.InvalidNodeRefException; 25 import org.alfresco.service.cmr.repository.AssociationRef; 26 import org.alfresco.service.cmr.repository.NodeRef; 27 import org.alfresco.service.cmr.repository.NodeService; 28 import org.alfresco.service.cmr.repository.StoreRef; 29 import org.alfresco.service.namespace.QName; 30 import org.alfresco.service.namespace.RegexQNamePattern; 31 32 37 public class NodeStoreInspector 38 { 39 46 public static String dumpNodeStore(NodeService nodeService, StoreRef storeRef) 47 { 48 StringBuilder builder = new StringBuilder (); 49 50 if (nodeService.exists(storeRef) == true) 51 { 52 NodeRef rootNode = nodeService.getRootNode(storeRef); 53 builder.append(outputNode(0, nodeService, rootNode)); 54 } 55 else 56 { 57 builder. 58 append("The store "). 59 append(storeRef.toString()). 60 append(" does not exist."); 61 } 62 63 return builder.toString(); 64 } 65 66 73 public static String dumpNode(NodeService nodeService, NodeRef nodeRef) 74 { 75 StringBuilder builder = new StringBuilder (); 76 77 if (nodeService.exists(nodeRef) == true) 78 { 79 builder.append(outputNode(0, nodeService, nodeRef)); 80 } 81 else 82 { 83 builder. 84 append("The node "). 85 append(nodeRef.toString()). 86 append(" does not exist."); 87 } 88 89 return builder.toString(); 90 } 91 92 100 private static String outputNode(int iIndent, NodeService nodeService, NodeRef nodeRef) 101 { 102 StringBuilder builder = new StringBuilder (); 103 104 try 105 { 106 QName nodeType = nodeService.getType(nodeRef); 107 builder. 108 append(getIndent(iIndent)). 109 append("node: "). 110 append(nodeRef.getId()). 111 append(" ("). 112 append(nodeType.getLocalName()); 113 114 Collection <QName> aspects = nodeService.getAspects(nodeRef); 115 for (QName aspect : aspects) 116 { 117 builder. 118 append(", "). 119 append(aspect.getLocalName()); 120 } 121 122 builder.append(")\n"); 123 124 Map <QName, Serializable > props = nodeService.getProperties(nodeRef); 125 for (QName name : props.keySet()) 126 { 127 String valueAsString = "null"; 128 Serializable value = props.get(name); 129 if (value != null) 130 { 131 valueAsString = value.toString(); 132 } 133 134 builder. 135 append(getIndent(iIndent+1)). 136 append("@"). 137 append(name.getLocalName()). 138 append(" = "). 139 append(valueAsString). 140 append("\n"); 141 142 } 143 144 Collection <ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(nodeRef); 145 for (ChildAssociationRef childAssocRef : childAssocRefs) 146 { 147 builder. 148 append(getIndent(iIndent+1)). 149 append("-> "). 150 append(childAssocRef.getQName().toString()). 151 append(" ("). 152 append(childAssocRef.getQName().toString()). 153 append(")\n"); 154 155 builder.append(outputNode(iIndent+2, nodeService, childAssocRef.getChildRef())); 156 } 157 158 Collection <AssociationRef> assocRefs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL); 159 for (AssociationRef assocRef : assocRefs) 160 { 161 builder. 162 append(getIndent(iIndent+1)). 163 append("-> associated to "). 164 append(assocRef.getTargetRef().getId()). 165 append("\n"); 166 } 167 } 168 catch (InvalidNodeRefException invalidNode) 169 { 170 invalidNode.printStackTrace(); 171 } 172 173 return builder.toString(); 174 } 175 176 182 private static String getIndent(int iIndent) 183 { 184 StringBuilder builder = new StringBuilder (iIndent*3); 185 for (int i = 0; i < iIndent; i++) 186 { 187 builder.append(" "); 188 } 189 return builder.toString(); 190 } 191 192 } 193 | Popular Tags |