You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by logancillo <al...@gmail.com> on 2008/01/23 11:58:15 UTC

building a jni bridge between java and xalan-c

hi people, i need some help! i m trying to build in c++ a litle project with
xalan-c. 
The idea is to include the functionality of xalanC in my project java, for
it, i download the last sources of xalan and xerces and form a project in
netbeans 6.0.

main.c

#include <stdio.h>
#include <stdlib.h>
#include "WraperXalanC.h"

/*
 * 
 */
int main(int argc, char** argv) 
{
    
    WraperXalanC a;
    return (EXIT_SUCCESS);
}

WraperXalanC.h

#include <string.h>
#include <iostream>

#include <xalanc/Include/PlatformDefinitions.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>

#ifndef _WRAPERXALANC_H
#define	_WRAPERXALANC_H

using namespace std;


 class WraperXalanC
 {
    
    bool inicializado;

    public:
     WraperXalanC();
     
     ~WraperXalanC();
     
     void inicializar();  
     
     XalanCompiledStylesheet crearTranslet(char *cadena);
     
     XSLTResultTarget renderView(char *xml,XalanCompiledStylesheet
plantillaXsl);
 };

#endif	/* _WRAPERXALANC_H */ 

WraperXalanC.cc

#include "WraperXalanC.h"

public class WraperXalanC{
    
    public:
     WraperXalanC(){
         
         inicializado=false;
         if (!inicializado){
             inicializar();
             inicializado=true;
         }
     }
     
     ~WraperXalanC(){}
     
     void inicializar(){
             try
             {
                    XALAN_USING_XERCES(XMLPlatformUtils)
                    XALAN_USING_XALAN(XalanTransformer)
                    
                    XALAN_USING_STD(cerr)
                    XALAN_USING_STD(cout)
                    XALAN_USING_STD(endl)
                    XALAN_USING_STD(ostrstream)
                    XALAN_USING_XALAN(XalanCompiledStylesheet)
                    XALAN_USING_XALAN(XalanDOMString)
                    XALAN_USING_XALAN(XalanParsedSource)
                    XALAN_USING_XALAN(XalanTransformer)
                    XALAN_USING_XALAN(XSLTInputSource)
                    XALAN_USING_XALAN(XSLTResultTarget)
                    // Call the static initializer for Xerces.
                    XMLPlatformUtils::Initialize();
                    // Initialize Xalan.
                    XalanTransformer::initialize();
                    
                    
                    cout<<"XALANC inicializado.";
             }catch(...){
                cout<<"Error al inicializar XALANC";
             }
	
     }
     
     XalanCompiledStylesheet crearTranslet(char *cadena){
        
         //Tiene que ser local al metodo? no podria ser utilizado por todos?
         XalanTransformer theXalanTransformer;
         XalanCompiledStylesheet* compiledStylesheet = null;
         int error=
theXalanTransformer.compileStylesheet(cadena,compiledStylesheet);
         
         return compiledStylesheet;
     }
     
     XSLTResultTarget renderView(char *xml,XalanCompiledStylesheet
plantillaXsl){
         
         XalanTransformer theXalanTransformer;
         XSLTResultTarget theResultTarget;
         // hago la transformacion
         int theResult = theXalanTransformer.transform(xml, plantillaXsl,
theResultTarget);
         //habria que convertir el XSLTResultTarget en un chorro de bytes o
algo asi
         if (theResult!=0){
             //la conversion no ha tenido exito!
         }
         //habria que devolver el objeto resultante, o por lo menos la
informacion 
         //contenida en el, debe ser algo a bajo nivel
         theResultTarget.getCharacterStream();
         return theResultTarget;
     }
 };
};

the errors are:

WraperXalanC.h:32: error: ‘XalanCompiledStylesheet’ does not name a type
WraperXalanC.h:34: error: ‘XalanCompiledStylesheet’ no se puede declarar

Ubuntu linux with netbeans6, jdk6, xalan-c 2.7.0 and current xerces

alonso@alonso-laptop:/usr/local/include$ g++ --version
g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
Copyright (C) 2006 Free Software Foundation, Inc.
Esto es software libre; vea el código para las condiciones de copia.  NO hay
garantía; ni siquiera para MERCANTIBILIDAD o IDONEIDAD PARA UN PROPÓSITO EN
PARTICULAR


