Update of
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository
In directory james.mmbase.org:/tmp/cvs-serv15240
Modified Files:
RepositoryUtil.java
Log Message:
CMSC-1298 Clone channel feature
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository
See also: http://www.mmbase.org/jira/browse/CMSC-1298
Index: RepositoryUtil.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/RepositoryUtil.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- RepositoryUtil.java 9 Mar 2009 06:28:22 -0000 1.41
+++ RepositoryUtil.java 20 Mar 2009 08:24:20 -0000 1.42
@@ -566,12 +566,33 @@
* - Content Node
* @return true if the node has a related creation channel
*/
+ public static boolean hasCreationChannel(Node content,Node channel) {
+
+ if(!isChannel(channel)) {
+ return false;
+ }
+ NodeList channels =
content.getRelatedNodes(content.getCloud().getNodeManager(CONTENTCHANNEL),
CREATIONREL, DESTINATION);
+ if(channels == null || channels.size() < 1) {
+ return false;
+ }
+ Node parentChannel = channels.getNode(0);
+ if(parentChannel.getNumber() == channel.getNumber()) {
+ return true;
+ }
+ return false;
+ }
+ /**
+ * Check if a contentnode has a creationchannel
+ *
+ * @param content
+ * - Content Node
+ * @return true if the node has a related creation channel
+ */
public static boolean hasCreationChannel(Node content) {
int count = content
.countRelatedNodes(content.getCloud().getNodeManager(CONTENTCHANNEL),
CREATIONREL, DESTINATION);
return count > 0;
}
-
/**
* Get creation channel
*
@@ -1215,6 +1236,20 @@
}
public static Node copyChannel(Node sourceChannel, Node destChannel) {
+ List<Integer> channelList = new ArrayList<Integer>();
+ iterateChannels(sourceChannel,channelList);
+ StringBuilder output = new StringBuilder().append(" -Start: ");
+ Map<Integer, Integer> copiedNodes = new HashMap<Integer, Integer>();
+
+ Node newNode =
copyChannel(sourceChannel,destChannel,channelList,copiedNodes,output);
+ output.append("<br/><br/>copiedNodes has #" + copiedNodes.size() +
":<br/>" + copiedNodes.toString());
+ if(log.isDebugEnabled()) {
+ log.debug("#################:"+output.toString());
+ }
+ return newNode;
+ }
+
+ public static Node copyChannel(Node sourceChannel, Node destChannel,
List<Integer> channelList,Map<Integer, Integer> copiedNodes ,StringBuilder
output) {
if (!isParent(sourceChannel, destChannel)) {
Node newChannel = CloneUtil.cloneNode(sourceChannel);
appendChild(destChannel, newChannel);
@@ -1222,21 +1257,12 @@
NodeList children = getOrderedChildren(sourceChannel);
for (Iterator<Node> iter = children.iterator(); iter.hasNext();) {
Node childChannel = iter.next();
- copyChannel(childChannel, newChannel);
+ copyChannel(childChannel,
newChannel,channelList,copiedNodes,output);
}
String cloneCopy = PropertiesUtil.getProperty("clonecopy");
- if(cloneCopy != null && "true".equalsIgnoreCase(cloneCopy)) {
- StringBuilder output = new StringBuilder().append("Start");
- Map<Integer, Integer> copiedNodes = new HashMap<Integer,
Integer>();
- List<Integer> channelNumbers = new ArrayList<Integer>();
+ if("true".equalsIgnoreCase(cloneCopy)) {
cloneAssetNodes(sourceChannel,newChannel,copiedNodes,output);
- iterateChannels(sourceChannel,channelNumbers);
- cloneRelatedNodes(sourceChannel,
newChannel,copiedNodes,output,channelNumbers);
- output.append("<br/><br/>copiedNodes has #" + copiedNodes.size() +
":<br/>" + copiedNodes.toString());
- if(log.isDebugEnabled()) {
- log.debug("#################:"+output.toString());
- }
-
+ cloneRelatedNodes(sourceChannel,
newChannel,copiedNodes,output,channelList);
}
else {
CloneUtil.cloneRelations(sourceChannel, newChannel, CONTENTREL,
CONTENTELEMENT);
@@ -1450,15 +1476,11 @@
continue;
}
- if (!(AssetElementUtil.isAssetElement(rel.getDestination()) ||
ContentElementUtil.isContentElement(rel.getDestination()))) {
+ if (!isChannel(rel.getDestination()) &&
!isRelatedWithCurrentChannelTree(rel.getDestination(),channels)) {
output.append("skipped " + relManager.getName() + "; ");
- continue; //Skip contentchannels and collection channels.
+ continue; //Skip nodes not in the current channel tree.
}
- if (!isRelatedWithCurrentChannelTree(rel.getDestination(),channels)) {
- output.append("skipped " + relManager.getName() + "; ");
- continue; //Skip contentchannels and collection channels.
- }
if (isChannel(rel.getDestination()) ||
relManager.getName().equalsIgnoreCase("deletionrel")
// || relManager.getName().equalsIgnoreCase("creationrel")
@@ -1478,6 +1500,7 @@
//Only clone node, when it hasn't been cloned before.
Node destChild;
+
if (copiedNodes.get(sourceChild.getNumber()) == null) {
destChild = cloneNode(sourceChild,copiedNodes,channels);
copiedNodes.put(Integer.valueOf(sourceChild.getNumber()),Integer.valueOf(destChild.getNumber()));
@@ -1505,15 +1528,15 @@
}
destRel.commit();
- //If no clone was needed, but reused an existing clone, the
relations are fine already..continue!
- if (!cloned) continue;
+
//Creation channels are skipped at copying relations, so do it by
hand.
- if (hasCreationChannel(sourceChild) && isChannel(destNode)) {
+ if (hasCreationChannel(sourceChild,sourceNode) &&
isChannel(destNode)) {
addCreationChannel(destChild, destNode);
output.append("added creationrel to " + destChild.getNumber() +
";");
}
-
+ //If no clone was needed, but reused an existing clone, the
relations are fine already..continue!
+ if (!cloned) continue;
//If destChild is an image, also change title
if
(destChild.getNodeManager().getName().equalsIgnoreCase("images")) {
destChild.setStringValue("title",
destChild.getStringValue("title") + "-North");
@@ -1637,21 +1660,10 @@
*/
public static boolean isRelatedWithCurrentChannelTree(Node
sourceNode,List<Integer> channels) {
- if (AssetElementUtil.isAssetElement(sourceNode)) {
-
- Node creationNode = getCreationChannel(sourceNode);
- if(creationNode != null &&
channels.contains(creationNode.getNumber())) {
+ Node creationChannel = getCreationChannel(sourceNode);
+ if(creationChannel != null &&
channels.contains(creationChannel.getNumber())) {
return true;
}
- }
- else if (ContentElementUtil.isContentElement(sourceNode)) {
- NodeList contentChannels = getContentChannelsForContent(sourceNode);
- for(int i = 0 ; i < contentChannels.size() ; i++) {
- if (channels.contains(contentChannels.getNode(i).getNumber())) {
- return true;
- }
- }
- }
return false;
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs