int classStartIndex = imageLoaderClass.lastIndexOf('.'); if (classStartIndex != -1) { imageLoaderClass = imageLoaderClass.substring( classStartIndex + 1 ); this.preprocessor.addVariable("polish.classes.ImageLoader", imageLoaderClass );
if (imageLoaderClass != null) { int classStartIndex = imageLoaderClass.lastIndexOf('.'); if (classStartIndex != -1) { imageLoaderClass = imageLoaderClass.substring( classStartIndex + 1 ); this.preprocessor.addVariable("polish.classes.ImageLoader", imageLoaderClass ); }
	private void preprocess( Device device, Locale locale ) {		System.out.println("preprocessing for device [" +  device.getIdentifier() + "]." );		try {			this.numberOfChangedFiles = 0;			String targetDir = this.buildSetting.getWorkDir().getAbsolutePath() 				+ File.separatorChar + device.getVendorName() 				+ File.separatorChar + device.getName();			if (locale != null) {				targetDir += File.separatorChar + locale.toString();			}			device.setBaseDir( targetDir );			targetDir += File.separatorChar + "source";			device.setSourceDir(targetDir);			// initialise the preprocessor:			this.preprocessor.setTargetDir( targetDir );			// set variables and symbols:			this.preprocessor.setSymbols( device.getFeatures() );			this.preprocessor.setVariables( device.getCapabilities() );			this.preprocessor.addVariable( "polish.identifier", device.getIdentifier() );			this.preprocessor.addVariable( "polish.name", device.getName() );			this.preprocessor.addVariable( "polish.vendor", device.getVendorName() );			this.preprocessor.addVariable( "polish.version", this.infoSetting.getVersion() );			long lastLocaleModification = 0;			TranslationManager translationManager = null;			// set localization-variables:			if (locale != null) {				this.preprocessor.addVariable("polish.locale", locale.toString() );				this.preprocessor.addVariable("polish.language", locale.getLanguage() );				this.preprocessor.addVariable("polish.country", locale.getCountry() );								// load localized messages, this also sets localized variables automatically:				translationManager = this.resourceManager.getTranslationManager(device, locale, this.preprocessor );				this.translationPreprocessor.setTranslationManager( translationManager );				lastLocaleModification = translationManager.getLastModificationTime();			}			// set info-variables:			String jarName = this.infoSetting.getJarName();			jarName = PropertyUtil.writeProperties(jarName, this.preprocessor.getVariables());			this.preprocessor.addVariable( "polish.jarName", jarName );			String jarPath = this.buildSetting.getDestDir().getAbsolutePath() + File.separator + jarName;			this.preprocessor.addVariable( "polish.jarPath", jarPath );			String jadName = jarName.substring(0, jarName.lastIndexOf('.') ) + ".jad";			this.preprocessor.addVariable( "polish.jadName", jadName );			String jadPath = this.buildSetting.getDestDir().getAbsolutePath() + File.separator + jadName;			this.preprocessor.addVariable( "polish.jadPath", jadPath );			// set conditional variables:			if (this.conditionalVariables != null) {				// add variables which fulfill the conditions: 				BooleanEvaluator evaluator = this.preprocessor.getBooleanEvaluator();				for (int i = 0; i < this.conditionalVariables.length; i++) {					Variable var = this.conditionalVariables[i];					if (var.isConditionFulfilled( evaluator, this.project )) {						this.preprocessor.addVariable(var.getName(), var.getValue() );					}				}			}			// now set the full-screen-settings:			String value = this.preprocessor.getVariable("polish.FullScreen");			if (value != null) {				if ("menu".equalsIgnoreCase(value)) {					this.preprocessor.addSymbol("polish.useMenuFullScreen");					this.preprocessor.addSymbol("polish.useFullScreen");									} else if ("yes".equalsIgnoreCase( value ) || "true".equalsIgnoreCase(value)) {					this.preprocessor.addSymbol("polish.useFullScreen");									}			} else {				FullScreenSetting fullScreenSetting = this.buildSetting.getFullScreenSetting();				if (fullScreenSetting != null) {					if (fullScreenSetting.isMenu()) {						this.preprocessor.addSymbol("polish.useMenuFullScreen");						this.preprocessor.addSymbol("polish.useFullScreen");					} else if (fullScreenSetting.isEnabled()) {						this.preprocessor.addSymbol("polish.useFullScreen");					}				}			}			// adjust polish.classes.ImageLoader in case the default package is used:			if (this.useDefaultPackage) {				String imageLoaderClass = this.preprocessor.getVariable("polish.classes.ImageLoader");				int classStartIndex = imageLoaderClass.lastIndexOf('.');				if (classStartIndex != -1) {					imageLoaderClass = imageLoaderClass.substring( classStartIndex + 1 );					this.preprocessor.addVariable("polish.classes.ImageLoader", imageLoaderClass );				}			}			// get the last modfication time of the build.xml file			// so that it can be checked whether there are any changes at all:			File buildXml = new File( this.project.getBaseDir().getAbsolutePath() 						+ File.separatorChar + "build.xml" );			long buildXmlLastModified = buildXml.lastModified();			// check if the polish gui is used at all:			boolean usePolishGui = this.buildSetting.usePolishGui()				  && ( device.supportsPolishGui() || this.buildSetting.alwaysUsePolishGui());			if (!usePolishGui) {				// check if a preprocessing variable is set for using the Polish GUI:				value = this.preprocessor.getVariable("polish.usePolishGui");				if (value != null) {					if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "always".equalsIgnoreCase(value)) {						usePolishGui = true;										}				}			}			this.preprocessor.setUsePolishGui(usePolishGui);			long lastCssModification = lastLocaleModification;			StyleSheet cssStyleSheet = null;			if (usePolishGui) {				cssStyleSheet = this.resourceManager.loadStyleSheet( this.styleSheet, device, locale );				if (cssStyleSheet.lastModified() > lastLocaleModification) {					lastCssModification = cssStyleSheet.lastModified();				}			}			this.preprocessor.setSyleSheet( cssStyleSheet, device );			this.preprocessor.notifyDevice(device, usePolishGui);			// preprocess each source file:			for (int i = 0; i < this.sourceDirs.length; i++) {				File sourceDir = this.sourceDirs[i];				TextFile[] files = this.sourceFiles[i];				processSourceDir(sourceDir, files, device, usePolishGui, targetDir, buildXmlLastModified, lastCssModification, false);			} // for each source folder			this.preprocessor.notifyPolishPackageStart();			// now process the J2ME package files:			processSourceDir(this.polishSourceDir, this.polishSourceFiles, device, usePolishGui, targetDir, buildXmlLastModified, lastCssModification, true);			// notify preprocessor about the end of preprocessing:			this.preprocessor.notifyDeviceEnd( device, usePolishGui );									// now all files have been preprocessed.			// Now the StyleSheet.java file needs to be written,			// but only when the polish GUI should be used:			File baseDirectory = new File( targetDir );			if (usePolishGui) {				// check if the CSS declarations have changed since the last run:				File targetFile =  this.styleSheetSourceFile.getTargetFile( baseDirectory, this.useDefaultPackage );					//new File( targetDir + File.separatorChar + this.styleSheetSourceFile.getFilePath() );								boolean cssIsNew = (!targetFile.exists())					|| ( lastCssModification > targetFile.lastModified() )					|| ( buildXmlLastModified > targetFile.lastModified() );				if (cssIsNew) {					//System.out.println("CSS is new and the style sheet will be generated.");					if (this.styleSheetCode == null) {						// the style sheet has not been preprocessed:						this.styleSheetCode = new StringList( this.styleSheetSourceFile.getContent() );						String className = "de.enough.polish.ui.StyleSheet";						this.preprocessor.preprocess( className, this.styleSheetCode );					}					// now insert the CSS information for this device					// into the StyleSheet.java source-code:					CssConverter cssConverter = new CssConverter( this.cssAttributesManager );					this.styleSheetCode.reset();					cssConverter.convertStyleSheet(this.styleSheetCode, 							this.preprocessor.getStyleSheet(),							device,							this.preprocessor ); 									//this.styleSheetSourceFile.saveToDir(targetDir, this.styleSheetCode.getArray(), false );					if (this.useDefaultPackage) {						this.styleSheetCode.reset();						this.importConverter.processImports(true, device.isMidp1(), this.styleSheetCode, device, this.preprocessor);						this.styleSheetCode.reset();						this.importConverter.removeDirectPackages( this.styleSheetCode, this.preprocessor.getTextFileManager() );					}					FileUtil.writeTextFile(targetFile, this.styleSheetCode.getArray());					this.numberOfChangedFiles++;				//} else {				//	System.out.println("CSSS is not new - last CSS modification == " + lastCssModification + " <= StyleSheet.java.lastModified() == " + targetFile.lastModified() );				}							}			// now check if the de.enough.polish.util.Locale.java needs to be rewritten:			if (locale != null) {				File targetFile =  this.localeSourceFile.getTargetFile( baseDirectory, this.useDefaultPackage );				//File targetFile = new File( targetDir + File.separatorChar + this.localeSourceFile.getFilePath() );								boolean localizationIsNew = (!targetFile.exists())					|| ( lastLocaleModification > targetFile.lastModified() )					|| ( buildXmlLastModified > targetFile.lastModified() );				if (localizationIsNew) {					//System.out.println("Localization is new and the Locale.java will be generated.");					if (this.localeCode == null) {						// the style sheet has not been preprocessed:						this.localeCode = new StringList( this.localeSourceFile.getContent() );						String className = "de.enough.polish.util.Locale";						this.preprocessor.preprocess( className, this.localeCode );					}										// now insert the localozation data for this device					// into the Locale.java source-code:					translationManager.processLocaleCode( this.localeCode );					//this.localeSourceFile.saveToDir(targetDir, this.localeCode.getArray(), false );					if (this.useDefaultPackage) {						this.localeCode.reset();						this.importConverter.processImports(true, device.isMidp1(), this.localeCode, device, this.preprocessor);					}					FileUtil.writeTextFile(targetFile, this.localeCode.getArray());					this.numberOfChangedFiles++;				}			}			device.setNumberOfChangedFiles( this.numberOfChangedFiles );		} catch (FileNotFoundException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		} catch (IOException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		} catch (BuildException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		}	}