anybody could help me?

 
-- 
View this message in context: http://www.nabble.com/building-a-jni-bridge-between-java-and-xalan-c-tp15039293p15039293.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: building a jni bridge between java and xalan-c

Posted by logancillo <al...@gmail.com>.
hi again Dave!


thx for your tips! then , what i need is to build my jni bridge in c++, isnt
it?

i wrote a preliminar c++ app:

// 
// File:   es_yell_frontlite_servlets_ContenedorRecursivoWidgets.h
// Author: alonso
//
// Created on 30 de enero de 2008, 12:02
//

#ifndef _ES_YELL_FRONTLITE_SERVLETS_CONTENEDORRECURSIVOWIDGETS_H
#define	_ES_YELL_FRONTLITE_SERVLETS_CONTENEDORRECURSIVOWIDGETS_H
#include <jni.h>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <stdio.h>
#include <iostream.h>
#include <strstream>
XALAN_USING_STD(cout);
XALAN_USING_STD(endl);
XALAN_USING_STD(cerr);
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XERCES(XMLException)
XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(XalanCompiledStylesheet)
XALAN_USING_XALAN(XSLTInputSource)
XALAN_USING_STD(istrstream)
            
typedef XalanTransformer tXalanTransformer;

class XalanCpp_Engine{
    
    private :
    tXalanTransformer theXalanTransformer;
        
    /*
 * Class:     es_yell_frontlite_servlets_ContenedorRecursivoWidgets
 * Method:    generarTransletConXalanC
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;
 */
    public:
    JNIEXPORT jobject JNICALL
Java_es_yell_frontlite_servlets_ContenedorRecursivoWidgets_generarTransletConXalanC
    (JNIEnv *pEnv, jobject pObj, jstring rutaRelativaFicheroXSL, jstring
xsl);
};

#endif	/* _ES_YELL_FRONTLITE_SERVLETS_CONTENEDORRECURSIVOWIDGETS_H */

this is implementation file:

#include
"../XalanCpp_Engine/es_yell_frontlite_servlets_ContenedorRecursivoWidgets.h"

XalanCpp_Engine::JNIEXPORT jobject JNICALL 
Java_es_yell_frontlite_servlets_ContenedorRecursivoWidgets_generarTransletConXalanC
(JNIEnv *pEnv, jobject pObj, jstring rutaRelativaFicheroXSL, jstring xsl){

    cout<<"-->creando translet "<<rutaRelativaFicheroXSL<<endl;
    
    static XalanTransformer theXalanTransformer;
    const XalanCompiledStylesheet *compiledStylesheet = 0;
    int theResult =0;
    jboolean copy = JNI_FALSE; 
    const char *theStylesheet = env->GetStringUTFChars(xsl, &copy);
    if (theStylesheet == NULL) {
        return NULL; // Could be out of memory
    }
    cout<<"xsl: "<<theStylesheet<<endl;
    // Call the static initializer for Xerces.
    try
    {
        XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch)
    {
        cerr << "Error during Xerces initialization.  Error code was "
        << toCatch.getCode()
        << "."
        << endl;
        theResult = -1;
    }
    if ( theResult == 0)
    {
        // Initialize Xalan.
	XalanTransformer::initialize();
        // Create a XalanTransformer.
        
        istrstream str(theStylesheet, strlen(theStylesheet));        
        const XSLTInputSource msgToTransform(&str); 
        int theResult = theXalanTransformer
                    .compileStylesheet(msgToTransform,compiledStylesheet);
    }
    if(theResult != 0)
    {
        cerr << "CompileStylesheet Error: " <<
theXalanTransformer.getLastError()
	<< endl
	<< endl;
    }
    return (jobject) compiledStylesheet;
    //return NULL;
}

Unfortunately it doesnt compile, its giving me this error: 

es_yell_frontlite_servlets_ContenedorRecursivoWidgets.cc:3: error: ‘jobject’
en la clase ‘XalanCpp_Engine’ no nombra a un tipo

