/** * Copy the source resource to target, including all subresources, with default settings * (schedule values are copied, the active state is copied, logging is not activated for the * new resources) * @param source * @param target * may be virtual * @param ra * @throws ResourceOperationException if something goes wrong... * @throws SecurityException if the caller does not have the read permission for any * of the input resources, or the write permission for any of the target resources * @throws NullPointerException if any of source, target or ra is null */ public static void copy(Resource source, Resource target, ResourceAccess ra) { new CopyHelper(null, source, target, ra).commit(); }
void copy(final Resource source, final Resource copy) { if (source.isReference(false)) { if (config.isCopyReferences()) { copy.setAsReference(source.getLocationResource()); } return; } if (!copy.exists()) { copy.create(); newlyCreated.add(copy); } copyInternal(source, copy, ""); }
/** * @throws ResourceOperationException * @throws SecurityException */ void commit() { try { copy(source, target); if (activationCount != null && activationCount.get() > 0) transaction.commit(); } catch (Exception e) { Resource r = null; for (ListIterator<Resource> it=newlyCreated.listIterator();it.hasPrevious();r=it.previous()) { try { r.delete(); } catch (Exception ee) { LoggerFactory.getLogger(CopyHelper.class).warn("Failed to rollback resource creation for {}: {}",r,ee.toString()); } } throw e; } }
if (isNew) newlyCreated.add(copy); copyInternal(source, copy, newRelativePath);
copy(sub, copy, newRelativePath);
/** * Copy the source resource to target, including all subresources. * @param source * @param target * may be virtual * @param ra * @param config * @throws ResourceOperationException if something goes wrong... * @throws SecurityException if the caller does not have the read permission for any * of the input resources, or the write permission for any of the target resources * @throws NullPointerException if any of source, target or ra is null */ public static void copy(Resource source, Resource target, ResourceAccess ra, ResourceCopyConfiguration config) { new CopyHelper(config, source, target, ra).commit(); }