diff options
Diffstat (limited to 'src/org/openoffice/tools/SkeletonMaker.java')
-rw-r--r-- | src/org/openoffice/tools/SkeletonMaker.java | 109 |
1 files changed, 61 insertions, 48 deletions
diff --git a/src/org/openoffice/tools/SkeletonMaker.java b/src/org/openoffice/tools/SkeletonMaker.java index ad319b6..febb932 100644 --- a/src/org/openoffice/tools/SkeletonMaker.java +++ b/src/org/openoffice/tools/SkeletonMaker.java @@ -1,67 +1,55 @@ package org.openoffice.tools; -import java.util.ArrayList; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; +import org.openoffice.tools.language.Language; +import org.openoffice.tools.language.LanguageHelper; import org.openoffice.tools.options.Command; import org.openoffice.tools.options.HelpFormatter; import org.openoffice.tools.options.SubcommandLine; import org.openoffice.tools.types.TypeManager; -import com.sun.star.reflection.XInterfaceAttributeTypeDescription2; -import com.sun.star.reflection.XPropertyTypeDescription; +import freemarker.template.Template; public class SkeletonMaker { - private static final int MAX_INTERFACES = 12; - + // The file template names + public static final String COMPONENT = "component.tpl"; + public static void generateComponent( CommandLine pArgs ) { TypeManager manager = null; + PrintWriter writer = null; try { - // Get the language first - String lang = getLanguage( pArgs ); - // Load the types manager String inifile = pArgs.getOptionValue( "unoinstall" ); manager = new TypeManager( inifile ); manager.initRegistries( pArgs.getOptionValues( "l" ) ); - // Check the types - String[] types = pArgs.getOptionValues( "t" ); - ArrayList<String> interfaces = new ArrayList<String>(); - ArrayList<String> services = new ArrayList<String>(); - ArrayList<XPropertyTypeDescription> members = new ArrayList<XPropertyTypeDescription>(); - - // Get the service, interfaces and members from the types - for (String type : types) { - manager.checkType( type, services, interfaces, members ); - } - - // TODO For ProtocolHandler case, check the frame.ProtocolHandler and frame.XDispatch types + // Extract all the informations from the types + TypeChecker checker = new TypeChecker( manager ); + checker.check( pArgs ); - // Check for the property helper - ArrayList<XInterfaceAttributeTypeDescription2> attributes = new ArrayList<XInterfaceAttributeTypeDescription2>(); - ArrayList<String> propinterfaces = new ArrayList<String>(); - String propertyHelper = manager.checkPropertyHelper( pArgs, services, interfaces, attributes, propinterfaces ); + // Print everything + writer = getWriter( pArgs ); - // Check the default interfaces - checkDefaultInterfaces( interfaces, services, propertyHelper ); - - if ( interfaces.size() > MAX_INTERFACES ) { - throw new DumpException( "The skeletonmaker supports components with 12 interfaces only (limitation of the UNO implementation helpers)!" ); - } - - boolean supportXComp = manager.checkXComponentSupport( interfaces ); - - // TODO Print everything + Language lang = getLanguage( pArgs ); + Template tpl = lang.getTemplate( COMPONENT ); + tpl.process( checker.getTemplateModel( ), writer ); + writer.flush(); } catch ( Exception e ) { e.printStackTrace(); } finally { + // Close the file stream if possible + try { writer.close(); } catch ( Exception e ) { } + // Close the running OOo if ( manager != null ) { manager.dispose(); @@ -69,22 +57,47 @@ public class SkeletonMaker { } } - private static void checkDefaultInterfaces(ArrayList<String> pInterfaces, - ArrayList<String> pServices, String pPropertyHelper) { + private static PrintWriter getWriter( CommandLine pArgs ) throws IOException { + PrintWriter writer = new PrintWriter( System.out ); + String outPath = pArgs.getOptionValue( "o" ); + if ( outPath != null && !outPath.equals( "stdout" ) ) { + String implName = pArgs.getOptionValue( "n" ).replace( '.', '/' ); + Language lang = getLanguage( pArgs ); + String ext = lang.getExtension(); + + String targetPath = getFilenameFromType( outPath, implName, ext ); + + File out = new File( targetPath ); + writer = new PrintWriter( out ); + } - if ( pServices.isEmpty() ) { - pInterfaces.remove( "com.sun.star.lang.XServiceInfo" ); + return writer; + } + + private static String getFilenameFromType(String pOutPath, + String pImplName, String pExt) { + StringBuffer buf = new StringBuffer(); + if ( pOutPath.isEmpty() ) { + buf.append( "." ); } else { - if ( !pInterfaces.contains( "com.sun.star.lang.XServiceInfo" ) ) { - pInterfaces.add( "com.sun.star.lang.XServiceInfo" ); - } + buf.append( pOutPath ); } - if ( pPropertyHelper.equals( TypeManager.NOPROPERTYHELPER ) ) { - pInterfaces.remove( "com.sun.star.beans.XPropertySet" ); - pInterfaces.remove( "com.sun.star.beans.XFastPropertySet" ); - pInterfaces.remove( "com.sun.star.beans.XPropertyAccess" ); + String sep = System.getProperty( "file.separator" ); + + buf.append( sep ); + buf.append( pImplName ); + buf.append( pExt ); + + String filename = buf.toString(); + // Clean up the separators + if ( sep.equals( "/" ) ) { + filename = filename.replace( "\\\\", sep ); + } else { + filename = filename.replace( "/", sep ); } + + return filename; } public static void main(String[] args) { @@ -108,8 +121,8 @@ public class SkeletonMaker { } } - private static String getLanguage( CommandLine pArgs ) { - String[] langs = LanguageHelper.getLanguages(); + private static Language getLanguage( CommandLine pArgs ) { + String[] langs = LanguageHelper.getLanguagesIds(); String lang = null; int i = 0; while ( lang == null && i < langs.length ) { @@ -118,6 +131,6 @@ public class SkeletonMaker { } i++; } - return lang; + return LanguageHelper.getLanguage( lang ); } } |