wich translated to english :

error: jobject in class XalanCpp_Engine does not name a type

what do i m doing wrong? Am I directed well? The purpose of all that is to
be able to invoke from my java program this logic, that is to say, that this
method returns to me a precompiled translet and to be able to save this
object in a hashMap structure of my java application.

sorry for my poor english.

pls, help me! 
-- 
View this message in context: http://www.nabble.com/building-a-jni-bridge-between-java-and-xalan-c-tp15039293p15181009.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: building a jni bridge between java and xalan-c

Posted by David Bertoni <db...@apache.org>.
logancillo wrote:
> hi Dave, i solved the problem with first compilation error, an include was
> absent!
> 
> now its giving me more errors, hope you can help me!
> 
> this is original error message, in spanish:
> 
> WraperXalanC.h:41: error: tipo abstracto de devolución inválido para la
> función miembro ‘XalanCompiledStylesheet WraperXalanC::crearTranslet(char*)’ 
> translation : invalid abstract return
XalanCompiledStylesheet is an abstract base class, and you cannot return it 
by value.  You will need to return a pointer or reference to a class that 
implements the class.

> /usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:39:
> nota:   porque las siguientes funciones virtual son puras en
> ‘XalanCompiledStylesheet’: translation: Because the following virtual
> functions are pure
> /usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:46:
> nota: 	virtual const xalanc_1_10::StylesheetRoot*
> xalanc_1_10::XalanCompiledStylesheet::getStylesheetRoot() const
> WraperXalanC.h:43: error: no se puede declarar que el parámetro
> ‘plantillaXsl’ sea del tipo abstracto ‘XalanCompiledStylesheet’
> /usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:39:
> nota:   ya que el tipo ‘XalanCompiledStylesheet’ tiene funciones virtuales
> puras
> make[1]: *** [build/Debug/GNU-Linux-x86/newmain.o] Error 1
> make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'
> make: *** [.build-impl] Error 2
> 
> Build failed. Exit value 2.
> 
> I need that method XalanCompiledStylesheet WraperXalanC::crearTranslet(char
> *cadena) returns the compiled stylesheet in order that the method could be
> invoked from my java program across jni, that is to say, I need a method
> that given a chain of characters returns me the precompiled object  in order
> that I could save it in a hashmap java object  and could be invoked at any
> time. I dont know if its possible
Please read the documentation of the APIs very carefully, as the code 
you've written has a number of problems.  For example, the documentation 
for XalanTransformer::compileStylesheet says:

/**
  * Creates a compiled stylesheet.  The input source can be
  * a file name, a stream or a root node.   The XalanTransformer
  * instance owns the XalanCompiledStylesheet instance and will
  * delete it when the XalanTransformer instance goes out of scope,
  * or you explicitly call destroyStylesheet().  You must not delete
  * the instance yourself.
  *
  * @param theStylesheetSource input source
  * @param theCompiledStylesheet a reference to a pointer to 
XalanCompileStylesheet.
  * @return 0 for success
*/

Since the lifetime of the XalanCompiledStylesheet is the lifetime of the 
XalanTransformer instance, and you're creating that instance on the stack 
in your function, everything created by the XalanTransformer will be 
destroyed when your function exits, so your current code cannot work.

If you're going to insist on using Xalan-C through a JNI wrapper, rather 
than using the Java version of Xalan, then you should consider using the C 
API in src/xalanc/XalanTransformer/XalanCAPI.h.  That will isolate you from 
some of the details of C++ APIs.

Dave

Re: building a jni bridge between java and xalan-c

Posted by logancillo <al...@gmail.com>.
hi Dave, i solved the problem with first compilation error, an include was
absent!

now its giving me more errors, hope you can help me!

this is original error message, in spanish:

