/** * Import a story from one document (e.g., an InCopy article) into this document, updating style * references as necessary. * * @param incxStory The story to be imported. * @return The imported story object. * @throws Exception */ public Story importStory(Story incxStory) throws Exception { Map<String, ParagraphStyle> paraStyleMap = new HashMap<String, ParagraphStyle>(); Story newStory = new Story(); this.assignIdAndRegister(newStory); Iterator<TextStyleRange> iter = incxStory.getTextStyleRangeIterator(); while (iter.hasNext()) { TextStyleRange incomingTxsr = iter.next(); TextStyleRange txsr = (TextStyleRange) this.clone(incomingTxsr); InDesignObject incomingStyle = incomingTxsr.getParagraphStyle(); if (incomingStyle == null) { throw new Exception( "Failed to get object for referenced paragraph style ID [" + txsr.getObjectReferenceProperty(PROP_PRST) + "]"); } String styleName = incomingStyle.getPName(); ParagraphStyle targetPStyle = this.getParagraphStyle(styleName); if (targetPStyle == null) { targetPStyle = (ParagraphStyle) this.clone(incomingStyle); this.addParagraphStyle(targetPStyle); } txsr.setObjectReferenceProperty(PROP_PRST, targetPStyle); incomingStyle = incomingTxsr.getCharacterStyle(); if (incomingStyle == null) { logger.warn( "Failed to get object for referenced character style ID [" + txsr.getObjectReferenceProperty(PROP_PRST) + "]"); } else { styleName = incomingStyle.getPName(); CharacterStyle targetCStyle = this.getCharacterStyle(styleName); if (targetCStyle == null) { targetCStyle = (CharacterStyle) this.clone(incomingStyle); this.addCharacterStyle(targetCStyle); } txsr.setObjectReferenceProperty(PROP_CRST, targetCStyle); } newStory.addChild(txsr); } this.addChild(newStory); return newStory; }