~ubuntu-branches/ubuntu/wily/kbibtex/wily

« back to all changes in this revision

Viewing changes to src/xsltransform.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Hanke
  • Date: 2011-07-18 09:29:48 UTC
  • mfrom: (1.1.6) (2.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20110718092948-ksxjmg7kdfamolmg
Tags: 0.3-1
* First upstream release for KDE4 (Closes: #634255). A number of search
  engines are still missing, in comparison to the 0.2 series.
* Bumped Standards-Version to 3.9.2, no changes necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
*   Copyright (C) 2004-2009 by Thomas Fischer                             *
3
 
*   fischer@unix-ag.uni-kl.de                                             *
4
 
*                                                                         *
5
 
*   This program is free software; you can redistribute it and/or modify  *
6
 
*   it under the terms of the GNU General Public License as published by  *
7
 
*   the Free Software Foundation; either version 2 of the License, or     *
8
 
*   (at your option) any later version.                                   *
9
 
*                                                                         *
10
 
*   This program is distributed in the hope that it will be useful,       *
11
 
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
*   GNU General Public License for more details.                          *
14
 
*                                                                         *
15
 
*   You should have received a copy of the GNU General Public License     *
16
 
*   along with this program; if not, write to the                         *
17
 
*   Free Software Foundation, Inc.,                                       *
18
 
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
***************************************************************************/
20
 
#include <libxml/parser.h>
21
 
#include <libxml/tree.h>
22
 
#include <libxml/xmlstring.h>
23
 
#include <libxslt/transform.h>
24
 
#include <libxslt/xsltutils.h>
25
 
 
26
 
#include <qfile.h>
27
 
#include <qstring.h>
28
 
 
29
 
#include "xsltransform.h"
30
 
 
31
 
namespace BibTeX
32
 
{
33
 
 
34
 
    XSLTransform::XSLTransform( const QString& xsltFilename )
35
 
    {
36
 
        m_xlstStylesheet = xsltParseStylesheetFile(( const xmlChar* ) xsltFilename.latin1() );
37
 
        if ( m_xlstStylesheet == NULL )
38
 
            qDebug( "Could not load XSLT file '%s'.", xsltFilename.latin1() );
39
 
    }
40
 
 
41
 
    XSLTransform::~XSLTransform()
42
 
    {
43
 
        xsltFreeStylesheet( m_xlstStylesheet );
44
 
    }
45
 
 
46
 
    QString XSLTransform::transform( const QString& xmlText )
47
 
    {
48
 
        QString result = QString::null;
49
 
        QCString xmlCText = xmlText.utf8();
50
 
        xmlDocPtr document = xmlParseMemory( xmlCText, xmlCText.length() );
51
 
        if ( document )
52
 
        {
53
 
            if ( m_xlstStylesheet )
54
 
            {
55
 
                xmlDocPtr resultDocument = xsltApplyStylesheet( m_xlstStylesheet, document, NULL );
56
 
                if ( resultDocument )
57
 
                {
58
 
                    // Save the result into the QString
59
 
                    xmlChar * mem;
60
 
                    int size;
61
 
                    xmlDocDumpMemoryEnc( resultDocument, &mem, &size, "UTF-8" );
62
 
                    result = QString::fromUtf8( QCString(( char * )( mem ), size + 1 ) );
63
 
                    xmlFree( mem );
64
 
 
65
 
                    xmlFreeDoc( resultDocument );
66
 
                }
67
 
                else
68
 
                    qDebug( "Applying XSLT stylesheet to XML document failed" );
69
 
            }
70
 
            else
71
 
                qDebug( "XSLT stylesheet is not available or not valid" );
72
 
 
73
 
            xmlFreeDoc( document );
74
 
        }
75
 
        else
76
 
            qDebug( "XML document is not available or not valid" );
77
 
 
78
 
        return result;
79
 
    }
80
 
 
81
 
}