WraperXalanC.h:41: error: tipo abstracto de devolución inválido para la
función miembro ‘XalanCompiledStylesheet WraperXalanC::crearTranslet(char*)’ 
translation : invalid abstract return
/usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:39:
nota:   porque las siguientes funciones virtual son puras en
‘XalanCompiledStylesheet’: translation: Because the following virtual
functions are pure
/usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:46:
nota: 	virtual const xalanc_1_10::StylesheetRoot*
xalanc_1_10::XalanCompiledStylesheet::getStylesheetRoot() const
WraperXalanC.h:43: error: no se puede declarar que el parámetro
‘plantillaXsl’ sea del tipo abstracto ‘XalanCompiledStylesheet’
/usr/local/include/xalanc/XalanTransformer/XalanCompiledStylesheet.hpp:39:
nota:   ya que el tipo ‘XalanCompiledStylesheet’ tiene funciones virtuales
puras
make[1]: *** [build/Debug/GNU-Linux-x86/newmain.o] Error 1
make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.

I need that method XalanCompiledStylesheet WraperXalanC::crearTranslet(char
*cadena) returns the compiled stylesheet in order that the method could be
invoked from my java program across jni, that is to say, I need a method
that given a chain of characters returns me the precompiled object  in order
that I could save it in a hashmap java object  and could be invoked at any
time. I dont know if its possible

I hope to have explained well, as you can see, i have some doubts! 
 






