Commit 0458247a authored by Louis-Nol Pouchet's avatar Louis-Nol Pouchet
Browse files

2005-05-16 Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>

	This patch re-activate XML session support. Usage is the same as 
	before, but the class is named xml_session.
	
	* include/vaucanson/xml/session.hh,
	* include/vaucanson/xml/session.hxx: New. XML session support.

	* include/vaucanson/xml/xml_converter.hh,
	* include/vaucanson/xml/xml_converter.hxx,
	* include/vaucanson/xml/xerces_parser.hxx,
	* include/vaucanson/xml/tools.hh,
	* include/vaucanson/xml/tools.hxx: Code maintainance to ease XML 
	session handling.

	* src/demos/xml/make_session.cc,
	* src/demos/xml/display_session.cc: New. Re-add demos for session. 
	These demos are temporarely limited to boolean automata. 

	* src/tests/xml/trans_ref.xml,
	* src/tests/xml/r_ref.xml,
	* src/tests/xml/z_ref.xml,
	* src/tests/xml/z_min_plus_ref.xml,
	* src/tests/xml/b_ref.xml,
	* src/tests/xml/z_max_plus_ref.xml,
	* src/tests/xml/fmp_ref.xml: Fix. Add an extraneous blank line at end 
	of file.

	* src/tests/xml/session_ref.xml
	* src/tests/xml/session_ref.dot,
	* src/tests/xml/xml_session_tester.cc: Add tests for XML sessions.
	* src/tests/xml/tester.sh: Update accordingly.
	
	* include/Makefile.am,
	* src/tests/xml/Makefile.am,
	* src/demos/xml/Makefile.am: Update.

	* doc/xml/vaucanson.xsd: Fix maxOccurs parameter for sessions (was set 
	to 1, set to unbounded).
parent d21d2ed5
2005-05-16 Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
This patch re-activate XML session support. Usage is the same as
before, but the class is named xml_session.
* include/vaucanson/xml/session.hh,
* include/vaucanson/xml/session.hxx: New. XML session support.
* include/vaucanson/xml/xml_converter.hh,
* include/vaucanson/xml/xml_converter.hxx,
* include/vaucanson/xml/xerces_parser.hxx,
* include/vaucanson/xml/tools.hh,
* include/vaucanson/xml/tools.hxx: Code maintainance to ease XML
session handling.
* src/demos/xml/make_session.cc,
* src/demos/xml/display_session.cc: New. Re-add demos for session.
These demos are temporarely limited to boolean automata.
* src/tests/xml/trans_ref.xml,
* src/tests/xml/r_ref.xml,
* src/tests/xml/z_ref.xml,
* src/tests/xml/z_min_plus_ref.xml,
* src/tests/xml/b_ref.xml,
* src/tests/xml/z_max_plus_ref.xml,
* src/tests/xml/fmp_ref.xml: Fix. Add an extraneous blank line at end
of file.
* src/tests/xml/session_ref.xml
* src/tests/xml/session_ref.dot,
* src/tests/xml/xml_session_tester.cc: Add tests for XML sessions.
* src/tests/xml/tester.sh: Update accordingly.
* include/Makefile.am,
* src/tests/xml/Makefile.am,
* src/demos/xml/Makefile.am: Update.
* doc/xml/vaucanson.xsd: Fix maxOccurs parameter for sessions (was set
to 1, set to unbounded).
2005-05-15 Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
 
