/** * Clones an object only if it hasn't been already cloned. Returns the clone. * * @param sourceObj * @return The clone of the source object. * @throws Exception */ public InDesignComponent cloneIfNew(InDesignObject sourceObj, InDesignComponent targetParent) throws Exception { Map<String, InDesignObject> cloneMap = getCloneMapForDoc(sourceObj.getDocument()); if (cloneMap.containsKey(sourceObj.getId())) return cloneMap.get(sourceObj.getId()); InDesignComponent clone = this.clone(sourceObj); if (targetParent != null) targetParent.addChild(clone); return clone; }