logancillo wrote:
> 
> hi again Dave, i solved last compilation error and now it gives me new
> errors:
> 
> 
> netbeans output console
> 
> Running "/usr/bin/make  -f Makefile CONF=Debug clean" in
> /home/alonso/curro/pruebaXalanC
> 
> /usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf
> make[1]: se ingresa al directorio `/home/alonso/curro/pruebaXalanC'
> rm -f -r build/Debug
> rm -f dist/Debug/GNU-Linux-x86/libpruebaXalanC.so
> make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'
> 
> Clean successful. Exit value 0.
> 
> Running "/usr/bin/make  -f Makefile CONF=Debug" in
> /home/alonso/curro/pruebaXalanC
> 
> /usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
> make[1]: se ingresa al directorio `/home/alonso/curro/pruebaXalanC'
> mkdir -p build/Debug/GNU-Linux-x86
> g++ -m32   -c -g -I/usr/include -I/usr/include/c++/4.1.2
> -I/usr/local/include -I/usr/include/c++/4.1.2/backward -fPIC  -o
> build/Debug/GNU-Linux-x86/newmain.o newmain.c
> En el fichero incluído de
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/strstream:51,
>                  de WraperXalanC.h:12,
>                  de newmain.c:10:
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2:
> aviso: #warning This file includes at least one deprecated or antiquated
> header. Please consider using one of the 32 headers found in section
> 17.4.1.2 of the C++ standard. Examples include substituting the <X> header
> for the <X.h> header for C++ includes, or <iostream> instead of the
> deprecated header <iostream.h>. To disable this warning use
> -Wno-deprecated.
> mkdir -p build/Debug/GNU-Linux-x86
> g++ -m32   -c -g -I/usr/include -I/usr/include/c++/4.1.2
> -I/usr/local/include -I/usr/include/c++/4.1.2/backward -fPIC  -o
> build/Debug/GNU-Linux-x86/WraperXalanC.o WraperXalanC.cc
> En el fichero incluído de
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/strstream:51,
>                  de WraperXalanC.h:12,
>                  de WraperXalanC.cc:1:
> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2:
> aviso: #warning This file includes at least one deprecated or antiquated
> header. Please consider using one of the 32 headers found in section
> 17.4.1.2 of the C++ standard. Examples include substituting the <X> header
> for the <X.h> header for C++ includes, or <iostream> instead of the
> deprecated header <iostream.h>. To disable this warning use
> -Wno-deprecated.
> WraperXalanC.cc: In member function ‘XalanCompiledStylesheet
> WraperXalanC::crearTranslet(char*)’:
> WraperXalanC.cc:42: error: el tipo de devolución ‘struct
> XalanCompiledStylesheet’ es un tipo de dato incompleto
> WraperXalanC.cc: In member function ‘XSLTResultTarget
> WraperXalanC::renderView(char*, XalanCompiledStylesheet)’:
> WraperXalanC.cc:56: error: ‘plantillaXsl’ has incomplete type
> /usr/local/include/xalanc/XalanTransformer/XalanTransformer.hpp:70: error:
> forward declaration of ‘const struct XalanCompiledStylesheet’
> make[1]: *** [build/Debug/GNU-Linux-x86/WraperXalanC.o] Error 1
> make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'
> make: *** [.build-impl] Error 2
> 
> Build failed. Exit value 2.
> 
> 
> 
> WraperXalan.cc
> 
> #include "WraperXalanC.h"
> 
>      WraperXalanC::WraperXalanC()
>      {
>          
>          inicializado=false;
>          if (!inicializado){
>              inicializar();
>              inicializado=true;
>          }
>      }
>      
>      WraperXalanC::~WraperXalanC(){}
>      
>      void WraperXalanC::inicializar()
>      {
>              try
>              {
>                     XALAN_USING_XERCES(XMLPlatformUtils)
>                     XALAN_USING_XALAN(XalanTransformer)
>                     
>                     XALAN_USING_STD(cerr)
>                     XALAN_USING_STD(cout)
>                     XALAN_USING_STD(endl)
>                     XALAN_USING_XALAN(XalanCompiledStylesheet)
>                     XALAN_USING_XALAN(XalanDOMString)
>                     XALAN_USING_XALAN(XalanParsedSource)
>                     XALAN_USING_XALAN(XalanTransformer)
>                     XALAN_USING_XALAN(XSLTInputSource)
>                     XALAN_USING_XALAN(XSLTResultTarget)
>                     // Call the static initializer for Xerces.
>                     XMLPlatformUtils::Initialize();
>                     // Initialize Xalan.
>                     XalanTransformer::initialize();
>                     cout<<"XALANC inicializado.";
>              }catch(...){
>                 cout<<"Error al inicializar XALANC";
>              }
> 	
>      }
>      
>      XalanCompiledStylesheet WraperXalanC::crearTranslet(char *cadena)
>      {
>         
>          //Tiene que ser local al metodo? no podria ser utilizado por
> todos?
>          //va a ser de hilo seguro?? si es local al metodo seguro que si
>          XalanTransformer theXalanTransformer;
>          const XalanCompiledStylesheet *compiledStylesheet = NULL;
>          istrstream str(cadena, strlen(cadena));        
>          const XSLTInputSource msgToTransform(&str); 
>          int theResult = theXalanTransformer.
>                            
> compileStylesheet(msgToTransform,compiledStylesheet);
>          return compiledStylesheet;
>      }
>      
>      XSLTResultTarget WraperXalanC::renderView(char
> *xml,XalanCompiledStylesheet plantillaXsl)
>      {
>          
>          XalanTransformer theXalanTransformer;
>          XSLTResultTarget theResultTarget;
>          // hago la transformacion
>          int theResult = theXalanTransformer.transform(xml, plantillaXsl,
> theResultTarget);
>          //habria que convertir el XSLTResultTarget en un chorro de bytes
> o algo asi
>          if (theResult!=0){
>              //la conversion no ha tenido exito!
>          }
>          //habria que devolver el objeto resultante, o por lo menos la
> informacion 
>          //contenida en el, debe ser algo a bajo nivel
>          theResultTarget.getCharacterStream();
>          return theResultTarget;
>      }
> 
> 
> WraperXalan.h
> /* 
>  * File:   WraperXalanC.h
>  * Author: alonso
>  *
>  * Created on 22 de enero de 2008, 15:47
>  */
> #ifndef _WRAPERXALANC_H
> #define	_WRAPERXALANC_H
> 
> #include <string>
> #include <iostream>
> #include <strstream>
> 
> #include <xalanc/Include/PlatformDefinitions.hpp>
> //#include <xercesc/util/PlatformUtils.hpp>
> #include <xalanc/XalanTransformer/XalanTransformer.hpp>
> //#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>
> #include <xalanc/XSLT/XSLTResultTarget.hpp>
> 
> using namespace std;
> 
> XALAN_USING_XALAN(XalanTransformer)
> XALAN_USING_XALAN(XalanCompiledStylesheet)
> XALAN_USING_XALAN(XSLTResultTarget)
> XALAN_USING_XALAN(XSLTInputSource)
>      
> typedef XalanCompiledStylesheet XalanCompiledStylesheet;
> typedef XSLTResultTarget XSLTResultTarget;
>  
> class WraperXalanC
> {
>     bool inicializado;
> 
>     public:
>      WraperXalanC();
>      
>      ~WraperXalanC();
>      
>      void inicializar();  
>      
>      XalanCompiledStylesheet crearTranslet(char *cadena);
>   //   void prueba(XSLTResultTarget& ert);
>      XSLTResultTarget renderView(char *xml, XalanCompiledStylesheet
> plantillaXsl);
>  };
> 
> #endif	/* _WRAPERXALANC_H */
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/building-a-jni-bridge-between-java-and-xalan-c-tp15039293p15062318.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: building a jni bridge between java and xalan-c

