Created
April 9, 2013 15:14
-
-
Save skuro/5346541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static List<String> ASSOC_NAMES_TO_EXTRACT = Arrays.asList(new String[]{"imageRef","thumbnailRef"}); | |
/** | |
* Gets a list of associations of type my:imageRef and my:thumbnailRef, given an Alfresco node; | |
* Implementation is not optimal | |
* @param nodeRef The Alfresco NodeRef that contains the associations we want to extract | |
* @return a List of associations of type my:imageRef and my:thumbnailRef | |
*/ | |
public List<AssociationRef> getAssociations(NodeRef nodeRef) { | |
List<AssociationRef> associations = serviceRegistry.getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL); | |
List<AssociationRef> toReturn = new ArrayList<AssociationRef>(); | |
// extract only my:imageRef and my:thumbnailRef assocs | |
for(AssociationRef association : associations) { | |
QName assocQname = association.getTypeQName(); | |
if (ASSOC_NAMES_TO_EXTRACT.contains(assocQname.getLocalName())) { | |
toReturn.add(association); | |
} | |
} | |
return toReturn; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final RegexQNamePattern IMAGE_ASSOCIATIONS = new RegexQNamePattern( | |
".*thumbnailRef$|.*imageRef$"); | |
/** | |
* Gets a list of associations of type my:imageRef and my:thumbnailRef, given an Alfresco node; | |
* @param nodeRef The Alfresco NodeRef that contains the associations we want to extract | |
* @return a List of associations of type my:imageRef and my:thumbnailRef | |
*/ | |
public List<AssociationRef> getAssociations(NodeRef nodeRef) { | |
return serviceRegistry.getNodeService().getTargetAssocs(nodeRef, IMAGE_ASSOCIATIONS); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I am assuming that your custom Alfresco contentModel defines the following namespace | |
* <namespace uri="http:/session.it/alfresco/model/content/1.0" prefix="my"/> | |
*/ | |
static final RegexQNamePattern ALL_MY_ASSOCIATIONS = | |
new RegexQNamePattern("^\\{http:\\/session.it\\/alfresco\\/model\\/content\\/1.0\\}.*"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment