public void load(Element docElem) throws Exception {
   this.dataSource = docElem.getOwnerDocument();
   Iterator<Element> elemIter = DataUtil.getElementChildrenIterator(docElem);
   while (elemIter.hasNext()) {
     Element child = elemIter.next();
     logger.debug("load(): Element: " + child.getNodeName());
     if (child.getNodeName().equals(CFLO_TAGNAME)) {
       logger.debug("load(): Creating new Story...");
       this.newStory(child);
     } else if (child.getNodeName().equals(DOCP_TAGNAME)) {
       logger.debug("load(): Getting document preferences...");
       this.newDocumentPreferences(child);
     } else if (child.getNodeName().equals(MSPR_TAGNAME)) {
       logger.debug("load(): Creating new Master Spread...");
       this.newMasterSpread(child);
     } else if (child.getNodeName().equals(SPRD_TAGNAME)) {
       logger.debug("load(): Creating new Spread...");
       this.newSpread(child);
     } else {
       logger.debug(" + Creating new unhandled child " + child.getNodeName() + "...");
       InDesignComponent comp = this.newInDesignComponent(child);
       this.addChild(comp);
     }
   }
 }
 public void load(InputSource source) throws Exception {
   DocumentBuilder builder = DataUtil.constructNonValidatingDocumentBuilder();
   Document dom = builder.parse(source);
   Element docElem = dom.getDocumentElement();
   if (docElem == null) {
     throw new IOException("No root element for input document " + source.getSystemId());
   }
   load(docElem);
   logger.debug("load(): Setting dataSource to " + dom);
   this.dataSource = dom;
 }
 /**
  * Construct a new document by cloning an existing document, copying only the master spreads. Note
  * that this is different from a generic loadObject(InDesignObject) operation (as for
  * InDesignObject), which is a full copy.
  *
  * @param inddDoc
  * @throws Exception
  */
 public InDesignDocument(InDesignDocument inddDoc, boolean removeSpreads) throws Exception {
   Document cloneSourceDoc = inddDoc.getDataSource();
   if (cloneSourceDoc == null)
     throw new Exception("Got null data source from input InDesign document.");
   this.dataSource = (Document) cloneSourceDoc.cloneNode(true);
   logger.debug("InDesignDocument(inddDoc): setting dataSource to " + dataSource);
   Element clonedDataSource = this.dataSource.getDocumentElement();
   if (removeSpreads) {
     // Now delete the components that hold actual content, namely spreads and stories:
     for (Element spread : DataUtil.getElementChildren(clonedDataSource, null, SPRD_TAGNAME)) {
       clonedDataSource.removeChild(spread);
     }
     // FIXME: For stories, we only want to delete stories that are associated with frames on
     // normal spreads, not master spreads. So for now just leaving them in.
     //			for (Element story : DataUtil.getElementChildren(clonedDataSource, null, CFLO_TAGNAME)) {
     //				clonedDataSource.removeChild(story);
     //			}
   }
   this.load(clonedDataSource);
   this.spreads.clear(); // Just to make sure
   // Now make sure there is a spread as a document must have at least one spread.
   Spread spread = this.newSpread(this.getMasterSpreads().get(0).getName());
   spread.addPage(1);
 }