Posted by logancillo <al...@gmail.com>.
hi again Dave, i solved last compilation error and now it gives me new
errors:


netbeans output console

Running "/usr/bin/make  -f Makefile CONF=Debug clean" in
/home/alonso/curro/pruebaXalanC

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf
make[1]: se ingresa al directorio `/home/alonso/curro/pruebaXalanC'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/libpruebaXalanC.so
make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'

Clean successful. Exit value 0.

Running "/usr/bin/make  -f Makefile CONF=Debug" in
/home/alonso/curro/pruebaXalanC

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: se ingresa al directorio `/home/alonso/curro/pruebaXalanC'
mkdir -p build/Debug/GNU-Linux-x86
g++ -m32   -c -g -I/usr/include -I/usr/include/c++/4.1.2
-I/usr/local/include -I/usr/include/c++/4.1.2/backward -fPIC  -o
build/Debug/GNU-Linux-x86/newmain.o newmain.c
En el fichero incluído de
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/strstream:51,
                 de WraperXalanC.h:12,
                 de newmain.c:10:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2:
aviso: #warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X> header
for the <X.h> header for C++ includes, or <iostream> instead of the
deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
mkdir -p build/Debug/GNU-Linux-x86
g++ -m32   -c -g -I/usr/include -I/usr/include/c++/4.1.2
-I/usr/local/include -I/usr/include/c++/4.1.2/backward -fPIC  -o
build/Debug/GNU-Linux-x86/WraperXalanC.o WraperXalanC.cc
En el fichero incluído de
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/strstream:51,
                 de WraperXalanC.h:12,
                 de WraperXalanC.cc:1:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2:
