Skip to content
This repository
tree: a76b1c4915
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 91 lines (64 sloc) 2.401 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#ifndef _XSCRIPT_STYLESHEET_H_
#define _XSCRIPT_STYLESHEET_H_

#include <map>
#include <vector>

#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>

#include <xscript/xml.h>
#include <xscript/xml_helpers.h>

#include <libxslt/xsltInternals.h>

namespace xscript {

class Block;
class Param;
class Object;
class Context;
class StylesheetFactory;


class Stylesheet : public Xml {
public:
    virtual ~Stylesheet();
    virtual const std::string& name() const;

    inline xsltStylesheetPtr stylesheet() const {
        return stylesheet_.get();
    }

    inline const std::string& contentType() const {
        return content_type_;
    }

    inline const std::string& outputMethod() const {
        return output_method_;
    }

    inline const std::string& outputEncoding() const {
        return output_encoding_;
    }

    inline bool haveOutputInfo() const {
        return have_output_info_;
    }

    XmlDocHelper apply(Object *obj, Context *ctx, const XmlDocHelper &doc);

    static Context* getContext(xsltTransformContextPtr tctx);
    static Stylesheet* getStylesheet(xsltTransformContextPtr tctx);
    static const Block* getBlock(xsltTransformContextPtr tctx);
    static boost::shared_ptr<Stylesheet> create(const std::string &name);

    Block* block(xmlNodePtr node);

protected:
    Stylesheet(const std::string &name);

    virtual void parse();
    void parseStylesheet(xsltStylesheetPtr style);
    void parseNode(xmlNodePtr node);

    void detectOutputMethod(const XsltStylesheetHelper &sh);
    void detectOutputEncoding(const XsltStylesheetHelper &sh);
    void detectOutputInfo(const XsltStylesheetHelper &sh);

    void setupContentType(const char *type);
    std::string detectContentType(const XmlDocHelper &doc) const;

    void appendXsltParams(const std::vector<Param*>& params, const Context *ctx, xsltTransformContextPtr tctx);

    static void attachContextData(xsltTransformContextPtr tctx, Context *ctx, Stylesheet *stylesheet, const Block *block);
    static boost::shared_ptr<Stylesheet> createWithParse(const std::string &name);

private:
    friend class StylesheetFactory;

private:
    std::string name_;
    XsltStylesheetHelper stylesheet_;
    std::map<xmlNodePtr, Block*> blocks_;
    std::string content_type_, output_method_, output_encoding_;
    bool have_output_info_;
};

} // namespace xscript

#endif // _XSCRIPT_STYLESHEET_H_
Something went wrong with that request. Please try again.