Package org.eclipse.compare

Examples of org.eclipse.compare.EventSequenceComparator


         
          leftES.add(loader.process( e ));
          //log("" + leftES.get( leftES.size()-1 ).hashCode() );
        }
      }
      EventSequenceComparator leftESC = new EventSequenceComparator(leftES);


      //log("\n\n right");
      List<EventSequence> rightES = new ArrayList<EventSequence>();
      for (int i = 0 ; i < xml2.getChildNodes().getLength(); i++ ) {
        if (xml2.getChildNodes().item(i).getNodeType()!=3) {
          Element e = (Element)xml2.getChildNodes().item(i);
         
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a", "http://schemas.openxmlformats.org/drawingml/2006/main");
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a14", "http://schemas.microsoft.com/office/drawing/2010/main");
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:m", "http://schemas.openxmlformats.org/officeDocument/2006/math" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:mc", "http://schemas.openxmlformats.org/markup-compatibility/2006" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:o", "urn:schemas-microsoft-com:office:office" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:v", "urn:schemas-microsoft-com:vml" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:w10", "urn:schemas-microsoft-com:office:word" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:w14", "http://schemas.microsoft.com/office/word/2010/wordml" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:w15", "http://schemas.microsoft.com/office/word/2012/wordml" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wne", "http://schemas.microsoft.com/office/word/2006/wordml" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk" );
          e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" );
         
          rightES.add(loader.process( e ));
          //log("" + rightES.get( rightES.size()-1 ).hashCode() );
        }
      }
      EventSequenceComparator rightESC = new EventSequenceComparator(rightES);

      log("top level LCS - determining top level LCS...");
      RangeDifference[] rd = RangeDifferencer.findDifferences(leftESC, rightESC);

      SmartXMLFormatter formatter = new SmartXMLFormatter(out);
      formatter.setConfig(diffxConfig);

      String rootNodeName = xml1.getNodeName();
      openResult(rootNodeName, out);

      if (rd.length==0) {
        log("top level LCS done; there are no differences!");
        addComment("No differences", formatter);
        // Note that our hashcode acts like a canonicaliser
        // - attribute order doesn't matter.

        // So just feed the leftESC into the formatter and return
        for(EventSequence es : leftES) {
            formatter.declarePrefixMapping(es.getPrefixMapping());
          formatEventSequence(es,formatter);
        }
        closeResult(rootNodeName, out);
        return;
      }

      // Debug: Raw output
      for (int i=0; i<rd.length; i++ ) {
        RangeDifference rdi = rd[i];
        log( rdi.kindString() + " left " + rdi.leftStart() + "," + rdi.leftLength()
            + " right " + rdi.rightStart() + "," + rdi.rightLength() );
      }

      log("top level LCS done; now performing child actions ...");


      int leftIdx = 0;
      for (int i=0; i<rd.length; i++ ) {

        RangeDifference rdi = rd[i];

        // No change
        if (rdi.leftStart() > leftIdx) {

          for (int k = leftIdx ; k< rdi.leftStart() ; k++) {
            // This just goes straight into the output,
            // since it is the same on the left and the right.
            // Since it is the same on both side, we handle
            // it here (on the left side), and
            // ignore it on the right
            //out.append("\n<!-- Adding same -->\n");
            addComment("Adding same", formatter);
              formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
            formatEventSequence(leftESC.getItem(k), formatter);
            //out.append("\n<!-- .. Adding same done -->");
            addComment(".. Adding same done ", formatter);

            // If we wanted to difference sdt's which
            // were treated the as the same (via their id)
            // this is where we'd have to change
            // (in addition to changing EventSequence for
            //  such things so that hashcode returned their
            //  id!)
          }
          leftIdx = rdi.leftStart();
        }

        EventSequence seq1 = new EventSequence();
        // Evil hack - doesn't work
        // seq1.mapPrefix("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");

        for (int k = rdi.leftStart() ; k< rdi.leftEnd() ; k++) {

          if (rdi.kind()==rdi.CHANGE) {
            // This we need to diff
            //leftReport.append( "#" );
            seq1.addSequence(leftESC.getItem(k));

            // Don't forget our existing prefix mappings!
            PrefixMapping existingPM = leftESC.getItem(k).getPrefixMapping();
            addToPrefixMapping(seq1.getPrefixMapping(), existingPM);
          } else {
            // Does this happen?
            // This just goes straight into the output,
              formatter.declarePrefixMapping(leftESC.getItem(k).getPrefixMapping());
            //out.append("\n<!-- Adding same II -->\n");
            addComment("Adding same II", formatter);
            formatEventSequence(leftESC.getItem(k), formatter);
            //out.append("\n<!-- .. Adding same done -->");
            addComment(".. Adding same done", formatter);
          }
        }


        EventSequence seq2 = new EventSequence();
        // Evil hack - doesn't work
        //seq2.mapPrefix("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
        for (int k = rdi.rightStart() ; k< rdi.rightEnd() ; k++) {
          if (rdi.kind()==rdi.CHANGE) {
            // This is the RHS of the diff
            //rightReport.append( "#" );
            seq2.addSequence(rightESC.getItem(k));

            // Don't forget our existing prefix mappings!
            PrefixMapping existingPM = rightESC.getItem(k).getPrefixMapping();
            addToPrefixMapping(seq2.getPrefixMapping(), existingPM);

          }
        }
View Full Code Here

TOP

Related Classes of org.eclipse.compare.EventSequenceComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.