Element firstEntry = DOM.findChild(target,Atom.NAMESPACE_STRING,"entry");
NodeListener firstEntry = null; Element theFirstEntry = DOM.findChild(target,Atom.NAMESPACE_STRING,"entry"); if (theFirstEntry!=null) { firstEntry = new NodeListener((StoredNode)theFirstEntry); ownerDocument.getMetadata().setIndexListener(firstEntry); }
   public void mergeFeed(final Txn transaction,final ElementImpl target,Element source,final String updated) {      final List toRemove = new ArrayList();      DOM.forEachChild(target,new NodeHandler() {         public void process(Node parent, Node child) {            if (child.getNodeType()==Node.ELEMENT_NODE) {               String ns = child.getNamespaceURI();               if (ns!=null && ns.equals(Atom.NAMESPACE_STRING)) {                  String lname = child.getLocalName();                  if (lname.equals("updated")) {                     // Changed updated                     DOMDB.replaceText(transaction,(ElementImpl)child,updated);                  } else if (lname.equals("link")) {                     Element echild = (Element)child;                     String rel = echild.getAttribute("rel");                     if (!rel.equals("edit")) {                        // remove it                        toRemove.add(child);                     }                  } else if (!lname.equals("id") && !lname.equals("published") && !lname.equals("entry")) {                     // remove it                     toRemove.add(child);                  }               } else {                  // remove it                  toRemove.add(child);               }            } else {               toRemove.add(child);            }         }      });      for (Iterator childrenToRemove = toRemove.iterator(); childrenToRemove.hasNext(); ) {         Node child = (Node)childrenToRemove.next();         target.removeChild(transaction,child);      }      final Document ownerDocument = target.getOwnerDocument();      NodeList nl = source.getChildNodes();      Element firstEntry = DOM.findChild(target,Atom.NAMESPACE_STRING,"entry");      for (int i=0; i<nl.getLength(); i++) {         Node child = nl.item(i);         if (child.getNodeType()==Node.ELEMENT_NODE) {            String ns = child.getNamespaceURI();            if (ns!=null && ns.equals(Atom.NAMESPACE_STRING)) {               String lname = child.getLocalName();               // Skip server controls updated, published, and id elements               if (lname.equals("updated") ||                   lname.equals("published") ||                   lname.equals("id")) {                  continue;               }               // Skip the edit link relations               if (lname.equals("link")) {                  String rel = ((Element)child).getAttribute("rel");                  if (rel.equals("edit")) {                     continue;                  }               }            }            if (firstEntry==null) {               DOMDB.appendChild(transaction,target,child);               DOMDB.appendChild(transaction,target,ownerDocument.createTextNode("\n"));            } else {               DOMDB.insertBefore(transaction,target,child,firstEntry);               DOMDB.insertBefore(transaction,target,ownerDocument.createTextNode("\n"),firstEntry);               // TODO: this is a total hack.  Somehow, the insertion order is wrong due to firstEntry changing position               firstEntry = DOM.findChild(target,Atom.NAMESPACE_STRING,"entry");            }         }      }   }