]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.cc
* added show/hide cursro methods
[helm.git] / helm / DEVEL / mathml_editor / src / CMathMLFactoryXSLTDiff.cc
1
2 #include "dom.hh"
3 #include "Diff.hh"
4 #include "TNode.hh"
5 #include "TDocument.hh"
6 #include "CMathMLFactoryXSLTDiff.hh"
7 #include "AMathMLConsumer.hh"
8
9 CMathMLFactoryXSLTDiff::CMathMLFactoryXSLTDiff(ALogger& l, const DOMX::XSLTStylesheet& s)
10   : AMathMLFactory(l), style(s)
11 {
12   DOM::DOMImplementation di;
13   DOM::DocumentType dt;
14   result = di.createDocument(MATHML_NS_URI, "m:math", dt);
15 }
16
17 void
18 CMathMLFactoryXSLTDiff::documentModified(TDocument& doc)
19 {
20 #if 0
21   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
22   if (TNode dirty = doc.dirtyNode()) 
23     if (false && result.get_documentElement().hasAttribute("xref"))
24       dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
25                                        DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
26 #endif
27   DOM::Document res = style.apply(doc.document());
28   assert(res);
29   //cout << "*** THE DIRTY FRAGMENT HAS ID = " << std::string(dirty["id"]) << endl;
30   //style.save(doc.document(), stdout);
31   cout << "*** THE CURRENT DOCUMENT:" << endl;
32   if (result) style.save(result, stdout);
33   cout << "*** THE NEW DOCUMENT:" << endl;
34   style.save(res, stdout);
35   cout << "*** THE DIFF:" << endl;
36   DOMX::Diff diff = DOMX::Diff::diff(result, res);
37   style.save(diff.document(), stdout);
38   diff.patch();
39
40   doc.clearDirty();
41 }
42
43 bool
44 CMathMLFactoryXSLTDiff::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
45 {
46   assert(e1);
47   assert(e2);
48   if (e1.getAttribute("xref") == id)
49     {
50       DOMX::Diff diff = DOMX::Diff::diff(e1, e2);
51       style.save(diff.document(), stdout);
52       diff.patch();
53       return true;
54     }
55   else
56     {
57       DOM::Node p = e1.get_firstChild();
58       while (p)
59         {
60           while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
61           if (p)
62             if (subst(p, id, e2)) return true;
63             else p = p.get_nextSibling();
64         }
65       return false;
66     }
67 }
68