# Wie aktualisiert man den Java-Kode mit FOP1.0?



## sindylee2 (13. Dez 2011)

Hallo Experten,

Apache FOP ist nun zu 1.0 aktualisiert, dazu muss ich meinen Java-Kode entsprechend ändern. Ich benutze bis jetzt immer FOP0.20.5, mein Teil-XSLFORender sieht so aus:


```
Class fopLoggerClass = Class.forName("org.apache.avalon.framework.logger.Logger");
            Class fopConsoleLoggerClass = Class.forName("org.apache.avalon.framework.logger.ConsoleLogger");
            Constructor fopConsoleLoggerConstructor = fopConsoleLoggerClass.getConstructor(int.class);
            Field levelerror = fopConsoleLoggerClass.getField("LEVEL_ERROR");
            int levelerrorValue = levelerror.getInt(null);
            Object fopConsoleLoggerObject = fopConsoleLoggerConstructor.newInstance(levelerrorValue);
            
            Class fopDriverClass = Class.forName("org.apache.fop.apps.Driver");
            _fopDriverObject = fopDriverClass.newInstance();
            Method fopDriverSetLogger = fopDriverClass.getMethod("setLogger", fopLoggerClass);
            fopDriverSetLogger.invoke(_fopDriverObject, fopConsoleLoggerObject);
            
            Class fopMessageHandlerClass = Class.forName("org.apache.fop.messaging.MessageHandler");
            Method fopMessageHandlerSetScreenLogger = fopMessageHandlerClass.getMethod("setScreenLogger", fopLoggerClass);
            fopMessageHandlerSetScreenLogger.invoke(null, fopConsoleLoggerObject);
            
            if(_configurationUrl != null && _configurationUrl.trim().length() > 0)
            {
                //
                // Make a new anonymous instance of Options, since the
                // constructor will write the configurations settings as static values
                // into the configuration object of FOP.
                //
                
                FileUrlHandler fuh = new FileUrlHandler(_configurationUrl);
                Class fopOptionsClass = Class.forName("org.apache.fop.apps.Options");
                Constructor fopOptionsConstructor = fopOptionsClass.getConstructor(java.io.File.class);
                fopOptionsConstructor.newInstance(fuh.getFile()); // Make a new anonymous instance of Options !!
            }
            
            Field fopDriverRenderPDF = fopDriverClass.getField("RENDER_PDF");
            int fopDriverRenderPDFValue = fopDriverRenderPDF.getInt(null);
            Method fopDriverSetRenderer = fopDriverClass.getMethod("setRenderer", int.class);
            fopDriverSetRenderer.invoke(_fopDriverObject, fopDriverRenderPDFValue);
            
            _fopDriverSetInputSource = fopDriverClass.getMethod("setInputSource", org.xml.sax.InputSource.class);
            _fopDriverSetOutputStream = fopDriverClass.getMethod("setOutputStream", java.io.OutputStream.class);
            _fopDriverRun = fopDriverClass.getMethod("run");
            
            String version = "?";
            
            // Try to get the FOP version number from the Version class in the fop package.
            // NOTE that this is successfull only after instancing a driver object.
            
            try
            {
                Class fopVersionClass = Class.forName("org.apache.fop.apps.Version");
                Method fopVersionGetVersion = fopVersionClass.getMethod("getVersion");
                Object ret = fopVersionGetVersion.invoke(null);
                String vers = (String)ret;
                
                if(vers != null && vers.trim().length() != 0)
                {
                    version = vers;
                }
                
            } catch(Exception all){}
            
            _version = "FOP"+VERSION_PATTERN+version;
```

Die Frage ist, wie kann ich meine "XSLTFORenderer"-Klasse verändern?

Danke erst mal im Voraus!


----------



## Noctarius (13. Dez 2011)

Sorry aber das ist ja gruseliger Code. Wieso machst du das alles per Reflection? Oo


----------