aviso: #warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X> header
for the <X.h> header for C++ includes, or <iostream> instead of the
deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
WraperXalanC.cc: In member function ‘XalanCompiledStylesheet
WraperXalanC::crearTranslet(char*)’:
WraperXalanC.cc:42: error: el tipo de devolución ‘struct
XalanCompiledStylesheet’ es un tipo de dato incompleto
WraperXalanC.cc: In member function ‘XSLTResultTarget
WraperXalanC::renderView(char*, XalanCompiledStylesheet)’:
WraperXalanC.cc:56: error: ‘plantillaXsl’ has incomplete type
/usr/local/include/xalanc/XalanTransformer/XalanTransformer.hpp:70: error:
forward declaration of ‘const struct XalanCompiledStylesheet’
make[1]: *** [build/Debug/GNU-Linux-x86/WraperXalanC.o] Error 1
make[1]: se sale del directorio `/home/alonso/curro/pruebaXalanC'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.



WraperXalan.cc

#include "WraperXalanC.h"

     WraperXalanC::WraperXalanC()
     {
         
         inicializado=false;
         if (!inicializado){
             inicializar();
             inicializado=true;
         }
     }
     
     WraperXalanC::~WraperXalanC(){}
     
     void WraperXalanC::inicializar()
     {
             try
             {
                    XALAN_USING_XERCES(XMLPlatformUtils)
                    XALAN_USING_XALAN(XalanTransformer)
                    
                    XALAN_USING_STD(cerr)
                    XALAN_USING_STD(cout)
                    XALAN_USING_STD(endl)
                    XALAN_USING_XALAN(XalanCompiledStylesheet)
                    XALAN_USING_XALAN(XalanDOMString)
                    XALAN_USING_XALAN(XalanParsedSource)
                    XALAN_USING_XALAN(XalanTransformer)
                    XALAN_USING_XALAN(XSLTInputSource)
                    XALAN_USING_XALAN(XSLTResultTarget)
                    // Call the static initializer for Xerces.
                    XMLPlatformUtils::Initialize();
                    // Initialize Xalan.
                    XalanTransformer::initialize();
                    cout<<"XALANC inicializado.";
             }catch(...){
                cout<<"Error al inicializar XALANC";
             }
	
     }
     
     XalanCompiledStylesheet WraperXalanC::crearTranslet(char *cadena)
     {
        
         //Tiene que ser local al metodo? no podria ser utilizado por todos?
         //va a ser de hilo seguro?? si es local al metodo seguro que si
         XalanTransformer theXalanTransformer;
         const XalanCompiledStylesheet *compiledStylesheet = NULL;
         istrstream str(cadena, strlen(cadena));        
         const XSLTInputSource msgToTransform(&str); 
         int theResult = theXalanTransformer.
                           
compileStylesheet(msgToTransform,compiledStylesheet);
         return compiledStylesheet;
     }
     
     XSLTResultTarget WraperXalanC::renderView(char
*xml,XalanCompiledStylesheet plantillaXsl)
     {
         
         XalanTransformer theXalanTransformer;
         XSLTResultTarget theResultTarget;
         // hago la transformacion
         int theResult = theXalanTransformer.transform(xml, plantillaXsl,
theResultTarget);
         //habria que convertir el XSLTResultTarget en un chorro de bytes o
algo asi
         if (theResult!=0){
             //la conversion no ha tenido exito!
         }
         //habria que devolver el objeto resultante, o por lo menos la
informacion 
         //contenida en el, debe ser algo a bajo nivel
         theResultTarget.getCharacterStream();
         return theResultTarget;
     }


WraperXalan.h
/* 
 * File:   WraperXalanC.h
 * Author: alonso
 *
 * Created on 22 de enero de 2008, 15:47
 */
#ifndef _WRAPERXALANC_H
#define	_WRAPERXALANC_H

#include <string>
#include <iostream>
#include <strstream>

#include <xalanc/Include/PlatformDefinitions.hpp>
//#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
//#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>
#include <xalanc/XSLT/XSLTResultTarget.hpp>

using namespace std;

XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(XalanCompiledStylesheet)
XALAN_USING_XALAN(XSLTResultTarget)
XALAN_USING_XALAN(XSLTInputSource)
     
typedef XalanCompiledStylesheet XalanCompiledStylesheet;
typedef XSLTResultTarget XSLTResultTarget;
 
class WraperXalanC
{
    bool inicializado;

    public:
     WraperXalanC();
     
     ~WraperXalanC();
     
     void inicializar();  
     
     XalanCompiledStylesheet crearTranslet(char *cadena);
  //   void prueba(XSLTResultTarget& ert);
     XSLTResultTarget renderView(char *xml, XalanCompiledStylesheet
plantillaXsl);
 };

#endif	/* _WRAPERXALANC_H */


-- 
View this message in context: http://www.nabble.com/building-a-jni-bridge-between-java-and-xalan-c-tp15039293p15045580.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.


Re: building a jni bridge between java and xalan-c

Posted by David Bertoni <db...@apache.org>.
logancillo wrote:
> hi people, i need some help! i m trying to build in c++ a litle project with
> xalan-c. 
> The idea is to include the functionality of xalanC in my project java, for
> it, i download the last sources of xalan and xerces and form a project in
> netbeans 6.0.
Why don't you just use Xalan-J?

> 
> main.c
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include "WraperXalanC.h"
> 
> /*
>  * 
>  */
> int main(int argc, char** argv) 
> {
>     
>     WraperXalanC a;
>     return (EXIT_SUCCESS);
> }
...
> 
> the errors are:
> 
> WraperXalanC.h:32: error: ‘XalanCompiledStylesheet’ does not name a type
> WraperXalanC.h:34: error: ‘XalanCompiledStylesheet’ no se puede declarar
Since all of Xalan-C's symbols are in a namespace, you need a using 
declaration.  You can use this handy macro that's already been defined by 
Xalan-C:

XALAN_USING_XALAN(XalanCompiledStylesheet)

Dave