/** * @param objectClass * @param child * @return * @throws Exception */ private InDesignComponent newComponent(Class<? extends InDesignComponent> clazz, Element child) throws InstantiationException, Exception { InDesignComponent comp = (InDesignComponent) clazz.newInstance(); comp.setDocument(this); comp.loadComponent(child); return comp; }
/** * Unconditionally clone an InDesign Object. * * @param sourceObj * @return The clone of the object. * @throws Exception */ public InDesignComponent clone(InDesignComponent sourceComp) throws Exception { if (sourceComp instanceof InDesignObject) { return clone((InDesignObject) sourceComp); } logger.debug("Cloning component " + sourceComp.getClass().getSimpleName()); InDesignComponent clone = sourceComp.getClass().newInstance(); clone.setDocument(this); clone.loadComponent(sourceComp); return clone; }
/** * 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; }
/** @return */ public String reportChildObjects() { StringBuilder report = new StringBuilder("Child Objects::\n"); for (InDesignComponent comp : this.getChildren()) { String dsName = comp.getInxTagName(); if (comp instanceof InDesignObject) { InDesignObject obj = (InDesignObject) comp; report.append("[").append(obj.getId()).append("] "); } report .append(comp.getClass().getSimpleName()) .append(", <") .append(dsName) .append(">") .append("\n"); } return report.toString(); }
public void addChild(InDesignComponent comp) throws Exception { super.addChild(comp); if (comp instanceof Story) { this.stories.add((Story) comp); // FIXME: Need to do some more refactoring in order to be able to do // this processing at this point. // } else if (comp instanceof MasterSpread) { // MasterSpread masterSpread = (MasterSpread)comp; // this.masterSpreads.put(masterSpread.getPName(), masterSpread); // } else if (comp instanceof Spread) { // this.spreads.add((Spread)comp); } else if (comp instanceof ParagraphStyle) { this.pstylesByName.put(comp.getPName(), (ParagraphStyle) comp); } else if (comp instanceof CharacterStyle) { this.cstylesByName.put(comp.getPName(), (CharacterStyle) comp); } else if (comp instanceof DocumentPreferences) { this.docPrefs = (DocumentPreferences) comp; } }