* src/tests/xml/tester.sh: Fix the XML test script.
......
......@@ -188,8 +188,8 @@ set using the <drawing> tag.
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="automaton" type="automaton" minOccurs="0"/>
<xs:element name="transducer" type="transducer" minOccurs="0"/>
<xs:element name="automaton" type="automaton" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="transducer" type="transducer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="geometry" type="geometry_full" minOccurs="0"/>
<xs:element name="drawing" type="drawing" minOccurs="0"/>
</xs:sequence>
......
......@@ -354,6 +354,8 @@ XMLSOURCES = \
vaucanson/xml/XML.hxx \
vaucanson/xml/node.hh \
vaucanson/xml/node.hxx \
vaucanson/xml/session.hh \
vaucanson/xml/session.hxx \
vaucanson/xml/tools.hh \
vaucanson/xml/tools.hxx \
vaucanson/xml/xerces_parser.hh \
......
// session.hh: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_XML_SESSION_HH
# define VCSN_XML_SESSION_HH
/**
* @file session.hh
*
* XML session management.
*
*
* @see vcsn::xml::XML, vcsn::xml::xerces_parser
*
* @author Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
*/
# include <iostream>
# include <xercesc/dom/DOM.hpp>
# include <vaucanson/xml/xml_converter.hh>
namespace vcsn
{
namespace xml
{
/**
* @brief Session mangement class. Use stream operators to use.
* For example :
*
* xml_session s;
* std::cin >> s;
* s >> automaton;
* s << automaton2;
* std::cout << s;
*
*/
struct xml_session
{
xml_session();
~xml_session();
xercesc::DOMImplementation* impl;
xercesc::DOMDocument* doc;
xercesc::DOMElement* root;
};
} // ! xml
template<typename S, typename T>
xml::xml_session& op_rin(S&, xml::xml_session&, T&);
template<typename S, typename T>
xml::xml_session& op_rout(const S&, xml::xml_session&, const T&);
template <class IStream>
IStream& operator >> (IStream&, xml::xml_session&);
template <class OStream>
OStream& operator << (OStream&, const xml::xml_session&);
} // !vcsn
# ifndef VCSN_USE_INTERFACE_ONLY
# include <vaucanson/xml/session.hxx>
# endif // VCSN_USE_INTERFACE_ONLY
#endif // VCSN_XML_SESSION_HH
// session.hxx: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2005 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group consists of the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@liafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
#ifndef VCSN_XML_SESSION_HXX
# define VCSN_XML_SESSION_HXX
/**
* @file session.hxx
*
* XML session management.
*
*
* @see vcsn::xml::XML, vcsn::xml::xerces_parser
*
* @author Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
*/
namespace vcsn
{
namespace xml
{
xml_session::xml_session()
{
using namespace xercesc;
XMLPlatformUtils::Initialize();
impl = DOMImplementationRegistry::getDOMImplementation(STR2XML("LS"));
doc = impl->createDocument(STR2XML("http://vaucanson.lrde.epita.fr"),
STR2XML("session"), 0);
root = doc->getDocumentElement();
}
xml_session::~xml_session()
{
xercesc::XMLPlatformUtils::Terminate();
}
} // ! xml
template<typename S, typename T>
xml::xml_session&
op_rout(const S& structure,
xml::xml_session& s,
const T& value)
{
xercesc::XMLPlatformUtils::Initialize();
Element<S, T> a(structure, value);
xml::xml_converter<Element<S, T> > x;
x.create_document(a);
xercesc::DOMNode* node =
s.doc->importNode(static_cast<xercesc::DOMNode*>(x.root_get()), true);
s.root->appendChild(node);
return s;
}
template <class S, class T>
xml::xml_session& op_rin(S& structure,
xml::xml_session& s,
T& value)
{
using namespace xercesc;
using namespace vcsn;
using namespace vcsn::xml;
XMLPlatformUtils::Initialize();
Element<S, T> a(structure, value);
if (! s.root->getFirstChild())
FAIL("No more automaton in session");
for (DOMNode* n = s.root->getFirstChild(); n; n = n->getNextSibling())
if (n->getNodeType() == DOMNode::ELEMENT_NODE)
{
DOMElement* elt = static_cast<DOMElement*>(n);
typedef Element<S, T> automaton_t;
typedef Node<automaton_t> node_t;
Factory<node_t, std::string> f;
register_all_factory(f, automaton_t);
typename node_t::map_t str2state;
node_t* node = factory_create(f, xml2str(n->getNodeName()));
node->process(elt, a, str2state, f);
s.root->removeChild(n);
}
op_assign(structure.self(), value, a.value());
return s;
}
template <class IStream>
IStream& operator >> (IStream& is, xml::xml_session& s)
{
using namespace xercesc;
xercesc::XMLPlatformUtils::Initialize();
DOMNode* node = xml::xerces_parser::stream_parser(is);
for (DOMNode* n = node->getFirstChild(); n; n = n->getNextSibling())
if (n->getNodeType() == DOMNode::ELEMENT_NODE)
(s.root)->appendChild(s.doc->importNode(n, true));
return is;
}
template <class OStream>
OStream& operator << (OStream& out, const xml::xml_session& s)
{
xercesc::XMLPlatformUtils::Initialize();
xml::tools::print_document(s.root, out);
return out;
}
} // !vcsn
#endif // VCSN_XML_SESSION_HXX
......@@ -44,6 +44,9 @@
* @author Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
*/
# include <xercesc/dom/DOM.hpp>
# include <xercesc/framework/MemBufFormatTarget.hpp>
# include <xercesc/util/XMLString.hpp>
# include <xercesc/util/PlatformUtils.hpp>
# include <vaucanson/design_pattern/element.hh>
# include <vaucanson/tools/usual_macros.hh>
......@@ -86,19 +89,22 @@ namespace vcsn
xercesc::DOMDocument* doc,
xercesc::DOMElement* elt);
template <class T>
typename T::series_set_elt_t get_series(xercesc::DOMElement*, T&);
template <class T>
typename T::series_set_elt_t get_series(xercesc::DOMElement*, T&);
template <class U, class V>
void insert_letter(Element<vcsn::algebra::AlphabetSet<U>, V>&,
const std::string&);
template <class U, class V>
void insert_letter(Element<vcsn::algebra::AlphabetSet<U>, V>&,
const std::string&);
template <class U>
void ensure_monoid_type(const xercesc::DOMElement*, const U&);
template <class U>
void ensure_monoid_type(const xercesc::DOMElement*, const U&);
template <class T, class U>
void ensure_semiring_type(const xercesc::DOMElement*, const T&, const U&);
template <class T, class U>
void ensure_semiring_type(const xercesc::DOMElement*, const T&,
const U&);
template <class OStream>
void print_document(const xercesc::DOMElement*, OStream&);
} // ! tools
......
......@@ -531,6 +531,43 @@ GET_SEMIRING_OPERATIONS(vcsn::z_min_plus_automaton::semiring_t, "tropicalMin")
FAIL("Bad monoid type");
}
/**
* Print XML tree to output stream.
*
* @param OStream Type of output stream.
*
* @arg node XML root node to print.
* @arg os Output stream.
*
*/
template <class OStream>
void print_document(const xercesc::DOMElement* node, OStream& os)
{
using namespace xercesc;
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(STR2XML("LS"));
DOMWriter* serializer =
((DOMImplementationLS*)impl)->createDOMWriter();
// Set serializer properties.
if (serializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
true))
serializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
if (serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// Create buffer.
MemBufFormatTarget buf;
if (node)
{
serializer->writeNode(&buf, *node);
os << buf.getRawBuffer();
os << std::endl;
}
}
} // ! tools
} // ! xml
......
......@@ -99,7 +99,7 @@ namespace vcsn
if (err->has_error())
FAIL(err->get_msg());
// parser->release();
delete err;
return doc;
}
......@@ -119,18 +119,14 @@ namespace vcsn
DOMNodeList* nodelist;
/// FIXME: Handle sessions here.
nodelist = doc->
getElementsByTagNameNS(STR2XML("http://vaucanson.lrde.epita.fr"),
STR2XML("automaton"));
nodelist = doc->getElementsByTagName(STR2XML("session"));
if (! nodelist->getLength())
{
nodelist = doc->
getElementsByTagNameNS(STR2XML("http://vaucanson.lrde.epita.fr"),
STR2XML("transducer"));
if (! nodelist->getLength())
FAIL("Cannot find any automaton / transducer root.");
}
nodelist = doc->getElementsByTagName(STR2XML("automaton"));
if (! nodelist->getLength())
nodelist = doc->getElementsByTagName(STR2XML("transducer"));
if (! nodelist->getLength())
FAIL("Cannot find any appropriate root.");
DOMElement* node = static_cast<DOMElement*>(nodelist->item(0));
return node;
}
......
......@@ -44,7 +44,6 @@
* @author Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
*/
# include <xercesc/framework/MemBufFormatTarget.hpp>
# include <xercesc/dom/DOM.hpp>
# include <xercesc/util/XMLString.hpp>
# include <xercesc/util/PlatformUtils.hpp>
......@@ -102,10 +101,11 @@ namespace vcsn
template <class IStream>
void load(Auto& a, IStream& in);
private:
template <class OStream>
void create_document(const Auto& aut);
void print_document(OStream&);
xercesc::DOMElement* root_get() { return root_;}
private:
std::string create_state(hstate_t, const Auto&, xercesc::DOMElement*);
void create_transition(hedge_t, const Auto&,
xercesc::DOMElement*, map_t&);
......
......@@ -52,6 +52,13 @@ namespace vcsn
template <class Auto>
template <class OStream>
void xml_converter<Auto>::save(const Auto& aut, OStream& os)
{
create_document(aut);
tools::print_document(root_, os);
}
template <class Auto>
void xml_converter<Auto>::create_document(const Auto& aut)
{
typedef typename Auto::state_iterator state_iterator;
typedef typename Auto::edge_iterator edge_iterator;
......@@ -66,8 +73,8 @@ namespace vcsn
// Document creation.
impl_ = DOMImplementationRegistry::getDOMImplementation(STR2XML("LS"));
doc_ = impl_->createDocument(STR2XML
("http://vaucanson.lrde.epita.fr"),
STR2XML(root_name), 0);
("http://vaucanson.lrde.epita.fr"),
STR2XML(root_name), 0);
root_ = doc_->getDocumentElement();
// Create type tag.
......@@ -99,9 +106,6 @@ namespace vcsn
content->appendChild(node);
for_each_final_state(f, aut)
create_final(*f, aut, node, state2str);
// Print result to stream.
print_document(os);
}
......@@ -193,29 +197,7 @@ namespace vcsn
/// FIXME: Code this !
}
// Print XML document to stream.
template <class Auto>
template <class OStream>
void xml_converter<Auto>::print_document(OStream& os)
{
using namespace xercesc;
if (! impl_)
impl_ = DOMImplementationRegistry::getDOMImplementation(STR2XML("LS"));
DOMWriter* serializer = ((DOMImplementationLS*)impl_)->createDOMWriter();
// Set serializer properties.
if (serializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
true))
serializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
if (serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// Create buffer.
MemBufFormatTarget buf;
serializer->writeNode(&buf, *root_);
os << buf.getRawBuffer();
}
/**
* @brief Load automaton from stream.
*
......
......@@ -10,6 +10,8 @@ if XML_CHECK
noinst_PROGRAMS = \
static_boolean \
make_session \
display_session \
b \
z \
r \
......@@ -21,6 +23,8 @@ vaucanson.xsd:
ln -sf $(top_builddir)/doc/xml/vaucanson.xsd
static_boolean_SOURCES = static_boolean.cc
make_session_SOURCES = make_session.cc
display_session_SOURCES = display_session.cc
b_SOURCES = algorithms.cc
b_CPPFLAGS = $(AM_CPPFLAGS) \
......
// display_session.cc: this file is part of the Vaucanson project.
//
// Vaucanson, a generic library for finite state machines.
// Copyright (C) 2004 The Vaucanson Group.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// The Vaucanson Group represents the following contributors:
// * Jacques Sakarovitch <sakarovitch@enst.fr>
// * Sylvain Lombardy <lombardy@iafa.jussieu.fr>
// * Thomas Claveirole <thomas.claveirole@lrde.epita.fr>
// * Loic Fosse <loic.fosse@lrde.epita.fr>
// * Thanh-Hoc Nguyen <nguyen@enst.fr>
// * Raphael Poss <raphael.poss@lrde.epita.fr>
// * Yann Regis-Gianas <yann.regis-gianas@lrde.epita.fr>
// * Maxime Rey <maxime.rey@lrde.epita.fr>
// * Sarah O'Connor <sarah.o-connor@lrde.epita.fr>
// * Louis-Noel Pouchet <louis-noel.pouchet@lrde.epita.fr>
//
/*
* @file display_session.cc
*
* ./make_session <session file>
*
* Display all automata from a session.
*
* Works only with boolean automata.
*/
#include <sstream>
#include <fstream>
#include <vaucanson/boolean_automaton.hh>
#include <vaucanson/tools/usual_macros.hh>
#include <vaucanson/tools/dot_display.hh>
#include <vaucanson/xml/session.hh>
int
usage(int, char** argv)
{
std::cerr << "Usage: " << argv[0] << " <session file>" << std::endl;
return 1;
}
int
main(int argc, char** argv)
{
if (argc != 2)
return usage(argc, argv);
std::ifstream in (argv[1]);
if (in.fail()) </