From: <vac...@us...> - 2009-05-31 18:19:25
|
Revision: 144 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=144&view=rev Author: vaclavslavik Date: 2009-05-31 18:19:17 +0000 (Sun, 31 May 2009) Log Message: ----------- pretified xsltwrapp code formatting; no real changes Modified Paths: -------------- trunk/include/xsltwrapp/init.h trunk/include/xsltwrapp/stylesheet.h trunk/include/xsltwrapp/xsltwrapp.h trunk/src/libxslt/init.cxx trunk/src/libxslt/result.h trunk/src/libxslt/stylesheet.cxx Modified: trunk/include/xsltwrapp/init.h =================================================================== --- trunk/include/xsltwrapp/init.h 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/include/xsltwrapp/init.h 2009-05-31 18:19:17 UTC (rev 144) @@ -1,11 +1,11 @@ /* * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -30,10 +30,12 @@ * SUCH DAMAGE. */ -/** @file - * This file contains the definition of the xslt::init class. -**/ +/** + @file + This file contains the definition of the xslt::init class. + */ + #ifndef _xsltwrapp_init_h_ #define _xsltwrapp_init_h_ @@ -41,41 +43,41 @@ #include "xmlwrapp/init.h" /// XSLT library namespace -namespace xslt { +namespace xslt +{ /** - * The xslt::init class is used to configure the XSLT engine. - * - * If you want to use any of the xslt::init member functions, do so before - * you start any threads or use any other part of xsltwrapp. The member - * functions may alter global and/or static variables. In other words, this - * class is not thread safe. - * - * @note In xmlwrapp versions prior to 0.6.0, this class was used to initialize - * the library and exactly one instance had to be created before first - * use. This is no longer true: user code doesn't have to create any - * instances, but it @em can create as many instances as it wants. -**/ -class init : public xml::init { + The xslt::init class is used to configure the XSLT engine. + + If you want to use any of the xslt::init member functions, do so before + you start any threads or use any other part of xsltwrapp. The member + functions may alter global and/or static variables. In other words, this + class is not thread safe. + + @note In xmlwrapp versions prior to 0.6.0, this class was used to initialize + the library and exactly one instance had to be created before first + use. This is no longer true: user code doesn't have to create any + instances, but it @em can create as many instances as it wants. + */ +class init : public xml::init +{ public: - init (void); - ~init (void); + init(); + ~init(); - //#################################################################### - /** - * This function controls whether or not the XSLT engine will process - * XInclusions by default while parsing the stylesheet. The default is - * true. - * - * @param flag True to enable XInclusing processing; False otherwise. - * @author Peter Jones - **/ - //#################################################################### - static void process_xincludes (bool flag); + /** + This function controls whether or not the XSLT engine will process + XInclusions by default while parsing the stylesheet. The default is + true. + @param flag True to enable XInclusing processing; False otherwise. + @author Peter Jones + */ + static void process_xincludes(bool flag); + private: - init (const init&); - init& operator= (const init&); + init(const init&); + init& operator=(const init&); void init_library(); void shutdown_library(); @@ -83,11 +85,14 @@ static int ms_counter; }; // end xslt::init class + // use a "nifty counter" to ensure that any source file that uses xsltwrapp // will initialize the library prior to its first use -namespace { - xslt::init g_xsltwrapp_initializer; +namespace +{ +xslt::init g_xsltwrapp_initializer; } } // end xslt namespace -#endif + +#endif // _xsltwrapp_init_h_ Modified: trunk/include/xsltwrapp/stylesheet.h =================================================================== --- trunk/include/xsltwrapp/stylesheet.h 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/include/xsltwrapp/stylesheet.h 2009-05-31 18:19:17 UTC (rev 144) @@ -1,11 +1,11 @@ /* * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -30,10 +30,12 @@ * SUCH DAMAGE. */ -/** @file - * This file contains the definition of the xslt::stylesheet class. -**/ +/** + @file + This file contains the definition of the xslt::stylesheet class. + */ + #ifndef _xsltwrapp_stylesheet_h_ #define _xsltwrapp_stylesheet_h_ @@ -45,139 +47,127 @@ #include <map> #include <string> -namespace xslt { +namespace xslt +{ /** - * The xslt::stylesheet class is used to hold information about an XSLT - * stylesheet. You can use it to load in a stylesheet and then use that - * stylesheet to transform an XML document to something else. -**/ -class stylesheet { + The xslt::stylesheet class is used to hold information about an XSLT + stylesheet. You can use it to load in a stylesheet and then use that + stylesheet to transform an XML document to something else. + */ +class stylesheet +{ public: /// Type for passing parameters to the stylesheet typedef std::map<std::string, std::string> param_type; - //#################################################################### - /** - * Create a new xslt::stylesheet object and load and parse the - * stylesheet in the given filename. - * - * @param filename The name of the file that contains the stylesheet. - * @author Peter Jones - **/ - //#################################################################### - explicit stylesheet (const char *filename); + /** + Create a new xslt::stylesheet object and load and parse the + stylesheet in the given filename. - //#################################################################### - /** - * Create a new xslt::stylesheet object from an xml::document object - * that contains the parsed stylesheet. The given xml::document is - * passed by value. This is needed because the stylesheet will own the - * document and free it. - * - * @param doc The parsed stylesheet. - * @author Peter Jones - **/ - //#################################################################### - explicit stylesheet (xml::document doc); + @param filename The name of the file that contains the stylesheet. + @author Peter Jones + */ + explicit stylesheet(const char *filename); - //#################################################################### - /** - * Clean up after an xslt::stylesheet. - * - * @author Peter Jones - **/ - //#################################################################### - ~stylesheet (void); + /** + Create a new xslt::stylesheet object from an xml::document object + that contains the parsed stylesheet. The given xml::document is + passed by value. This is needed because the stylesheet will own the + document and free it. - //#################################################################### - /** - * Apply this stylesheet to the given XML document. The result document - * is placed in the second document parameter. - * - * @param doc The XML document to transform. - * @param result The result tree after applying this stylesheet. - * @return True if the transformation was successful and the results placed in result. - * @return False if there was an error, result is not modified. - * @author Peter Jones - **/ - //#################################################################### - bool apply (const xml::document &doc, xml::document &result); + @param doc The parsed stylesheet. + @author Peter Jones + */ + explicit stylesheet(xml::document doc); - //#################################################################### - /** - * Apply this stylesheet to the given XML document. The result document - * is placed in the second document parameter. + /** + Clean up after an xslt::stylesheet. - * @param doc The XML document to transform. - * @param result The result tree after applying this stylesheet. - * @param with_params Override xsl:param elements using the given key/value map - * @return True if the transformation was successful and the results placed in result. - * @return False if there was an error, result is not modified. - * @author Peter Jones - **/ - //#################################################################### - bool apply (const xml::document &doc, xml::document &result, const param_type &with_params); + @author Peter Jones + */ + ~stylesheet(); - //#################################################################### - /** - * Apply this stylesheet to the given XML document. The results document - * is returned. If there is an error during transformation, this - * function will throw a std::runtime_error exception. - * - * Each time you call this member function, the xml::document object - * that was returned from the last call becomes invalid. That is, of - * course, unless you copied it first. - * - * @param doc The XML document to transform. - * @return A reference to the result tree. - * @author Peter Jones - **/ - //#################################################################### - xml::document& apply (const xml::document &doc); + /** + Apply this stylesheet to the given XML document. The result document + is placed in the second document parameter. - //#################################################################### - /** - * Apply this stylesheet to the given XML document. The results document - * is returned. If there is an error during transformation, this - * function will throw a std::runtime_error exception. - * - * Each time you call this member function, the xml::document object - * that was returned from the last call becomes invalid. That is, of - * course, unless you copied it first. - * - * @param doc The XML document to transform. - * @param with_params Override xsl:param elements using the given key/value map - * @return A reference to the result tree. - * @author Peter Jones - **/ - //#################################################################### - xml::document& apply (const xml::document &doc, const param_type &with_params); + @param doc The XML document to transform. + @param result The result tree after applying this stylesheet. + @return True if the transformation was successful and the results placed in result. + @return False if there was an error, result is not modified. + @author Peter Jones + */ + bool apply(const xml::document& doc, xml::document& result); - //#################################################################### - /** - * If you used one of the xslt::stylesheet::apply member functions that - * return a bool, you can use this function to get the text message for - * the transformation error. - * - * If you are using one of the apply member functions that throws - * exceptions, this function should not be used. The text message for - * the transformation error will be given to the std::runtime_error - * constructor. - * - * @return The last error message. - * @author Peter Jones - **/ - //#################################################################### - const std::string& get_error_message (void) const; + /** + Apply this stylesheet to the given XML document. The result document + is placed in the second document parameter. + @param doc The XML document to transform. + @param result The result tree after applying this stylesheet. + @param with_params Override xsl:param elements using the given key/value map + @return True if the transformation was successful and the results placed in result. + @return False if there was an error, result is not modified. + @author Peter Jones + */ + bool apply(const xml::document& doc, xml::document& result, const param_type& with_params); + + /** + Apply this stylesheet to the given XML document. The results document + is returned. If there is an error during transformation, this + function will throw a std::runtime_error exception. + + Each time you call this member function, the xml::document object + that was returned from the last call becomes invalid. That is, of + course, unless you copied it first. + + @param doc The XML document to transform. + @return A reference to the result tree. + @author Peter Jones + */ + xml::document& apply(const xml::document& doc); + + /** + Apply this stylesheet to the given XML document. The results document + is returned. If there is an error during transformation, this + function will throw a std::runtime_error exception. + + Each time you call this member function, the xml::document object + that was returned from the last call becomes invalid. That is, of + course, unless you copied it first. + + @param doc The XML document to transform. + @param with_params Override xsl:param elements using the given key/value map + @return A reference to the result tree. + @author Peter Jones + */ + xml::document& apply(const xml::document& doc, const param_type& with_params); + + /** + If you used one of the xslt::stylesheet::apply member functions that + return a bool, you can use this function to get the text message for + the transformation error. + + If you are using one of the apply member functions that throws + exceptions, this function should not be used. The text message for + the transformation error will be given to the std::runtime_error + constructor. + + @return The last error message. + @author Peter Jones + */ + const std::string& get_error_message() const; + private: - struct pimpl; pimpl *pimpl_; + struct pimpl; + pimpl *pimpl_; // an xslt::stylesheet cannot yet be copied or assigned to. - stylesheet (const stylesheet&); - stylesheet& operator= (const stylesheet&); + stylesheet(const stylesheet&); + stylesheet& operator=(const stylesheet&); }; // end xslt::stylesheet class - + } // end xslt namespace -#endif + +#endif // _xsltwrapp_stylesheet_h_ Modified: trunk/include/xsltwrapp/xsltwrapp.h =================================================================== --- trunk/include/xsltwrapp/xsltwrapp.h 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/include/xsltwrapp/xsltwrapp.h 2009-05-31 18:19:17 UTC (rev 144) @@ -5,7 +5,7 @@ * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A Modified: trunk/src/libxslt/init.cxx =================================================================== --- trunk/src/libxslt/init.cxx 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/src/libxslt/init.cxx 2009-05-31 18:19:17 UTC (rev 144) @@ -1,11 +1,11 @@ /* * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -30,38 +30,50 @@ * SUCH DAMAGE. */ -/** @file - * This file contains the implementation of the xslt::init class. -**/ +/** + @file -// defintion include + This file contains the implementation of the xslt::init class. + */ + #include "xsltwrapp/init.h" -// libxslt includes #include <libxslt/xslt.h> #include <libxslt/xsltInternals.h> #include <libxslt/transform.h> #include <libxslt/xsltutils.h> #include <libexslt/exslt.h> -//#################################################################### -namespace { - extern "C" void xslt_error (void *, const char*, ...); +namespace +{ + +extern "C" void xslt_error(void *, const char*, ...) +{ + // don't do anything } -//#################################################################### + +} // anonymous namespace + + int xslt::init::ms_counter = 0; -//#################################################################### -xslt::init::init (void) { + + +xslt::init::init() +{ if ( ms_counter++ == 0 ) init_library(); } -//#################################################################### -xslt::init::~init (void) { + + +xslt::init::~init(void) +{ if ( --ms_counter == 0 ) shutdown_library(); } -//#################################################################### -void xslt::init::init_library() { + + +void xslt::init::init_library() +{ xsltInit(); // set some defautls @@ -74,17 +86,15 @@ // load EXSLT exsltRegisterAll(); } -//#################################################################### -void xslt::init::shutdown_library() { + + +void xslt::init::shutdown_library() +{ xsltCleanupGlobals(); } -//#################################################################### -void xslt::init::process_xincludes (bool flag) { + + +void xslt::init::process_xincludes(bool flag) +{ xsltSetXIncludeDefault(flag ? 1 : 0); } -//#################################################################### -namespace { - extern "C" void xslt_error (void*, const char*, ...) - { /* don't do anything */ } -} -//#################################################################### Modified: trunk/src/libxslt/result.h =================================================================== --- trunk/src/libxslt/result.h 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/src/libxslt/result.h 2009-05-31 18:19:17 UTC (rev 144) @@ -1,11 +1,11 @@ /* * Copyright (C) 2008 Vadim Zeitlin (va...@ze...) * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -30,10 +30,12 @@ * SUCH DAMAGE. */ -/** @file - * This file contains the declaration of the xslt::result class. -**/ +/** + @file + This file contains the declaration of the xslt::result class. + */ + #ifndef _xsltwrapp_result_h_ #define _xsltwrapp_result_h_ @@ -43,57 +45,55 @@ // forward declarations typedef struct _xmlDoc *xmlDocPtr; -namespace xslt { +namespace xslt +{ -namespace impl { +namespace impl +{ /** - * The xslt::result class is used as a callback by xml::document to allow - * special treatment of XML documents which were created by XSLT. - * - * This class is only meant to be used internally by the library and is - * necessary to avoid the dependency of xml::document, which is part of - * libxmlwrapp, on libxslt which should be only a dependency of libxsltwrapp - * as this precludes calling the XSLT functions which must be used with such - * "result" documents directly from xml::document code. - * - * @author Vadim Zeitlin - * @internal -**/ -class result { + @internal + + The xslt::result class is used as a callback by xml::document to allow + special treatment of XML documents which were created by XSLT. + + This class is only meant to be used internally by the library and is + necessary to avoid the dependency of xml::document, which is part of + libxmlwrapp, on libxslt which should be only a dependency of libxsltwrapp + as this precludes calling the XSLT functions which must be used with such + "result" documents directly from xml::document code. + + @author Vadim Zeitlin + */ +class result +{ public: - //#################################################################### /** - * Save the contents of the given XML document in the provided string. - * - * @param s The string to place the XML text data. - **/ - //#################################################################### + Save the contents of the given XML document in the provided string. + + @param s The string to place the XML text data. + */ virtual void save_to_string(std::string &s) const = 0; - //#################################################################### - /** - * Save the contents of the given XML document in the provided filename. - * - * @param filename The name of the file to place the XML text data into. - * @param compression_level 0 is no compression, 1-9 allowed, where 1 is for better speed, and 9 is for smaller size - * @return True if the data was saved successfully. - * @return False otherwise. - **/ - //#################################################################### - virtual bool save_to_file (const char *filename, - int compression_level) const = 0; + /** + Save the contents of the given XML document in the provided filename. - //#################################################################### - /** - * Trivial but virtual base class destructor. - **/ - //#################################################################### - virtual ~result (void) { } + @param filename + The name of the file to place the XML text data into. + @param compression_level + 0 is no compression, 1-9 allowed, where 1 is for better speed, + and 9 is for smaller size + @return True if the data was saved successfully, false otherwise. + */ + virtual bool save_to_file(const char *filename, + int compression_level) const = 0; + + /// Trivial but virtual base class destructor. + virtual ~result() {} }; } // end impl namespace } // end xslt namespace -#endif +#endif // _xsltwrapp_result_h_ Modified: trunk/src/libxslt/stylesheet.cxx =================================================================== --- trunk/src/libxslt/stylesheet.cxx 2009-05-30 18:55:52 UTC (rev 143) +++ trunk/src/libxslt/stylesheet.cxx 2009-05-31 18:19:17 UTC (rev 144) @@ -1,11 +1,11 @@ /* * Copyright (C) 2001-2003 Peter J Jones (pj...@pm...) * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -15,7 +15,7 @@ * 3. Neither the name of the Author nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A @@ -30,10 +30,12 @@ * SUCH DAMAGE. */ -/** @file - * This file contains the implementation of the xslt::stylesheet class. -**/ +/** + @file + This file contains the implementation of the xslt::stylesheet class. + */ + // xmlwrapp includes #include "xsltwrapp/stylesheet.h" #include "xmlwrapp/document.h" @@ -55,33 +57,35 @@ #include <vector> #include <map> -namespace { +namespace +{ // implementation of xslt::result using xslt::stylesheet: we pass this object // to xml::document for the documents obtained via XSLT so that some operations // (currently only saving) could be done differently for them -class result_impl : public xslt::impl::result { +class result_impl : public xslt::impl::result +{ public: // We don't own the pointers given to us, their lifetime must be greater // than the lifetime of this object. - result_impl(xmlDocPtr doc, xsltStylesheetPtr ss) : doc_(doc), ss_(ss) { } + result_impl(xmlDocPtr doc, xsltStylesheetPtr ss) : doc_(doc), ss_(ss) {} virtual void save_to_string(std::string &s) const { - xmlChar *xml_string; - int xml_string_length; + xmlChar *xml_string; + int xml_string_length; - if (xsltSaveResultToString(&xml_string, &xml_string_length, doc_, ss_) >= 0) - { - xml::impl::xmlchar_helper helper(xml_string); - if (xml_string_length) s.assign(helper.get(), xml_string_length); - } + if (xsltSaveResultToString(&xml_string, &xml_string_length, doc_, ss_) >= 0) + { + xml::impl::xmlchar_helper helper(xml_string); + if (xml_string_length) s.assign(helper.get(), xml_string_length); + } } virtual bool - save_to_file (const char *filename, int /* compression_level */) const + save_to_file(const char *filename, int /* compression_level */) const { - return xsltSaveResultToFilename(filename, doc_, ss_, 0) >= 0; + return xsltSaveResultToFilename(filename, doc_, ss_, 0) >= 0; } private: @@ -89,145 +93,169 @@ xsltStylesheetPtr ss_; }; + +void make_vector_param(std::vector<const char*> &v, + const xslt::stylesheet::param_type &p) +{ + v.reserve(p.size()); + + xslt::stylesheet::param_type::const_iterator i = p.begin(), end = p.end(); + for (; i != end; ++i) + { + v.push_back(i->first.c_str()); + v.push_back(i->second.c_str()); + } + + v.push_back(static_cast<const char*>(0)); +} + + +xmlDocPtr apply_stylesheet(xsltStylesheetPtr s, xmlDocPtr d, + const xslt::stylesheet::param_type *p = NULL) +{ + /* + * TODO TODO TODO TODO + * + * use a transform context to capture error messages + * + * TODO TODO TODO TODO + */ + std::vector<const char*> v; + if (p) + make_vector_param(v, *p); + return xsltApplyStylesheet(s, d, p ? &v[0] : 0); +} + } // end of anonymous namespace -//#################################################################### -namespace { - void make_vector_param (std::vector<const char*> &v, const xslt::stylesheet::param_type &p); - xmlDocPtr apply_stylesheet (xsltStylesheetPtr s, xmlDocPtr d, const xslt::stylesheet::param_type *p=0); -} -//#################################################################### -struct xslt::stylesheet::pimpl { + +struct xslt::stylesheet::pimpl +{ pimpl (void) : ss_(0) { } xsltStylesheetPtr ss_; xml::document doc_; std::string error_; }; -//#################################################################### -xslt::stylesheet::stylesheet (const char *filename) { + + +xslt::stylesheet::stylesheet(const char *filename) +{ std::auto_ptr<pimpl> ap(pimpl_ = new pimpl); xml::tree_parser parser(filename); xmlDocPtr xmldoc = static_cast<xmlDocPtr>(parser.get_document().get_doc_data()); - if ( (pimpl_->ss_ = xsltParseStylesheetDoc(xmldoc)) == 0) { - // TODO error_ can't get set yet. Need changes from libxslt first - if (pimpl_->error_.empty()) pimpl_->error_ = "unknown XSLT parser error"; - throw std::runtime_error(pimpl_->error_); + if ( (pimpl_->ss_ = xsltParseStylesheetDoc(xmldoc)) == 0) + { + // TODO error_ can't get set yet. Need changes from libxslt first + if (pimpl_->error_.empty()) + pimpl_->error_ = "unknown XSLT parser error"; + throw std::runtime_error(pimpl_->error_); } - /* - * if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is - * now owned by the stylesheet and will be cleaned up in our destructor. - */ + // if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is + // now owned by the stylesheet and will be cleaned up in our destructor. parser.get_document().release_doc_data(); ap.release(); } -//#################################################################### -xslt::stylesheet::stylesheet (xml::document doc) { + + +xslt::stylesheet::stylesheet(xml::document doc) +{ xmlDocPtr xmldoc = static_cast<xmlDocPtr>(doc.get_doc_data()); std::auto_ptr<pimpl> ap(pimpl_ = new pimpl); - if ( (pimpl_->ss_ = xsltParseStylesheetDoc(xmldoc)) == 0) { - // TODO error_ can't get set yet. Need changes from libxslt first - if (pimpl_->error_.empty()) pimpl_->error_ = "unknown XSLT parser error"; - throw std::runtime_error(pimpl_->error_); + if ( (pimpl_->ss_ = xsltParseStylesheetDoc(xmldoc)) == 0) + { + // TODO error_ can't get set yet. Need changes from libxslt first + if (pimpl_->error_.empty()) + pimpl_->error_ = "unknown XSLT parser error"; + throw std::runtime_error(pimpl_->error_); } - /* - * if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is - * now owned by the stylesheet and will be cleaned up in our destructor. - */ + // if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is + // now owned by the stylesheet and will be cleaned up in our destructor. doc.release_doc_data(); ap.release(); } -//#################################################################### -xslt::stylesheet::~stylesheet (void) { - if (pimpl_->ss_) xsltFreeStylesheet(pimpl_->ss_); + + +xslt::stylesheet::~stylesheet() +{ + if (pimpl_->ss_) + xsltFreeStylesheet(pimpl_->ss_); delete pimpl_; } -//#################################################################### -bool xslt::stylesheet::apply (const xml::document &doc, xml::document &result) { + + +bool xslt::stylesheet::apply(const xml::document &doc, xml::document &result) +{ xmlDocPtr input = static_cast<xmlDocPtr>(doc.get_doc_data_read_only()); - xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input); + xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input); - if (xmldoc) { - result.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); - return true; + if (xmldoc) + { + result.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); + return true; } return false; } -//#################################################################### -bool xslt::stylesheet::apply (const xml::document &doc, xml::document &result, const param_type &with_params) { + + +bool xslt::stylesheet::apply(const xml::document &doc, xml::document &result, + const param_type &with_params) +{ xmlDocPtr input = static_cast<xmlDocPtr>(doc.get_doc_data_read_only()); - xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input, &with_params); + xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input, &with_params); - if (xmldoc) { - result.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); - return true; + if (xmldoc) + { + result.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); + return true; } return false; } -//#################################################################### -xml::document& xslt::stylesheet::apply (const xml::document &doc) { + + +xml::document& xslt::stylesheet::apply(const xml::document &doc) +{ xmlDocPtr input = static_cast<xmlDocPtr>(doc.get_doc_data_read_only()); xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input); - if (xmldoc == 0) { - if (pimpl_->error_.empty()) pimpl_->error_ = "unknown XSLT transformation error"; - throw std::runtime_error(pimpl_->error_); + if (xmldoc == 0) + { + if (pimpl_->error_.empty()) + pimpl_->error_ = "unknown XSLT transformation error"; + throw std::runtime_error(pimpl_->error_); } pimpl_->doc_.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); return pimpl_->doc_; } -//#################################################################### -xml::document& xslt::stylesheet::apply (const xml::document &doc, const param_type &with_params) { + + +xml::document& xslt::stylesheet::apply(const xml::document &doc, + const param_type &with_params) +{ xmlDocPtr input = static_cast<xmlDocPtr>(doc.get_doc_data_read_only()); xmlDocPtr xmldoc = apply_stylesheet(pimpl_->ss_, input, &with_params); - if (xmldoc == 0) { - if (pimpl_->error_.empty()) pimpl_->error_ = "unknown XSLT transformation error"; - throw std::runtime_error(pimpl_->error_); + if (xmldoc == 0) + { + if (pimpl_->error_.empty()) + pimpl_->error_ = "unknown XSLT transformation error"; + throw std::runtime_error(pimpl_->error_); } pimpl_->doc_.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_)); return pimpl_->doc_; } -//#################################################################### -const std::string& xslt::stylesheet::get_error_message (void) const { - return pimpl_->error_; -} -//#################################################################### -namespace { - //#################################################################### - void make_vector_param (std::vector<const char*> &v, const xslt::stylesheet::param_type &p) { - v.reserve(p.size()); - xslt::stylesheet::param_type::const_iterator i=p.begin(), end=p.end(); - for (; i!=end; ++i) { - v.push_back(i->first.c_str()); - v.push_back(i->second.c_str()); - } - v.push_back(static_cast<const char*>(0)); - } - //#################################################################### - xmlDocPtr apply_stylesheet (xsltStylesheetPtr s, xmlDocPtr d, const xslt::stylesheet::param_type *p) { - /* - * TODO TODO TODO TODO - * - * use a transform context to capture error messages - * - * TODO TODO TODO TODO - */ - std::vector<const char*> v; - if (p) make_vector_param(v, *p); - return xsltApplyStylesheet(s, d, p ? &v[0] : 0); - } - //#################################################################### +const std::string& xslt::stylesheet::get_error_message() const +{ + return pimpl_->error_; } -//#################################################################### This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |