/**
 * Copyright 2009  Michael Leupold <lemma@confuego.org>
 *
 * 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 (at your option) version 3, or any
 * later version accepted by the membership of KDE e.V. (or its
 * successor approved by the membership of KDE e.V.), which shall
 * act as a proxy defined in Section 6 of version 3 of the license.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef XSLTRANSFORMATION_H
#define XSLTRANSFORMATION_H

#include "parserprivate.h"

#include <KUrl>
#include <QString>

extern "C" {
    #include <libxml/tree.h>
    #include <libxslt/xsltInternals.h>
    #include <libxslt/security.h>
}

/**
 * This class encapsulates most of the code to xsl transform some xml.
 */
class XslTransformation
{
public:
    XslTransformation();
    ~XslTransformation();

    /**
     * Set the URL to load the stylesheet from.
     * @param url has to be an absolute url
     * @return @c true if loading succeeds, @c false else
     */
    bool loadStylesheet(const KUrl &url);

    /**
     * Set the input data for the transformation
     * @return @c true if the input is valid xml, @c false else
     */
    bool setInput(const KUrl &url, const QString &input);

    /**
     * If set to @c true no local file access is allowed.
     */
    void setOnlyRemote(bool remote);

    /**
     * Do the actual transformation
     * @return @c true if the transformation succeeds, @c false else
     */
    bool transform();

    /**
     * Get the transformation's output data
     */
    QString output() const;

    /**
     * Get the transformation's output mime-type
     */
    QString mimeType() const;

    /**
     * Check if the transformation resulted in an error
     */
    bool hasError() const;

    /**
     * Return the errors
     */
    QList<TransformationError> errors() const;

private:
    xsltStylesheetPtr m_xsltStylesheet;
    KUrl m_inputUrl;
    xmlDocPtr m_inputDoc; // input document
    QString m_output; // output data
    QString m_mimeType; // output mime-type
    QList<TransformationError> m_errors; // transformation errors
};

#endif
