text
stringlengths
30
1.67M
<s> package com . izforge . izpack . installer . unpacker ; import java . io . File ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . io . OutputStream ; import java . util . jar . JarOutputStream ; import java . util . jar . Pack200 ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . os . FileQueue ; class Pack200FileUnpacker extends FileUnpacker { private final PackResources resources ; private final Pack200 . Unpacker unpacker ; public Pack200FileUnpacker ( Cancellable cancellable , PackResources resources , Pack200 . Unpacker unpacker , FileQueue queue ) { super ( cancellable , queue ) ; this . resources = resources ; this . unpacker = unpacker ; } @ Override public void unpack ( PackFile file , ObjectInputStream packInputStream , File target ) throws IOException , InstallerException { int key = packInputStream . readInt ( ) ; InputStream in = null ; OutputStream out = null ; JarOutputStream jarOut = null ; try { in = resources . getInputStream ( "<STR_LIT>" + key ) ; out = getTarget ( file , target ) ; jarOut = new JarOutputStream ( out ) ; unpacker . unpack ( in , jarOut ) ; jarOut . close ( ) ; } finally { FileUtils . close ( in ) ; FileUtils . close ( out ) ; FileUtils . close ( jarOut ) ; } postCopy ( file ) ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . data . ParsableFile ; import com . izforge . izpack . util . PlatformModelMatcher ; public class ScriptParser { private final VariableSubstitutor replacer ; private final PlatformModelMatcher matcher ; public ScriptParser ( VariableSubstitutor replacer , PlatformModelMatcher matcher ) { this . replacer = replacer ; this . matcher = matcher ; } public void parse ( ParsableFile parsable ) throws Exception { if ( ! matcher . matchesCurrentPlatform ( parsable . getOsConstraints ( ) ) ) { return ; } File file = new File ( parsable . getPath ( ) ) ; File parsedFile ; try { parsedFile = File . createTempFile ( "<STR_LIT>" , null , file . getParentFile ( ) ) ; } catch ( IOException exception ) { throw new IOException ( "<STR_LIT>" + parsable . getPath ( ) + "<STR_LIT>" + file . getParentFile ( ) , exception ) ; } FileInputStream inFile = new FileInputStream ( file ) ; BufferedInputStream in = new BufferedInputStream ( inFile , <NUM_LIT> ) ; FileOutputStream outFile = new FileOutputStream ( parsedFile ) ; BufferedOutputStream out = new BufferedOutputStream ( outFile , <NUM_LIT> ) ; replacer . substitute ( in , out , parsable . getType ( ) , parsable . getEncoding ( ) ) ; in . close ( ) ; out . close ( ) ; if ( ! file . delete ( ) ) { throw new IOException ( "<STR_LIT>" + file ) ; } if ( ! parsedFile . renameTo ( file ) ) { throw new IOException ( "<STR_LIT>" + parsedFile + "<STR_LIT:U+0020toU+0020>" + file ) ; } } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . File ; import java . io . IOException ; import java . io . ObjectInputStream ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . util . os . FileQueue ; public class DefaultFileUnpacker extends FileUnpacker { public DefaultFileUnpacker ( Cancellable cancellable , FileQueue queue ) { super ( cancellable , queue ) ; } @ Override public void unpack ( PackFile file , ObjectInputStream packInputStream , File target ) throws IOException , InstallerException { copy ( file , packInputStream , target ) ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . os . FileQueue ; public class FileQueueFactory { private final boolean supportsQueue ; private final Librarian librarian ; public FileQueueFactory ( Platform platform , Librarian librarian ) { supportsQueue = platform . isA ( Platform . Name . WINDOWS ) ; this . librarian = librarian ; } public boolean isSupported ( ) { return supportsQueue ; } public FileQueue create ( ) { return supportsQueue ? new FileQueue ( librarian ) : null ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . IOException ; import java . io . InputStream ; import java . io . InterruptedIOException ; import java . net . URL ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . exception . ResourceInterruptedException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . installer . web . WebRepositoryAccessor ; import com . izforge . izpack . util . IoHelper ; public class GUIPackResources extends AbstractPackResources { private static final String tempSubPath = "<STR_LIT>" ; public GUIPackResources ( Resources resources , InstallData installData ) { super ( resources , installData ) ; } protected InputStream getWebPackStream ( String name , String webDirURL ) { InputStream result ; InstallData installData = getInstallData ( ) ; String baseName = installData . getInfo ( ) . getInstallerBase ( ) ; String packURL = webDirURL + "<STR_LIT:/>" + baseName + "<STR_LIT>" + name + "<STR_LIT>" ; String tempFolder = IoHelper . translatePath ( installData . getInfo ( ) . getUninstallerPath ( ) + GUIPackResources . tempSubPath , installData . getVariables ( ) ) ; String tempFile ; try { tempFile = WebRepositoryAccessor . getCachedUrl ( packURL , tempFolder ) ; } catch ( InterruptedIOException exception ) { throw new ResourceInterruptedException ( "<STR_LIT>" + webDirURL + "<STR_LIT>" , exception ) ; } catch ( IOException exception ) { throw new ResourceException ( "<STR_LIT>" + webDirURL , exception ) ; } try { URL url = new URL ( "<STR_LIT>" + tempFile + "<STR_LIT>" + name ) ; result = url . openStream ( ) ; } catch ( IOException exception ) { throw new ResourceException ( "<STR_LIT>" , exception ) ; } return result ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . InstallerListeners ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . PlatformModelMatcher ; public class Unpacker extends UnpackerBase { public Unpacker ( InstallData installData , PackResources resources , RulesEngine rules , VariableSubstitutor variableSubstitutor , UninstallData uninstallData , FileQueueFactory factory , Housekeeper housekeeper , InstallerListeners listeners , Prompt prompt , PlatformModelMatcher matcher ) { super ( installData , resources , rules , variableSubstitutor , uninstallData , factory , housekeeper , listeners , prompt , matcher ) ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import com . izforge . izpack . api . event . ProgressListener ; public interface IUnpacker extends Runnable { public boolean getResult ( ) ; void setProgressListener ( ProgressListener listener ) ; boolean interrupt ( long wait ) ; void setDisableInterrupt ( boolean disable ) ; boolean isInterruptDisabled ( ) ; } </s>
<s> package com . izforge . izpack . installer . unpacker ; import static com . izforge . izpack . api . handler . Prompt . Option ; import static com . izforge . izpack . api . handler . Prompt . Options ; import static com . izforge . izpack . api . handler . Prompt . Type ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . io . ObjectOutputStream ; import java . net . URI ; import java . net . URISyntaxException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Set ; import java . util . TreeSet ; import java . util . jar . Pack200 ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . event . InstallerListener ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . exception . ResourceInterruptedException ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . handler . ProgressHandler ; import com . izforge . izpack . core . handler . PromptUIHandler ; import com . izforge . izpack . data . ExecutableFile ; import com . izforge . izpack . data . ParsableFile ; import com . izforge . izpack . data . UpdateCheck ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . event . InstallerListeners ; import com . izforge . izpack . installer . util . PackHelper ; import com . izforge . izpack . util . FileExecutor ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . file . DirectoryScanner ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . file . GlobPatternMapper ; import com . izforge . izpack . util . file . types . FileSet ; import com . izforge . izpack . util . os . FileQueue ; public abstract class UnpackerBase implements IUnpacker { private final InstallData installData ; private final UninstallData uninstallData ; private final PackResources resources ; private final RulesEngine rules ; private final VariableSubstitutor variableSubstitutor ; private final FileQueueFactory queueFactory ; private final Housekeeper housekeeper ; private final InstallerListeners listeners ; private ProgressListener listener ; private File absoluteInstallSource ; private Pack200 . Unpacker unpacker ; private final Prompt prompt ; private final PlatformModelMatcher matcher ; private boolean result = true ; private final Cancellable cancellable ; private enum State { READY , UNPACKING , INTERRUPT , INTERRUPTED } private State state = State . READY ; private boolean disableInterrupt = false ; private static final Logger logger = Logger . getLogger ( UnpackerBase . class . getName ( ) ) ; public UnpackerBase ( InstallData installData , PackResources resources , RulesEngine rules , VariableSubstitutor variableSubstitutor , UninstallData uninstallData , FileQueueFactory factory , Housekeeper housekeeper , InstallerListeners listeners , Prompt prompt , PlatformModelMatcher matcher ) { this . installData = installData ; this . resources = resources ; this . rules = rules ; this . variableSubstitutor = variableSubstitutor ; this . uninstallData = uninstallData ; this . queueFactory = factory ; this . housekeeper = housekeeper ; this . listeners = listeners ; this . prompt = prompt ; this . matcher = matcher ; cancellable = new Cancellable ( ) { @ Override public boolean isCancelled ( ) { return isInterrupted ( ) ; } } ; } @ Override public void setProgressListener ( ProgressListener listener ) { this . listener = listener ; } public void run ( ) { unpack ( ) ; } public void unpack ( ) { state = State . UNPACKING ; try { List < ParsableFile > parsables = new ArrayList < ParsableFile > ( ) ; List < ExecutableFile > executables = new ArrayList < ExecutableFile > ( ) ; List < UpdateCheck > updateChecks = new ArrayList < UpdateCheck > ( ) ; FileQueue queue = queueFactory . isSupported ( ) ? queueFactory . create ( ) : null ; List < Pack > packs = installData . getSelectedPacks ( ) ; preUnpack ( packs ) ; unpack ( packs , queue , parsables , executables , updateChecks ) ; postUnpack ( packs , queue , parsables , executables , updateChecks ) ; } catch ( Exception exception ) { setResult ( false ) ; logger . log ( Level . SEVERE , exception . getMessage ( ) , exception ) ; listener . stopAction ( ) ; if ( exception instanceof ResourceInterruptedException ) { prompt . message ( Type . INFORMATION , "<STR_LIT>" ) ; } else { String message = exception . getMessage ( ) ; if ( message == null || "<STR_LIT>" . equals ( message ) ) { message = "<STR_LIT>" + exception . toString ( ) ; } prompt . message ( Type . ERROR , message ) ; } housekeeper . shutDown ( <NUM_LIT:4> ) ; } finally { cleanup ( ) ; } } public boolean getResult ( ) { return result ; } @ Override public boolean interrupt ( long timeout ) { boolean result ; if ( isInterruptDisabled ( ) ) { result = false ; } else { synchronized ( this ) { if ( state != State . READY && state != State . INTERRUPTED ) { state = State . INTERRUPT ; try { wait ( timeout ) ; } catch ( InterruptedException ignore ) { } result = state == State . INTERRUPTED ; } else { result = true ; } } } return result ; } @ Override public synchronized void setDisableInterrupt ( boolean disable ) { if ( state == State . INTERRUPT || state == State . INTERRUPTED ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } disableInterrupt = disable ; } public synchronized boolean isInterruptDisabled ( ) { return disableInterrupt ; } protected void preUnpack ( List < Pack > packs ) { logger . fine ( "<STR_LIT>" ) ; listener . startAction ( "<STR_LIT>" , packs . size ( ) ) ; listeners . beforePacks ( packs , listener ) ; } protected void unpack ( List < Pack > packs , FileQueue queue , List < ParsableFile > parsables , List < ExecutableFile > executables , List < UpdateCheck > updateChecks ) { int count = packs . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { Pack pack = packs . get ( i ) ; if ( shouldUnpack ( pack ) ) { listeners . beforePack ( pack , i , listener ) ; unpack ( pack , i , queue , parsables , executables , updateChecks ) ; checkInterrupt ( ) ; listeners . afterPack ( pack , i , listener ) ; } } } protected void unpack ( Pack pack , int packNo , FileQueue queue , List < ParsableFile > parsables , List < ExecutableFile > executables , List < UpdateCheck > updateChecks ) { InputStream in = null ; ObjectInputStream packInputStream = null ; try { in = resources . getPackStream ( pack . getName ( ) ) ; packInputStream = new ObjectInputStream ( in ) ; int fileCount = packInputStream . readInt ( ) ; String stepName = getStepName ( pack ) ; listener . nextStep ( stepName , packNo + <NUM_LIT:1> , fileCount ) ; for ( int i = <NUM_LIT:0> ; i < fileCount ; ++ i ) { PackFile file = ( PackFile ) packInputStream . readObject ( ) ; if ( shouldUnpack ( file ) ) { unpack ( file , packInputStream , i , pack , queue ) ; } else { skip ( file , pack , packInputStream ) ; } } readParsableFiles ( packInputStream , parsables ) ; readExecutableFiles ( packInputStream , executables ) ; readUpdateChecks ( packInputStream , updateChecks ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new InstallerException ( "<STR_LIT>" + pack . getName ( ) , exception ) ; } finally { FileUtils . close ( packInputStream ) ; FileUtils . close ( in ) ; } } private boolean shouldUnpack ( PackFile file ) { boolean result = true ; if ( file . hasCondition ( ) ) { result = isConditionTrue ( file . getCondition ( ) ) ; } if ( result && file . osConstraints ( ) != null && ! file . osConstraints ( ) . isEmpty ( ) ) { result = matcher . matchesCurrentPlatform ( file . osConstraints ( ) ) ; } return result ; } protected void unpack ( PackFile file , ObjectInputStream packInputStream , int fileNo , Pack pack , FileQueue queue ) throws IOException { if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "<STR_LIT>" + file . getTargetPath ( ) ) ; } Variables variables = getInstallData ( ) . getVariables ( ) ; String path = IoHelper . translatePath ( file . getTargetPath ( ) , variables ) ; File target = new File ( path ) ; File dir = target ; if ( ! file . isDirectory ( ) ) { dir = target . getParentFile ( ) ; } createDirectory ( dir , file , pack ) ; getUninstallData ( ) . addFile ( path , pack . isUninstall ( ) ) ; if ( file . isDirectory ( ) ) { return ; } listeners . beforeFile ( target , file , pack ) ; listener . progress ( fileNo , path ) ; if ( target . exists ( ) && ( file . override ( ) != OverrideType . OVERRIDE_TRUE ) && ! isOverwriteFile ( file , target ) ) { if ( ! file . isBackReference ( ) && ! pack . isLoose ( ) ) { if ( file . isPack200Jar ( ) ) { skip ( packInputStream , Integer . SIZE / <NUM_LIT:8> ) ; } else { skip ( packInputStream , file . length ( ) ) ; } } } else { handleOverrideRename ( file , target ) ; extract ( file , target , packInputStream , pack , queue ) ; } } protected void extract ( PackFile file , File target , ObjectInputStream packInputStream , Pack pack , FileQueue queue ) throws IOException { ObjectInputStream packStream = packInputStream ; InputStream in = null ; try { FileUnpacker unpacker ; if ( ! pack . isLoose ( ) && file . isBackReference ( ) ) { in = resources . getPackStream ( file . previousPackId ) ; packStream = new ObjectInputStream ( in ) ; skip ( in , file . offsetInPreviousPack - <NUM_LIT:4> ) ; } unpacker = createFileUnpacker ( file , pack , queue , cancellable ) ; unpacker . unpack ( file , packStream , target ) ; checkInterrupt ( ) ; if ( ! unpacker . isQueued ( ) ) { listeners . afterFile ( target , file , pack ) ; } } finally { FileUtils . close ( in ) ; if ( packStream != packInputStream ) { FileUtils . close ( packStream ) ; } } } protected void skip ( PackFile file , Pack pack , ObjectInputStream packInputStream ) throws IOException { if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "<STR_LIT>" + file . getTargetPath ( ) ) ; } if ( ! pack . isLoose ( ) && ! file . isBackReference ( ) ) { skip ( packInputStream , file . length ( ) ) ; } } protected FileUnpacker createFileUnpacker ( PackFile file , Pack pack , FileQueue queue , Cancellable cancellable ) throws IOException , InstallerException { FileUnpacker unpacker ; if ( pack . isLoose ( ) ) { unpacker = new LooseFileUnpacker ( getAbsoluteInstallSource ( ) , cancellable , queue , prompt ) ; } else if ( file . isPack200Jar ( ) ) { unpacker = new Pack200FileUnpacker ( cancellable , resources , getPack200Unpacker ( ) , queue ) ; } else { unpacker = new DefaultFileUnpacker ( cancellable , queue ) ; } return unpacker ; } protected void postUnpack ( List < Pack > packs , FileQueue queue , List < ParsableFile > parsables , List < ExecutableFile > executables , List < UpdateCheck > updateChecks ) throws IOException { InstallData installData = getInstallData ( ) ; if ( queue != null && ! queue . isEmpty ( ) ) { queue . execute ( ) ; installData . setRebootNecessary ( queue . isRebootNecessary ( ) ) ; } checkInterrupt ( ) ; parseFiles ( parsables ) ; checkInterrupt ( ) ; executeFiles ( executables ) ; checkInterrupt ( ) ; performUpdateChecks ( updateChecks ) ; checkInterrupt ( ) ; listeners . afterPacks ( packs , listener ) ; checkInterrupt ( ) ; writeInstallationInformation ( ) ; listener . stopAction ( ) ; } protected void cleanup ( ) { state = State . READY ; } protected InstallData getInstallData ( ) { return installData ; } protected UninstallData getUninstallData ( ) { return uninstallData ; } protected PackResources getResources ( ) { return resources ; } protected VariableSubstitutor getVariableSubstitutor ( ) { return variableSubstitutor ; } protected ProgressListener getProgressListener ( ) { return listener ; } protected Prompt getPrompt ( ) { return prompt ; } protected boolean shouldUnpack ( Pack pack ) { boolean result = true ; if ( pack . hasCondition ( ) ) { result = rules . isConditionTrue ( pack . getCondition ( ) ) ; } return result ; } protected void setResult ( boolean result ) { this . result = result ; } protected boolean isConditionTrue ( String id ) { return rules . isConditionTrue ( id ) ; } protected String getStepName ( Pack pack ) { return pack . isHidden ( ) ? "<STR_LIT>" : PackHelper . getPackName ( pack , installData . getMessages ( ) ) ; } protected void createDirectory ( File dir , PackFile file , Pack pack ) { if ( ! dir . exists ( ) ) { if ( ! listeners . isFileListener ( ) ) { if ( ! dir . mkdirs ( ) ) { throw new IzPackException ( "<STR_LIT>" + dir . getPath ( ) ) ; } } else { File parent = dir . getParentFile ( ) ; if ( parent != null ) { createDirectory ( parent , file , pack ) ; } listeners . beforeDir ( dir , file , pack ) ; if ( ! dir . mkdir ( ) ) { throw new IzPackException ( "<STR_LIT>" + dir . getPath ( ) ) ; } listeners . afterDir ( dir , file , pack ) ; } } } private void parseFiles ( List < ParsableFile > files ) { if ( ! files . isEmpty ( ) ) { ScriptParser parser = new ScriptParser ( getVariableSubstitutor ( ) , matcher ) ; for ( ParsableFile file : files ) { try { parser . parse ( file ) ; } catch ( Exception exception ) { throw new InstallerException ( "<STR_LIT>" + file . getPath ( ) , exception ) ; } checkInterrupt ( ) ; } } } private void executeFiles ( List < ExecutableFile > executables ) { if ( ! executables . isEmpty ( ) ) { FileExecutor executor = new FileExecutor ( executables ) ; PromptUIHandler handler = new ProgressHandler ( listener , prompt ) ; if ( executor . executeFiles ( ExecutableFile . POSTINSTALL , matcher , handler ) != <NUM_LIT:0> ) { throw new InstallerException ( "<STR_LIT>" ) ; } } } protected synchronized boolean isInterrupted ( ) { boolean result = false ; if ( state == State . INTERRUPT ) { setResult ( false ) ; state = State . INTERRUPTED ; result = true ; notifyAll ( ) ; } else { if ( state == State . INTERRUPTED ) { result = true ; } } return result ; } protected void checkInterrupt ( ) { if ( isInterrupted ( ) ) { throw new ResourceInterruptedException ( "<STR_LIT>" ) ; } } protected void performUpdateChecks ( List < UpdateCheck > checks ) { if ( checks != null && ! checks . isEmpty ( ) ) { logger . info ( "<STR_LIT>" ) ; File absoluteInstallPath = new File ( installData . getInstallPath ( ) ) . getAbsoluteFile ( ) ; FileSet fileset = new FileSet ( ) ; List < File > filesToDelete = new ArrayList < File > ( ) ; List < File > dirsToDelete = new ArrayList < File > ( ) ; try { fileset . setDir ( absoluteInstallPath ) ; for ( UpdateCheck check : checks ) { if ( check . includesList != null ) { for ( String include : check . includesList ) { fileset . createInclude ( ) . setName ( variableSubstitutor . substitute ( include ) ) ; } } if ( check . excludesList != null ) { for ( String exclude : check . excludesList ) { fileset . createExclude ( ) . setName ( variableSubstitutor . substitute ( exclude ) ) ; } } } DirectoryScanner scanner = fileset . getDirectoryScanner ( ) ; scanner . scan ( ) ; String [ ] srcFiles = scanner . getIncludedFiles ( ) ; String [ ] srcDirs = scanner . getIncludedDirectories ( ) ; Set < File > installedFiles = new TreeSet < File > ( ) ; for ( String name : uninstallData . getInstalledFilesList ( ) ) { File file = new File ( name ) ; if ( ! file . isAbsolute ( ) ) { file = new File ( absoluteInstallPath , name ) ; } installedFiles . add ( file ) ; } for ( String srcFile : srcFiles ) { File newFile = new File ( scanner . getBasedir ( ) , srcFile ) ; if ( ! installedFiles . contains ( newFile ) ) { filesToDelete . add ( newFile ) ; } } for ( String srcDir : srcDirs ) { if ( ! srcDir . isEmpty ( ) ) { File newDir = new File ( scanner . getBasedir ( ) , srcDir ) ; if ( ! installedFiles . contains ( newDir ) ) { dirsToDelete . add ( newDir ) ; } } } } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } for ( File f : filesToDelete ) { if ( ! f . delete ( ) ) { logger . warning ( "<STR_LIT>" + f ) ; } else { logger . fine ( "<STR_LIT>" + f ) ; } } Collections . sort ( dirsToDelete ) ; Collections . reverse ( dirsToDelete ) ; for ( File d : dirsToDelete ) { if ( ! d . exists ( ) ) { break ; } File [ ] files = d . listFiles ( ) ; if ( files != null && files . length != <NUM_LIT:0> ) { break ; } if ( ! d . delete ( ) ) { logger . warning ( "<STR_LIT>" + d ) ; } else { logger . fine ( "<STR_LIT>" + d ) ; } } } } protected void writeInstallationInformation ( ) throws IOException { if ( ! installData . getInfo ( ) . isWriteInstallationInformation ( ) ) { logger . fine ( "<STR_LIT>" ) ; return ; } logger . fine ( "<STR_LIT>" ) ; String installDir = installData . getInstallPath ( ) ; List < Pack > installedPacks = new ArrayList < Pack > ( installData . getSelectedPacks ( ) ) ; File installationInfo = new File ( installDir + File . separator + InstallData . INSTALLATION_INFORMATION ) ; if ( ! installationInfo . exists ( ) ) { logger . fine ( "<STR_LIT>" + installationInfo . getAbsolutePath ( ) ) ; File dir = new File ( installData . getInstallPath ( ) ) ; if ( ! dir . exists ( ) ) { if ( ! dir . mkdirs ( ) ) { throw new InstallerException ( "<STR_LIT>" + dir ) ; } } if ( ! installationInfo . createNewFile ( ) ) { throw new InstallerException ( "<STR_LIT>" + installationInfo ) ; } } else { logger . fine ( "<STR_LIT>" ) ; FileInputStream fin = new FileInputStream ( installationInfo ) ; ObjectInputStream oin = new ObjectInputStream ( fin ) ; List < Pack > packs ; try { packs = ( List < Pack > ) oin . readObject ( ) ; } catch ( Exception exception ) { throw new InstallerException ( "<STR_LIT>" , exception ) ; } for ( Pack pack : packs ) { installedPacks . add ( pack ) ; } FileUtils . close ( oin ) ; FileUtils . close ( fin ) ; } FileOutputStream fout = new FileOutputStream ( installationInfo ) ; ObjectOutputStream oout = new ObjectOutputStream ( fout ) ; oout . writeObject ( installedPacks ) ; oout . writeObject ( installData . getVariables ( ) . getProperties ( ) ) ; logger . fine ( "<STR_LIT>" ) ; FileUtils . close ( oout ) ; FileUtils . close ( fout ) ; } protected File getAbsoluteInstallSource ( ) throws IOException , InstallerException { if ( absoluteInstallSource == null ) { URI uri ; try { uri = getClass ( ) . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . toURI ( ) ; } catch ( URISyntaxException exception ) { throw new InstallerException ( exception ) ; } if ( ! "<STR_LIT:file>" . equals ( uri . getScheme ( ) ) ) { throw new InstallerException ( "<STR_LIT>" + uri ) ; } absoluteInstallSource = new File ( uri . getSchemeSpecificPart ( ) ) . getAbsoluteFile ( ) ; if ( absoluteInstallSource . getName ( ) . endsWith ( "<STR_LIT>" ) ) { absoluteInstallSource = absoluteInstallSource . getParentFile ( ) ; } } return absoluteInstallSource ; } protected void skip ( InputStream stream , long bytes ) throws IOException { long skipped = stream . skip ( bytes ) ; if ( skipped != bytes ) { throw new IOException ( "<STR_LIT>" + bytes + "<STR_LIT>" + skipped ) ; } } protected boolean isOverwriteFile ( PackFile pf , File file ) { boolean result = false ; if ( pf . override ( ) != OverrideType . OVERRIDE_FALSE ) { if ( pf . override ( ) == OverrideType . OVERRIDE_TRUE ) { result = true ; } else if ( pf . override ( ) == OverrideType . OVERRIDE_UPDATE ) { result = ( file . lastModified ( ) < pf . lastModified ( ) ) ; } else { Option defChoice = null ; if ( pf . override ( ) == OverrideType . OVERRIDE_ASK_FALSE ) { defChoice = Option . NO ; } else if ( pf . override ( ) == OverrideType . OVERRIDE_ASK_TRUE ) { defChoice = Option . YES ; } Messages messages = installData . getMessages ( ) ; Option answer = prompt . confirm ( Type . QUESTION , messages . get ( "<STR_LIT>" ) + "<STR_LIT:U+0020-U+0020>" + file . getName ( ) , messages . get ( "<STR_LIT>" ) + file . getAbsolutePath ( ) , Options . YES_NO , defChoice ) ; result = ( answer == Option . YES ) ; } } return result ; } protected void handleOverrideRename ( PackFile pf , File file ) { if ( file . exists ( ) && pf . overrideRenameTo ( ) != null ) { GlobPatternMapper mapper = new GlobPatternMapper ( ) ; mapper . setFrom ( "<STR_LIT:*>" ) ; mapper . setTo ( pf . overrideRenameTo ( ) ) ; mapper . setCaseSensitive ( true ) ; String [ ] newFileNameArr = mapper . mapFileName ( file . getName ( ) ) ; if ( newFileNameArr != null ) { String newFileName = newFileNameArr [ <NUM_LIT:0> ] ; File newPathFile = new File ( file . getParent ( ) , newFileName ) ; if ( newPathFile . exists ( ) ) { if ( ! newPathFile . delete ( ) ) { logger . warning ( "<STR_LIT>" + newPathFile ) ; } } if ( ! file . renameTo ( newPathFile ) ) { throw new InstallerException ( "<STR_LIT>" + file + "<STR_LIT>" + newPathFile ) ; } } else { throw new InstallerException ( "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" + pf . overrideRenameTo ( ) + "<STR_LIT:\">" ) ; } } } protected void readParsableFiles ( ObjectInputStream stream , List < ParsableFile > parsables ) throws IOException , ClassNotFoundException { int count = stream . readInt ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; ++ i ) { ParsableFile file = ( ParsableFile ) stream . readObject ( ) ; if ( ! file . hasCondition ( ) || isConditionTrue ( file . getCondition ( ) ) ) { String path = IoHelper . translatePath ( file . getPath ( ) , installData . getVariables ( ) ) ; file . setPath ( path ) ; parsables . add ( file ) ; } } } protected void readExecutableFiles ( ObjectInputStream stream , List < ExecutableFile > executables ) throws IOException , ClassNotFoundException { int count = stream . readInt ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; ++ i ) { ExecutableFile file = ( ExecutableFile ) stream . readObject ( ) ; if ( ! file . hasCondition ( ) || isConditionTrue ( file . getCondition ( ) ) ) { Variables variables = installData . getVariables ( ) ; file . path = IoHelper . translatePath ( file . path , variables ) ; if ( null != file . argList && ! file . argList . isEmpty ( ) ) { for ( int j = <NUM_LIT:0> ; j < file . argList . size ( ) ; j ++ ) { String arg = file . argList . get ( j ) ; arg = IoHelper . translatePath ( arg , variables ) ; file . argList . set ( j , arg ) ; } } executables . add ( file ) ; if ( file . executionStage == ExecutableFile . UNINSTALL ) { uninstallData . addExecutable ( file ) ; } } } } protected void readUpdateChecks ( ObjectInputStream stream , List < UpdateCheck > updateChecks ) throws IOException , ClassNotFoundException { int count = stream . readInt ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; ++ i ) { UpdateCheck check = ( UpdateCheck ) stream . readObject ( ) ; updateChecks . add ( check ) ; } } private Pack200 . Unpacker getPack200Unpacker ( ) { if ( unpacker == null ) { unpacker = Pack200 . newUnpacker ( ) ; } return unpacker ; } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . InputStream ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . exception . ResourceInterruptedException ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; public interface PackResources { InputStream getPackStream ( String name ) ; InputStream getInputStream ( String name ) ; } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . ObjectInputStream ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . util . os . FileQueue ; public class LooseFileUnpacker extends FileUnpacker { private final File sourceDir ; private final Prompt prompt ; private static final Logger logger = Logger . getLogger ( LooseFileUnpacker . class . getName ( ) ) ; public LooseFileUnpacker ( File sourceDir , Cancellable cancellable , FileQueue queue , Prompt prompt ) { super ( cancellable , queue ) ; this . sourceDir = sourceDir ; this . prompt = prompt ; } @ Override public void unpack ( PackFile file , ObjectInputStream packInputStream , File target ) throws IOException , InstallerException { File resolvedFile = new File ( sourceDir , file . getRelativeSourcePath ( ) ) ; if ( ! resolvedFile . exists ( ) ) { final File userDir = new File ( System . getProperty ( "<STR_LIT>" ) ) ; resolvedFile = new File ( userDir , file . getRelativeSourcePath ( ) ) ; } if ( resolvedFile . exists ( ) ) { InputStream stream = new FileInputStream ( resolvedFile ) ; file = new PackFile ( resolvedFile . getParentFile ( ) , resolvedFile , file . getTargetPath ( ) , file . osConstraints ( ) , file . override ( ) , file . overrideRenameTo ( ) , file . blockable ( ) , file . getAdditionals ( ) ) ; copy ( file , stream , target ) ; } else { logger . warning ( "<STR_LIT>" + file . getRelativeSourcePath ( ) ) ; if ( prompt . confirm ( Prompt . Type . WARNING , "<STR_LIT>" , "<STR_LIT>" + file . getRelativeSourcePath ( ) , Prompt . Options . OK_CANCEL ) == Prompt . Option . OK ) { throw new InstallerException ( "<STR_LIT>" ) ; } } } } </s>
<s> package com . izforge . izpack . installer . unpacker ; import java . io . InputStream ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . ResourceException ; import com . izforge . izpack . api . resource . Resources ; public class ConsolePackResources extends AbstractPackResources { public ConsolePackResources ( Resources resources , InstallData installData ) { super ( resources , installData ) ; } @ Override protected InputStream getWebPackStream ( String name , String webDirURL ) { throw new ResourceException ( "<STR_LIT>" + name + "<STR_LIT>" + webDirURL + "<STR_LIT>" ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . util . Console ; class ConsoleInstallAction extends AbstractInstallAction { private final Console console ; public ConsoleInstallAction ( Console console , InstallData installData , UninstallDataWriter writer ) { super ( installData , writer ) ; this . console = console ; } @ Override public boolean run ( ConsolePanelView panel ) { PanelConsole view = panel . getView ( ) ; return view . runConsole ( getInstallData ( ) , console ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . PrintWriter ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . FileUtils ; class GeneratePropertiesAction extends ConsoleAction { private final PrintWriter writer ; public GeneratePropertiesAction ( InstallData installData , String path ) throws FileNotFoundException { super ( installData ) ; writer = new PrintWriter ( new FileOutputStream ( path ) , true ) ; } @ Override public boolean isInstall ( ) { return false ; } @ Override public boolean run ( ConsolePanelView panel ) { return panel . getView ( ) . runGeneratePropertiesFile ( getInstallData ( ) , writer ) ; } @ Override public boolean complete ( ) { FileUtils . close ( writer ) ; return true ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . util . List ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . installer . panel . AbstractPanels ; import com . izforge . izpack . installer . panel . Panels ; public class ConsolePanels extends AbstractPanels < ConsolePanelView , PanelConsole > { private ConsoleAction action ; public ConsolePanels ( List < ConsolePanelView > panels , Variables variables ) { super ( panels , variables ) ; } public void setAction ( ConsoleAction action ) { this . action = action ; } @ Override protected boolean switchPanel ( ConsolePanelView newPanel , ConsolePanelView oldPanel ) { boolean result = false ; newPanel . executePreActivationActions ( ) ; if ( action != null ) { do { result = action . run ( newPanel ) ; if ( ! result ) { break ; } } while ( ! newPanel . isValid ( ) ) ; } return result ; } } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . api . data . InstallData ; abstract class ConsoleAction { private final InstallData installData ; public ConsoleAction ( InstallData installData ) { this . installData = installData ; } public abstract boolean run ( ConsolePanelView panel ) ; public abstract boolean complete ( ) ; public boolean isInstall ( ) { return true ; } protected InstallData getInstallData ( ) { return installData ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . util . Properties ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; class PropertyInstallAction extends AbstractInstallAction { private final Properties properties ; public PropertyInstallAction ( InstallData installData , UninstallDataWriter writer , Properties properties ) { super ( installData , writer ) ; this . properties = properties ; } @ Override public boolean run ( ConsolePanelView panel ) { return panel . getView ( ) . runConsoleFromProperties ( getInstallData ( ) , properties ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . io . PrintWriter ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . Console ; public abstract class AbstractPanelConsole implements PanelConsole { @ Override public boolean runGeneratePropertiesFile ( InstallData installData , PrintWriter printWriter ) { return true ; } @ Override public boolean runConsole ( InstallData installData ) { return runConsole ( installData , new Console ( ) ) ; } protected boolean promptEndPanel ( InstallData installData , Console console ) { boolean result ; int value = console . prompt ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ) ; result = value == <NUM_LIT:1> || value != <NUM_LIT:2> && runConsole ( installData , console ) ; return result ; } } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; public abstract class AbstractInstallAction extends ConsoleAction { private final UninstallDataWriter writer ; public AbstractInstallAction ( InstallData installData , UninstallDataWriter writer ) { super ( installData ) ; this . writer = writer ; } @ Override public boolean complete ( ) { boolean result = true ; if ( writer . isUninstallRequired ( ) ) { result = writer . write ( ) ; } return result ; } } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . handler . AbstractUIHandler ; import com . izforge . izpack . core . handler . ConsolePrompt ; import com . izforge . izpack . core . handler . PromptUIHandler ; import com . izforge . izpack . installer . panel . PanelView ; import com . izforge . izpack . util . Console ; public class ConsolePanelView extends PanelView < PanelConsole > { private final Console console ; private final ConsolePrompt prompt ; public ConsolePanelView ( Panel panel , ObjectFactory factory , InstallData installData , Console console ) { super ( panel , PanelConsole . class , factory , installData ) ; this . console = console ; this . prompt = new ConsolePrompt ( console ) ; } public Class < PanelConsole > getViewClass ( ) { Panel panel = getPanel ( ) ; Class < PanelConsole > result = getClass ( panel . getClassName ( ) + "<STR_LIT>" ) ; if ( result == null ) { result = getClass ( panel . getClassName ( ) + "<STR_LIT>" ) ; } return result ; } @ Override protected PanelConsole createView ( Panel panel , Class < PanelConsole > viewClass ) { Class < PanelConsole > impl = getViewClass ( ) ; if ( impl == null ) { throw new IzPackException ( "<STR_LIT>" + panel . getClassName ( ) ) ; } return getFactory ( ) . create ( impl ) ; } @ Override protected AbstractUIHandler getHandler ( ) { return new PromptUIHandler ( prompt ) { @ Override public void emitNotification ( String message ) { console . println ( message ) ; } } ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . io . PrintWriter ; import java . util . Properties ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . Console ; public interface PanelConsole { boolean runGeneratePropertiesFile ( InstallData installData , PrintWriter printWriter ) ; boolean runConsoleFromProperties ( InstallData installData , Properties properties ) ; boolean runConsole ( InstallData installData ) ; boolean runConsole ( InstallData installData , Console console ) ; } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . installer . automation . PanelAutomationHelper ; public class ConsolePanelAutomationHelper extends PanelAutomationHelper { public ConsolePanelAutomationHelper ( ) { super ( ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . util . Properties ; import java . util . StringTokenizer ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . Console ; public abstract class AbstractTextPanelConsole extends AbstractPanelConsole { private static final Logger logger = Logger . getLogger ( AbstractTextPanelConsole . class . getName ( ) ) ; @ Override public boolean runConsoleFromProperties ( InstallData installData , Properties properties ) { return true ; } @ Override public boolean runConsole ( InstallData installData , Console console ) { boolean result ; String text = getText ( ) ; if ( text != null ) { result = paginateText ( text , console ) ; } else { logger . warning ( "<STR_LIT>" ) ; result = false ; } return result && promptEndPanel ( installData , console ) ; } protected abstract String getText ( ) ; protected boolean paginateText ( String text , Console console ) { boolean result = true ; int lines = <NUM_LIT> ; int line = <NUM_LIT:0> ; StringTokenizer tokens = new StringTokenizer ( text , "<STR_LIT:n>" ) ; while ( tokens . hasMoreTokens ( ) ) { String token = tokens . nextToken ( ) ; console . println ( token ) ; line ++ ; if ( line >= lines && tokens . hasMoreTokens ( ) ) { if ( ! promptContinue ( console ) ) { result = false ; break ; } line = <NUM_LIT:0> ; } } return result ; } protected boolean promptContinue ( Console console ) { String value = console . prompt ( "<STR_LIT>" , "<STR_LIT:x>" ) ; console . println ( ) ; return ! value . equalsIgnoreCase ( "<STR_LIT:x>" ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import com . izforge . izpack . util . Console ; abstract public class PanelConsoleHelper extends AbstractPanelConsole { @ Deprecated public int askEndOfConsolePanel ( ) { return new Console ( ) . prompt ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ) ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . factory . ObjectFactory ; class PanelConsoleFactory { private final ObjectFactory factory ; private static final Logger logger = Logger . getLogger ( PanelConsoleFactory . class . getName ( ) ) ; public PanelConsoleFactory ( ObjectFactory factory ) { this . factory = factory ; } public PanelConsole create ( Panel panel ) throws InstallerException { Class < PanelConsole > impl = getClass ( panel ) ; return factory . create ( impl ) ; } public Class < PanelConsole > getClass ( Panel panel ) { Class < PanelConsole > result = getClass ( panel . getClassName ( ) + "<STR_LIT>" ) ; if ( result == null ) { result = getClass ( panel . getClassName ( ) + "<STR_LIT>" ) ; } return result ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private Class < PanelConsole > getClass ( String name ) { Class < PanelConsole > result = null ; try { Class type = Class . forName ( name ) ; if ( ! PanelConsole . class . isAssignableFrom ( type ) ) { logger . warning ( name + "<STR_LIT>" + PanelConsole . class . getName ( ) + "<STR_LIT>" ) ; } else { result = ( Class < PanelConsole > ) type ; } } catch ( ClassNotFoundException e ) { logger . fine ( "<STR_LIT>" + name + "<STR_LIT::U+0020>" + e . toString ( ) ) ; } return result ; } } </s>
<s> package com . izforge . izpack . installer . console ; import java . io . FileInputStream ; import java . io . IOException ; import java . util . Enumeration ; import java . util . Properties ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . Info ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . installer . base . InstallerBase ; import com . izforge . izpack . installer . bootstrap . Installer ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . requirement . RequirementsChecker ; import com . izforge . izpack . util . Console ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . file . FileUtils ; public class ConsoleInstaller extends InstallerBase { private final ConsolePanels panels ; private InstallData installData ; private final RequirementsChecker requirements ; private UninstallDataWriter uninstallDataWriter ; private Console console ; private final Housekeeper housekeeper ; private static final Logger logger = Logger . getLogger ( ConsoleInstaller . class . getName ( ) ) ; public ConsoleInstaller ( ConsolePanels panels , AutomatedInstallData installData , RequirementsChecker requirements , UninstallDataWriter uninstallDataWriter , Console console , Housekeeper housekeeper ) { this . panels = panels ; this . installData = installData ; this . requirements = requirements ; this . uninstallDataWriter = uninstallDataWriter ; this . console = console ; this . housekeeper = housekeeper ; } public boolean canInstall ( ) { boolean success = true ; for ( ConsolePanelView panel : panels . getPanelViews ( ) ) { if ( panel . getViewClass ( ) == null ) { success = false ; logger . warning ( "<STR_LIT>" + panel . getPanel ( ) . getClassName ( ) ) ; } } return success ; } public void setMediaPath ( String path ) { installData . setMediaPath ( path ) ; } public void run ( int type , String path ) { boolean success = false ; ConsoleAction action = null ; if ( ! canInstall ( ) ) { console . println ( "<STR_LIT>" ) ; shutdown ( false , false ) ; } else { try { if ( requirements . check ( ) ) { action = createConsoleAction ( type , path , console ) ; panels . setAction ( action ) ; while ( panels . hasNext ( ) ) { success = panels . next ( ) ; if ( ! success ) { break ; } } if ( success ) { success = panels . isValid ( ) ; if ( success ) { success = action . complete ( ) ; } } } } catch ( Throwable t ) { success = false ; logger . log ( Level . SEVERE , t . getMessage ( ) , t ) ; } finally { if ( action != null && action . isInstall ( ) ) { shutdown ( success , console ) ; } else { shutdown ( success , false ) ; } } } } protected void shutdown ( boolean exitSuccess , Console console ) { boolean reboot = false ; if ( installData . isRebootNecessary ( ) ) { console . println ( "<STR_LIT>" ) ; switch ( installData . getInfo ( ) . getRebootAction ( ) ) { case Info . REBOOT_ACTION_ALWAYS : reboot = true ; } if ( reboot ) { console . println ( "<STR_LIT>" ) ; } } shutdown ( exitSuccess , reboot ) ; } protected void shutdown ( boolean exitSuccess , boolean reboot ) { if ( exitSuccess && ! installData . isInstallSuccess ( ) ) { logger . severe ( "<STR_LIT>" ) ; exitSuccess = false ; } installData . setInstallSuccess ( exitSuccess ) ; if ( exitSuccess ) { console . println ( "<STR_LIT>" ) ; } else { console . println ( "<STR_LIT>" ) ; } terminate ( exitSuccess , reboot ) ; } protected void terminate ( boolean exitSuccess , boolean reboot ) { housekeeper . shutDown ( exitSuccess ? <NUM_LIT:0> : <NUM_LIT:1> , reboot ) ; } protected Console getConsole ( ) { return console ; } private ConsoleAction createConsoleAction ( int type , String path , Console console ) throws IOException { ConsoleAction action ; switch ( type ) { case Installer . CONSOLE_GEN_TEMPLATE : action = createGeneratePropertiesAction ( path ) ; break ; case Installer . CONSOLE_FROM_TEMPLATE : action = createInstallFromPropertiesFileAction ( path ) ; break ; case Installer . CONSOLE_FROM_SYSTEMPROPERTIES : action = new PropertyInstallAction ( installData , uninstallDataWriter , System . getProperties ( ) ) ; break ; case Installer . CONSOLE_FROM_SYSTEMPROPERTIESMERGE : action = createInstallFromSystemPropertiesMergeAction ( path , console ) ; break ; default : action = createInstallAction ( ) ; } return action ; } private ConsoleAction createInstallAction ( ) { return new ConsoleInstallAction ( console , installData , uninstallDataWriter ) ; } private ConsoleAction createGeneratePropertiesAction ( String path ) throws IOException { return new GeneratePropertiesAction ( installData , path ) ; } private ConsoleAction createInstallFromPropertiesFileAction ( String path ) throws IOException { FileInputStream in = new FileInputStream ( path ) ; try { Properties properties = new Properties ( ) ; properties . load ( in ) ; return new PropertyInstallAction ( installData , uninstallDataWriter , properties ) ; } finally { FileUtils . close ( in ) ; } } private ConsoleAction createInstallFromSystemPropertiesMergeAction ( String path , Console console ) throws IOException { FileInputStream in = new FileInputStream ( path ) ; try { Properties properties = new Properties ( ) ; properties . load ( in ) ; Properties systemProperties = System . getProperties ( ) ; Enumeration < ? > e = systemProperties . propertyNames ( ) ; while ( e . hasMoreElements ( ) ) { String key = ( String ) e . nextElement ( ) ; String newValue = systemProperties . getProperty ( key ) ; String oldValue = ( String ) properties . setProperty ( key , newValue ) ; if ( oldValue != null ) { console . println ( "<STR_LIT>" + key + "<STR_LIT>" + oldValue + "<STR_LIT>" + newValue + "<STR_LIT:'>" ) ; } } return new PropertyInstallAction ( installData , uninstallDataWriter , properties ) ; } finally { FileUtils . close ( in ) ; } } } </s>
<s> package com . izforge . izpack . event ; import java . io . File ; import java . util . List ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . event . InstallerListener ; import com . izforge . izpack . api . event . ProgressListener ; import com . izforge . izpack . api . event . ProgressNotifiers ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . api . handler . AbstractUIProgressHandler ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . util . helper . SpecHelper ; @ Deprecated public class SimpleInstallerListener implements InstallerListener { protected static final String LANG_FILE_NAME = "<STR_LIT>" ; private Messages messages ; private AutomatedInstallData installData = null ; private SpecHelper specHelper = null ; private final Resources resources ; private final ProgressNotifiers notifiers ; private AbstractUIProgressHandler handler ; public SimpleInstallerListener ( Resources resources ) { this ( resources , null , false ) ; } public SimpleInstallerListener ( Resources resources , ProgressNotifiers notifiers ) { this ( resources , notifiers , false ) ; } public SimpleInstallerListener ( Resources resources , boolean useSpecHelper ) { this ( resources , null , useSpecHelper ) ; } public SimpleInstallerListener ( Resources resources , ProgressNotifiers notifiers , boolean useSpecHelper ) { super ( ) ; if ( useSpecHelper ) { setSpecHelper ( new SpecHelper ( resources ) ) ; } this . resources = resources ; this . notifiers = notifiers ; } public void setHandler ( AbstractUIProgressHandler handler ) { this . handler = handler ; } @ Override public void initialise ( ) { try { afterInstallerInitialization ( installData ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforePacks ( List < Pack > packs ) { try { beforePacks ( installData , packs . size ( ) , handler ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforePack ( Pack pack , int index ) { try { beforePack ( pack , index , handler ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterPack ( Pack pack , int index ) { try { afterPack ( pack , index , handler ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterPacks ( List < Pack > packs , ProgressListener listener ) { try { afterPacks ( installData , handler ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforeDir ( File dir , PackFile packFile , Pack pack ) { try { beforeDir ( dir , packFile ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterDir ( File dir , PackFile packFile , Pack pack ) { try { afterDir ( dir , packFile ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void beforeFile ( File file , PackFile packFile , Pack pack ) { try { beforeFile ( file , packFile ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } @ Override public void afterFile ( File file , PackFile packFile , Pack pack ) { try { afterFile ( file , packFile ) ; } catch ( IzPackException exception ) { throw exception ; } catch ( Exception exception ) { throw new IzPackException ( exception ) ; } } public void afterFile ( File file , PackFile pf ) throws Exception { } public void afterDir ( File dir , PackFile pf ) throws Exception { } public void afterPacks ( AutomatedInstallData idata , AbstractUIProgressHandler handler ) throws Exception { } public void afterPack ( Pack pack , Integer i , AbstractUIProgressHandler handler ) throws Exception { } public void beforePacks ( AutomatedInstallData idata , Integer npacks , AbstractUIProgressHandler handler ) throws Exception { } public void beforePack ( Pack pack , Integer i , AbstractUIProgressHandler handler ) throws Exception { } public boolean isFileListener ( ) { return false ; } public void beforeFile ( File file , PackFile pf ) throws Exception { } public void beforeDir ( File dir , PackFile pf ) throws Exception { } public void afterInstallerInitialization ( AutomatedInstallData data ) throws Exception { } public SpecHelper getSpecHelper ( ) { return specHelper ; } public void setSpecHelper ( SpecHelper helper ) { specHelper = helper ; } public AutomatedInstallData getInstalldata ( ) { return installData ; } public void setInstalldata ( AutomatedInstallData data ) { installData = data ; messages = installData . getMessages ( ) ; } protected ProgressNotifiers getNotifiers ( ) { return notifiers ; } protected int getProgressBarCallerId ( ) { return notifiers != null ? notifiers . indexOf ( this ) + <NUM_LIT:1> : <NUM_LIT:0> ; } protected void setProgressBarCaller ( ) { if ( notifiers != null ) { notifiers . addNotifier ( this ) ; } } protected boolean informProgressBar ( ) { return notifiers != null && notifiers . notifyProgress ( ) ; } protected String getMsg ( String id ) { return ( messages != null ) ? messages . get ( id ) : id ; } protected Resources getResources ( ) { return resources ; } } </s>
<s> package com . izforge . izpack . util . xml ; import com . izforge . izpack . api . adaptator . IXMLElement ; public class XMLHelper { public final static String YES = "<STR_LIT>" ; public final static String NO = "<STR_LIT>" ; public final static String TRUE = "<STR_LIT>" ; public final static String FALSE = "<STR_LIT>" ; public final static String ON = "<STR_LIT>" ; public final static String OFF = "<STR_LIT>" ; public final static String _1 = "<STR_LIT:1>" ; public final static String _0 = "<STR_LIT:0>" ; public XMLHelper ( ) { super ( ) ; } public static boolean attributeIsTrue ( IXMLElement element , String name ) { String value = element . getAttribute ( name , "<STR_LIT>" ) . toUpperCase ( ) ; if ( value . equals ( YES ) ) { return ( true ) ; } else if ( value . equals ( TRUE ) ) { return ( true ) ; } else if ( value . equals ( ON ) ) { return ( true ) ; } else if ( value . equals ( _1 ) ) { return ( true ) ; } return ( false ) ; } public static boolean attributeIsFalse ( IXMLElement element , String name ) { String value = element . getAttribute ( name , "<STR_LIT>" ) . toUpperCase ( ) ; if ( value . equals ( "<STR_LIT>" ) ) { return ( true ) ; } else if ( value . equals ( "<STR_LIT>" ) ) { return ( true ) ; } else if ( value . equals ( "<STR_LIT>" ) ) { return ( true ) ; } else if ( value . equals ( "<STR_LIT:0>" ) ) { return ( true ) ; } return ( false ) ; } } </s>
<s> package com . izforge . izpack . util ; import javax . swing . event . HyperlinkEvent ; import javax . swing . event . HyperlinkListener ; public class HyperlinkHandler implements HyperlinkListener { public void hyperlinkUpdate ( HyperlinkEvent e ) { try { if ( e . getEventType ( ) == HyperlinkEvent . EventType . ACTIVATED ) { String urls = e . getURL ( ) . toExternalForm ( ) ; if ( com . izforge . izpack . util . OsVersion . IS_OSX ) { Runtime . getRuntime ( ) . exec ( "<STR_LIT>" + urls ) ; } else if ( com . izforge . izpack . util . OsVersion . IS_UNIX ) { String [ ] launchers = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; for ( String launcher : launchers ) { try { Runtime . getRuntime ( ) . exec ( launcher . replaceAll ( "<STR_LIT>" , urls ) ) ; System . out . println ( "<STR_LIT:OK>" ) ; break ; } catch ( Exception ignore ) { System . out . println ( launcher + "<STR_LIT>" ) ; } } } else { Runtime . getRuntime ( ) . exec ( "<STR_LIT>" + urls ) ; } } } catch ( Exception err ) { err . printStackTrace ( ) ; } } } </s>
<s> package com . izforge . izpack . util . os ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . NativeLibraryClient ; import java . io . IOException ; public class WinSetupAPIBase implements NativeLibraryClient { protected static final int INVALID_HANDLE_VALUE = - <NUM_LIT:1> ; public static final int SP_COPY_DELETESOURCE = <NUM_LIT> ; public static final int SP_COPY_REPLACEONLY = <NUM_LIT> ; public static final int SP_COPY_NEWER = <NUM_LIT> ; public static final int SP_COPY_NEWER_OR_SAME = SP_COPY_NEWER ; public static final int SP_COPY_NOOVERWRITE = <NUM_LIT> ; public static final int SP_COPY_NODECOMP = <NUM_LIT> ; public static final int SP_COPY_LANGUAGEAWARE = <NUM_LIT> ; public static final int SP_COPY_SOURCE_ABSOLUTE = <NUM_LIT> ; public static final int SP_COPY_SOURCEPATH_ABSOLUTE = <NUM_LIT> ; public static final int SP_COPY_IN_USE_NEEDS_REBOOT = <NUM_LIT> ; public static final int SP_COPY_FORCE_IN_USE = <NUM_LIT> ; public static final int SP_COPY_NOSKIP = <NUM_LIT> ; public static final int SP_FLAG_CABINETCONTINUATION = <NUM_LIT> ; public static final int SP_COPY_FORCE_NOOVERWRITE = <NUM_LIT> ; public static final int SP_COPY_FORCE_NEWER = <NUM_LIT> ; public static final int SP_COPY_WARNIFSKIP = <NUM_LIT> ; public static final int SP_COPY_NOBROWSE = <NUM_LIT> ; public static final int SP_COPY_NEWER_ONLY = <NUM_LIT> ; public static final int SP_COPY_SOURCE_SIS_MASTER = <NUM_LIT> ; public static final int SP_COPY_OEMINF_CATALOG_ONLY = <NUM_LIT> ; public static final int SP_COPY_REPLACE_BOOT_FILE = <NUM_LIT> ; public static final int SP_COPY_NOPRUNE = <NUM_LIT> ; public static final int SPFILEQ_FILE_IN_USE = <NUM_LIT> ; public static final int SPFILEQ_REBOOT_RECOMMENDED = <NUM_LIT> ; public static final int SPFILEQ_REBOOT_IN_PROGRESS = <NUM_LIT> ; public WinSetupAPIBase ( Librarian librarian ) { try { librarian . loadLibrary ( "<STR_LIT>" , this ) ; } catch ( UnsatisfiedLinkError error ) { throw new IzPackException ( "<STR_LIT>" , error ) ; } } public void freeLibrary ( String name ) { } ; protected native int SetupOpenFileQueue ( Object handler ) throws IOException ; protected native void SetupCloseFileQueue ( int queuehandle ) ; protected native void SetupQueueCopy ( int queuehandle , String SourceRootPath , String SourcePath , String SourceFileName , String SourceDescription , String SourceTagFile , String TargetDirectory , String TargetFileName , int CopyStyle ) throws IOException ; protected native void SetupQueueDelete ( int queuehandle , String PathPart1 , String PathPart2 ) throws IOException ; protected native void SetupQueueRename ( int queuehandle , String SourcePath , String SourceFileName , String TargetPath , String TargetFileName ) throws IOException ; protected native boolean SetupCommitFileQueue ( int queuehandle ) throws IOException ; protected native int SetupPromptReboot ( int queuehandle , boolean scanonly ) throws IOException ; } </s>
<s> package com . izforge . izpack . util . os ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; public class FileQueueCopy implements FileQueueOperation { private static final Logger logger = Logger . getLogger ( FileQueueCopy . class . getName ( ) ) ; protected File fromFile = null ; protected File toFile = null ; protected int copyStyle = WinSetupAPIBase . SP_COPY_NOOVERWRITE ; public FileQueueCopy ( File fromFile , File toFile ) { this ( fromFile , toFile , false , false ) ; } public FileQueueCopy ( File fromFile , File toFile , boolean deleteSource , boolean forceInUse ) { this . fromFile = fromFile ; this . toFile = toFile ; setDeleteSource ( deleteSource ) ; setForceInUse ( forceInUse ) ; } public void setDeleteSource ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_DELETESOURCE ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_DELETESOURCE ) ; } } public void setForceInUse ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_FORCE_IN_USE ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_FORCE_IN_USE ) ; } } public void setInUseNeedsReboot ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_IN_USE_NEEDS_REBOOT ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_IN_USE_NEEDS_REBOOT ) ; } } public void setLanguageAware ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_LANGUAGEAWARE ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_LANGUAGEAWARE ) ; } } public void setNewerOrSame ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_NEWER_OR_SAME ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_NEWER_OR_SAME ) ; } } public void setNewerOnly ( boolean flag ) { if ( flag ) { this . copyStyle &= WinSetupAPIBase . SP_COPY_NEWER_ONLY ; } } public void setReplaceOnly ( boolean flag ) { if ( flag ) { this . copyStyle |= WinSetupAPIBase . SP_COPY_REPLACEONLY ; } else { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_REPLACEONLY ) ; } } public void setOverwrite ( boolean flag ) { if ( flag ) { this . copyStyle &= ( ~ WinSetupAPIBase . SP_COPY_NOOVERWRITE ) ; } else { this . copyStyle |= WinSetupAPIBase . SP_COPY_NOOVERWRITE ; } } public void addTo ( WinSetupFileQueue filequeue ) throws IOException { if ( fromFile . equals ( toFile ) ) { logger . warning ( "<STR_LIT>" + fromFile ) ; } else { try { logger . fine ( "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile + "<STR_LIT>" + Integer . toHexString ( copyStyle ) + "<STR_LIT:)>" ) ; filequeue . addCopy ( fromFile , toFile , copyStyle ) ; } catch ( IOException ioe ) { String msg = "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile + "<STR_LIT>" + ioe . getMessage ( ) ; throw new IOException ( msg ) ; } } } } </s>
<s> package com . izforge . izpack . util . os ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . StringTool ; import java . io . File ; import java . io . UnsupportedEncodingException ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; public class Win_Shortcut extends Shortcut { private static final Logger logger = Logger . getLogger ( Win_Shortcut . class . getName ( ) ) ; private ShellLink shortcut ; private final Librarian librarian ; public Win_Shortcut ( Librarian librarian ) { this . librarian = librarian ; } @ Override public void initialize ( int type , String name ) throws Exception { switch ( type ) { case APPLICATIONS : { shortcut = new ShellLink ( ShellLink . PROGRAM_MENU , name , librarian ) ; break ; } case START_MENU : { shortcut = new ShellLink ( ShellLink . START_MENU , name , librarian ) ; break ; } case DESKTOP : { shortcut = new ShellLink ( ShellLink . DESKTOP , name , librarian ) ; break ; } case START_UP : { shortcut = new ShellLink ( ShellLink . STARTUP , name , librarian ) ; break ; } default : { shortcut = new ShellLink ( ShellLink . PROGRAM_MENU , name , librarian ) ; break ; } } } @ Override public String getBasePath ( ) throws Exception { String result = shortcut . getLinkPath ( shortcut . getUserType ( ) ) ; return result ; } @ Override public List < String > getProgramGroups ( int userType ) { int type = ShellLink . CURRENT_USER ; if ( userType == ALL_USERS ) { type = ShellLink . ALL_USERS ; } else { type = ShellLink . CURRENT_USER ; } String linkPath = shortcut . getLinkPath ( type ) ; if ( linkPath == null ) { return ( new ArrayList < String > ( ) ) ; } File path = new File ( linkPath ) ; File [ ] file = path . listFiles ( ) ; List < String > groups = new ArrayList < String > ( ) ; if ( file != null ) { for ( File aFile : file ) { String aFilename = aFile . getName ( ) ; if ( aFile . isDirectory ( ) ) { groups . add ( aFilename ) ; } } } return groups ; } @ Override public String getFileName ( ) { String aFilename = shortcut . getFileName ( ) ; return aFilename ; } @ Override public String getDirectoryCreated ( ) { String directoryCreated = shortcut . getDirectoryCreated ( ) ; return ( directoryCreated ) ; } @ Override public boolean multipleUsers ( ) { boolean result = false ; String allUsers = shortcut . getallUsersLinkPath ( ) ; String currentUsers = shortcut . getcurrentUserLinkPath ( ) ; if ( allUsers == null || currentUsers == null ) { result = false ; } else { result = allUsers . length ( ) > <NUM_LIT:0> && currentUsers . length ( ) > <NUM_LIT:0> ; } return result ; } @ Override public boolean supported ( ) { return true ; } @ Override public void setArguments ( String arguments ) { shortcut . setArguments ( arguments ) ; } @ Override public void setDescription ( String description ) { shortcut . setDescription ( description ) ; } @ Override public void setIconLocation ( String path , int index ) { shortcut . setIconLocation ( path , index ) ; } @ Override public String getIconLocation ( ) { return shortcut . getIconLocation ( ) ; } @ Override public void setProgramGroup ( String groupName ) { shortcut . setProgramGroup ( groupName ) ; } @ Override public void setShowCommand ( int show ) throws IllegalArgumentException { switch ( show ) { case HIDE : { shortcut . setShowCommand ( ShellLink . MINNOACTIVE ) ; break ; } case NORMAL : { shortcut . setShowCommand ( ShellLink . NORMAL ) ; break ; } case MINIMIZED : { shortcut . setShowCommand ( ShellLink . MINNOACTIVE ) ; break ; } case MAXIMIZED : { shortcut . setShowCommand ( ShellLink . MAXIMIZED ) ; break ; } default : { throw ( new IllegalArgumentException ( show + "<STR_LIT>" ) ) ; } } } @ Override public int getShowCommand ( ) { int showCommand = shortcut . getShowCommand ( ) ; switch ( showCommand ) { case ShellLink . NORMAL : showCommand = NORMAL ; break ; case ShellLink . MINNOACTIVE : case ShellLink . MINIMIZED : showCommand = MINIMIZED ; break ; case ShellLink . MAXIMIZED : showCommand = MAXIMIZED ; break ; default : break ; } return showCommand ; } @ Override public void setTargetPath ( String path ) { shortcut . setTargetPath ( path ) ; } @ Override public void setWorkingDirectory ( String dir ) { shortcut . setWorkingDirectory ( dir ) ; } @ Override public String getWorkingDirectory ( ) { String result = shortcut . getWorkingDirectory ( ) ; return result ; } @ Override public void setLinkName ( String name ) { shortcut . setLinkName ( name ) ; } @ Override public int getLinkType ( ) { int typ = shortcut . getLinkType ( ) ; switch ( typ ) { case ShellLink . DESKTOP : typ = DESKTOP ; break ; case ShellLink . PROGRAM_MENU : typ = APPLICATIONS ; break ; case ShellLink . START_MENU : typ = START_MENU ; break ; case ShellLink . STARTUP : typ = START_UP ; break ; default : break ; } return typ ; } @ Override public void setLinkType ( int type ) throws IllegalArgumentException , UnsupportedEncodingException { switch ( type ) { case DESKTOP : { shortcut . setLinkType ( ShellLink . DESKTOP ) ; break ; } case APPLICATIONS : { shortcut . setLinkType ( ShellLink . PROGRAM_MENU ) ; break ; } case START_MENU : { shortcut . setLinkType ( ShellLink . START_MENU ) ; break ; } case START_UP : { shortcut . setLinkType ( ShellLink . STARTUP ) ; break ; } default : { throw ( new IllegalArgumentException ( type + "<STR_LIT>" ) ) ; } } } @ Override public int getUserType ( ) { int utype = shortcut . getUserType ( ) ; switch ( utype ) { case ShellLink . ALL_USERS : utype = ALL_USERS ; break ; case ShellLink . CURRENT_USER : utype = CURRENT_USER ; break ; } return utype ; } @ Override public void setUserType ( int type ) { if ( type == CURRENT_USER ) { if ( shortcut . getcurrentUserLinkPath ( ) . length ( ) > <NUM_LIT:0> ) { shortcut . setUserType ( ShellLink . CURRENT_USER ) ; } } else if ( type == ALL_USERS ) { if ( shortcut . getallUsersLinkPath ( ) . length ( ) > <NUM_LIT:0> ) { shortcut . setUserType ( ShellLink . ALL_USERS ) ; } } } @ Override public void save ( ) throws Exception { shortcut . save ( ) ; } @ Override public int getHotkey ( ) { int result = shortcut . getHotkey ( ) ; return result ; } @ Override public void setHotkey ( int hotkey ) { shortcut . setHotkey ( hotkey ) ; } @ Override public String getProgramsFolder ( int current_user ) { int USER = <NUM_LIT:0> ; if ( current_user == Shortcut . CURRENT_USER ) { USER = ShellLink . CURRENT_USER ; } else if ( current_user == Shortcut . ALL_USERS ) { USER = ShellLink . ALL_USERS ; } String result = null ; try { result = new String ( shortcut . getLinkPath ( USER ) . getBytes ( StringTool . getPlatformEncoding ( ) ) , StringTool . getPlatformEncoding ( ) ) ; } catch ( UnsupportedEncodingException e ) { logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; } return result ; } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . UnsupportedEncodingException ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . List ; import java . util . Properties ; import java . util . StringTokenizer ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . ResourceNotFoundException ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . util . FileExecutor ; import com . izforge . izpack . util . StringTool ; import com . izforge . izpack . util . unix . ShellScript ; import com . izforge . izpack . util . unix . UnixHelper ; import com . izforge . izpack . util . unix . UnixUser ; import com . izforge . izpack . util . unix . UnixUsers ; public class Unix_Shortcut extends Shortcut implements Unix_ShortcutConstants { private static final Logger logger = Logger . getLogger ( Unix_Shortcut . class . getName ( ) ) ; private static String version = "<STR_LIT>" ; private static String rev = "<STR_LIT>" ; private static String DESKTOP_EXT = "<STR_LIT>" ; private static String template = "<STR_LIT>" ; private final static String N = "<STR_LIT:n>" ; private final static String H = "<STR_LIT:#>" ; private final static String S = "<STR_LIT:U+0020>" ; private final static String C = H + S ; private final static String QM = "<STR_LIT:\">" ; private int ShortcutType ; private static ShellScript rootScript = null ; private static ShellScript uninstallScript = null ; private List < UnixUser > users ; private String createdDirectory ; private int itsUserType ; private String itsGroupName ; private String itsName ; private String itsFileName ; private Properties props ; public StringBuffer hlp ; public ShellScript myInstallScript ; public final String FS = File . separator ; public final String myHome = System . getProperty ( "<STR_LIT>" ) ; private String su ; private String xdgDesktopIconCmd ; private String myXdgDesktopIconScript ; private String myXdgDesktopIconCmd ; private final Resources resources ; private final InstallData installData ; public Unix_Shortcut ( Resources resources , InstallData installData ) { this . resources = resources ; this . installData = installData ; hlp = new StringBuffer ( ) ; String userLanguage = System . getProperty ( "<STR_LIT>" , "<STR_LIT:en>" ) ; hlp . append ( "<STR_LIT>" + N ) ; hlp . append ( "<STR_LIT>" + $Categories + N ) ; hlp . append ( "<STR_LIT>" + $Comment + N ) ; hlp . append ( "<STR_LIT>" ) . append ( userLanguage ) . append ( "<STR_LIT>" + $Comment + N ) ; hlp . append ( "<STR_LIT>" + $Encoding + N ) ; hlp . append ( "<STR_LIT>" + $E_QUOT + $Exec + $E_QUOT + S + $Arguments + N ) ; hlp . append ( "<STR_LIT>" + $GenericName + N ) ; hlp . append ( "<STR_LIT>" ) . append ( userLanguage ) . append ( "<STR_LIT>" + $GenericName + N ) ; hlp . append ( "<STR_LIT>" + $Icon + N ) ; hlp . append ( "<STR_LIT>" + $MimeType + N ) ; hlp . append ( "<STR_LIT>" + $Name + N ) ; hlp . append ( "<STR_LIT>" ) . append ( userLanguage ) . append ( "<STR_LIT>" + $Name + N ) ; hlp . append ( "<STR_LIT>" + $P_QUOT + $Path + $P_QUOT + N ) ; hlp . append ( "<STR_LIT>" + $ServiceTypes + N ) ; hlp . append ( "<STR_LIT>" + $SwallowExec + N ) ; hlp . append ( "<STR_LIT>" + $SwallowTitle + N ) ; hlp . append ( "<STR_LIT>" + $Terminal + N ) ; hlp . append ( "<STR_LIT>" + $Options_For_Terminal + N ) ; hlp . append ( "<STR_LIT>" + $Type + N ) ; hlp . append ( "<STR_LIT>" + $URL + N ) ; hlp . append ( "<STR_LIT>" + $X_KDE_SubstituteUID + N ) ; hlp . append ( "<STR_LIT>" + $X_KDE_Username + N ) ; hlp . append ( N ) ; hlp . append ( C + "<STR_LIT>" + S ) . append ( getClass ( ) . getName ( ) ) . append ( S ) . append ( rev ) . append ( N ) ; hlp . append ( C ) . append ( version ) ; template = hlp . toString ( ) ; props = new Properties ( ) ; initProps ( ) ; if ( rootScript == null ) { rootScript = new ShellScript ( ) ; } if ( uninstallScript == null ) { uninstallScript = new ShellScript ( ) ; } if ( myInstallScript == null ) { myInstallScript = new ShellScript ( ) ; } } private void initProps ( ) { String [ ] propsArray = { $Comment , $$LANG_Comment , $Encoding , $Exec , $Arguments , $GenericName , $$LANG_GenericName , $MimeType , $Name , $$LANG_Name , $Path , $ServiceTypes , $SwallowExec , $SwallowTitle , $Terminal , $Options_For_Terminal , $Type , $X_KDE_SubstituteUID , $X_KDE_Username , $Icon , $URL , $E_QUOT , $P_QUOT , $Categories , $TryExec } ; for ( String aPropsArray : propsArray ) { props . put ( aPropsArray , "<STR_LIT>" ) ; } } @ Override public void initialize ( int aType , String aName ) throws Exception { this . itsName = aName ; props . put ( $Name , aName ) ; } @ Override public boolean supported ( ) { return true ; } @ Override public String getDirectoryCreated ( ) { return this . createdDirectory ; } @ Override public String getFileName ( ) { return ( this . itsFileName ) ; } @ Override public List < String > getProgramGroups ( int userType ) { List < String > groups = new ArrayList < String > ( ) ; File kdeShareApplnk = getKdeShareApplnkFolder ( userType ) ; try { File [ ] listing = kdeShareApplnk . listFiles ( ) ; for ( File aListing : listing ) { if ( aListing . isDirectory ( ) ) { groups . add ( aListing . getName ( ) ) ; } } } catch ( Exception e ) { } return ( groups ) ; } @ Override public String getProgramsFolder ( int current_user ) { String result = "<STR_LIT>" ; result = getKdeShareApplnkFolder ( current_user ) . toString ( ) ; return result ; } private File getKdeShareApplnkFolder ( int userType ) { if ( userType == Shortcut . ALL_USERS ) { return new File ( File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ) ; } else { return new File ( System . getProperty ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ) ; } } @ Override public boolean multipleUsers ( ) { return ( true ) ; } @ Override public void save ( ) throws Exception { String target = null ; String shortCutDef = this . replace ( ) ; boolean rootUser4All = this . getUserType ( ) == Shortcut . ALL_USERS ; boolean create4All = this . getCreateForAll ( ) ; if ( "<STR_LIT>" . equals ( this . itsGroupName ) && ( this . getLinkType ( ) == Shortcut . DESKTOP ) ) { this . itsFileName = target ; File shortCutLocation = null ; File ApplicationShortcutPath ; String ApplicationShortcutPathName = installData . getVariable ( "<STR_LIT>" ) ; if ( null != ApplicationShortcutPathName && ! ApplicationShortcutPathName . equals ( "<STR_LIT>" ) ) { ApplicationShortcutPath = new File ( ApplicationShortcutPathName ) ; if ( ApplicationShortcutPath . isAbsolute ( ) ) { if ( ! ApplicationShortcutPath . exists ( ) && ApplicationShortcutPath . mkdirs ( ) && ApplicationShortcutPath . canWrite ( ) ) { shortCutLocation = ApplicationShortcutPath ; } if ( ApplicationShortcutPath . exists ( ) && ApplicationShortcutPath . isDirectory ( ) && ApplicationShortcutPath . canWrite ( ) ) { shortCutLocation = ApplicationShortcutPath ; } } else { File relativePath = new File ( installData . getInstallPath ( ) + FS + ApplicationShortcutPath ) ; relativePath . mkdirs ( ) ; shortCutLocation = new File ( relativePath . toString ( ) ) ; } } else { shortCutLocation = new File ( installData . getInstallPath ( ) ) ; } File writtenDesktopFile = writeAppShortcutWithOutSpace ( shortCutLocation . toString ( ) , this . itsName , shortCutDef ) ; uninstaller . addFile ( writtenDesktopFile . toString ( ) , true ) ; String cmd = getXdgDesktopIconCmd ( ) ; if ( cmd != null ) { createExtXdgDesktopIconCmd ( shortCutLocation ) ; myInstallScript . appendln ( new String [ ] { myXdgDesktopIconCmd , "<STR_LIT>" , "<STR_LIT>" , StringTool . escapeSpaces ( writtenDesktopFile . toString ( ) ) } ) ; ShellScript myUninstallScript = new ShellScript ( ) ; myUninstallScript . appendln ( new String [ ] { myXdgDesktopIconCmd , "<STR_LIT>" , "<STR_LIT>" , StringTool . escapeSpaces ( writtenDesktopFile . toString ( ) ) } ) ; uninstaller . addUninstallScript ( myUninstallScript . getContentAsString ( ) ) ; } else { File myDesktopFile ; do { myDesktopFile = new File ( myHome + FS + "<STR_LIT>" + writtenDesktopFile . getName ( ) + "<STR_LIT:->" + System . currentTimeMillis ( ) + DESKTOP_EXT ) ; } while ( myDesktopFile . exists ( ) ) ; copyTo ( writtenDesktopFile , myDesktopFile ) ; uninstaller . addFile ( myDesktopFile . toString ( ) , true ) ; } if ( rootUser4All && create4All ) { if ( cmd != null ) { installDesktopFileToAllUsersDesktop ( writtenDesktopFile ) ; } else { copyDesktopFileToAllUsersDesktop ( writtenDesktopFile ) ; } } } else { if ( rootUser4All && create4All ) { { File theIcon = new File ( this . getIconLocation ( ) ) ; File commonIcon = new File ( "<STR_LIT>" + theIcon . getName ( ) ) ; try { copyTo ( theIcon , commonIcon ) ; uninstaller . addFile ( commonIcon . toString ( ) , true ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + theIcon + "<STR_LIT:U+0020toU+0020>" + commonIcon + "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT>" , e ) ; } this . itsFileName = target ; File writtenFile = writeAppShortcut ( "<STR_LIT>" , this . itsName , shortCutDef ) ; setWrittenFileName ( writtenFile . getName ( ) ) ; uninstaller . addFile ( writtenFile . toString ( ) , true ) ; } } else { String localApps = myHome + "<STR_LIT>" ; String localPixmaps = myHome + "<STR_LIT>" ; try { java . io . File file = new java . io . File ( localApps ) ; file . mkdirs ( ) ; file = new java . io . File ( localPixmaps ) ; file . mkdirs ( ) ; } catch ( Exception ignore ) { logger . warning ( "<STR_LIT>" + localApps + "<STR_LIT>" + localPixmaps ) ; } File theIcon = new File ( this . getIconLocation ( ) ) ; File commonIcon = new File ( localPixmaps + theIcon . getName ( ) ) ; try { copyTo ( theIcon , commonIcon ) ; uninstaller . addFile ( commonIcon . toString ( ) , true ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + theIcon + "<STR_LIT:U+0020toU+0020>" + commonIcon + "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT>" , e ) ; } this . itsFileName = target ; File writtenFile = writeAppShortcut ( localApps , this . itsName , shortCutDef ) ; setWrittenFileName ( writtenFile . getName ( ) ) ; uninstaller . addFile ( writtenFile . toString ( ) , true ) ; } } } public void createExtXdgDesktopIconCmd ( File shortCutLocation ) throws IOException , ResourceNotFoundException { ShellScript myXdgDesktopIconScript = new ShellScript ( null ) ; String lines = "<STR_LIT>" ; lines = resources . getString ( "<STR_LIT>" , null ) ; myXdgDesktopIconScript . append ( lines ) ; myXdgDesktopIconCmd = new String ( shortCutLocation + FS + "<STR_LIT>" ) ; myXdgDesktopIconScript . write ( myXdgDesktopIconCmd ) ; FileExecutor . getExecOutput ( new String [ ] { UnixHelper . getCustomCommand ( "<STR_LIT>" ) , "<STR_LIT>" , myXdgDesktopIconCmd } , true ) ; } private void installDesktopFileToAllUsersDesktop ( File writtenDesktopFile ) { for ( UnixUser user : getUsers ( ) ) { if ( user . getHome ( ) . equals ( myHome ) ) { logger . info ( "<STR_LIT>" + user . getHome ( ) + "<STR_LIT>" + myHome ) ; continue ; } try { rootScript . append ( new String [ ] { getSuCommand ( ) , user . getName ( ) , "<STR_LIT>" } ) ; rootScript . appendln ( new String [ ] { "<STR_LIT:\">" + myXdgDesktopIconCmd , "<STR_LIT>" , "<STR_LIT>" , StringTool . escapeSpaces ( writtenDesktopFile . toString ( ) ) + "<STR_LIT:\">" } ) ; uninstallScript . append ( new String [ ] { getSuCommand ( ) , user . getName ( ) , "<STR_LIT>" } ) ; uninstallScript . appendln ( new String [ ] { "<STR_LIT:\">" + myXdgDesktopIconCmd , "<STR_LIT>" , "<STR_LIT>" , StringTool . escapeSpaces ( writtenDesktopFile . toString ( ) ) + "<STR_LIT:\">" } ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; } } logger . fine ( "<STR_LIT>" ) ; logger . fine ( rootScript . getContentAsString ( ) ) ; } private String getSuCommand ( ) { if ( su == null ) { su = UnixHelper . getSuCommand ( ) ; } return su ; } private String getXdgDesktopIconCmd ( ) { if ( xdgDesktopIconCmd == null ) { xdgDesktopIconCmd = UnixHelper . getCustomCommand ( "<STR_LIT>" ) ; } return xdgDesktopIconCmd ; } private List < UnixUser > getUsers ( ) { if ( users == null ) { users = UnixUsers . getUsersWithValidShellsExistingHomesAndDesktops ( ) ; } return users ; } private void copyDesktopFileToAllUsersDesktop ( File writtenDesktopFile ) throws IOException { String chmod = UnixHelper . getCustomCommand ( "<STR_LIT>" ) ; String chown = UnixHelper . getCustomCommand ( "<STR_LIT>" ) ; String rm = UnixHelper . getRmCommand ( ) ; String copy = UnixHelper . getCpCommand ( ) ; File dest = null ; File tempFile = File . createTempFile ( this . getClass ( ) . getName ( ) , Long . toString ( System . currentTimeMillis ( ) ) + "<STR_LIT>" ) ; copyTo ( writtenDesktopFile , tempFile ) ; FileExecutor . getExecOutput ( new String [ ] { chmod , "<STR_LIT>" , tempFile . toString ( ) } ) ; for ( UnixUser user : getUsers ( ) ) { if ( user . getHome ( ) . equals ( myHome ) ) { logger . info ( "<STR_LIT>" + user . getHome ( ) + "<STR_LIT>" + myHome ) ; continue ; } try { dest = new File ( user . getHome ( ) + FS + "<STR_LIT>" + FS + writtenDesktopFile . getName ( ) ) ; rootScript . append ( getSuCommand ( ) ) ; rootScript . append ( S ) ; rootScript . append ( user . getName ( ) ) ; rootScript . append ( S ) ; rootScript . append ( "<STR_LIT>" ) ; rootScript . append ( S ) ; rootScript . append ( '<CHAR_LIT:">' ) ; rootScript . append ( copy ) ; rootScript . append ( S ) ; rootScript . append ( tempFile . toString ( ) ) ; rootScript . append ( S ) ; rootScript . append ( StringTool . replace ( dest . toString ( ) , "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; rootScript . appendln ( '<CHAR_LIT:">' ) ; rootScript . append ( '<STR_LIT:\n>' ) ; rootScript . append ( chown ) ; rootScript . append ( S ) ; rootScript . append ( user . getName ( ) ) ; rootScript . append ( S ) ; rootScript . appendln ( StringTool . replace ( dest . toString ( ) , "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; rootScript . append ( '<STR_LIT:\n>' ) ; rootScript . append ( '<STR_LIT:\n>' ) ; uninstallScript . append ( getSuCommand ( ) ) ; uninstallScript . append ( S ) ; uninstallScript . append ( user . getName ( ) ) ; uninstallScript . append ( S ) ; uninstallScript . append ( "<STR_LIT>" ) ; uninstallScript . append ( S ) ; uninstallScript . append ( '<CHAR_LIT:">' ) ; uninstallScript . append ( rm ) ; uninstallScript . append ( S ) ; uninstallScript . append ( StringTool . replace ( dest . toString ( ) , "<STR_LIT:U+0020>" , "<STR_LIT>" ) ) ; uninstallScript . appendln ( '<CHAR_LIT:">' ) ; uninstallScript . appendln ( ) ; } catch ( Exception e ) { logger . log ( Level . INFO , "<STR_LIT>" + e . getMessage ( ) , e ) ; } } rootScript . append ( rm ) ; rootScript . append ( S ) ; rootScript . appendln ( tempFile . toString ( ) ) ; rootScript . appendln ( ) ; } @ Override public void execPostAction ( ) { logger . fine ( "<STR_LIT>" ) ; String pseudoUnique = this . getClass ( ) . getName ( ) + Long . toString ( System . currentTimeMillis ( ) ) ; String scriptFilename = null ; try { scriptFilename = File . createTempFile ( pseudoUnique , "<STR_LIT>" ) . toString ( ) ; } catch ( IOException e ) { scriptFilename = System . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) + "<STR_LIT:/>" + pseudoUnique + "<STR_LIT>" ; e . printStackTrace ( ) ; } rootScript . write ( scriptFilename ) ; rootScript . exec ( ) ; rootScript . delete ( ) ; logger . fine ( rootScript . toString ( ) ) ; pseudoUnique = this . getClass ( ) . getName ( ) + Long . toString ( System . currentTimeMillis ( ) ) ; try { scriptFilename = File . createTempFile ( pseudoUnique , "<STR_LIT>" ) . toString ( ) ; } catch ( IOException e ) { scriptFilename = System . getProperty ( "<STR_LIT>" , "<STR_LIT>" ) + "<STR_LIT:/>" + pseudoUnique + "<STR_LIT>" ; e . printStackTrace ( ) ; } myInstallScript . write ( scriptFilename ) ; myInstallScript . exec ( ) ; myInstallScript . delete ( ) ; logger . fine ( myInstallScript . toString ( ) ) ; logger . fine ( uninstallScript . toString ( ) ) ; uninstaller . addUninstallScript ( uninstallScript . getContentAsString ( ) ) ; } public static void copyTo ( File inFile , File outFile ) throws IOException { char [ ] cbuff = new char [ <NUM_LIT> ] ; BufferedReader reader = new BufferedReader ( new FileReader ( inFile ) ) ; BufferedWriter writer = new BufferedWriter ( new FileWriter ( outFile ) ) ; int readBytes = <NUM_LIT:0> ; while ( ( readBytes = reader . read ( cbuff , <NUM_LIT:0> , cbuff . length ) ) != - <NUM_LIT:1> ) { writer . write ( cbuff , <NUM_LIT:0> , readBytes ) ; } reader . close ( ) ; writer . close ( ) ; } private String writtenFileName ; public String getWrittenFileName ( ) { return writtenFileName ; } protected void setWrittenFileName ( String s ) { writtenFileName = s ; } private File writeAppShortcut ( String targetPath , String shortcutName , String shortcutDef ) { return writeAppShortcutWithSimpleSpacehandling ( targetPath , shortcutName , shortcutDef , false ) ; } private File writeAppShortcutWithOutSpace ( String targetPath , String shortcutName , String shortcutDef ) { return writeAppShortcutWithSimpleSpacehandling ( targetPath , shortcutName , shortcutDef , true ) ; } private File writeAppShortcutWithSimpleSpacehandling ( String targetPath , String shortcutName , String shortcutDef , boolean replaceSpacesWithMinus ) { if ( ! ( targetPath . endsWith ( "<STR_LIT:/>" ) || targetPath . endsWith ( "<STR_LIT:\\>" ) ) ) { targetPath += File . separatorChar ; } File shortcutFile ; do { shortcutFile = new File ( targetPath + ( replaceSpacesWithMinus == true ? StringTool . replaceSpacesWithMinus ( shortcutName ) : shortcutName ) + "<STR_LIT:->" + System . currentTimeMillis ( ) + DESKTOP_EXT ) ; } while ( shortcutFile . exists ( ) ) ; FileWriter fileWriter = null ; try { fileWriter = new FileWriter ( shortcutFile ) ; } catch ( IOException e1 ) { System . out . println ( e1 . getMessage ( ) ) ; } try { fileWriter . write ( shortcutDef ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } try { fileWriter . close ( ) ; } catch ( IOException e2 ) { e2 . printStackTrace ( ) ; } return shortcutFile ; } @ Override public void setArguments ( String args ) { props . put ( $Arguments , args ) ; } @ Override public void setDescription ( String description ) { props . put ( $Comment , description ) ; } @ Override public void setIconLocation ( String path , int index ) { props . put ( $Icon , path ) ; } @ Override public void setLinkName ( String aName ) { this . itsName = aName ; props . put ( $Name , aName ) ; } @ Override public void setLinkType ( int aType ) throws IllegalArgumentException , UnsupportedEncodingException { ShortcutType = aType ; } @ Override public void setProgramGroup ( String aGroupName ) { this . itsGroupName = aGroupName ; } @ Override public void setShowCommand ( int show ) { } @ Override public void setTargetPath ( String aPath ) { StringTokenizer whiteSpaceTester = new StringTokenizer ( aPath ) ; if ( whiteSpaceTester . countTokens ( ) > <NUM_LIT:1> ) { props . put ( $E_QUOT , QM ) ; } props . put ( $Exec , aPath ) ; } @ Override public void setUserType ( int aUserType ) { this . itsUserType = aUserType ; } @ Override public void setWorkingDirectory ( String aDirectory ) { StringTokenizer whiteSpaceTester = new StringTokenizer ( aDirectory ) ; if ( whiteSpaceTester . countTokens ( ) > <NUM_LIT:1> ) { props . put ( $P_QUOT , QM ) ; } props . put ( $Path , aDirectory ) ; } @ Override public String toString ( ) { return this . itsName + N + template ; } public String replace ( ) { String result = template ; Enumeration < Object > enumeration = props . keys ( ) ; while ( enumeration . hasMoreElements ( ) ) { String key = ( String ) enumeration . nextElement ( ) ; result = StringTool . replace ( result , key , props . getProperty ( key ) ) ; } return result ; } @ Override public void setEncoding ( String aEncoding ) { props . put ( $Encoding , aEncoding ) ; } @ Override public void setKdeSubstUID ( String trueFalseOrNothing ) { props . put ( $X_KDE_SubstituteUID , trueFalseOrNothing ) ; } @ Override public void setKdeUserName ( String aUserName ) { props . put ( $X_KDE_Username , aUserName ) ; } @ Override public void setMimetype ( String aMimetype ) { props . put ( $MimeType , aMimetype ) ; } @ Override public void setTerminal ( String trueFalseOrNothing ) { props . put ( $Terminal , trueFalseOrNothing ) ; } @ Override public void setTerminalOptions ( String someTerminalOptions ) { props . put ( $Options_For_Terminal , someTerminalOptions ) ; } @ Override public void setType ( String aType ) { props . put ( $Type , aType ) ; } @ Override public void setURL ( String anUrl ) { props . put ( $URL , anUrl ) ; } @ Override public int getUserType ( ) { return itsUserType ; } @ Override public void setCategories ( String theCategories ) { props . put ( $Categories , theCategories ) ; } @ Override public void setTryExec ( String aTryExec ) { props . put ( $TryExec , aTryExec ) ; } @ Override public int getLinkType ( ) { return ShortcutType ; } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; public class FileQueueDelete implements FileQueueOperation { private static final Logger logger = Logger . getLogger ( FileQueueDelete . class . getName ( ) ) ; protected File file ; public FileQueueDelete ( File file ) { this . file = file ; } public FileQueueDelete ( String file ) { this . file = new File ( file ) ; } public void addTo ( WinSetupFileQueue fileQueue ) throws IOException { if ( file != null ) { if ( file . exists ( ) ) { if ( file . isDirectory ( ) ) { logger . warning ( "<STR_LIT>" + file . getAbsolutePath ( ) + "<STR_LIT>" ) ; } else { logger . fine ( "<STR_LIT>" + file . getAbsolutePath ( ) ) ; try { fileQueue . addDelete ( file ) ; } catch ( IOException ioe ) { String msg = "<STR_LIT>" + file + "<STR_LIT>" + ioe . getMessage ( ) ; throw new IOException ( msg ) ; } } } else { logger . warning ( "<STR_LIT>" + file . getAbsolutePath ( ) + "<STR_LIT>" ) ; } } } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; public class FileQueueMove extends FileQueueCopy { private static final Logger logger = Logger . getLogger ( FileQueueMove . class . getName ( ) ) ; public FileQueueMove ( File fromFile , File toFile ) { this ( fromFile , toFile , false ) ; } public FileQueueMove ( File fromFile , File toFile , boolean forceInUse ) { super ( fromFile , toFile , true , forceInUse ) ; } @ Override public void addTo ( WinSetupFileQueue filequeue ) throws IOException { try { logger . fine ( "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile + "<STR_LIT>" + Integer . toHexString ( copyStyle ) + "<STR_LIT:)>" ) ; filequeue . addMove ( fromFile , toFile ) ; } catch ( IOException e ) { throw new IOException ( "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile + "<STR_LIT>" + e . getMessage ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . os ; import com . izforge . izpack . installer . data . UninstallData ; import java . io . UnsupportedEncodingException ; import java . util . List ; public class Shortcut { public static final int APPLICATIONS = <NUM_LIT:1> ; public static final int START_MENU = <NUM_LIT:2> ; public static final int DESKTOP = <NUM_LIT:3> ; public static final int START_UP = <NUM_LIT:4> ; public static final int HIDE = <NUM_LIT:0> ; public static final int NORMAL = <NUM_LIT:1> ; public static final int MINIMIZED = <NUM_LIT:2> ; public static final int MAXIMIZED = <NUM_LIT:3> ; public static final int CURRENT_USER = <NUM_LIT:1> ; public static final int ALL_USERS = <NUM_LIT:2> ; private Boolean createForAll ; protected UninstallData uninstaller ; public void initialize ( int type , String name ) throws Exception { } public String getBasePath ( ) throws Exception { return ( "<STR_LIT>" ) ; } public List < String > getProgramGroups ( int userType ) { return null ; } public String getFileName ( ) { return ( "<STR_LIT>" ) ; } public String getDirectoryCreated ( ) { return ( null ) ; } public boolean multipleUsers ( ) { return ( false ) ; } public boolean supported ( ) { return ( false ) ; } public void setArguments ( String arguments ) { } public void setDescription ( String description ) { } public void setIconLocation ( String path , int index ) { } public String getIconLocation ( ) { return "<STR_LIT>" ; } public void setProgramGroup ( String groupName ) { } public void setShowCommand ( int show ) { } public int getShowCommand ( ) { return Shortcut . NORMAL ; } public void setTargetPath ( String path ) { } public void setWorkingDirectory ( String dir ) { } public String getWorkingDirectory ( ) { return "<STR_LIT>" ; } public void setLinkName ( String name ) { } public int getLinkType ( ) { return Shortcut . DESKTOP ; } public void setLinkType ( int type ) throws IllegalArgumentException , UnsupportedEncodingException { } public void setUserType ( int type ) { } public int getUserType ( ) { return CURRENT_USER ; } public void save ( ) throws Exception { } public int getHotkey ( ) { return <NUM_LIT:0> ; } public void setHotkey ( int hotkey ) { } public void setEncoding ( String string ) { } public void setMimetype ( String string ) { } public void setTerminal ( String string ) { } public void setTerminalOptions ( String string ) { } public void setType ( String string ) { } public void setKdeUserName ( String string ) { } public void setKdeSubstUID ( String string ) { } public void setURL ( String string ) { } public String getProgramsFolder ( int current_user ) { return null ; } public void setCreateForAll ( Boolean aCreateForAll ) { this . createForAll = aCreateForAll ; } public Boolean getCreateForAll ( ) { return createForAll ; } public void setCategories ( String theCategories ) { } public void setTryExec ( String aTryExec ) { } public void setUninstaller ( UninstallData theUninstaller ) { uninstaller = theUninstaller ; } public void execPostAction ( ) { } public void cleanUp ( ) { } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . IOException ; public interface FileQueueOperation { public abstract void addTo ( WinSetupFileQueue filequeue ) throws IOException ; } </s>
<s> package com . izforge . izpack . util . os ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . Librarian ; import java . io . File ; import java . io . IOException ; import java . util . logging . Logger ; public class WinSetupFileQueue extends WinSetupAPIBase { private static final Logger logger = Logger . getLogger ( WinSetupFileQueue . class . getName ( ) ) ; private int reboot = <NUM_LIT:0> ; private int handle = INVALID_HANDLE_VALUE ; public WinSetupFileQueue ( Librarian librarian ) throws Exception { this ( librarian , null ) ; } public WinSetupFileQueue ( Librarian librarian , WinSetupQueueCallbackInterface handler ) throws IOException { super ( librarian ) ; this . handle = SetupOpenFileQueue ( handler ) ; } protected void addCopy ( File sourcefile , File targetfile , int copyStyle ) throws IOException { SetupQueueCopy ( this . handle , sourcefile . getParent ( ) , null , sourcefile . getName ( ) , null , null , targetfile . getParent ( ) , targetfile . getName ( ) , copyStyle ) ; } public void addCopy ( File sourcefile , File targetfile ) throws IOException { addCopy ( sourcefile , targetfile , false ) ; } public void addCopy ( File sourcefile , File targetfile , boolean forceInUse ) throws IOException { int style = <NUM_LIT:0> ; if ( forceInUse ) { style |= SP_COPY_FORCE_IN_USE ; } addCopy ( sourcefile , targetfile , style ) ; } public void addDelete ( File file ) throws IOException { SetupQueueDelete ( this . handle , file . getParent ( ) , file . getName ( ) ) ; } public void addRename ( File sourcefile , File targetfile ) throws IOException { SetupQueueRename ( this . handle , sourcefile . getParent ( ) , sourcefile . getName ( ) , targetfile . getParent ( ) , targetfile . getName ( ) ) ; } public void addMove ( File sourcefile , File targetfile ) throws IOException { addCopy ( sourcefile , targetfile , false ) ; } public void addMove ( File sourcefile , File targetfile , boolean forceInUse ) throws IOException { int style = SP_COPY_DELETESOURCE ; if ( forceInUse ) { style |= SP_COPY_FORCE_IN_USE ; } addCopy ( sourcefile , targetfile , style ) ; } public boolean commit ( ) throws IOException { boolean result = SetupCommitFileQueue ( this . handle ) ; if ( result ) { reboot = SetupPromptReboot ( this . handle , true ) ; if ( ( reboot & SPFILEQ_FILE_IN_USE ) != <NUM_LIT:0> ) { logger . info ( "<STR_LIT>" ) ; } if ( ( reboot & SPFILEQ_REBOOT_RECOMMENDED ) != <NUM_LIT:0> ) { logger . info ( "<STR_LIT>" ) ; } if ( ( reboot & SPFILEQ_REBOOT_IN_PROGRESS ) != <NUM_LIT:0> ) { logger . info ( "<STR_LIT>" ) ; } } return result ; } public void close ( ) { SetupCloseFileQueue ( this . handle ) ; this . handle = INVALID_HANDLE_VALUE ; } public boolean isRebootNecessary ( ) { return reboot > <NUM_LIT:0> ; } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . File ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . util . DefaultTargetPlatformFactory ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . TargetFactory ; public class WinSetupAPIMain { public static void main ( String [ ] args ) { if ( args . length > <NUM_LIT:0> ) { try { ObjectFactory dummy = new ObjectFactory ( ) { @ Override public < T > T create ( Class < T > type , Object ... parameters ) { return null ; } @ Override public < T > T create ( String className , Class < T > superType , Object ... parameters ) { return null ; } } ; Platforms platforms = new Platforms ( ) ; Platform platform = platforms . getCurrentPlatform ( ) ; TargetFactory factory = new TargetFactory ( new DefaultTargetPlatformFactory ( dummy , platform , platforms ) ) ; Librarian librarian = new Librarian ( factory , new Housekeeper ( ) ) ; System . out . println ( "<STR_LIT>" ) ; WinSetupFileQueue fq = new WinSetupFileQueue ( librarian , new WinSetupDefaultCallbackHandler ( ) ) ; String name = args [ <NUM_LIT:0> ] ; char c = name . charAt ( <NUM_LIT:0> ) ; switch ( c ) { case '<CHAR_LIT:c>' : if ( args . length == <NUM_LIT:3> ) { File srcfile = new File ( args [ <NUM_LIT:1> ] ) ; File destfile = new File ( args [ <NUM_LIT:2> ] ) ; System . out . println ( "<STR_LIT>" + args [ <NUM_LIT:1> ] + "<STR_LIT>" + args [ <NUM_LIT:2> ] ) ; fq . addCopy ( srcfile , destfile ) ; } else { usageNotes ( ) ; } break ; case '<CHAR_LIT>' : if ( args . length == <NUM_LIT:3> ) { File srcfile = new File ( args [ <NUM_LIT:1> ] ) ; File destfile = new File ( args [ <NUM_LIT:2> ] ) ; System . out . println ( "<STR_LIT>" + args [ <NUM_LIT:1> ] + "<STR_LIT>" + args [ <NUM_LIT:2> ] ) ; fq . addMove ( srcfile , destfile ) ; } else { usageNotes ( ) ; } break ; case '<CHAR_LIT>' : if ( args . length == <NUM_LIT:2> ) { File file = new File ( args [ <NUM_LIT:1> ] ) ; System . out . println ( "<STR_LIT>" + args [ <NUM_LIT:1> ] ) ; fq . addDelete ( file ) ; } else { usageNotes ( ) ; } break ; default : usageNotes ( ) ; break ; } System . out . println ( "<STR_LIT>" ) ; fq . commit ( ) ; System . out . println ( "<STR_LIT>" ) ; fq . close ( ) ; } catch ( Exception e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } finally { System . exit ( <NUM_LIT:1> ) ; } } else { usageNotes ( ) ; } } private static void usageNotes ( ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; public class WinSetupDefaultCallbackHandler implements WinSetupQueueCallbackInterface { private List < SystemErrorException > exceptions ; public int handleNeedMedia ( String tagfile , String description , String sourcePath , String sourceFile ) { File file = new File ( sourcePath , sourceFile ) ; if ( file . exists ( ) && file . canRead ( ) ) { return FILEOP_RETRY ; } addException ( "<STR_LIT>" + file . getPath ( ) + "<STR_LIT>" ) ; return FILEOP_ABORT ; } public int handleCopyError ( String source , String target , int errCode , String errMsg ) { addException ( errCode , "<STR_LIT>" + source + "<STR_LIT>" + target + "<STR_LIT::U+0020>" + errMsg ) ; return FILEOP_ABORT ; } public int handleDeleteError ( String target , int errCode , String errMsg ) { addException ( errCode , "<STR_LIT>" + target + "<STR_LIT::U+0020>" + errMsg ) ; return FILEOP_SKIP ; } public int handleRenameError ( String source , String target , int errCode , String errMsg ) { addException ( errCode , "<STR_LIT>" + source + "<STR_LIT>" + target + "<STR_LIT::U+0020>" + errMsg ) ; return FILEOP_ABORT ; } public List < SystemErrorException > getExceptions ( ) { return exceptions ; } private void addException ( String errMsg ) { addException ( <NUM_LIT:0> , errMsg ) ; } private void addException ( int errCode , String errMsg ) { if ( exceptions == null ) { exceptions = new ArrayList < SystemErrorException > ( ) ; } exceptions . add ( new SystemErrorException ( errCode , errMsg ) ) ; } } </s>
<s> package com . izforge . izpack . util . os ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; import com . izforge . izpack . util . Librarian ; public class FileQueue { private List < FileQueueOperation > operations = new ArrayList < FileQueueOperation > ( ) ; protected WinSetupFileQueue filequeue ; private final Librarian librarian ; public FileQueue ( Librarian librarian ) { this . librarian = librarian ; } public void add ( FileQueueOperation op ) { operations . add ( op ) ; } public boolean isEmpty ( ) { return operations . isEmpty ( ) ; } public void execute ( ) throws IOException { WinSetupDefaultCallbackHandler handler = new WinSetupDefaultCallbackHandler ( ) ; try { filequeue = new WinSetupFileQueue ( librarian , handler ) ; } catch ( IOException ioe ) { throw new IOException ( "<STR_LIT>" + ioe . getMessage ( ) ) ; } try { for ( FileQueueOperation operation : operations ) { operation . addTo ( filequeue ) ; } filequeue . commit ( ) ; List < SystemErrorException > exceptions = handler . getExceptions ( ) ; if ( exceptions != null ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( "<STR_LIT>" ) ; for ( SystemErrorException exception : exceptions ) { buf . append ( '<STR_LIT:\t>' ) ; buf . append ( exception . toString ( ) ) ; buf . append ( '<STR_LIT:\n>' ) ; } throw new IOException ( buf . toString ( ) ) ; } } catch ( IOException ioe ) { throw new IOException ( "<STR_LIT>" + ioe . getMessage ( ) ) ; } finally { filequeue . close ( ) ; } } public boolean isRebootNecessary ( ) { return filequeue != null && filequeue . isRebootNecessary ( ) ; } public List < FileQueueOperation > getOperations ( ) { return operations ; } } </s>
<s> package com . izforge . izpack . util . os ; public interface WinSetupQueueCallbackInterface { public final static int FILEOP_ABORT = <NUM_LIT:0> ; public final static int FILEOP_DOIT = <NUM_LIT:1> ; public final static int FILEOP_SKIP = <NUM_LIT:2> ; public final static int FILEOP_RETRY = FILEOP_DOIT ; public final static int FILEOP_NEWPATH = <NUM_LIT:4> ; public int handleNeedMedia ( String tagfile , String description , String sourcePath , String sourceFile ) ; public int handleCopyError ( String source , String target , int errCode , String errMsg ) ; public int handleDeleteError ( String target , int errCode , String errMsg ) ; public int handleRenameError ( String source , String target , int errCode , String errMsg ) ; } </s>
<s> package com . izforge . izpack . util . os ; import com . izforge . izpack . util . Librarian ; import com . izforge . izpack . util . NativeLibraryClient ; import java . io . File ; import java . io . UnsupportedEncodingException ; public class ShellLink implements NativeLibraryClient { public static final int HIDE = <NUM_LIT:0> ; public static final int NORMAL = <NUM_LIT:1> ; public static final int MINIMIZED = <NUM_LIT:2> ; public static final int MAXIMIZED = <NUM_LIT:3> ; public static final int MINNOACTIVE = <NUM_LIT:7> ; private static final int MIN_SHOW = <NUM_LIT:0> ; private static final int MAX_SHOW = <NUM_LIT:7> ; public static final int DESKTOP = <NUM_LIT:1> ; public static final int PROGRAM_MENU = <NUM_LIT:2> ; public static final int START_MENU = <NUM_LIT:3> ; public static final int STARTUP = <NUM_LIT:4> ; private static final int MIN_TYPE = <NUM_LIT:1> ; private static final int MAX_TYPE = <NUM_LIT:4> ; private static final int SL_OK = <NUM_LIT:1> ; private static final int SL_ERROR = - <NUM_LIT:1> ; private static final int SL_INITIALIZED = - <NUM_LIT:2> ; private static final int SL_NOT_INITIALIZED = - <NUM_LIT:3> ; private static final int SL_OUT_OF_HANDLES = - <NUM_LIT:4> ; private static final int SL_NO_IPERSIST = - <NUM_LIT:5> ; private static final int SL_NO_SAVE = - <NUM_LIT:6> ; private static final int SL_WRONG_DATA_TYPE = - <NUM_LIT:7> ; private static final int UNINITIALIZED = - <NUM_LIT:1> ; private static final String LINK_EXTENSION = "<STR_LIT>" ; public static final int CURRENT_USER = <NUM_LIT:0> ; public static final int ALL_USERS = <NUM_LIT:1> ; private int nativeHandle = UNINITIALIZED ; private String currentUserLinkPath ; private String allUsersLinkPath ; private String groupName = "<STR_LIT>" ; private String linkName = "<STR_LIT>" ; private String linkFileName = "<STR_LIT>" ; private String linkDirectory = "<STR_LIT>" ; private String arguments = "<STR_LIT>" ; private String description = "<STR_LIT>" ; private String iconPath = "<STR_LIT>" ; private String targetPath = "<STR_LIT>" ; private String workingDirectory = "<STR_LIT>" ; private String dummyString = "<STR_LIT>" ; private int hotkey = <NUM_LIT:0> ; private int iconIndex = <NUM_LIT:0> ; private int showCommand = NORMAL ; private int linkType = DESKTOP ; private int userType = CURRENT_USER ; private boolean initializeSucceeded = false ; private final Librarian librarian ; private native int initializeCOM ( ) ; private native int releaseCOM ( ) ; private native int getInterface ( ) ; private native int releaseInterface ( ) ; private native int GetArguments ( ) ; private native int GetDescription ( ) ; private native int GetHotkey ( ) ; private native int GetIconLocation ( ) ; private native int GetPath ( ) ; private native int GetShowCommand ( ) ; private native int GetWorkingDirectory ( ) ; private native int Resolve ( ) ; private native int SetArguments ( ) ; private native int SetDescription ( ) ; private native int SetHotkey ( ) ; private native int SetIconLocation ( ) ; private native int SetPath ( ) ; private native int SetShowCommand ( ) ; private native int SetWorkingDirectory ( ) ; private native int saveLink ( String name ) ; private native int loadLink ( String name ) ; private native int GetFullLinkPath ( int usertype , int linktype ) ; private native void FreeLibrary ( String name ) ; public ShellLink ( int type , String name , Librarian librarian ) throws Exception { if ( ( type < MIN_TYPE ) || ( type > MAX_TYPE ) ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } if ( name == null ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } linkName = name ; linkType = type ; this . librarian = librarian ; initialize ( ) ; setAllLinkPaths ( ) ; } public ShellLink ( String name , int userType , Librarian librarian ) throws Exception { if ( name == null ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } this . userType = userType ; this . librarian = librarian ; initialize ( ) ; int pathEnd = name . lastIndexOf ( File . separator ) ; int nameStart = pathEnd + <NUM_LIT:1> ; int nameEnd = name . lastIndexOf ( '<CHAR_LIT:.>' ) ; if ( nameEnd < <NUM_LIT:0> ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } linkName = name . substring ( nameStart , nameEnd ) ; if ( userType == CURRENT_USER ) { currentUserLinkPath = name . substring ( <NUM_LIT:0> , pathEnd ) ; } else { allUsersLinkPath = name . substring ( <NUM_LIT:0> , pathEnd ) ; } linkFileName = fullLinkName ( userType ) ; if ( loadLink ( linkFileName ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } get ( ) ; } public ShellLink ( int linkType , int userType , String group , String name , Librarian librarian ) throws Exception { if ( ( linkType < MIN_TYPE ) || ( linkType > MAX_TYPE ) ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } if ( name == null ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } this . linkType = linkType ; this . userType = userType ; this . librarian = librarian ; initialize ( ) ; setAllLinkPaths ( ) ; if ( group != null ) { groupName = group ; } linkName = name ; linkFileName = fullLinkName ( userType ) ; if ( loadLink ( linkFileName ) != SL_OK ) { throw new Exception ( "<STR_LIT>" + linkFileName ) ; } get ( ) ; } private void initialize ( ) throws Exception { try { librarian . loadLibrary ( "<STR_LIT>" , this ) ; } catch ( UnsatisfiedLinkError exception ) { throw new Exception ( "<STR_LIT>" , exception ) ; } try { if ( initializeCOM ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } else { initializeSucceeded = true ; } } catch ( Throwable exception ) { throw ( new Exception ( "<STR_LIT>" + exception . toString ( ) ) ) ; } int successCode = getInterface ( ) ; if ( successCode != SL_OK ) { releaseCOM ( ) ; initializeSucceeded = false ; if ( successCode == SL_OUT_OF_HANDLES ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } else { throw ( new Exception ( "<STR_LIT>" ) ) ; } } } protected void finalize ( ) throws Throwable { releaseInterface ( ) ; if ( initializeSucceeded ) { releaseCOM ( ) ; initializeSucceeded = false ; } super . finalize ( ) ; } public void freeLibrary ( String name ) { int result = releaseInterface ( ) ; if ( initializeSucceeded ) { result = releaseCOM ( ) ; initializeSucceeded = false ; } FreeLibrary ( name ) ; } private String fullLinkPath ( int userType ) { StringBuffer path = new StringBuffer ( ) ; if ( userType == CURRENT_USER ) { path . append ( currentUserLinkPath ) ; } else { path . append ( allUsersLinkPath ) ; } if ( ( groupName != null ) && ( groupName . length ( ) > <NUM_LIT:0> ) ) { path . append ( File . separator ) ; path . append ( groupName ) ; } return ( path . toString ( ) ) ; } private String fullLinkName ( int userType ) { StringBuffer name = new StringBuffer ( ) ; name . append ( fullLinkPath ( userType ) ) ; name . append ( File . separator ) ; name . append ( linkName ) ; name . append ( LINK_EXTENSION ) ; return ( name . toString ( ) ) ; } private void set ( ) throws Exception { if ( SetArguments ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetDescription ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetHotkey ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetIconLocation ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetPath ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetShowCommand ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( SetWorkingDirectory ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } } private void get ( ) throws Exception { if ( GetArguments ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetDescription ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetHotkey ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetIconLocation ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetPath ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetShowCommand ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( GetWorkingDirectory ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } } public void setProgramGroup ( String groupName ) { this . groupName = groupName ; } public void setArguments ( String arguments ) { this . arguments = arguments ; } public void setDescription ( String description ) { this . description = description ; } public void setHotkey ( int hotkey ) { this . hotkey = hotkey ; } public void setIconLocation ( String path , int index ) { this . iconPath = path ; this . iconIndex = index ; } public void setTargetPath ( String path ) { this . targetPath = path ; } public void setShowCommand ( int show ) { if ( ( show < MIN_SHOW ) || ( show > MAX_SHOW ) ) { throw ( new IllegalArgumentException ( "<STR_LIT>" + show ) ) ; } this . showCommand = show ; } public void setWorkingDirectory ( String dir ) { this . workingDirectory = dir ; } public void setLinkName ( String name ) { linkName = name ; } public void setLinkType ( int type ) throws IllegalArgumentException , UnsupportedEncodingException { if ( ( type < MIN_TYPE ) || ( type > MAX_TYPE ) ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } linkType = type ; setAllLinkPaths ( ) ; } public int getLinkType ( ) { return linkType ; } public void setUserType ( int type ) throws IllegalArgumentException { if ( ( type == CURRENT_USER ) || ( type == ALL_USERS ) ) { userType = type ; } else { throw ( new IllegalArgumentException ( type + "<STR_LIT>" ) ) ; } } public int getUserType ( ) { return userType ; } public String getLinkPath ( int userType ) { String result = null ; if ( userType == CURRENT_USER ) { result = currentUserLinkPath ; } else { result = allUsersLinkPath ; } return result ; } public String getArguments ( ) { return ( arguments ) ; } public String getDescription ( ) { return ( description ) ; } public int getHotkey ( ) { return ( hotkey ) ; } public String getIconLocation ( ) { return ( iconPath ) ; } public int getIconIndex ( ) { return ( iconIndex ) ; } public String getTargetPath ( ) { return ( targetPath ) ; } public int getShowCommand ( ) { return ( showCommand ) ; } public String getWorkingDirectory ( ) { return ( workingDirectory ) ; } public String getFileName ( ) { return ( linkFileName ) ; } public String getDirectoryCreated ( ) { return ( linkDirectory ) ; } public String getLinkName ( ) { return ( linkName ) ; } public String getcurrentUserLinkPath ( ) { return currentUserLinkPath ; } public String getallUsersLinkPath ( ) { return allUsersLinkPath ; } public void save ( ) throws Exception { set ( ) ; int result = Resolve ( ) ; if ( result != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } File directory = new File ( fullLinkPath ( userType ) ) ; if ( ! directory . exists ( ) ) { directory . mkdirs ( ) ; linkDirectory = directory . getPath ( ) ; } else { linkDirectory = "<STR_LIT>" ; } File allUsersFileObj = null ; long aufLastModVal = <NUM_LIT:0> ; if ( userType == CURRENT_USER ) { allUsersFileObj = new File ( fullLinkName ( ALL_USERS ) ) ; aufLastModVal = allUsersFileObj . lastModified ( ) ; } String saveTo = fullLinkName ( userType ) ; result = saveLink ( saveTo ) ; if ( result == SL_NO_IPERSIST ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } else if ( result == SL_NO_SAVE ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } if ( allUsersFileObj != null ) { try { if ( allUsersFileObj . exists ( ) && allUsersFileObj . lastModified ( ) > aufLastModVal ) { final File curUserFileObj = new File ( saveTo ) ; moveFileTo ( allUsersFileObj , curUserFileObj ) ; allUsersFileObj . getParentFile ( ) . delete ( ) ; } } catch ( Exception ex ) { } } linkFileName = saveTo ; } public void save ( String name ) throws Exception { if ( name == null ) { throw ( new IllegalArgumentException ( "<STR_LIT>" ) ) ; } set ( ) ; if ( Resolve ( ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } File directory = new File ( name . substring ( <NUM_LIT:0> , name . lastIndexOf ( File . separatorChar ) ) ) ; if ( ! directory . exists ( ) ) { directory . mkdirs ( ) ; linkDirectory = directory . getPath ( ) ; } else { linkDirectory = null ; } if ( saveLink ( name ) != SL_OK ) { throw ( new Exception ( "<STR_LIT>" ) ) ; } linkFileName = name ; } protected void moveFileTo ( File srcFileObj , File destFileObj ) { if ( destFileObj . exists ( ) ) { final File tempFileObj = new File ( destFileObj . getPath ( ) + System . currentTimeMillis ( ) ) ; destFileObj . renameTo ( tempFileObj ) ; srcFileObj . renameTo ( destFileObj ) ; tempFileObj . delete ( ) ; } else { srcFileObj . renameTo ( destFileObj ) ; } } private void setAllLinkPaths ( ) throws IllegalArgumentException { currentUserLinkPath = "<STR_LIT>" ; allUsersLinkPath = "<STR_LIT>" ; GetFullLinkPath ( CURRENT_USER , linkType ) ; GetFullLinkPath ( ALL_USERS , linkType ) ; if ( userType == CURRENT_USER && currentUserLinkPath . length ( ) == <NUM_LIT:0> ) { userType = ALL_USERS ; } else if ( userType == ALL_USERS && allUsersLinkPath . length ( ) == <NUM_LIT:0> ) { userType = CURRENT_USER ; } if ( allUsersLinkPath . length ( ) == <NUM_LIT:0> && currentUserLinkPath . length ( ) == <NUM_LIT:0> ) { throw ( new IllegalArgumentException ( "<STR_LIT>" + linkType + "<STR_LIT>" ) ) ; } } } </s>
<s> package com . izforge . izpack . util . os ; public class SystemErrorException extends Exception { private int errorCode = <NUM_LIT:0> ; public SystemErrorException ( ) { super ( ) ; } public SystemErrorException ( String message ) { super ( message ) ; } public SystemErrorException ( int errorCode , String message ) { super ( message ) ; this . errorCode = errorCode ; } public String toString ( ) { return super . toString ( ) ; } public void setErrorCode ( int errorCode ) { this . errorCode = errorCode ; } public int getErrorCode ( ) { return errorCode ; } } </s>
<s> package com . izforge . izpack . util . os ; public interface Unix_ShortcutConstants { public final static String $Comment = "<STR_LIT>" ; public final static String $$LANG_Comment = "<STR_LIT>" ; public final static String $Encoding = "<STR_LIT>" ; public final static String $Exec = "<STR_LIT>" ; public final static String $Arguments = "<STR_LIT>" ; public final static String $GenericName = "<STR_LIT>" ; public final static String $$LANG_GenericName = "<STR_LIT>" ; public final static String $MimeType = "<STR_LIT>" ; public final static String $Name = "<STR_LIT>" ; public final static String $$LANG_Name = "<STR_LIT>" ; public final static String $Path = "<STR_LIT>" ; public final static String $ServiceTypes = "<STR_LIT>" ; public final static String $SwallowExec = "<STR_LIT>" ; public final static String $SwallowTitle = "<STR_LIT>" ; public final static String $Terminal = "<STR_LIT>" ; public final static String $Options_For_Terminal = "<STR_LIT>" ; public final static String $Type = "<STR_LIT>" ; public final static String $X_KDE_SubstituteUID = "<STR_LIT>" ; public final static String $X_KDE_Username = "<STR_LIT>" ; public final static String $Icon = "<STR_LIT>" ; public final static String $URL = "<STR_LIT>" ; public final static String $E_QUOT = "<STR_LIT>" ; public final static String $P_QUOT = "<STR_LIT>" ; public final static String $Categories = "<STR_LIT>" ; public final static String $TryExec = "<STR_LIT>" ; } </s>
<s> package com . izforge . izpack . util . os ; import com . coi . tools . os . izpack . Registry ; import com . coi . tools . os . win . RegDataContainer ; import com . izforge . izpack . api . exception . NativeLibException ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . os . RegistryHandler ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . util . Librarian ; import java . util . List ; import java . util . Properties ; public class Win_RegistryHandler extends RegistryHandler { private final Librarian librarian ; private Registry registry ; public Win_RegistryHandler ( Librarian librarian ) { this . librarian = librarian ; } public void setValue ( String key , String value , String contents ) throws NativeLibException { if ( contents . contains ( "<STR_LIT>" ) && getRegistry ( ) . valueExist ( key , value ) ) { Object ob = getRegistry ( ) . getValueAsObject ( key , value ) ; if ( ob instanceof String ) { Properties props = new Properties ( ) ; props . put ( "<STR_LIT>" , ob ) ; VariableSubstitutor variableSubstitutor = new VariableSubstitutorImpl ( props ) ; try { contents = variableSubstitutor . substitute ( contents ) ; } catch ( Exception e ) { } } } getRegistry ( ) . setValue ( key , value , contents ) ; } public void setValue ( String key , String value , String [ ] contents ) throws NativeLibException { getRegistry ( ) . setValue ( key , value , contents ) ; } public void setValue ( String key , String value , byte [ ] contents ) throws NativeLibException { getRegistry ( ) . setValue ( key , value , contents ) ; } public void setValue ( String key , String value , long contents ) throws NativeLibException { getRegistry ( ) . setValue ( key , value , contents ) ; } public RegDataContainer getValue ( String key , String value , RegDataContainer defaultVal ) throws NativeLibException { if ( valueExist ( key , value ) ) { return ( getValue ( key , value ) ) ; } return ( defaultVal ) ; } public boolean keyExist ( String key ) throws NativeLibException { return ( getRegistry ( ) . keyExist ( key ) ) ; } public boolean valueExist ( String key , String value ) throws NativeLibException { return ( getRegistry ( ) . valueExist ( key , value ) ) ; } public String [ ] getSubkeys ( String key ) throws NativeLibException { return ( getRegistry ( ) . getSubkeys ( key ) ) ; } public String [ ] getValueNames ( String key ) throws NativeLibException { return ( getRegistry ( ) . getValueNames ( key ) ) ; } public RegDataContainer getValue ( String key , String value ) throws NativeLibException { return ( getRegistry ( ) . getValue ( key , value ) ) ; } public void createKey ( String key ) throws NativeLibException { getRegistry ( ) . createKey ( key ) ; } public void deleteKey ( String key ) throws NativeLibException { getRegistry ( ) . deleteKey ( key ) ; } public void deleteKeyIfEmpty ( String key ) throws NativeLibException { getRegistry ( ) . deleteKeyIfEmpty ( key ) ; } public void deleteValue ( String key , String value ) throws NativeLibException { getRegistry ( ) . deleteValue ( key , value ) ; } public void setRoot ( int i ) throws NativeLibException { getRegistry ( ) . setRoot ( i ) ; } public int getRoot ( ) throws NativeLibException { return ( getRegistry ( ) . getRoot ( ) ) ; } public void setLogPrevSetValueFlag ( boolean flagVal ) throws NativeLibException { getRegistry ( ) . setLogPrevSetValueFlag ( flagVal ) ; } public boolean getLogPrevSetValueFlag ( ) throws NativeLibException { return ( getRegistry ( ) . getLogPrevSetValueFlag ( ) ) ; } public void activateLogging ( ) throws NativeLibException { getRegistry ( ) . activateLogging ( ) ; } public void suspendLogging ( ) throws NativeLibException { getRegistry ( ) . suspendLogging ( ) ; } public void resetLogging ( ) throws NativeLibException { getRegistry ( ) . resetLogging ( ) ; } public List < Object > getLoggingInfo ( ) throws NativeLibException { return ( getRegistry ( ) . getLoggingInfo ( ) ) ; } public void setLoggingInfo ( List info ) throws NativeLibException { getRegistry ( ) . setLoggingInfo ( info ) ; } public void addLoggingInfo ( List info ) throws NativeLibException { getRegistry ( ) . addLoggingInfo ( info ) ; } public void rewind ( ) throws NativeLibException { getRegistry ( ) . rewind ( ) ; } private synchronized Registry getRegistry ( ) throws NativeLibException { if ( registry == null ) { try { registry = new Registry ( librarian ) ; } catch ( Throwable exception ) { throw new NativeLibException ( "<STR_LIT>" + exception . getMessage ( ) , exception ) ; } } return registry ; } } </s>
<s> package com . izforge . izpack . util ; import java . io . File ; import java . io . IOException ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . Info . TempDir ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . FileUtils ; public class TemporaryDirectory implements CleanupClient { private static final Logger logger = Logger . getLogger ( TemporaryDirectory . class . getName ( ) ) ; private File tempdir ; private final InstallData installData ; private final TempDir tempDirDescription ; private boolean deleteOnExit = false ; private final Housekeeper housekeeper ; public TemporaryDirectory ( TempDir tempDirDescription , InstallData installData , Housekeeper housekeeper ) { if ( null == tempDirDescription ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( null == installData ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . installData = installData ; this . tempDirDescription = tempDirDescription ; this . housekeeper = housekeeper ; } public void create ( ) throws IOException { try { tempdir = File . createTempFile ( tempDirDescription . getPrefix ( ) , tempDirDescription . getSuffix ( ) ) ; tempdir . delete ( ) ; tempdir . mkdir ( ) ; } catch ( IOException e ) { logger . log ( Level . SEVERE , "<STR_LIT>" + e . getMessage ( ) , e ) ; throw e ; } installData . setVariable ( tempDirDescription . getVariableName ( ) , tempdir . getAbsolutePath ( ) ) ; housekeeper . registerForCleanup ( this ) ; } public void deleteOnExit ( ) { deleteOnExit = true ; } @ Override public void cleanUp ( ) { if ( null != tempdir ) { if ( deleteOnExit ) { if ( ! FileUtils . deleteRecursively ( tempdir ) ) { logger . warning ( "<STR_LIT>" + tempdir . getAbsolutePath ( ) + "<STR_LIT>" ) ; } } else { logger . warning ( "<STR_LIT>" + tempdir . getAbsolutePath ( ) ) ; } } else { logger . warning ( "<STR_LIT>" ) ; } } } </s>
<s> package com . izforge . izpack . panels . target ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertNull ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . IOException ; import java . util . Properties ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . panels . test . TestConsolePanelContainer ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . test . util . TestConsole ; import com . izforge . izpack . util . Console ; @ RunWith ( PicoRunner . class ) @ Container ( TestConsolePanelContainer . class ) public class TargetPanelConsoleTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private final InstallData installData ; private final TestConsole console ; public TargetPanelConsoleTest ( InstallData installData , TestConsole console ) { this . console = console ; this . installData = installData ; installData . setInstallPath ( null ) ; } @ Test public void testRunConsoleIncompatibleInstallation ( ) throws Exception { File root = temporaryFolder . getRoot ( ) ; File badDir = new File ( root , "<STR_LIT>" ) ; assertTrue ( badDir . mkdirs ( ) ) ; File goodDir = new File ( root , "<STR_LIT>" ) ; installData . setDefaultInstallPath ( badDir . getAbsolutePath ( ) ) ; TargetPanelTestHelper . createBadInstallationInfo ( badDir ) ; console . addScript ( "<STR_LIT>" , "<STR_LIT:n>" ) ; TargetPanelConsole panel = new TargetPanelConsole ( ) ; assertFalse ( panel . runConsole ( installData , console ) ) ; assertTrue ( console . scriptCompleted ( ) ) ; assertNull ( installData . getInstallPath ( ) ) ; console . addScript ( "<STR_LIT>" , goodDir . getAbsolutePath ( ) , "<STR_LIT:1>" ) ; assertTrue ( panel . runConsole ( installData , console ) ) ; assertTrue ( console . scriptCompleted ( ) ) ; assertEquals ( goodDir . getAbsolutePath ( ) , installData . getInstallPath ( ) ) ; } @ Test public void testIncompatibleInstallationFromProperties ( ) throws IOException { File root = temporaryFolder . getRoot ( ) ; File badDir = new File ( root , "<STR_LIT>" ) ; assertTrue ( badDir . mkdirs ( ) ) ; TargetPanelTestHelper . createBadInstallationInfo ( badDir ) ; File goodDir = new File ( root , "<STR_LIT>" ) ; Properties properties = new Properties ( ) ; properties . setProperty ( InstallData . INSTALL_PATH , badDir . getAbsolutePath ( ) ) ; TargetPanelConsole panel = new TargetPanelConsole ( ) ; assertFalse ( panel . runConsoleFromProperties ( installData , properties ) ) ; properties . setProperty ( InstallData . INSTALL_PATH , goodDir . getAbsolutePath ( ) ) ; assertTrue ( panel . runConsoleFromProperties ( installData , properties ) ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import java . io . File ; import org . fest . swing . fixture . FrameFixture ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import com . izforge . izpack . api . GuiId ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . gui . IconsDatabase ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . panels . simplefinish . SimpleFinishPanel ; import com . izforge . izpack . panels . test . AbstractPanelTest ; import com . izforge . izpack . panels . test . TestGUIPanelContainer ; import com . izforge . izpack . test . Container ; @ Container ( TestGUIPanelContainer . class ) public class TargetPanelTest extends AbstractPanelTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; public TargetPanelTest ( TestGUIPanelContainer container , GUIInstallData installData , ResourceManager resourceManager , ObjectFactory factory , RulesEngine rules , IconsDatabase icons , UninstallDataWriter uninstallDataWriter ) { super ( container , installData , resourceManager , factory , rules , icons , uninstallDataWriter ) ; } @ Test public void testIncompatibleInstallation ( ) throws Exception { GUIInstallData installData = getInstallData ( ) ; String expectedMessage = TargetPanelTestHelper . getIncompatibleInstallationMessage ( installData ) ; File root = temporaryFolder . getRoot ( ) ; File badDir = new File ( root , "<STR_LIT>" ) ; assertTrue ( badDir . mkdirs ( ) ) ; File goodDir = new File ( root , "<STR_LIT>" ) ; installData . setDefaultInstallPath ( badDir . getAbsolutePath ( ) ) ; TargetPanelTestHelper . createBadInstallationInfo ( badDir ) ; FrameFixture fixture = show ( TargetPanel . class , SimpleFinishPanel . class ) ; Thread . sleep ( <NUM_LIT> ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof TargetPanel ) ; TargetPanel panel = ( TargetPanel ) getPanels ( ) . getView ( ) ; fixture . button ( GuiId . BUTTON_NEXT . id ) . click ( ) ; Thread . sleep ( <NUM_LIT> ) ; assertEquals ( panel , getPanels ( ) . getView ( ) ) ; fixture . optionPane ( ) . requireErrorMessage ( ) . requireMessage ( expectedMessage ) ; Thread . sleep ( <NUM_LIT> ) ; fixture . optionPane ( ) . okButton ( ) . click ( ) ; assertEquals ( panel , getPanels ( ) . getView ( ) ) ; fixture . textBox ( ) . setText ( goodDir . getAbsolutePath ( ) ) ; installData . setVariable ( "<STR_LIT>" , "<STR_LIT:false>" ) ; Thread . sleep ( <NUM_LIT> ) ; fixture . button ( GuiId . BUTTON_NEXT . id ) . click ( ) ; Thread . sleep ( <NUM_LIT> ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof SimpleFinishPanel ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertNull ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . ObjectOutputStream ; import java . util . ArrayList ; import org . junit . Test ; import com . izforge . izpack . api . data . AutomatedInstallData ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . file . FileUtils ; public class TargetPanelHelperTest { @ Test public void testGetPath ( ) { Variables variables = new DefaultVariables ( ) ; InstallData installData = new AutomatedInstallData ( variables , Platforms . WINDOWS_7 ) ; assertNull ( TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:default>" ) ; assertEquals ( "<STR_LIT:default>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , TargetPanelHelper . getPath ( installData ) ) ; } @ Test public void testGetPathForWindows ( ) { Variables variables = new DefaultVariables ( ) ; InstallData installData = new AutomatedInstallData ( variables , Platforms . WINDOWS_7 ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:default>" ) ; assertEquals ( "<STR_LIT:default>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:1>" ) ; assertEquals ( "<STR_LIT:1>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:2>" ) ; assertEquals ( "<STR_LIT:2>" , TargetPanelHelper . getPath ( installData ) ) ; } @ Test public void testGetPathForMac ( ) { Variables variables = new DefaultVariables ( ) ; InstallData installData = new AutomatedInstallData ( variables , Platforms . MAC_OSX ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:default>" ) ; assertEquals ( "<STR_LIT:default>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:1>" ) ; assertEquals ( "<STR_LIT:1>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:2>" ) ; assertEquals ( "<STR_LIT:2>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:3>" ) ; assertEquals ( "<STR_LIT:3>" , TargetPanelHelper . getPath ( installData ) ) ; } @ Test public void testGetPathForFedora ( ) { Variables variables = new DefaultVariables ( ) ; InstallData installData = new AutomatedInstallData ( variables , Platforms . FEDORA_LINUX ) ; variables . set ( "<STR_LIT>" , "<STR_LIT>" ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:default>" ) ; assertEquals ( "<STR_LIT:default>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:1>" ) ; assertEquals ( "<STR_LIT:1>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:2>" ) ; assertEquals ( "<STR_LIT:2>" , TargetPanelHelper . getPath ( installData ) ) ; variables . set ( "<STR_LIT>" , "<STR_LIT:3>" ) ; assertEquals ( "<STR_LIT:3>" , TargetPanelHelper . getPath ( installData ) ) ; } @ Test public void testIsIncompatibleInstallation ( ) throws IOException { File dir = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) ; FileUtils . delete ( dir ) ; assertFalse ( dir . exists ( ) ) ; assertFalse ( TargetPanelHelper . isIncompatibleInstallation ( dir . getPath ( ) ) ) ; assertTrue ( dir . mkdir ( ) ) ; assertFalse ( TargetPanelHelper . isIncompatibleInstallation ( dir . getPath ( ) ) ) ; File file = new File ( dir , InstallData . INSTALLATION_INFORMATION ) ; FileOutputStream stream = new FileOutputStream ( file ) ; ObjectOutputStream objStream = new ObjectOutputStream ( stream ) ; objStream . writeObject ( new ArrayList < Pack > ( ) ) ; objStream . close ( ) ; assertFalse ( TargetPanelHelper . isIncompatibleInstallation ( dir . getPath ( ) ) ) ; assertTrue ( file . delete ( ) ) ; stream = new FileOutputStream ( file ) ; objStream = new ObjectOutputStream ( stream ) ; objStream . writeObject ( new Integer ( <NUM_LIT:1> ) ) ; objStream . close ( ) ; assertTrue ( TargetPanelHelper . isIncompatibleInstallation ( dir . getPath ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . ObjectOutputStream ; import com . izforge . izpack . api . data . InstallData ; class TargetPanelTestHelper { public static void createBadInstallationInfo ( File dir ) throws IOException { File info = new File ( dir , InstallData . INSTALLATION_INFORMATION ) ; ObjectOutputStream stream = new ObjectOutputStream ( new FileOutputStream ( info ) ) ; stream . writeBoolean ( false ) ; stream . close ( ) ; } public static String getIncompatibleInstallationMessage ( InstallData installData ) { String messageId = "<STR_LIT>" ; String result = installData . getMessages ( ) . get ( messageId ) ; assertNotNull ( result ) ; assertTrue ( ! messageId . equals ( result ) ) ; return result ; } } </s>
<s> package com . izforge . izpack . panels . target ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; import java . io . File ; import java . io . IOException ; import org . junit . Rule ; import org . junit . Test ; import org . junit . rules . TemporaryFolder ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . panels . test . TestConsolePanelContainer ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; @ RunWith ( PicoRunner . class ) @ Container ( TestConsolePanelContainer . class ) public class TargetPanelAutomationTest { @ Rule public TemporaryFolder temporaryFolder = new TemporaryFolder ( ) ; private final InstallData installData ; public TargetPanelAutomationTest ( InstallData installData ) { this . installData = installData ; } @ Test public void testIncompatibleInstallation ( ) throws IOException { File root = temporaryFolder . getRoot ( ) ; File badDir = new File ( root , "<STR_LIT>" ) ; assertTrue ( badDir . mkdirs ( ) ) ; File goodDir = new File ( root , "<STR_LIT>" ) ; String expectedMessage = TargetPanelTestHelper . getIncompatibleInstallationMessage ( installData ) ; TargetPanelAutomation panel = new TargetPanelAutomation ( ) ; IXMLElement badPath = createElement ( badDir ) ; try { TargetPanelTestHelper . createBadInstallationInfo ( badDir ) ; panel . runAutomated ( installData , badPath ) ; fail ( "<STR_LIT>" ) ; } catch ( InstallerException expected ) { assertEquals ( expectedMessage , expected . getMessage ( ) ) ; } IXMLElement goodPath = createElement ( goodDir ) ; panel . runAutomated ( installData , goodPath ) ; assertEquals ( goodDir . getAbsolutePath ( ) , installData . getInstallPath ( ) ) ; } private IXMLElement createElement ( File dir ) { IXMLElement element = new XMLElementImpl ( "<STR_LIT:foo>" ) ; XMLElementImpl path = new XMLElementImpl ( "<STR_LIT>" , element ) ; path . setContent ( dir . getAbsolutePath ( ) ) ; element . addChild ( path ) ; return element ; } } </s>
<s> package com . izforge . izpack . panels . userinput . processorclient ; import static org . junit . Assert . assertEquals ; import java . awt . Toolkit ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . util . Platforms ; public class RuleInputFieldTest { @ Test public void testIPAddressRuleInputField ( ) { String layout = "<STR_LIT>" ; String set = "<STR_LIT>" ; String separator = null ; String validator = null ; String processor = null ; Toolkit toolkit = Mockito . mock ( Toolkit . class ) ; GUIInstallData installData = new GUIInstallData ( new DefaultVariables ( ) , Platforms . HP_UX ) ; RuleInputField field = new RuleInputField ( layout , set , separator , validator , processor , RuleInputField . DISPLAY_FORMAT , toolkit , installData ) ; assertEquals ( <NUM_LIT:4> , field . getNumFields ( ) ) ; assertEquals ( "<STR_LIT>" , field . getText ( ) ) ; assertEquals ( "<STR_LIT>" , field . getFieldContents ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , field . getFieldContents ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT:0>" , field . getFieldContents ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT:1>" , field . getFieldContents ( <NUM_LIT:3> ) ) ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import com . izforge . izpack . util . StringTool ; import junit . framework . Assert ; import junit . framework . TestCase ; public class StringToolTest extends TestCase { public void testReplace ( ) { String ref = "<STR_LIT>" ; Assert . assertEquals ( null , StringTool . replace ( null , null , null ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , null , null ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , "<STR_LIT>" , null ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , "<STR_LIT:->" , null ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , "<STR_LIT>" , "<STR_LIT:abc>" ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , "<STR_LIT:abc>" , "<STR_LIT:abc>" , false ) ) ; assertEquals ( "<STR_LIT>" , StringTool . replace ( ref , "<STR_LIT:abc>" , "<STR_LIT:abc>" , true ) ) ; } public void testNormalizePath ( ) { assertEquals ( "<STR_LIT>" , StringTool . normalizePath ( "<STR_LIT>" , "<STR_LIT:\\>" ) ) ; assertEquals ( "<STR_LIT>" , StringTool . normalizePath ( "<STR_LIT>" , "<STR_LIT:/>" ) ) ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . io . IOException ; import java . net . InetAddress ; import java . net . ServerSocket ; import java . util . Map ; import org . junit . Ignore ; import org . junit . Test ; import com . izforge . izpack . panels . userinput . processor . PortProcessor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import junit . framework . Assert ; @ Ignore public class PortProcessorTest { @ Test public void testProcessGenericBoundPort ( ) throws IOException { ServerSocket use = new ServerSocket ( <NUM_LIT:0> ) ; int usedPort = use . getLocalPort ( ) ; ProcessingClient pc = new ProcessingClientStub ( usedPort ) ; PortProcessor pp = new PortProcessor ( ) ; String result = pp . process ( pc ) ; Assert . assertTrue ( ( Integer . toString ( usedPort ) ) . equals ( result ) ) ; try { use . close ( ) ; } catch ( Throwable t ) { } } @ Test public void testProcessSpecificBoundPort ( ) throws IOException { ServerSocket use = new ServerSocket ( <NUM_LIT:0> , <NUM_LIT:0> , InetAddress . getByName ( "<STR_LIT:localhost>" ) ) ; int usedPort = use . getLocalPort ( ) ; ProcessingClient pc = new ProcessingClientStub ( "<STR_LIT:localhost>" , usedPort ) ; PortProcessor pp = new PortProcessor ( ) ; String result = pp . process ( pc ) ; System . out . println ( result ) ; Assert . assertFalse ( ( "<STR_LIT>" + Integer . toString ( usedPort ) ) . equals ( result ) ) ; try { use . close ( ) ; } catch ( Throwable t ) { } } @ Test public void testProcessGenericOnGenericBoundPortIPv6 ( ) throws IOException { ServerSocket use = new ServerSocket ( <NUM_LIT:0> , <NUM_LIT:0> , InetAddress . getByName ( "<STR_LIT>" ) ) ; int usedPort = use . getLocalPort ( ) ; ProcessingClient pc = new ProcessingClientStub ( "<STR_LIT>" , usedPort ) ; PortProcessor pp = new PortProcessor ( ) ; String result = pp . process ( pc ) ; Assert . assertFalse ( ( "<STR_LIT>" + Integer . toString ( usedPort ) ) . equals ( result ) ) ; try { use . close ( ) ; } catch ( Throwable t ) { } } @ Test public void testProcessGenericOnGenericBoundPortIPv4 ( ) throws IOException { ServerSocket use = new ServerSocket ( <NUM_LIT:0> , <NUM_LIT:0> , InetAddress . getByName ( "<STR_LIT>" ) ) ; int usedPort = use . getLocalPort ( ) ; ProcessingClient pc = new ProcessingClientStub ( "<STR_LIT>" , usedPort ) ; PortProcessor pp = new PortProcessor ( ) ; String result = pp . process ( pc ) ; Assert . assertFalse ( ( "<STR_LIT>" + Integer . toString ( usedPort ) ) . equals ( result ) ) ; try { use . close ( ) ; } catch ( Throwable t ) { } } @ Test public void testProcessSpecificOnGenericBoundPortIPv4 ( ) throws IOException { ServerSocket use = new ServerSocket ( <NUM_LIT:0> , <NUM_LIT:0> , InetAddress . getByName ( "<STR_LIT>" ) ) ; int usedPort = use . getLocalPort ( ) ; ProcessingClient pc = new ProcessingClientStub ( "<STR_LIT:127.0.0.1>" , usedPort ) ; PortProcessor pp = new PortProcessor ( ) ; String result = pp . process ( pc ) ; Assert . assertEquals ( "<STR_LIT>" + Integer . toString ( usedPort ) , result ) ; try { use . close ( ) ; } catch ( Throwable t ) { } } class ProcessingClientStub implements ProcessingClient { String [ ] fields ; public ProcessingClientStub ( String host , int port ) { fields = new String [ <NUM_LIT:2> ] ; fields [ <NUM_LIT:0> ] = host ; fields [ <NUM_LIT:1> ] = Integer . toString ( port ) ; } public ProcessingClientStub ( int port ) { fields = new String [ <NUM_LIT:1> ] ; fields [ <NUM_LIT:0> ] = Integer . toString ( port ) ; } public String getFieldContents ( int index ) { if ( index < fields . length ) { return fields [ index ] ; } else { throw new IndexOutOfBoundsException ( ) ; } } public int getNumFields ( ) { return fields . length ; } public String getText ( ) { return null ; } public Map < String , String > getValidatorParams ( ) { return null ; } public boolean hasParams ( ) { return false ; } } } </s>
<s> package com . izforge . izpack . panels . process ; import static org . hamcrest . MatcherAssert . assertThat ; import static org . junit . Assert . assertArrayEquals ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; import javax . swing . LookAndFeel ; import javax . swing . UIManager ; import org . fest . swing . fixture . DialogFixture ; import org . fest . swing . fixture . FrameFixture ; import org . hamcrest . text . StringContains ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; import org . jvnet . substance . skin . SubstanceBusinessLookAndFeel ; import com . izforge . izpack . api . GuiId ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . gui . IconsDatabase ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . panels . simplefinish . SimpleFinishPanel ; import com . izforge . izpack . panels . test . AbstractPanelTest ; import com . izforge . izpack . panels . test . TestGUIPanelContainer ; import com . izforge . izpack . test . Container ; @ Container ( TestGUIPanelContainer . class ) public class ProcessPanelTest extends AbstractPanelTest { private LookAndFeel lookAndFeel ; public ProcessPanelTest ( TestGUIPanelContainer container , GUIInstallData installData , ResourceManager resourceManager , ObjectFactory factory , RulesEngine rules , IconsDatabase icons , UninstallDataWriter uninstallDataWriter ) { super ( container , installData , resourceManager , factory , rules , icons , uninstallDataWriter ) ; } @ Before public void setUp ( ) { lookAndFeel = UIManager . getLookAndFeel ( ) ; } @ After public void tearDown ( ) throws Exception { super . tearDown ( ) ; UIManager . setLookAndFeel ( lookAndFeel ) ; } @ Test public void testExecuteClass ( ) throws Exception { getResourceManager ( ) . setResourceBasePath ( "<STR_LIT>" ) ; Executable . init ( ) ; Executable . setReturn ( true ) ; FrameFixture fixture = show ( ProcessPanel . class , SimpleFinishPanel . class ) ; Thread . sleep ( <NUM_LIT> ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof ProcessPanel ) ; fixture . button ( GuiId . BUTTON_NEXT . id ) . click ( ) ; Thread . sleep ( <NUM_LIT> ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof SimpleFinishPanel ) ; assertEquals ( <NUM_LIT:2> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:1> ) , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; } @ Test public void testExecuteClassException ( ) throws Exception { SubstanceBusinessLookAndFeel lookAndFeel = new SubstanceBusinessLookAndFeel ( ) ; if ( lookAndFeel . isSupportedLookAndFeel ( ) ) { UIManager . setLookAndFeel ( lookAndFeel ) ; } getResourceManager ( ) . setResourceBasePath ( "<STR_LIT>" ) ; Executable . init ( ) ; Executable . setException ( true ) ; FrameFixture fixture = show ( ProcessPanel . class , SimpleFinishPanel . class ) ; Thread . sleep ( <NUM_LIT> ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof ProcessPanel ) ; DialogFixture dialogFixture = fixture . dialog ( ) ; dialogFixture . requireVisible ( ) ; assertThat ( dialogFixture . label ( "<STR_LIT>" ) . text ( ) , StringContains . containsString ( "<STR_LIT>" ) ) ; dialogFixture . button ( ) . click ( ) ; Thread . sleep ( <NUM_LIT> ) ; fixture . button ( GuiId . BUTTON_NEXT . id ) . requireDisabled ( ) ; assertTrue ( getPanels ( ) . getView ( ) instanceof ProcessPanel ) ; assertEquals ( <NUM_LIT:1> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; } } </s>
<s> package com . izforge . izpack . panels . process ; import java . util . HashMap ; import java . util . Map ; public class Executable { private static boolean result = false ; private static boolean exception = false ; private static int invocations = <NUM_LIT:0> ; private static Map < Integer , String [ ] > args = new HashMap < Integer , String [ ] > ( ) ; public static void init ( ) { result = false ; exception = false ; invocations = <NUM_LIT:0> ; args . clear ( ) ; } public static void setReturn ( boolean result ) { Executable . result = result ; } public static void setException ( boolean exception ) { Executable . exception = exception ; } public static int getInvocations ( ) { return invocations ; } public static String [ ] getArgs ( int invocation ) { return args . get ( invocation ) ; } public boolean run ( AbstractUIProcessHandler handler , String ... args ) { Executable . args . put ( invocations , args ) ; ++ invocations ; if ( exception ) { throw new RuntimeException ( "<STR_LIT>" ) ; } return result ; } } </s>
<s> package com . izforge . izpack . panels . process ; import static org . junit . Assert . assertArrayEquals ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . fail ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . panels . test . TestConsolePanelContainer ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . util . PlatformModelMatcher ; @ RunWith ( PicoRunner . class ) @ Container ( TestConsolePanelContainer . class ) public class ProcessPanelAutomationTest { private final InstallData installData ; private final RulesEngine rules ; private final ResourceManager resources ; private final PlatformModelMatcher matcher ; public ProcessPanelAutomationTest ( InstallData installData , RulesEngine rules , ResourceManager resources , PlatformModelMatcher matcher ) { this . installData = installData ; this . rules = rules ; this . resources = resources ; this . matcher = matcher ; resources . setResourceBasePath ( "<STR_LIT>" ) ; } @ Test public void testExecuteClass ( ) { Executable . init ( ) ; Executable . setReturn ( true ) ; ProcessPanelAutomation panel = new ProcessPanelAutomation ( installData , rules , resources , matcher ) ; panel . runAutomated ( installData , new XMLElementImpl ( "<STR_LIT:root>" ) ) ; assertEquals ( <NUM_LIT:2> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:1> ) , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; } @ Test public void testExecuteClassException ( ) throws Exception { Executable . init ( ) ; Executable . setException ( true ) ; ProcessPanelAutomation panel = new ProcessPanelAutomation ( installData , rules , resources , matcher ) ; try { panel . runAutomated ( installData , new XMLElementImpl ( "<STR_LIT:root>" ) ) ; fail ( "<STR_LIT>" ) ; } catch ( InstallerException expected ) { } assertEquals ( <NUM_LIT:1> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; } } </s>
<s> package com . izforge . izpack . panels . process ; import static org . junit . Assert . assertArrayEquals ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import org . junit . Test ; import org . junit . runner . RunWith ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . handler . Prompt ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . panels . test . TestConsolePanelContainer ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . test . util . TestConsole ; import com . izforge . izpack . util . PlatformModelMatcher ; @ RunWith ( PicoRunner . class ) @ Container ( TestConsolePanelContainer . class ) public class ProcessPanelConsoleTest { private final InstallData installData ; private final RulesEngine rules ; private final ResourceManager resources ; private final Prompt prompt ; private final PlatformModelMatcher matcher ; private final TestConsole console ; public ProcessPanelConsoleTest ( InstallData installData , RulesEngine rules , ResourceManager resources , Prompt prompt , PlatformModelMatcher matcher , TestConsole console ) { this . installData = installData ; this . rules = rules ; this . resources = resources ; this . prompt = prompt ; this . matcher = matcher ; this . console = console ; resources . setResourceBasePath ( "<STR_LIT>" ) ; } @ Test public void testExecuteClass ( ) { Executable . init ( ) ; Executable . setReturn ( true ) ; ProcessPanelConsole panel = new ProcessPanelConsole ( rules , resources , prompt , matcher ) ; assertTrue ( panel . runConsole ( installData , console ) ) ; assertEquals ( <NUM_LIT:2> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:1> ) , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ) ; } @ Test public void testExecuteClassException ( ) throws Exception { Executable . init ( ) ; Executable . setException ( true ) ; ProcessPanelConsole panel = new ProcessPanelConsole ( rules , resources , prompt , matcher ) ; assertFalse ( panel . runConsole ( installData , console ) ) ; assertEquals ( <NUM_LIT:3> , console . getOutput ( ) . size ( ) ) ; assertTrue ( console . getOutput ( ) . get ( <NUM_LIT:2> ) . equals ( "<STR_LIT>" ) ) ; assertEquals ( <NUM_LIT:1> , Executable . getInvocations ( ) ) ; assertArrayEquals ( Executable . getArgs ( <NUM_LIT:0> ) , new String [ ] { "<STR_LIT>" } ) ; } } </s>
<s> package com . izforge . izpack . panels ; import static org . hamcrest . MatcherAssert . assertThat ; import java . util . Arrays ; import java . util . Collections ; import org . fest . swing . fixture . DialogFixture ; import org . fest . swing . fixture . FrameFixture ; import org . hamcrest . text . StringContains ; import org . junit . Before ; import org . junit . Test ; import org . mockito . Mockito ; import com . izforge . izpack . api . GuiId ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . data . binding . Help ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . gui . IconsDatabase ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . gui . IzPanelView ; import com . izforge . izpack . panels . finish . FinishPanel ; import com . izforge . izpack . panels . hello . HelloPanel ; import com . izforge . izpack . panels . htmlinfo . HTMLInfoPanel ; import com . izforge . izpack . panels . licence . LicencePanel ; import com . izforge . izpack . panels . simplefinish . SimpleFinishPanel ; import com . izforge . izpack . panels . test . AbstractPanelTest ; import com . izforge . izpack . panels . test . TestGUIPanelContainer ; public class PanelDisplayTest extends AbstractPanelTest { public PanelDisplayTest ( GUIInstallData guiInstallData , ResourceManager resourceManager , UninstallDataWriter uninstallDataWriter , TestGUIPanelContainer container , IconsDatabase icons , RulesEngine rules , ObjectFactory factory ) { super ( container , guiInstallData , resourceManager , factory , rules , icons , uninstallDataWriter ) ; } @ Before public void setUp ( ) { getResourceManager ( ) . setResourceBasePath ( "<STR_LIT>" ) ; } @ Test public void htmlInfoPanelShouldDisplayText ( ) throws Exception { FrameFixture frameFixture = show ( HTMLInfoPanel . class ) ; String textArea = frameFixture . textBox ( GuiId . HTML_INFO_PANEL_TEXT . id ) . text ( ) ; assertThat ( textArea , StringContains . containsString ( "<STR_LIT>" ) ) ; } @ Test public void licencePanelShouldDisplayText ( ) throws Exception { FrameFixture frameFixture = show ( LicencePanel . class , HTMLInfoPanel . class ) ; String textArea = frameFixture . textBox ( GuiId . LICENCE_TEXT_AREA . id ) . text ( ) ; assertThat ( textArea , StringContains . containsString ( "<STR_LIT>" ) ) ; } @ Test public void simpleFinishPanelShouldDisplayFinishingText ( ) throws Exception { FrameFixture frameFixture = show ( SimpleFinishPanel . class ) ; String text = frameFixture . label ( GuiId . SIMPLE_FINISH_LABEL . id ) . text ( ) ; assertThat ( text , StringContains . containsString ( "<STR_LIT>" ) ) ; } @ Test public void helloThenFinishPanelShouldDisplay ( ) throws Exception { UninstallDataWriter uninstallDataWriter = getUninstallDataWriter ( ) ; Mockito . when ( uninstallDataWriter . isUninstallRequired ( ) ) . thenReturn ( true ) ; FrameFixture frameFixture = show ( HelloPanel . class , SimpleFinishPanel . class ) ; String welcomeLabel = frameFixture . label ( GuiId . HELLO_PANEL_LABEL . id ) . text ( ) ; assertThat ( welcomeLabel , StringContains . containsString ( "<STR_LIT>" ) ) ; frameFixture . button ( GuiId . BUTTON_NEXT . id ) . click ( ) ; String uninstallLabel = frameFixture . label ( GuiId . SIMPLE_FINISH_UNINSTALL_LABEL . id ) . text ( ) ; assertThat ( uninstallLabel , StringContains . containsString ( "<STR_LIT>" ) ) ; } @ Test public void finishPanelShouldDisplay ( ) throws Exception { FrameFixture frameFixture = show ( FinishPanel . class ) ; String text = frameFixture . label ( GuiId . FINISH_PANEL_LABEL . id ) . text ( ) ; assertThat ( text , StringContains . containsString ( "<STR_LIT>" ) ) ; frameFixture . button ( GuiId . FINISH_PANEL_AUTO_BUTTON . id ) . requireVisible ( ) ; } @ Test public void helpShouldDisplay ( ) throws Exception { Panel panel = new Panel ( ) ; panel . setClassName ( HelloPanel . class . getName ( ) ) ; panel . setHelps ( Arrays . asList ( new Help ( "<STR_LIT>" , "<STR_LIT>" ) ) ) ; IzPanelView panelView = createPanelView ( panel ) ; FrameFixture frameFixture = show ( Collections . singletonList ( panelView ) ) ; frameFixture . button ( GuiId . BUTTON_HELP . id ) . requireVisible ( ) ; frameFixture . button ( GuiId . BUTTON_HELP . id ) . click ( ) ; DialogFixture dialogFixture = frameFixture . dialog ( GuiId . HELP_WINDOWS . id ) ; dialogFixture . requireVisible ( ) ; assertThat ( dialogFixture . textBox ( ) . text ( ) , StringContains . containsString ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . izforge . izpack . panels . test ; import java . util . Properties ; import org . mockito . Mockito ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import org . picocontainer . injectors . ProviderAdapter ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . core . container . PlatformProvider ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . factory . DefaultObjectFactory ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . core . rules . ConditionContainer ; import com . izforge . izpack . installer . automation . AutomatedInstaller ; import com . izforge . izpack . installer . container . provider . RulesProvider ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . unpacker . IUnpacker ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . PlatformModelMatcher ; import com . izforge . izpack . util . Platforms ; public abstract class AbstractTestPanelContainer extends AbstractContainer { @ Override public MutablePicoContainer getContainer ( ) { return super . getContainer ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { Properties properties = System . getProperties ( ) ; addComponent ( properties , properties ) ; addComponent ( Variables . class , DefaultVariables . class ) ; addComponent ( ResourceManager . class ) ; addComponent ( UninstallData . class ) ; addComponent ( ConditionContainer . class ) ; addComponent ( UninstallDataWriter . class , Mockito . mock ( UninstallDataWriter . class ) ) ; addComponent ( AutomatedInstaller . class ) ; container . addComponent ( new DefaultObjectFactory ( this ) ) ; addComponent ( IUnpacker . class , Mockito . mock ( IUnpacker . class ) ) ; addComponent ( Housekeeper . class , Mockito . mock ( Housekeeper . class ) ) ; addComponent ( Platforms . class ) ; addComponent ( Container . class , this ) ; addComponent ( PlatformModelMatcher . class ) ; container . addAdapter ( new ProviderAdapter ( new RulesProvider ( ) ) ) ; container . addAdapter ( new ProviderAdapter ( new PlatformProvider ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . panels . test ; import java . util . ArrayList ; import java . util . List ; import javax . swing . SwingUtilities ; import org . fest . swing . fixture . FrameFixture ; import org . junit . After ; import org . junit . runner . RunWith ; import org . mockito . Mockito ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . factory . ObjectFactory ; import com . izforge . izpack . api . rules . RulesEngine ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . gui . IconsDatabase ; import com . izforge . izpack . gui . log . Log ; import com . izforge . izpack . installer . base . InstallDataConfiguratorWithRules ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . gui . DefaultNavigator ; import com . izforge . izpack . installer . gui . InstallerController ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . gui . IzPanelView ; import com . izforge . izpack . installer . gui . IzPanels ; import com . izforge . izpack . test . Container ; import com . izforge . izpack . test . junit . PicoRunner ; import com . izforge . izpack . util . Housekeeper ; import com . izforge . izpack . util . Platforms ; @ RunWith ( PicoRunner . class ) @ Container ( TestGUIPanelContainer . class ) public class AbstractPanelTest { private final TestGUIPanelContainer container ; private GUIInstallData installData ; private FrameFixture frameFixture ; private ResourceManager resourceManager ; private UninstallDataWriter uninstallDataWriter ; private final IconsDatabase icons ; private final RulesEngine rules ; private final ObjectFactory factory ; private IzPanels panels ; public AbstractPanelTest ( TestGUIPanelContainer container , GUIInstallData installData , ResourceManager resourceManager , ObjectFactory factory , RulesEngine rules , IconsDatabase icons , UninstallDataWriter uninstallDataWriter ) { this . container = container ; this . installData = installData ; this . resourceManager = resourceManager ; this . factory = factory ; this . rules = rules ; this . icons = icons ; this . uninstallDataWriter = uninstallDataWriter ; } @ After public void tearDown ( ) throws Exception { if ( frameFixture != null ) { frameFixture . cleanUp ( ) ; } } protected GUIInstallData getInstallData ( ) { return installData ; } protected ResourceManager getResourceManager ( ) { return resourceManager ; } protected UninstallDataWriter getUninstallDataWriter ( ) { return uninstallDataWriter ; } protected IzPanels getPanels ( ) { return panels ; } protected FrameFixture show ( Class ... panelClasses ) throws Exception { List < IzPanelView > panelList = new ArrayList < IzPanelView > ( ) ; for ( Class panelClass : panelClasses ) { Panel panel = new Panel ( ) ; panel . setClassName ( panelClass . getName ( ) ) ; panelList . add ( createPanelView ( panel ) ) ; } return show ( panelList ) ; } protected FrameFixture show ( final List < IzPanelView > panelViews ) throws Exception { final InstallerFrame [ ] handle = new InstallerFrame [ <NUM_LIT:1> ] ; SwingUtilities . invokeAndWait ( new Runnable ( ) { @ Override public void run ( ) { panels = new IzPanels ( panelViews , container , installData ) ; DefaultNavigator navigator = new DefaultNavigator ( panels , icons , installData ) ; InstallerFrame frame = new InstallerFrame ( "<STR_LIT>" , installData , rules , icons , panels , uninstallDataWriter , resourceManager , Mockito . mock ( UninstallData . class ) , Mockito . mock ( Housekeeper . class ) , navigator , Mockito . mock ( Log . class ) ) ; handle [ <NUM_LIT:0> ] = frame ; } } ) ; InstallerFrame frame = handle [ <NUM_LIT:0> ] ; frameFixture = new FrameFixture ( frame ) ; container . getContainer ( ) . addComponent ( frame ) ; InstallDataConfiguratorWithRules configuratorWithRules = new InstallDataConfiguratorWithRules ( installData , rules , Platforms . UNIX ) ; InstallerController controller = new InstallerController ( configuratorWithRules , frame ) ; controller . buildInstallation ( ) ; controller . launchInstallation ( ) ; return frameFixture ; } protected IzPanelView createPanelView ( Panel panel ) { return new IzPanelView ( panel , factory , installData ) ; } } </s>
<s> package com . izforge . izpack . panels . test ; import org . mockito . Mockito ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import org . picocontainer . injectors . ProviderAdapter ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . gui . log . Log ; import com . izforge . izpack . installer . base . InstallDataConfiguratorWithRules ; import com . izforge . izpack . installer . container . provider . IconsProvider ; import com . izforge . izpack . test . provider . GUIInstallDataMockProvider ; public class TestGUIPanelContainer extends AbstractTestPanelContainer { public TestGUIPanelContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { super . fillContainer ( container ) ; addComponent ( InstallDataConfiguratorWithRules . class ) ; addComponent ( Log . class , Mockito . mock ( Log . class ) ) ; container . addAdapter ( new ProviderAdapter ( new GUIInstallDataMockProvider ( ) ) ) ; container . addAdapter ( new ProviderAdapter ( new IconsProvider ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . panels . test ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import org . picocontainer . injectors . ProviderAdapter ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . core . handler . ConsolePrompt ; import com . izforge . izpack . test . provider . InstallDataMockProvider ; import com . izforge . izpack . test . util . TestConsole ; public class TestConsolePanelContainer extends AbstractTestPanelContainer { public TestConsolePanelContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { super . fillContainer ( container ) ; addComponent ( TestConsole . class ) ; addComponent ( ConsolePrompt . class ) ; container . addAdapter ( new ProviderAdapter ( new InstallDataMockProvider ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import java . io . File ; import java . io . FileInputStream ; import java . io . ObjectInputStream ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Pack ; import com . izforge . izpack . util . Platform ; import com . izforge . izpack . util . file . FileUtils ; class TargetPanelHelper { private static final String TARGET_PANEL_DIR = "<STR_LIT>" ; private static final String PREFIX = TARGET_PANEL_DIR + "<STR_LIT:.>" ; private static final Logger logger = Logger . getLogger ( TargetPanelHelper . class . getName ( ) ) ; public static String getPath ( InstallData installData ) { String defaultPath = installData . getDefaultInstallPath ( ) ; if ( defaultPath == null ) { defaultPath = installData . getVariable ( "<STR_LIT>" ) ; } String path = getTargetPanelDir ( installData ) ; if ( path != null ) { path = installData . getVariables ( ) . replace ( path ) ; } if ( path == null && defaultPath != null ) { path = installData . getVariables ( ) . replace ( defaultPath ) ; } return path ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static boolean isIncompatibleInstallation ( String dir ) { boolean result = false ; File file = new File ( dir , InstallData . INSTALLATION_INFORMATION ) ; if ( file . exists ( ) ) { FileInputStream input = null ; ObjectInputStream objectInput = null ; try { input = new FileInputStream ( file ) ; objectInput = new ObjectInputStream ( input ) ; List < Object > packs = ( List < Object > ) objectInput . readObject ( ) ; for ( Object pack : packs ) { if ( ! ( pack instanceof Pack ) ) { return true ; } } } catch ( Throwable exception ) { logger . log ( Level . FINE , "<STR_LIT>" + file . getPath ( ) + "<STR_LIT>" , exception ) ; result = true ; } finally { FileUtils . close ( objectInput ) ; FileUtils . close ( input ) ; } } return result ; } private static String getTargetPanelDir ( InstallData installData ) { Platform platform = installData . getPlatform ( ) ; String path = null ; if ( platform . getSymbolicName ( ) != null ) { path = installData . getVariable ( PREFIX + platform . getSymbolicName ( ) . toLowerCase ( ) ) ; } if ( path == null ) { path = getTargetPanelDir ( installData , platform . getName ( ) ) ; } if ( path == null ) { path = installData . getVariable ( TARGET_PANEL_DIR ) ; } return path ; } private static String getTargetPanelDir ( InstallData installData , Platform . Name name ) { String path = null ; List < Platform . Name > queue = new ArrayList < Platform . Name > ( ) ; queue . add ( name ) ; while ( ! queue . isEmpty ( ) ) { name = queue . remove ( <NUM_LIT:0> ) ; path = installData . getVariable ( PREFIX + name . toString ( ) . toLowerCase ( ) ) ; if ( path != null ) { break ; } Collections . addAll ( queue , name . getParents ( ) ) ; } return path ; } } </s>
<s> package com . izforge . izpack . panels . target ; import java . io . File ; import java . io . PrintWriter ; import java . util . Properties ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . installer . console . AbstractPanelConsole ; import com . izforge . izpack . installer . console . PanelConsole ; import com . izforge . izpack . util . Console ; public class TargetPanelConsole extends AbstractPanelConsole implements PanelConsole { public TargetPanelConsole ( ) { super ( ) ; } public boolean runGeneratePropertiesFile ( InstallData installData , PrintWriter printWriter ) { printWriter . println ( InstallData . INSTALL_PATH + "<STR_LIT:=>" ) ; return true ; } public boolean runConsoleFromProperties ( InstallData installData , Properties properties ) { boolean result = false ; String path = properties . getProperty ( InstallData . INSTALL_PATH ) ; if ( path == null || "<STR_LIT>" . equals ( path . trim ( ) ) ) { System . err . println ( "<STR_LIT>" ) ; } else if ( TargetPanelHelper . isIncompatibleInstallation ( path ) ) { System . err . println ( getIncompatibleInstallationMsg ( installData ) ) ; } else { path = installData . getVariables ( ) . replace ( path ) ; installData . setInstallPath ( path ) ; result = true ; } return result ; } @ Override public boolean runConsole ( InstallData installData , Console console ) { String defaultPath = TargetPanelHelper . getPath ( installData ) ; if ( defaultPath == null ) { defaultPath = "<STR_LIT>" ; } String path = console . prompt ( "<STR_LIT>" + defaultPath + "<STR_LIT>" , null ) ; if ( path != null ) { path = path . trim ( ) ; if ( path . isEmpty ( ) ) { path = defaultPath ; } path = installData . getVariables ( ) . replace ( path ) ; if ( TargetPanelHelper . isIncompatibleInstallation ( path ) ) { console . println ( getIncompatibleInstallationMsg ( installData ) ) ; return runConsole ( installData , console ) ; } else if ( ! path . isEmpty ( ) ) { File selectedDir = new File ( path ) ; if ( selectedDir . exists ( ) && selectedDir . isDirectory ( ) && selectedDir . list ( ) . length > <NUM_LIT:0> ) { console . println ( installData . getMessages ( ) . get ( "<STR_LIT>" ) ) ; } installData . setInstallPath ( path ) ; return promptEndPanel ( installData , console ) ; } return runConsole ( installData , console ) ; } else { return false ; } } private String getIncompatibleInstallationMsg ( InstallData installData ) { return installData . getMessages ( ) . get ( "<STR_LIT>" ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . installer . automation . PanelAutomation ; public class TargetPanelAutomation implements PanelAutomation { public TargetPanelAutomation ( ) { } public void makeXMLData ( InstallData idata , IXMLElement panelRoot ) { IXMLElement ipath = new XMLElementImpl ( "<STR_LIT>" , panelRoot ) ; ipath . setContent ( idata . getInstallPath ( ) ) ; IXMLElement prev = panelRoot . getFirstChildNamed ( "<STR_LIT>" ) ; if ( prev != null ) { panelRoot . removeChild ( prev ) ; } panelRoot . addChild ( ipath ) ; } public void runAutomated ( InstallData idata , IXMLElement panelRoot ) { IXMLElement ipath = panelRoot . getFirstChildNamed ( "<STR_LIT>" ) ; String path = ipath . getContent ( ) ; path = idata . getVariables ( ) . replace ( path ) ; if ( TargetPanelHelper . isIncompatibleInstallation ( path ) ) { throw new InstallerException ( idata . getMessages ( ) . get ( "<STR_LIT>" ) ) ; } idata . setInstallPath ( path ) ; } } </s>
<s> package com . izforge . izpack . panels . target ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . gui . log . Log ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . panels . path . PathInputPanel ; public class TargetPanel extends PathInputPanel { private static final long serialVersionUID = <NUM_LIT> ; public TargetPanel ( Panel panel , InstallerFrame parent , GUIInstallData installData , Resources resources , Log log ) { super ( panel , parent , installData , resources , log ) ; } public void panelActivate ( ) { String path = TargetPanelHelper . getPath ( installData ) ; if ( path != null ) { pathSelectionPanel . setPath ( path ) ; } super . panelActivate ( ) ; } public boolean isValidated ( ) { boolean result = false ; if ( TargetPanelHelper . isIncompatibleInstallation ( pathSelectionPanel . getPath ( ) ) ) { emitError ( getString ( "<STR_LIT>" ) , getString ( "<STR_LIT>" ) ) ; } else if ( super . isValidated ( ) ) { installData . setInstallPath ( pathSelectionPanel . getPath ( ) ) ; result = true ; } return result ; } public void makeXMLData ( IXMLElement panelRoot ) { new TargetPanelAutomation ( ) . makeXMLData ( installData , panelRoot ) ; } public String getSummaryBody ( ) { return ( this . installData . getInstallPath ( ) ) ; } } </s>
<s> package com . izforge . izpack . panels . defaulttarget ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . installer . automation . PanelAutomation ; public class DefaultTargetPanelAutomationHelper implements PanelAutomation { private VariableSubstitutor variableSubstitutor ; public DefaultTargetPanelAutomationHelper ( VariableSubstitutor variableSubstitutor ) { this . variableSubstitutor = variableSubstitutor ; } public void makeXMLData ( InstallData idata , IXMLElement panelRoot ) { IXMLElement ipath = new XMLElementImpl ( "<STR_LIT>" , panelRoot ) ; ipath . setContent ( idata . getInstallPath ( ) ) ; IXMLElement prev = panelRoot . getFirstChildNamed ( "<STR_LIT>" ) ; if ( prev != null ) { panelRoot . removeChild ( prev ) ; } panelRoot . addChild ( ipath ) ; } public void runAutomated ( InstallData idata , IXMLElement panelRoot ) { IXMLElement ipath = panelRoot . getFirstChildNamed ( "<STR_LIT>" ) ; String path = ipath . getContent ( ) ; try { path = variableSubstitutor . substitute ( path ) ; } catch ( Exception e ) { } idata . setInstallPath ( path ) ; } } </s>
<s> package com . izforge . izpack . panels . defaulttarget ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . gui . log . Log ; import com . izforge . izpack . installer . automation . PanelAutomation ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . panels . path . PathInputPanel ; public class DefaultTargetPanel extends PathInputPanel { private static final long serialVersionUID = <NUM_LIT> ; private PanelAutomation defaultTargetPanelAutomationHelper ; public DefaultTargetPanel ( Panel panel , InstallerFrame parent , GUIInstallData installData , Resources resources , DefaultTargetPanelAutomationHelper helper , Log log ) { super ( panel , parent , installData , resources , log ) ; this . defaultTargetPanelAutomationHelper = helper ; } public void panelActivate ( ) { pathSelectionPanel . setPath ( this . installData . getDefaultInstallPath ( ) ) ; parent . skipPanel ( ) ; } public boolean isValidated ( ) { return ( true ) ; } public void makeXMLData ( IXMLElement panelRoot ) { defaultTargetPanelAutomationHelper . makeXMLData ( this . installData , panelRoot ) ; } public String getSummaryBody ( ) { return ( this . installData . getInstallPath ( ) ) ; } } </s>
<s> package com . izforge . izpack . panels . xinfo ; import java . awt . Font ; import java . awt . GridBagConstraints ; import java . awt . GridBagLayout ; import java . awt . Insets ; import javax . swing . JLabel ; import javax . swing . JScrollPane ; import javax . swing . JTextArea ; import com . izforge . izpack . api . data . Panel ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . gui . LabelFactory ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . gui . IzPanel ; import com . izforge . izpack . installer . gui . LayoutHelper ; public class XInfoPanel extends IzPanel { private static final long serialVersionUID = <NUM_LIT> ; private JTextArea textArea ; private String info ; public XInfoPanel ( Panel panel , InstallerFrame parent , GUIInstallData installData , Resources resources ) { super ( panel , parent , installData , resources ) ; GridBagLayout layout = new GridBagLayout ( ) ; GridBagConstraints gbConstraints = new GridBagConstraints ( ) ; setLayout ( layout ) ; JLabel infoLabel = LabelFactory . create ( getString ( "<STR_LIT>" ) , parent . getIcons ( ) . get ( "<STR_LIT>" ) , JLabel . TRAILING ) ; LayoutHelper . buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) ; gbConstraints . insets = new Insets ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ; gbConstraints . fill = GridBagConstraints . BOTH ; gbConstraints . anchor = GridBagConstraints . SOUTHWEST ; layout . addLayoutComponent ( infoLabel , gbConstraints ) ; add ( infoLabel ) ; textArea = new JTextArea ( ) ; textArea . setEditable ( false ) ; String textAreaFont = installData . getVariable ( "<STR_LIT>" ) ; if ( textAreaFont != null && textAreaFont . length ( ) > <NUM_LIT:0> ) { Font font = Font . decode ( textAreaFont ) ; textArea . setFont ( font ) ; } JScrollPane scroller = new JScrollPane ( textArea ) ; LayoutHelper . buildConstraints ( gbConstraints , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1.0> , <NUM_LIT> ) ; gbConstraints . anchor = GridBagConstraints . CENTER ; layout . addLayoutComponent ( scroller , gbConstraints ) ; add ( scroller ) ; } private void loadInfo ( ) { info = getResources ( ) . getString ( "<STR_LIT>" , null , "<STR_LIT>" ) ; } private void parseText ( ) { info = installData . getVariables ( ) . replace ( info ) ; } public void panelActivate ( ) { loadInfo ( ) ; parseText ( ) ; textArea . setText ( info ) ; textArea . setCaretPosition ( <NUM_LIT:0> ) ; } public boolean isValidated ( ) { return true ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; public class PasswordUIElement extends UIElement { public PasswordUIElement ( ) { super ( ) ; } PasswordGroup passwordGroup ; public PasswordGroup getPasswordGroup ( ) { return passwordGroup ; } public void setPasswordGroup ( PasswordGroup passwordGroup ) { this . passwordGroup = passwordGroup ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . awt . Dimension ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import java . awt . event . FocusEvent ; import java . awt . event . FocusListener ; import java . io . File ; import java . util . ArrayList ; import java . util . Enumeration ; import java . util . List ; import java . util . logging . Logger ; import javax . swing . Box ; import javax . swing . BoxLayout ; import javax . swing . DefaultListModel ; import javax . swing . JButton ; import javax . swing . JFileChooser ; import javax . swing . JLabel ; import javax . swing . JList ; import javax . swing . JOptionPane ; import javax . swing . JPanel ; import javax . swing . JScrollPane ; import javax . swing . ListSelectionModel ; import com . izforge . izpack . api . resource . Messages ; import com . izforge . izpack . gui . ButtonFactory ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . panels . userinput . processorclient . StringInputProcessingClient ; import com . izforge . izpack . panels . userinput . validator . ValidatorContainer ; public class MultipleFileInputField extends JPanel implements ActionListener , FocusListener { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( MultipleFileInputField . class . getName ( ) ) ; boolean isDirectory ; InstallerFrame parentFrame ; List < ValidatorContainer > validators ; DefaultListModel model ; JList fileList ; JButton browseBtn ; JButton deleteBtn ; String set ; int size ; GUIInstallData data ; String fileExtension ; String fileExtensionDescription ; boolean allowEmpty ; boolean createMultipleVariables ; int visibleRows = <NUM_LIT:10> ; int preferredX = <NUM_LIT> ; int preferredY = <NUM_LIT> ; String labeltext ; public MultipleFileInputField ( InstallerFrame parent , GUIInstallData data , boolean directory , String set , int size , List < ValidatorContainer > validatorConfig , String fileExt , String fileExtDesc , boolean createMultipleVariables , int visibleRows , int preferredXSize , int preferredYSize , String labelText ) { this . parentFrame = parent ; this . data = data ; this . validators = validatorConfig ; this . set = set ; this . size = size ; this . fileExtension = fileExt ; this . fileExtensionDescription = fileExtDesc ; this . isDirectory = directory ; this . createMultipleVariables = createMultipleVariables ; this . visibleRows = visibleRows ; this . preferredX = preferredXSize ; this . preferredY = preferredYSize ; this . labeltext = labelText ; this . initialize ( ) ; } public void clearFiles ( ) { this . model . clear ( ) ; } public void addFile ( String file ) { this . model . addElement ( file ) ; } public void initialize ( ) { JPanel main = new JPanel ( ) ; main . setLayout ( new BoxLayout ( main , BoxLayout . Y_AXIS ) ) ; JPanel labelPanel = new JPanel ( ) ; labelPanel . setLayout ( new BoxLayout ( labelPanel , BoxLayout . X_AXIS ) ) ; JLabel label = new JLabel ( this . labeltext ) ; labelPanel . add ( label ) ; labelPanel . add ( Box . createHorizontalGlue ( ) ) ; main . add ( labelPanel ) ; model = new DefaultListModel ( ) ; fileList = new JList ( model ) ; fileList . setSelectionMode ( ListSelectionModel . SINGLE_SELECTION ) ; fileList . setVisibleRowCount ( visibleRows ) ; JPanel panel = new JPanel ( ) ; panel . setLayout ( new BoxLayout ( panel , BoxLayout . X_AXIS ) ) ; JPanel buttonPanel = new JPanel ( ) ; buttonPanel . setLayout ( new BoxLayout ( buttonPanel , BoxLayout . Y_AXIS ) ) ; Messages messages = data . getMessages ( ) ; browseBtn = ButtonFactory . createButton ( messages . get ( "<STR_LIT>" ) , data . buttonsHColor ) ; browseBtn . addActionListener ( this ) ; deleteBtn = ButtonFactory . createButton ( messages . get ( "<STR_LIT>" ) , data . buttonsHColor ) ; deleteBtn . addActionListener ( this ) ; JScrollPane scroller = new JScrollPane ( fileList ) ; scroller . setPreferredSize ( new Dimension ( preferredX , preferredY ) ) ; panel . add ( scroller ) ; buttonPanel . add ( browseBtn ) ; buttonPanel . add ( deleteBtn ) ; buttonPanel . add ( Box . createVerticalGlue ( ) ) ; panel . add ( buttonPanel ) ; main . add ( panel ) ; main . add ( Box . createVerticalGlue ( ) ) ; add ( main ) ; } @ Override public void actionPerformed ( ActionEvent arg0 ) { if ( arg0 . getSource ( ) == browseBtn ) { logger . fine ( "<STR_LIT>" ) ; String initialPath = "<STR_LIT:.>" ; if ( fileList . getSelectedValue ( ) != null ) { initialPath = ( String ) fileList . getSelectedValue ( ) ; } JFileChooser filechooser = new JFileChooser ( initialPath ) ; if ( isDirectory ) { filechooser . setFileSelectionMode ( JFileChooser . DIRECTORIES_ONLY ) ; } else { filechooser . setFileSelectionMode ( JFileChooser . FILES_ONLY ) ; if ( ( fileExtension != null ) && ( fileExtensionDescription != null ) ) { UserInputFileFilter fileFilter = new UserInputFileFilter ( ) ; fileFilter . setFileExt ( fileExtension ) ; fileFilter . setFileExtDesc ( fileExtensionDescription ) ; filechooser . setFileFilter ( fileFilter ) ; } } if ( filechooser . showOpenDialog ( parentFrame ) == JFileChooser . APPROVE_OPTION ) { String selectedFile = filechooser . getSelectedFile ( ) . getAbsolutePath ( ) ; model . addElement ( selectedFile ) ; logger . fine ( "<STR_LIT>" + selectedFile ) ; } } if ( arg0 . getSource ( ) == deleteBtn ) { logger . fine ( "<STR_LIT>" ) ; if ( fileList . getSelectedValue ( ) != null ) { model . removeElement ( fileList . getSelectedValue ( ) ) ; } } } public List < String > getSelectedFiles ( ) { List < String > result = null ; if ( model . size ( ) > <NUM_LIT:0> ) { result = new ArrayList < String > ( ) ; Enumeration < ? > elements = model . elements ( ) ; for ( ; elements . hasMoreElements ( ) ; ) { String element = ( String ) elements . nextElement ( ) ; result . add ( element ) ; } } return result ; } private void showMessage ( String messageType ) { JOptionPane . showMessageDialog ( parentFrame , parentFrame . getMessages ( ) . get ( "<STR_LIT>" + messageType + "<STR_LIT>" ) , parentFrame . getMessages ( ) . get ( "<STR_LIT>" + messageType + "<STR_LIT>" ) , JOptionPane . WARNING_MESSAGE ) ; } private boolean validateFile ( String input ) { boolean result = false ; if ( allowEmpty && ( ( input == null ) || ( input . length ( ) == <NUM_LIT:0> ) ) ) { result = true ; } else if ( input != null ) { File file = new File ( input ) ; if ( isDirectory && ! file . isDirectory ( ) ) { result = false ; showMessage ( "<STR_LIT>" ) ; } else if ( ! isDirectory && ! file . isFile ( ) ) { result = false ; showMessage ( "<STR_LIT>" ) ; } else { StringInputProcessingClient processingClient = new StringInputProcessingClient ( input , validators ) ; boolean success = processingClient . validate ( ) ; if ( ! success ) { JOptionPane . showMessageDialog ( parentFrame , processingClient . getValidationMessage ( ) , parentFrame . getMessages ( ) . get ( "<STR_LIT>" ) , JOptionPane . WARNING_MESSAGE ) ; } result = success ; } } else { if ( isDirectory ) { showMessage ( "<STR_LIT>" ) ; } else { showMessage ( "<STR_LIT>" ) ; } } return result ; } public boolean validateField ( ) { boolean result = false ; int fileCount = model . getSize ( ) ; if ( fileCount == <NUM_LIT:0> && allowEmpty ) { return true ; } else { for ( int i = <NUM_LIT:0> ; i < fileCount ; i ++ ) { result = validateFile ( ( String ) model . getElementAt ( i ) ) ; if ( ! result ) { break ; } } } return result ; } public boolean isAllowEmptyInput ( ) { return allowEmpty ; } public void setAllowEmptyInput ( boolean allowEmpty ) { this . allowEmpty = allowEmpty ; } @ Override public void focusGained ( FocusEvent e ) { } @ Override public void focusLost ( FocusEvent e ) { } public boolean isCreateMultipleVariables ( ) { return createMultipleVariables ; } public void setCreateMultipleVariables ( boolean createMultipleVariables ) { this . createMultipleVariables = createMultipleVariables ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JPasswordField ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . panels . userinput . processor . Processor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import com . izforge . izpack . panels . userinput . validator . Validator ; import com . izforge . izpack . panels . userinput . validator . ValidatorContainer ; public class PasswordGroup implements ProcessingClient { private static final Logger logger = Logger . getLogger ( PasswordGroup . class . getName ( ) ) ; private List < JPasswordField > fields = new ArrayList < JPasswordField > ( ) ; private List < ValidatorContainer > validatorContainers = null ; private Processor processor = null ; private String modifiedPassword = null ; private int currentValidator = <NUM_LIT:0> ; private GUIInstallData idata ; public PasswordGroup ( GUIInstallData idata , List < ValidatorContainer > validatorContainers , String processor ) { try { this . idata = idata ; this . validatorContainers = validatorContainers ; } catch ( Throwable t ) { logger . log ( Level . WARNING , "<STR_LIT>" + t , t ) ; this . validatorContainers = null ; } try { this . processor = ( Processor ) Class . forName ( processor ) . newInstance ( ) ; } catch ( Throwable t ) { logger . log ( Level . WARNING , "<STR_LIT>" + t , t ) ; this . processor = null ; } } public GUIInstallData getIdata ( ) { return idata ; } @ Override public int getNumFields ( ) { return ( fields . size ( ) ) ; } @ Override public String getFieldContents ( int index ) throws IndexOutOfBoundsException { if ( ( index < <NUM_LIT:0> ) || ( index >= fields . size ( ) ) ) { throw ( new IndexOutOfBoundsException ( ) ) ; } String contents = new String ( ( fields . get ( index ) ) . getPassword ( ) ) ; return ( contents ) ; } public void addField ( JPasswordField field ) { if ( field != null ) { fields . add ( field ) ; } } public boolean validateContents ( int i ) { boolean returnValue = true ; try { currentValidator = i ; ValidatorContainer container = getValidatorContainer ( i ) ; Validator validator = container . getValidator ( ) ; if ( validator != null ) { returnValue = validator . validate ( this ) ; } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; } return returnValue ; } public String getValidatorMessage ( int i ) { String returnValue = null ; try { ValidatorContainer container = getValidatorContainer ( i ) ; if ( container != null ) { returnValue = container . getMessage ( ) ; } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; } return returnValue ; } public int validatorSize ( ) { int size = <NUM_LIT:0> ; if ( validatorContainers != null ) { size = validatorContainers . size ( ) ; } return size ; } public ValidatorContainer getValidatorContainer ( ) { return getValidatorContainer ( currentValidator ) ; } public ValidatorContainer getValidatorContainer ( int i ) { ValidatorContainer container = null ; try { container = validatorContainers . get ( i ) ; } catch ( Exception e ) { container = null ; } return container ; } @ Override public boolean hasParams ( ) { return hasParams ( currentValidator ) ; } public boolean hasParams ( int i ) { boolean returnValue = false ; try { ValidatorContainer container = getValidatorContainer ( i ) ; if ( container != null ) { returnValue = container . hasParams ( ) ; } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; } return returnValue ; } @ Override public Map < String , String > getValidatorParams ( ) { return getValidatorParams ( currentValidator ) ; } public Map < String , String > getValidatorParams ( int i ) { Map < String , String > returnValue = null ; try { ValidatorContainer container = getValidatorContainer ( i ) ; if ( container != null ) { returnValue = container . getValidatorParams ( ) ; } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; } return returnValue ; } @ Override public String getText ( ) { return getValidatorMessage ( currentValidator ) ; } public void setModifiedPassword ( String value ) { modifiedPassword = value ; } public String getPassword ( ) { String returnValue = "<STR_LIT>" ; if ( modifiedPassword != null ) { returnValue = modifiedPassword ; if ( processor != null ) { logger . warning ( "<STR_LIT>" ) ; } } else if ( processor != null ) { returnValue = processor . process ( this ) ; } else if ( fields . size ( ) > <NUM_LIT:0> ) { returnValue = new String ( fields . get ( <NUM_LIT:0> ) . getPassword ( ) ) ; } return returnValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import javax . swing . * ; public class RadioButtonUIElement extends UIElement { public RadioButtonUIElement ( ) { super ( ) ; } ButtonGroup buttonGroup ; public ButtonGroup getButtonGroup ( ) { return buttonGroup ; } public void setButtonGroup ( ButtonGroup buttonGroup ) { this . buttonGroup = buttonGroup ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . awt . GridBagConstraints ; import java . awt . GridBagLayout ; import java . awt . Insets ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; import java . io . File ; import java . util . List ; import java . util . logging . Logger ; import javax . swing . JButton ; import javax . swing . JFileChooser ; import javax . swing . JOptionPane ; import javax . swing . JPanel ; import javax . swing . JTextField ; import com . izforge . izpack . gui . ButtonFactory ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . InstallerFrame ; import com . izforge . izpack . installer . gui . IzPanel ; import com . izforge . izpack . panels . userinput . processorclient . StringInputProcessingClient ; import com . izforge . izpack . panels . userinput . validator . ValidatorContainer ; public class FileInputField extends JPanel implements ActionListener { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( FileInputField . class . getName ( ) ) ; InstallerFrame parentFrame ; IzPanel parent ; List < ValidatorContainer > validators ; JTextField filetxt ; JButton browseBtn ; String set ; int size ; GUIInstallData installDataGUI ; String fileExtension ; String fileExtensionDescription ; boolean allowEmpty ; protected static final int INVALID = <NUM_LIT:0> , EMPTY = <NUM_LIT:1> ; public FileInputField ( IzPanel parent , GUIInstallData installDataGUI , boolean directory , String set , int size , List < ValidatorContainer > validatorConfig ) { this ( parent , installDataGUI , directory , set , size , validatorConfig , null , null ) ; } public FileInputField ( IzPanel parent , GUIInstallData installDataGUI , boolean directory , String set , int size , List < ValidatorContainer > validatorConfig , String fileExt , String fileExtDesc ) { this . parent = parent ; this . parentFrame = parent . getInstallerFrame ( ) ; this . installDataGUI = installDataGUI ; this . validators = validatorConfig ; this . set = set ; this . size = size ; this . fileExtension = fileExt ; this . fileExtensionDescription = fileExtDesc ; this . initialize ( ) ; } private void initialize ( ) { filetxt = new JTextField ( set , size ) ; filetxt . setCaretPosition ( <NUM_LIT:0> ) ; GridBagLayout layout = new GridBagLayout ( ) ; setLayout ( layout ) ; GridBagConstraints fileTextConstraint = new GridBagConstraints ( ) ; GridBagConstraints fileButtonConstraint = new GridBagConstraints ( ) ; fileTextConstraint . gridx = <NUM_LIT:0> ; fileTextConstraint . gridy = <NUM_LIT:0> ; fileTextConstraint . anchor = GridBagConstraints . WEST ; fileTextConstraint . insets = new Insets ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:5> ) ; fileButtonConstraint . gridx = <NUM_LIT:1> ; fileButtonConstraint . gridy = <NUM_LIT:0> ; fileButtonConstraint . anchor = GridBagConstraints . WEST ; browseBtn = ButtonFactory . createButton ( installDataGUI . getMessages ( ) . get ( "<STR_LIT>" ) , installDataGUI . buttonsHColor ) ; browseBtn . addActionListener ( this ) ; this . add ( filetxt , fileTextConstraint ) ; this . add ( browseBtn , fileButtonConstraint ) ; } public void setFile ( String filename ) { filetxt . setText ( filename ) ; } @ Override public void actionPerformed ( ActionEvent arg0 ) { if ( arg0 . getSource ( ) == browseBtn ) { logger . fine ( "<STR_LIT>" ) ; String initialPath = "<STR_LIT:.>" ; if ( filetxt . getText ( ) != null ) { initialPath = filetxt . getText ( ) ; } JFileChooser filechooser = new JFileChooser ( initialPath ) ; prepareFileChooser ( filechooser ) ; if ( filechooser . showOpenDialog ( parentFrame ) == JFileChooser . APPROVE_OPTION ) { String selectedFile = filechooser . getSelectedFile ( ) . getAbsolutePath ( ) ; filetxt . setText ( selectedFile ) ; logger . fine ( "<STR_LIT>" + selectedFile ) ; } } } protected void prepareFileChooser ( JFileChooser filechooser ) { filechooser . setFileSelectionMode ( JFileChooser . FILES_ONLY ) ; if ( ( fileExtension != null ) && ( fileExtensionDescription != null ) ) { UserInputFileFilter fileFilter = new UserInputFileFilter ( ) ; fileFilter . setFileExt ( fileExtension ) ; fileFilter . setFileExtDesc ( fileExtensionDescription ) ; filechooser . setFileFilter ( fileFilter ) ; } } public File getSelectedFile ( ) { File result = null ; if ( filetxt . getText ( ) != null ) { result = new File ( filetxt . getText ( ) ) ; } return result ; } protected void showMessage ( int k ) { if ( k == INVALID ) { showMessage ( "<STR_LIT>" ) ; } else if ( k == EMPTY ) { showMessage ( "<STR_LIT>" ) ; } } protected void showMessage ( String messageType ) { JOptionPane . showMessageDialog ( parentFrame , parentFrame . getMessages ( ) . get ( "<STR_LIT>" + messageType + "<STR_LIT>" ) , parentFrame . getMessages ( ) . get ( "<STR_LIT>" + messageType + "<STR_LIT>" ) , JOptionPane . WARNING_MESSAGE ) ; } public boolean validateField ( ) { boolean result = false ; String input = filetxt . getText ( ) ; boolean empty = ( input == null ) || ( input . length ( ) == <NUM_LIT:0> ) ; if ( empty && allowEmpty ) { result = true ; } else if ( ! empty ) { if ( input . startsWith ( "<STR_LIT>" ) ) { String home = System . getProperty ( "<STR_LIT>" ) ; input = home + input . substring ( <NUM_LIT:1> ) ; } File file = new File ( input ) . getAbsoluteFile ( ) ; input = file . toString ( ) ; filetxt . setText ( input ) ; if ( ! _validate ( file ) ) { result = false ; showMessage ( INVALID ) ; } else { StringInputProcessingClient processingClient = new StringInputProcessingClient ( input , validators ) ; boolean success = processingClient . validate ( ) ; if ( ! success ) { JOptionPane . showMessageDialog ( parentFrame , processingClient . getValidationMessage ( ) , parentFrame . getMessages ( ) . get ( "<STR_LIT>" ) , JOptionPane . WARNING_MESSAGE ) ; } result = success ; } } else { showMessage ( EMPTY ) ; } return result ; } protected boolean _validate ( File file ) { return file . isFile ( ) ; } public boolean isAllowEmptyInput ( ) { return allowEmpty ; } public void setAllowEmptyInput ( boolean allowEmpty ) { this . allowEmpty = allowEmpty ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Properties ; import java . util . StringTokenizer ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . resource . Resources ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . console . ConsolePanels ; import com . izforge . izpack . installer . console . PanelConsole ; import com . izforge . izpack . installer . console . PanelConsoleHelper ; import com . izforge . izpack . panels . userinput . processor . Processor ; import com . izforge . izpack . util . Console ; import com . izforge . izpack . util . OsVersion ; import com . izforge . izpack . util . helper . SpecHelper ; public class UserInputPanelConsoleHelper extends PanelConsoleHelper implements PanelConsole { private static final Logger logger = Logger . getLogger ( UserInputPanelConsoleHelper . class . getName ( ) ) ; protected int instanceNumber = <NUM_LIT:0> ; private static int instanceCount = <NUM_LIT:0> ; private static final String SPEC_FILE_NAME = "<STR_LIT>" ; private static final String NODE_ID = "<STR_LIT>" ; private static final String INSTANCE_IDENTIFIER = "<STR_LIT>" ; protected static final String PANEL_IDENTIFIER = "<STR_LIT:id>" ; private static final String FIELD_NODE_ID = "<STR_LIT:field>" ; protected static final String ATTRIBUTE_CONDITIONID_NAME = "<STR_LIT>" ; private static final String VARIABLE = "<STR_LIT>" ; private static final String SET = "<STR_LIT>" ; private static final String TEXT = "<STR_LIT>" ; private static final String SPEC = "<STR_LIT>" ; private static final String PWD = "<STR_LIT>" ; private static final String TYPE_ATTRIBUTE = "<STR_LIT:type>" ; private static final String TEXT_FIELD = "<STR_LIT:text>" ; private static final String COMBO_FIELD = "<STR_LIT>" ; private static final String STATIC_TEXT = "<STR_LIT>" ; private static final String CHOICE = "<STR_LIT>" ; private static final String DIR = "<STR_LIT>" ; private static final String FILE = "<STR_LIT:file>" ; private static final String PASSWORD = "<STR_LIT:password>" ; private static final String VALUE = "<STR_LIT:value>" ; private static final String RADIO_FIELD = "<STR_LIT>" ; private static final String TITLE_FIELD = "<STR_LIT:title>" ; private static final String CHECK_FIELD = "<STR_LIT>" ; private static final String RULE_FIELD = "<STR_LIT>" ; private static final String SPACE = "<STR_LIT>" ; private static final String DIVIDER = "<STR_LIT>" ; static final String DISPLAY_FORMAT = "<STR_LIT>" ; static final String PLAIN_STRING = "<STR_LIT>" ; static final String SPECIAL_SEPARATOR = "<STR_LIT>" ; static final String LAYOUT = "<STR_LIT>" ; static final String RESULT_FORMAT = "<STR_LIT>" ; private static final String DESCRIPTION = "<STR_LIT:description>" ; private static final String TRUE = "<STR_LIT:true>" ; private static final String NAME = "<STR_LIT:name>" ; private static final String FAMILY = "<STR_LIT>" ; private static final String OS = "<STR_LIT>" ; private static final String SELECTEDPACKS = "<STR_LIT>" ; private static Input SPACE_INTPUT_FIELD = new Input ( SPACE , null , null , SPACE , "<STR_LIT:r>" , <NUM_LIT:0> ) ; private static Input DIVIDER_INPUT_FIELD = new Input ( DIVIDER , null , null , DIVIDER , "<STR_LIT>" , <NUM_LIT:0> ) ; public List < Input > listInputs ; private final Resources resources ; private final ConsolePanels panels ; public UserInputPanelConsoleHelper ( Resources resources , ConsolePanels panels ) { instanceNumber = instanceCount ++ ; listInputs = new ArrayList < Input > ( ) ; this . resources = resources ; this . panels = panels ; } @ Override public boolean runConsoleFromProperties ( InstallData installData , Properties properties ) { collectInputs ( installData ) ; for ( Input listInput : listInputs ) { String strVariableName = listInput . strVariableName ; if ( strVariableName != null ) { String strVariableValue = properties . getProperty ( strVariableName ) ; if ( strVariableValue != null ) { installData . setVariable ( strVariableName , strVariableValue ) ; } } } return true ; } @ Override public boolean runGeneratePropertiesFile ( InstallData installData , PrintWriter printWriter ) { collectInputs ( installData ) ; for ( Input input : listInputs ) { if ( input . strVariableName != null ) { printWriter . println ( input . strVariableName + "<STR_LIT:=>" ) ; } } return true ; } @ Override public boolean runConsole ( InstallData installData , Console console ) { boolean processpanel = collectInputs ( installData ) ; if ( ! processpanel ) { return true ; } boolean status = true ; for ( Input field : listInputs ) { if ( TEXT_FIELD . equals ( field . strFieldType ) || FILE . equals ( field . strFieldType ) || RULE_FIELD . equals ( field . strFieldType ) || DIR . equals ( field . strFieldType ) ) { status = status && processTextField ( field , installData ) ; } else if ( COMBO_FIELD . equals ( field . strFieldType ) || RADIO_FIELD . equals ( field . strFieldType ) ) { status = status && processComboRadioField ( field , installData ) ; } else if ( CHECK_FIELD . equals ( field . strFieldType ) ) { status = status && processCheckField ( field , installData ) ; } else if ( STATIC_TEXT . equals ( field . strFieldType ) || TITLE_FIELD . equals ( field . strFieldType ) || DIVIDER . equals ( field . strFieldType ) || SPACE . equals ( field . strFieldType ) ) { status = status && processSimpleField ( field , installData ) ; } else if ( PASSWORD . equals ( field . strFieldType ) ) { status = status && processPasswordField ( field , installData ) ; } } return promptEndPanel ( installData , console ) ; } public boolean collectInputs ( InstallData installData ) { listInputs . clear ( ) ; IXMLElement spec = null ; List < IXMLElement > specElements ; String attribute ; String dataID ; String panelid = panels . getPanel ( ) . getPanelId ( ) ; String instance = Integer . toString ( instanceNumber ) ; SpecHelper specHelper = new SpecHelper ( resources ) ; try { specHelper . readSpec ( specHelper . getResource ( SPEC_FILE_NAME ) ) ; } catch ( Exception e1 ) { e1 . printStackTrace ( ) ; return false ; } specElements = specHelper . getSpec ( ) . getChildrenNamed ( NODE_ID ) ; for ( IXMLElement data : specElements ) { attribute = data . getAttribute ( INSTANCE_IDENTIFIER ) ; dataID = data . getAttribute ( PANEL_IDENTIFIER ) ; if ( ( ( attribute != null ) && instance . equals ( attribute ) ) || ( ( dataID != null ) && ( panelid != null ) && ( panelid . equals ( dataID ) ) ) ) { List < IXMLElement > forPacks = data . getChildrenNamed ( SELECTEDPACKS ) ; List < IXMLElement > forOs = data . getChildrenNamed ( OS ) ; if ( itemRequiredFor ( forPacks , installData ) && itemRequiredForOs ( forOs ) ) { spec = data ; break ; } } } if ( spec == null ) { return false ; } List < IXMLElement > fields = spec . getChildrenNamed ( FIELD_NODE_ID ) ; for ( IXMLElement field : fields ) { List < IXMLElement > forPacks = field . getChildrenNamed ( SELECTEDPACKS ) ; List < IXMLElement > forOs = field . getChildrenNamed ( OS ) ; if ( itemRequiredFor ( forPacks , installData ) && itemRequiredForOs ( forOs ) ) { String conditionid = field . getAttribute ( ATTRIBUTE_CONDITIONID_NAME ) ; if ( conditionid != null ) { if ( ! installData . getRules ( ) . isConditionTrue ( conditionid , installData ) ) { continue ; } } Input in = getInputFromField ( field , installData ) ; if ( in != null ) { listInputs . add ( in ) ; } } } return true ; } boolean processSimpleField ( Input input , InstallData idata ) { VariableSubstitutor variableSubstitutor = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; try { System . out . println ( variableSubstitutor . substitute ( input . strText ) ) ; } catch ( Exception e ) { System . out . println ( input . strText ) ; } return true ; } boolean processPasswordField ( Input input , InstallData idata ) { Password pwd = ( Password ) input ; boolean rtn = false ; for ( int i = <NUM_LIT:0> ; i < pwd . input . length ; i ++ ) { rtn = processTextField ( pwd . input [ i ] , idata ) ; if ( ! rtn ) { return rtn ; } } return rtn ; } boolean processTextField ( Input input , InstallData idata ) { String variable = input . strVariableName ; String set ; String fieldText ; if ( ( variable == null ) || ( variable . length ( ) == <NUM_LIT:0> ) ) { return false ; } if ( input . listChoices . size ( ) == <NUM_LIT:0> ) { logger . warning ( "<STR_LIT>" ) ; return false ; } set = idata . getVariable ( variable ) ; if ( set == null ) { set = input . strDefaultValue ; if ( set == null ) { set = "<STR_LIT>" ; } } if ( ! "<STR_LIT>" . equals ( set ) ) { VariableSubstitutor vs = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; try { set = vs . substitute ( set ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , e . toString ( ) , e ) ; } } fieldText = input . listChoices . get ( <NUM_LIT:0> ) . strText ; System . out . println ( fieldText + "<STR_LIT>" + set + "<STR_LIT>" ) ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String strIn = br . readLine ( ) ; if ( ! strIn . trim ( ) . equals ( "<STR_LIT>" ) ) { idata . setVariable ( variable , strIn ) ; } else { idata . setVariable ( variable , set ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } return true ; } boolean processComboRadioField ( Input input , InstallData idata ) { String variable = input . strVariableName ; if ( ( variable == null ) || ( variable . length ( ) == <NUM_LIT:0> ) ) { return false ; } String currentvariablevalue = idata . getVariable ( variable ) ; input . iSelectedChoice = - <NUM_LIT:1> ; boolean userinput = false ; if ( input . strText != null ) { System . out . println ( input . strText ) ; } List < Choice > lisChoices = input . listChoices ; if ( lisChoices . size ( ) == <NUM_LIT:0> ) { logger . warning ( "<STR_LIT>" ) ; return false ; } if ( currentvariablevalue != null ) { userinput = true ; } for ( int i = <NUM_LIT:0> ; i < lisChoices . size ( ) ; i ++ ) { Choice choice = lisChoices . get ( i ) ; String value = choice . strValue ; if ( userinput ) { if ( ( value != null ) && ( value . length ( ) > <NUM_LIT:0> ) && ( currentvariablevalue . equals ( value ) ) ) { input . iSelectedChoice = i ; } } else { String set = choice . strSet ; if ( set != null ) { if ( set != null && ! "<STR_LIT>" . equals ( set ) ) { VariableSubstitutor variableSubstitutor = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; set = variableSubstitutor . substitute ( set ) ; } if ( set . equals ( TRUE ) ) { input . iSelectedChoice = i ; } } } System . out . println ( i + "<STR_LIT>" + ( input . iSelectedChoice == i ? "<STR_LIT:x>" : "<STR_LIT:U+0020>" ) + "<STR_LIT>" + ( choice . strText != null ? choice . strText : "<STR_LIT>" ) ) ; } try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; boolean bKeepAsking = true ; while ( bKeepAsking ) { System . out . println ( "<STR_LIT>" ) ; String strIn = reader . readLine ( ) ; if ( strIn . trim ( ) . equals ( "<STR_LIT>" ) && input . iSelectedChoice != - <NUM_LIT:1> ) { bKeepAsking = false ; } int j = - <NUM_LIT:1> ; try { j = Integer . valueOf ( strIn ) ; } catch ( Exception ex ) { } if ( j >= <NUM_LIT:0> && j < lisChoices . size ( ) ) { input . iSelectedChoice = j ; bKeepAsking = false ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } idata . setVariable ( variable , input . listChoices . get ( input . iSelectedChoice ) . strValue ) ; return true ; } boolean processCheckField ( Input input , InstallData idata ) { String variable = input . strVariableName ; if ( ( variable == null ) || ( variable . length ( ) == <NUM_LIT:0> ) ) { return false ; } String currentvariablevalue = idata . getVariable ( variable ) ; if ( currentvariablevalue == null ) { currentvariablevalue = "<STR_LIT>" ; } List < Choice > lisChoices = input . listChoices ; if ( lisChoices . size ( ) == <NUM_LIT:0> ) { logger . warning ( "<STR_LIT>" ) ; return false ; } Choice choice = null ; for ( int i = <NUM_LIT:0> ; i < lisChoices . size ( ) ; i ++ ) { choice = lisChoices . get ( i ) ; String value = choice . strValue ; if ( ( value != null ) && ( value . length ( ) > <NUM_LIT:0> ) && ( currentvariablevalue . equals ( value ) ) ) { input . iSelectedChoice = i ; } else { String set = input . strDefaultValue ; if ( set != null ) { if ( set != null && ! "<STR_LIT>" . equals ( set ) ) { VariableSubstitutor vs = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; try { set = vs . substitute ( set ) ; } catch ( Exception e ) { } } if ( set . equals ( TRUE ) ) { input . iSelectedChoice = <NUM_LIT:1> ; } } } } System . out . println ( "<STR_LIT>" + ( input . iSelectedChoice == <NUM_LIT:1> ? "<STR_LIT:x>" : "<STR_LIT:U+0020>" ) + "<STR_LIT>" + ( choice . strText != null ? choice . strText : "<STR_LIT>" ) ) ; try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; boolean bKeepAsking = true ; while ( bKeepAsking ) { System . out . println ( "<STR_LIT>" ) ; String strIn = reader . readLine ( ) ; if ( strIn . trim ( ) . equals ( "<STR_LIT>" ) ) { bKeepAsking = false ; } int j = - <NUM_LIT:1> ; try { j = Integer . valueOf ( strIn ) ; } catch ( Exception ex ) { } if ( ( j == <NUM_LIT:0> ) || j == <NUM_LIT:1> ) { input . iSelectedChoice = j ; bKeepAsking = false ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } idata . setVariable ( variable , input . listChoices . get ( input . iSelectedChoice ) . strValue ) ; return true ; } public Input getInputFromField ( IXMLElement field , InstallData idata ) { String strVariableName = field . getAttribute ( VARIABLE ) ; String strFieldType = field . getAttribute ( TYPE_ATTRIBUTE ) ; if ( TITLE_FIELD . equals ( strFieldType ) ) { String strText = null ; strText = field . getAttribute ( TEXT ) ; return new Input ( strVariableName , null , null , TITLE_FIELD , strText , <NUM_LIT:0> ) ; } if ( STATIC_TEXT . equals ( strFieldType ) ) { String strText = null ; strText = field . getAttribute ( TEXT ) ; return new Input ( strVariableName , null , null , STATIC_TEXT , strText , <NUM_LIT:0> ) ; } if ( TEXT_FIELD . equals ( strFieldType ) || FILE . equals ( strFieldType ) || DIR . equals ( strFieldType ) ) { List < Choice > choicesList = new ArrayList < Choice > ( ) ; String strFieldText = null ; String strSet = null ; String strText = null ; IXMLElement spec = field . getFirstChildNamed ( SPEC ) ; IXMLElement description = field . getFirstChildNamed ( DESCRIPTION ) ; if ( spec != null ) { strText = spec . getAttribute ( TEXT ) ; strSet = spec . getAttribute ( SET ) ; } if ( description != null ) { strFieldText = description . getAttribute ( TEXT ) ; } choicesList . add ( new Choice ( strText , null , strSet ) ) ; return new Input ( strVariableName , strSet , choicesList , strFieldType , strFieldText , <NUM_LIT:0> ) ; } if ( RULE_FIELD . equals ( strFieldType ) ) { List < Choice > choicesList = new ArrayList < Choice > ( ) ; String strFieldText = null ; String strSet = null ; String strText = null ; IXMLElement spec = field . getFirstChildNamed ( SPEC ) ; IXMLElement description = field . getFirstChildNamed ( DESCRIPTION ) ; if ( spec != null ) { strText = spec . getAttribute ( TEXT ) ; strSet = spec . getAttribute ( SET ) ; } if ( description != null ) { strFieldText = description . getAttribute ( TEXT ) ; } if ( strSet != null && spec . getAttribute ( LAYOUT ) != null ) { StringTokenizer layoutTokenizer = new StringTokenizer ( spec . getAttribute ( LAYOUT ) ) ; List < String > listSet = Arrays . asList ( new String [ layoutTokenizer . countTokens ( ) ] ) ; StringTokenizer setTokenizer = new StringTokenizer ( strSet ) ; String token ; while ( setTokenizer . hasMoreTokens ( ) ) { token = setTokenizer . nextToken ( ) ; if ( token . contains ( "<STR_LIT::>" ) ) { listSet . set ( new Integer ( token . substring ( <NUM_LIT:0> , token . indexOf ( "<STR_LIT::>" ) ) ) , token . substring ( token . indexOf ( "<STR_LIT::>" ) + <NUM_LIT:1> ) ) ; } } int iCounter = <NUM_LIT:0> ; StringBuffer buffer = new StringBuffer ( ) ; String strRusultFormat = spec . getAttribute ( RESULT_FORMAT ) ; String strSpecialSeparator = spec . getAttribute ( SPECIAL_SEPARATOR ) ; while ( layoutTokenizer . hasMoreTokens ( ) ) { token = layoutTokenizer . nextToken ( ) ; if ( token . matches ( "<STR_LIT>" ) ) { buffer . append ( listSet . get ( iCounter ) != null ? listSet . get ( iCounter ) : "<STR_LIT>" ) ; iCounter ++ ; } else { if ( SPECIAL_SEPARATOR . equals ( strRusultFormat ) ) { buffer . append ( strSpecialSeparator ) ; } else if ( PLAIN_STRING . equals ( strRusultFormat ) ) { } else { buffer . append ( token ) ; } } } strSet = buffer . toString ( ) ; } choicesList . add ( new Choice ( strText , null , strSet ) ) ; return new Input ( strVariableName , strSet , choicesList , TEXT_FIELD , strFieldText , <NUM_LIT:0> ) ; } if ( COMBO_FIELD . equals ( strFieldType ) || RADIO_FIELD . equals ( strFieldType ) ) { List < Choice > choicesList = new ArrayList < Choice > ( ) ; String strFieldText = null ; int selection = - <NUM_LIT:1> ; IXMLElement spec = field . getFirstChildNamed ( SPEC ) ; IXMLElement description = field . getFirstChildNamed ( DESCRIPTION ) ; List < IXMLElement > choices = null ; if ( spec != null ) { choices = spec . getChildrenNamed ( CHOICE ) ; } if ( description != null ) { strFieldText = description . getAttribute ( TEXT ) ; } for ( int i = <NUM_LIT:0> ; i < choices . size ( ) ; i ++ ) { IXMLElement choice = choices . get ( i ) ; String processorClass = choice . getAttribute ( "<STR_LIT>" ) ; if ( processorClass != null && ! "<STR_LIT>" . equals ( processorClass ) ) { String choiceValues = "<STR_LIT>" ; try { choiceValues = ( ( Processor ) Class . forName ( processorClass ) . newInstance ( ) ) . process ( null ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; } String set = choice . getAttribute ( SET ) ; if ( set == null ) { set = "<STR_LIT>" ; } if ( set != null && ! "<STR_LIT>" . equals ( set ) ) { VariableSubstitutor variableSubstitutor = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; set = variableSubstitutor . substitute ( set ) ; } StringTokenizer tokenizer = new StringTokenizer ( choiceValues , "<STR_LIT::>" ) ; int counter = <NUM_LIT:0> ; while ( tokenizer . hasMoreTokens ( ) ) { String token = tokenizer . nextToken ( ) ; String choiceSet = null ; if ( token . equals ( set ) ) { choiceSet = "<STR_LIT:true>" ; selection = counter ; } choicesList . add ( new Choice ( token , token , choiceSet ) ) ; counter ++ ; } } else { String value = choice . getAttribute ( VALUE ) ; String set = choice . getAttribute ( SET ) ; if ( set != null ) { if ( set != null && ! "<STR_LIT>" . equals ( set ) ) { VariableSubstitutor variableSubstitutor = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; set = variableSubstitutor . substitute ( set ) ; } if ( set . equalsIgnoreCase ( TRUE ) ) { selection = i ; } } choicesList . add ( new Choice ( choice . getAttribute ( TEXT ) , value , set ) ) ; } } if ( choicesList . size ( ) == <NUM_LIT:1> ) { selection = <NUM_LIT:0> ; } return new Input ( strVariableName , null , choicesList , strFieldType , strFieldText , selection ) ; } if ( CHECK_FIELD . equals ( strFieldType ) ) { List < Choice > choicesList = new ArrayList < Choice > ( ) ; String strFieldText = null ; String strSet = null ; String strText = null ; int iSelectedChoice = <NUM_LIT:0> ; IXMLElement spec = field . getFirstChildNamed ( SPEC ) ; IXMLElement description = field . getFirstChildNamed ( DESCRIPTION ) ; if ( spec != null ) { strText = spec . getAttribute ( TEXT ) ; strSet = spec . getAttribute ( SET ) ; choicesList . add ( new Choice ( strText , spec . getAttribute ( "<STR_LIT:false>" ) , null ) ) ; choicesList . add ( new Choice ( strText , spec . getAttribute ( "<STR_LIT:true>" ) , null ) ) ; if ( strSet != null ) { if ( strSet . equalsIgnoreCase ( TRUE ) ) { iSelectedChoice = <NUM_LIT:1> ; } } } else { System . out . println ( "<STR_LIT>" ) ; } if ( description != null ) { strFieldText = description . getAttribute ( TEXT ) ; } return new Input ( strVariableName , strSet , choicesList , CHECK_FIELD , strFieldText , iSelectedChoice ) ; } if ( SPACE . equals ( strFieldType ) ) { return SPACE_INTPUT_FIELD ; } if ( DIVIDER . equals ( strFieldType ) ) { return DIVIDER_INPUT_FIELD ; } if ( PASSWORD . equals ( strFieldType ) ) { List < Choice > choicesList = new ArrayList < Choice > ( ) ; String strFieldText = null ; String strSet = null ; String strText = null ; IXMLElement spec = field . getFirstChildNamed ( SPEC ) ; if ( spec != null ) { List < IXMLElement > pwds = spec . getChildrenNamed ( PWD ) ; if ( pwds == null || pwds . size ( ) == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; return null ; } Input [ ] inputs = new Input [ pwds . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < pwds . size ( ) ; i ++ ) { IXMLElement pwde = pwds . get ( i ) ; strText = pwde . getAttribute ( TEXT ) ; strSet = pwde . getAttribute ( SET ) ; choicesList . add ( new Choice ( strText , null , strSet ) ) ; inputs [ i ] = new Input ( strVariableName , strSet , choicesList , strFieldType , strFieldText , <NUM_LIT:0> ) ; } return new Password ( strFieldType , inputs ) ; } System . out . println ( "<STR_LIT>" ) ; return null ; } System . out . println ( strFieldType + "<STR_LIT>" ) ; return null ; } private boolean itemRequiredFor ( List < IXMLElement > packs , InstallData idata ) { String selected ; String required ; if ( packs . size ( ) == <NUM_LIT:0> ) { return ( true ) ; } for ( int i = <NUM_LIT:0> ; i < idata . getSelectedPacks ( ) . size ( ) ; i ++ ) { selected = idata . getSelectedPacks ( ) . get ( i ) . getName ( ) ; for ( IXMLElement pack : packs ) { required = pack . getAttribute ( NAME , "<STR_LIT>" ) ; if ( selected . equals ( required ) ) { return ( true ) ; } } } return ( false ) ; } public boolean itemRequiredForOs ( List < IXMLElement > os ) { if ( os . size ( ) == <NUM_LIT:0> ) { return true ; } for ( IXMLElement osElement : os ) { String family = osElement . getAttribute ( FAMILY ) ; boolean match = false ; if ( "<STR_LIT>" . equals ( family ) ) { match = OsVersion . IS_WINDOWS ; } else if ( "<STR_LIT>" . equals ( family ) ) { match = OsVersion . IS_OSX ; } else if ( "<STR_LIT>" . equals ( family ) ) { match = OsVersion . IS_UNIX ; } if ( match ) { return true ; } } return false ; } public static class Input { public Input ( String strFieldType ) { this . strFieldType = strFieldType ; } public Input ( String strVariableName , String strDefaultValue , List < Choice > listChoices , String strFieldType , String strFieldText , int iSelectedChoice ) { this . strVariableName = strVariableName ; this . strDefaultValue = strDefaultValue ; this . listChoices = listChoices ; this . strFieldType = strFieldType ; this . strText = strFieldText ; this . iSelectedChoice = iSelectedChoice ; } String strVariableName ; String strDefaultValue ; List < Choice > listChoices ; String strFieldType ; String strText ; int iSelectedChoice = - <NUM_LIT:1> ; } public static class Choice { public Choice ( String strText , String strValue , String strSet ) { this . strText = strText ; this . strValue = strValue ; this . strSet = strSet ; } String strText ; String strValue ; String strSet ; } public static class Password extends Input { public Password ( String strFieldType , Input [ ] input ) { super ( strFieldType ) ; this . input = input ; } Input [ ] input ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; public enum UIElementType { LABEL , TEXT , CHECKBOX , MULTIPLE_FILE , FILE , DIRECTORY , RULE , COMBOBOX , RADIOBUTTON , PASSWORD , SEARCH , SEARCHBUTTON , SPACE , DIVIDER , DESCRIPTION } </s>
<s> package com . izforge . izpack . panels . userinput ; import javax . swing . JTextField ; import javax . swing . text . AttributeSet ; import javax . swing . text . BadLocationException ; import javax . swing . text . Document ; import javax . swing . text . PlainDocument ; import java . awt . Toolkit ; public class RuleTextField extends JTextField { private static final long serialVersionUID = <NUM_LIT> ; public static final int N = <NUM_LIT:1> ; public static final int H = <NUM_LIT:2> ; public static final int A = <NUM_LIT:3> ; public static final int O = <NUM_LIT:4> ; public static final int AN = <NUM_LIT:5> ; private int columns ; private int editLength ; private boolean unlimitedEdit ; private Toolkit toolkit ; public RuleTextField ( int digits , int editLength , int type , boolean unlimitedEdit , Toolkit toolkit ) { super ( digits + <NUM_LIT:1> ) ; setColumns ( digits ) ; this . toolkit = toolkit ; this . editLength = editLength ; this . unlimitedEdit = unlimitedEdit ; Rule rule = new Rule ( ) ; rule . setRuleType ( type , editLength , unlimitedEdit ) ; setDocument ( rule ) ; } protected Document createDefaultModel ( ) { Rule rule = new Rule ( ) ; return ( rule ) ; } public int getColumns ( ) { return ( columns ) ; } public int getEditLength ( ) { return ( editLength ) ; } public boolean unlimitedEdit ( ) { return ( unlimitedEdit ) ; } public void setColumns ( int columns ) { super . setColumns ( columns + <NUM_LIT:1> ) ; this . columns = columns ; } class Rule extends PlainDocument { private static final long serialVersionUID = <NUM_LIT> ; private int editLength ; private int type ; private boolean unlimitedEdit ; public void setRuleType ( int type , int editLength , boolean unlimitedEdit ) { this . type = type ; this . editLength = editLength ; this . unlimitedEdit = unlimitedEdit ; } public void insertString ( int offs , String str , AttributeSet a ) throws BadLocationException { if ( str == null ) { return ; } int totalSize = getLength ( ) + str . length ( ) ; if ( ( totalSize <= editLength ) || ( unlimitedEdit ) ) { boolean error = false ; if ( type == N ) { for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { if ( ! Character . isDigit ( str . charAt ( i ) ) ) { error = true ; } } } else if ( type == H ) { for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { char focusChar = Character . toUpperCase ( str . charAt ( i ) ) ; if ( ! Character . isDigit ( focusChar ) && ( focusChar != '<CHAR_LIT:A>' ) && ( focusChar != '<CHAR_LIT>' ) && ( focusChar != '<CHAR_LIT>' ) && ( focusChar != '<CHAR_LIT>' ) && ( focusChar != '<CHAR_LIT>' ) && ( focusChar != '<CHAR_LIT>' ) ) { error = true ; } } } else if ( type == A ) { for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { if ( ! Character . isLetter ( str . charAt ( i ) ) ) { error = true ; } } } else if ( type == AN ) { for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { if ( ! Character . isLetterOrDigit ( str . charAt ( i ) ) ) { error = true ; } } } else if ( type == O ) { } else { System . out . println ( "<STR_LIT>" + type ) ; } if ( ! error ) { super . insertString ( offs , str , a ) ; } else { toolkit . beep ( ) ; } } else { toolkit . beep ( ) ; } } } } </s>
<s> package com . izforge . izpack . panels . userinput . processorclient ; import com . izforge . izpack . panels . userinput . validator . Validator ; import com . izforge . izpack . panels . userinput . validator . ValidatorContainer ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public class StringInputProcessingClient implements ProcessingClient { private String input ; private List < ValidatorContainer > validators ; private ValidatorContainer currentValidator ; private String message ; public StringInputProcessingClient ( String input , List < ValidatorContainer > validators ) { this . input = input ; this . validators = validators ; } public String getFieldContents ( int index ) { return input ; } public int getNumFields ( ) { return <NUM_LIT:1> ; } public String getText ( ) { return this . input ; } public Map < String , String > getValidatorParams ( ) { return ( currentValidator != null ) ? currentValidator . getValidatorParams ( ) : new HashMap < String , String > ( ) ; } public boolean hasParams ( ) { return ( currentValidator != null ) ? currentValidator . hasParams ( ) : false ; } public boolean validate ( ) { boolean success = true ; if ( validators != null ) { for ( ValidatorContainer validator : validators ) { currentValidator = validator ; Validator validatorInstance = currentValidator . getValidator ( ) ; if ( validatorInstance != null ) { success = validatorInstance . validate ( this ) ; if ( ! success ) { message = currentValidator . getMessage ( ) ; break ; } } } } return success ; } public String getValidationMessage ( ) { return message ; } } </s>
<s> package com . izforge . izpack . panels . userinput . processorclient ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JComponent ; import javax . swing . JTextField ; import com . izforge . izpack . panels . userinput . validator . Validator ; public class TextInputField extends JComponent implements ProcessingClient { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( TextInputField . class . getName ( ) ) ; private Map < String , String > validatorParams ; private Validator validationService ; private JTextField field ; private boolean hasParams = false ; public TextInputField ( String set , int size , String validator , Map < String , String > validatorParams ) { this ( set , size , validator ) ; this . validatorParams = validatorParams ; this . hasParams = true ; } public TextInputField ( String set , int size , String validator ) { try { if ( validator != null ) { logger . fine ( "<STR_LIT>" + validator ) ; validationService = ( Validator ) Class . forName ( validator ) . newInstance ( ) ; } } catch ( Throwable e ) { validationService = null ; logger . log ( Level . WARNING , e . toString ( ) , e ) ; } com . izforge . izpack . gui . FlowLayout layout = new com . izforge . izpack . gui . FlowLayout ( ) ; layout . setAlignment ( com . izforge . izpack . gui . FlowLayout . LEADING ) ; layout . setVgap ( <NUM_LIT:0> ) ; setLayout ( layout ) ; field = new JTextField ( set , size ) ; field . setCaretPosition ( <NUM_LIT:0> ) ; add ( field ) ; } @ Override public Map < String , String > getValidatorParams ( ) { return validatorParams ; } @ Override public String getText ( ) { return ( field . getText ( ) ) ; } public void setText ( String value ) { field . setText ( value ) ; } @ Override public String getFieldContents ( int index ) { return field . getText ( ) ; } @ Override public int getNumFields ( ) { return <NUM_LIT:1> ; } public boolean validateContents ( ) { if ( validationService != null ) { logger . fine ( "<STR_LIT>" ) ; return ( validationService . validate ( this ) ) ; } else { logger . fine ( "<STR_LIT>" ) ; return ( true ) ; } } @ Override public boolean hasParams ( ) { return hasParams ; } } </s>
<s> package com . izforge . izpack . panels . userinput . processorclient ; import java . awt . Toolkit ; import java . awt . event . FocusEvent ; import java . awt . event . FocusListener ; import java . awt . event . KeyEvent ; import java . awt . event . KeyListener ; import java . io . Serializable ; import java . util . Map ; import java . util . StringTokenizer ; import java . util . Vector ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JComponent ; import javax . swing . JLabel ; import javax . swing . JTextField ; import javax . swing . event . CaretEvent ; import javax . swing . event . CaretListener ; import org . apache . regexp . RE ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . core . substitutor . VariableSubstitutorImpl ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . panels . userinput . RuleTextField ; import com . izforge . izpack . panels . userinput . processor . Processor ; import com . izforge . izpack . panels . userinput . validator . Validator ; public class RuleInputField extends JComponent implements KeyListener , FocusListener , CaretListener , ProcessingClient { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( RuleInputField . class . getName ( ) ) ; public static final int PLAIN_STRING = <NUM_LIT:1> ; public static final int DISPLAY_FORMAT = <NUM_LIT:2> ; public static final int SPECIAL_SEPARATOR = <NUM_LIT:3> ; public static final int ENCRYPTED = <NUM_LIT:4> ; private static int DEFAULT = DISPLAY_FORMAT ; private Vector < Serializable > items = new Vector < Serializable > ( ) ; private Vector < JTextField > inputFields = new Vector < JTextField > ( ) ; private boolean hasParams = false ; private Map < String , String > validatorParams ; private RuleTextField activeField ; private boolean backstep = false ; private Toolkit toolkit ; private String separator ; private int resultFormat = DEFAULT ; private Validator validationService ; private Processor encryptionService ; private VariableSubstitutor variableSubstitutor ; @ Override public boolean hasParams ( ) { return hasParams ; } public RuleInputField ( String format , String preset , String separator , String validator , Map < String , String > validatorParams , String processor , int resultFormat , Toolkit toolkit , GUIInstallData idata ) { this ( format , preset , separator , validator , processor , resultFormat , toolkit , idata ) ; this . validatorParams = validatorParams ; this . hasParams = true ; } public RuleInputField ( String format , String preset , String separator , String validator , String processor , int resultFormat , Toolkit toolkit , GUIInstallData idata ) { this . toolkit = toolkit ; this . separator = separator ; this . resultFormat = resultFormat ; variableSubstitutor = new VariableSubstitutorImpl ( idata . getVariables ( ) ) ; com . izforge . izpack . gui . FlowLayout layout = new com . izforge . izpack . gui . FlowLayout ( ) ; layout . setAlignment ( com . izforge . izpack . gui . FlowLayout . LEFT ) ; setLayout ( layout ) ; try { if ( validator != null ) { validationService = ( Validator ) Class . forName ( validator ) . newInstance ( ) ; } } catch ( Throwable t ) { validationService = null ; logger . log ( Level . WARNING , t . toString ( ) , t ) ; } try { if ( processor != null ) { encryptionService = ( Processor ) Class . forName ( processor ) . newInstance ( ) ; } } catch ( Throwable t ) { encryptionService = null ; logger . log ( Level . WARNING , t . toString ( ) , t ) ; } createItems ( format ) ; if ( ( preset != null ) && ( preset . length ( ) > <NUM_LIT:0> ) ) { setFields ( preset ) ; } activeField = ( RuleTextField ) inputFields . elementAt ( <NUM_LIT:0> ) ; activeField . grabFocus ( ) ; } @ Override public int getNumFields ( ) { return ( inputFields . size ( ) ) ; } @ Override public String getFieldContents ( int index ) throws IndexOutOfBoundsException { if ( ( index < <NUM_LIT:0> ) || ( index > ( inputFields . size ( ) - <NUM_LIT:1> ) ) ) { throw ( new IndexOutOfBoundsException ( ) ) ; } return inputFields . elementAt ( index ) . getText ( ) ; } @ Override public Map < String , String > getValidatorParams ( ) { return validatorParams ; } @ Override public String getText ( ) { Object item ; StringBuilder buffer = new StringBuilder ( ) ; int size = inputFields . size ( ) ; if ( resultFormat == ENCRYPTED ) { if ( encryptionService != null ) { buffer . append ( encryptionService . process ( this ) ) ; } else { resultFormat = DEFAULT ; } } else if ( resultFormat == PLAIN_STRING ) { for ( int i = <NUM_LIT:0> ; i < inputFields . size ( ) ; i ++ ) { buffer . append ( inputFields . elementAt ( i ) . getText ( ) ) ; } } else if ( resultFormat == DISPLAY_FORMAT ) { for ( int i = <NUM_LIT:0> ; i < items . size ( ) ; i ++ ) { item = items . elementAt ( i ) ; if ( item instanceof JTextField ) { buffer . append ( ( ( JTextField ) item ) . getText ( ) ) ; } else { buffer . append ( ( String ) item ) ; } } } else if ( resultFormat == SPECIAL_SEPARATOR ) { for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { buffer . append ( ( inputFields . elementAt ( i ) ) . getText ( ) ) ; if ( i < ( size - <NUM_LIT:1> ) ) { buffer . append ( separator ) ; } } } return ( buffer . toString ( ) ) ; } private void createItems ( String format ) { Object item ; JTextField field ; String token ; FieldSpec spec ; StringTokenizer tokenizer = new StringTokenizer ( format ) ; while ( tokenizer . hasMoreTokens ( ) ) { token = tokenizer . nextToken ( ) ; try { spec = new FieldSpec ( token ) ; field = new RuleTextField ( spec . getColumns ( ) , spec . getEditLength ( ) , spec . getType ( ) , spec . getUnlimitedEdit ( ) , toolkit ) ; if ( items . size ( ) > <NUM_LIT:0> ) { item = items . lastElement ( ) ; if ( item instanceof JTextField ) { items . add ( "<STR_LIT:U+0020>" ) ; } } items . add ( field ) ; inputFields . add ( field ) ; field . addFocusListener ( this ) ; field . addKeyListener ( this ) ; field . addCaretListener ( this ) ; } catch ( Throwable exception ) { if ( items . size ( ) == <NUM_LIT:0> ) { items . add ( token ) ; } else { item = items . lastElement ( ) ; if ( item instanceof String ) { items . setElementAt ( item + "<STR_LIT:U+0020>" + token , ( items . size ( ) - <NUM_LIT:1> ) ) ; } else { items . add ( token ) ; } } } } for ( int i = <NUM_LIT:0> ; i < items . size ( ) ; i ++ ) { item = items . elementAt ( i ) ; if ( item instanceof String ) { add ( new JLabel ( ( String ) item ) ) ; } else { add ( ( JTextField ) item ) ; } } } private void setFields ( String data ) { StringTokenizer tokenizer = new StringTokenizer ( data ) ; String token ; String indexString ; int index ; boolean process = false ; while ( tokenizer . hasMoreTokens ( ) ) { token = tokenizer . nextToken ( ) ; indexString = token . substring ( <NUM_LIT:0> , token . indexOf ( '<CHAR_LIT::>' ) ) ; try { index = Integer . parseInt ( indexString ) ; if ( index < inputFields . size ( ) ) { String val = token . substring ( ( token . indexOf ( '<CHAR_LIT::>' ) + <NUM_LIT:1> ) , token . length ( ) ) ; String className = "<STR_LIT>" ; if ( val . contains ( "<STR_LIT::>" ) ) { className = val . substring ( val . indexOf ( "<STR_LIT::>" ) + <NUM_LIT:1> ) ; val = val . substring ( <NUM_LIT:0> , val . indexOf ( "<STR_LIT::>" ) ) ; } if ( ! "<STR_LIT>" . equals ( className ) && ! process ) { process = true ; } val = variableSubstitutor . substitute ( val ) ; inputFields . elementAt ( index ) . setText ( val ) ; } } catch ( Throwable exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } if ( process ) { tokenizer = new StringTokenizer ( data ) ; while ( tokenizer . hasMoreTokens ( ) ) { token = tokenizer . nextToken ( ) ; indexString = token . substring ( <NUM_LIT:0> , token . indexOf ( '<CHAR_LIT::>' ) ) ; try { index = Integer . parseInt ( indexString ) ; if ( index < inputFields . size ( ) ) { String val = token . substring ( ( token . indexOf ( '<CHAR_LIT::>' ) + <NUM_LIT:1> ) , token . length ( ) ) ; String className = "<STR_LIT>" ; String presult = "<STR_LIT>" ; if ( val . contains ( "<STR_LIT::>" ) ) { className = val . substring ( val . indexOf ( "<STR_LIT::>" ) + <NUM_LIT:1> ) ; } if ( ! "<STR_LIT>" . equals ( className ) ) { Processor processor = ( Processor ) Class . forName ( className ) . newInstance ( ) ; presult = processor . process ( this ) ; } String [ ] td = new RE ( "<STR_LIT>" ) . split ( presult ) ; inputFields . elementAt ( index ) . setText ( td [ index ] ) ; } } catch ( Throwable exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } } } public boolean validateContents ( ) { if ( validationService != null ) { return ( validationService . validate ( this ) ) ; } else { return ( true ) ; } } @ Override public void keyTyped ( KeyEvent event ) { } @ Override public void keyPressed ( KeyEvent event ) { if ( event . getKeyCode ( ) == KeyEvent . VK_BACK_SPACE ) { int caretPosition = activeField . getCaretPosition ( ) ; if ( caretPosition == <NUM_LIT:0> ) { int activeIndex = inputFields . indexOf ( activeField ) ; if ( activeIndex > <NUM_LIT:0> ) { activeIndex -- ; backstep = true ; activeField = ( RuleTextField ) inputFields . elementAt ( activeIndex ) ; activeField . grabFocus ( ) ; } } } } @ Override public void keyReleased ( KeyEvent event ) { } @ Override public void focusGained ( FocusEvent event ) { activeField = ( RuleTextField ) event . getSource ( ) ; if ( backstep ) { activeField . setCaretPosition ( activeField . getText ( ) . length ( ) ) ; backstep = false ; } else { activeField . selectAll ( ) ; } } @ Override public void focusLost ( FocusEvent event ) { } @ Override public void caretUpdate ( CaretEvent event ) { if ( activeField != null ) { String text = activeField . getText ( ) ; int fieldSize = activeField . getEditLength ( ) ; int caretPosition = activeField . getCaretPosition ( ) ; int selection = activeField . getSelectionEnd ( ) - activeField . getSelectionStart ( ) ; if ( ( ! inputFields . lastElement ( ) . equals ( activeField ) ) && ( ! activeField . unlimitedEdit ( ) ) ) { if ( ( text . length ( ) == fieldSize ) && ( selection == <NUM_LIT:0> ) && ( caretPosition == fieldSize ) && ! backstep ) { activeField . transferFocus ( ) ; } } } } private static class FieldSpec { private int MIN_TOKENS = <NUM_LIT:2> ; private int MAX_TOKENS = <NUM_LIT:3> ; private int type ; private int columns ; private int editLength ; private boolean unlimitedEdit = false ; public FieldSpec ( String spec ) throws Exception { StringTokenizer tokenizer = new StringTokenizer ( spec , "<STR_LIT::>" ) ; if ( ( tokenizer . countTokens ( ) >= MIN_TOKENS ) && ( tokenizer . countTokens ( ) <= MAX_TOKENS ) ) { String token = tokenizer . nextToken ( ) . toUpperCase ( ) ; if ( "<STR_LIT:N>" . equals ( token ) ) { type = RuleTextField . N ; } else if ( "<STR_LIT>" . equals ( token ) ) { type = RuleTextField . H ; } else if ( "<STR_LIT:A>" . equals ( token ) ) { type = RuleTextField . A ; } else if ( "<STR_LIT>" . equals ( token ) ) { type = RuleTextField . O ; } else if ( "<STR_LIT>" . equals ( token ) ) { type = RuleTextField . AN ; } else { throw ( new Exception ( ) ) ; } try { token = tokenizer . nextToken ( ) ; columns = Integer . parseInt ( token ) ; } catch ( Throwable exception ) { throw ( new Exception ( ) ) ; } try { token = tokenizer . nextToken ( ) . toUpperCase ( ) ; editLength = Integer . parseInt ( token ) ; } catch ( Throwable exception ) { if ( "<STR_LIT>" . equals ( token ) ) { unlimitedEdit = true ; } else { throw ( new Exception ( ) ) ; } } } else { throw ( new Exception ( ) ) ; } } public int getColumns ( ) { return ( columns ) ; } public int getEditLength ( ) { return ( editLength ) ; } public int getType ( ) { return ( type ) ; } public boolean getUnlimitedEdit ( ) { return ( unlimitedEdit ) ; } } } </s>
<s> package com . izforge . izpack . panels . userinput . processorclient ; import java . util . Map ; public interface ProcessingClient { public int getNumFields ( ) ; public String getFieldContents ( int index ) ; public String getText ( ) ; public boolean hasParams ( ) ; public Map < String , String > getValidatorParams ( ) ; } </s>
<s> package com . izforge . izpack . panels . userinput ; import javax . swing . filechooser . FileFilter ; import java . io . File ; public class UserInputFileFilter extends FileFilter { String fileext = "<STR_LIT>" ; String description = "<STR_LIT>" ; public void setFileExt ( String fileext ) { this . fileext = fileext ; } public void setFileExtDesc ( String desc ) { this . description = desc ; } public boolean accept ( File pathname ) { if ( pathname . isDirectory ( ) ) { return true ; } else { return pathname . getAbsolutePath ( ) . endsWith ( this . fileext ) ; } } public String getDescription ( ) { return this . description ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . io . File ; import java . io . IOException ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JFileChooser ; import com . izforge . izpack . installer . data . GUIInstallData ; import com . izforge . izpack . installer . gui . IzPanel ; import com . izforge . izpack . panels . userinput . validator . ValidatorContainer ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . OsVersion ; public class DirInputField extends FileInputField { private static final long serialVersionUID = <NUM_LIT> ; private static final transient Logger logger = Logger . getLogger ( DirInputField . class . getName ( ) ) ; private final boolean mustExist ; private final boolean canCreate ; public DirInputField ( IzPanel parent , GUIInstallData installDataGUI , boolean directory , String set , int size , List < ValidatorContainer > validatorConfig , boolean mustExist , boolean canCreate ) { super ( parent , installDataGUI , directory , set , size , validatorConfig , null , null ) ; this . mustExist = mustExist ; this . canCreate = canCreate ; } @ Override protected void prepareFileChooser ( JFileChooser filechooser ) { filechooser . setFileSelectionMode ( JFileChooser . DIRECTORIES_ONLY ) ; } @ Override protected boolean _validate ( File dir ) { System . err . println ( dir . getAbsolutePath ( ) + "<STR_LIT>" + dir . isDirectory ( ) + "<STR_LIT>" + mustExist + "<STR_LIT>" + canCreate ) ; if ( dir . isDirectory ( ) ) { return true ; } else if ( mustExist ) { return false ; } else if ( canCreate ) { return verifyCreateOK ( dir ) ; } else { return true ; } } @ Override protected void showMessage ( int k ) { if ( k == INVALID ) { showMessage ( "<STR_LIT>" ) ; } else if ( k == EMPTY ) { showMessage ( "<STR_LIT>" ) ; } } private boolean verifyCreateOK ( File path ) { if ( ! path . exists ( ) ) { if ( ! parent . emitNotificationFeedback ( parent . getI18nStringForClass ( "<STR_LIT>" , "<STR_LIT>" ) + "<STR_LIT:n>" + path . getAbsolutePath ( ) ) ) { return false ; } } if ( ! isWriteable ( path ) ) { parent . emitError ( parentFrame . getMessages ( ) . get ( "<STR_LIT>" ) , parent . getI18nStringForClass ( "<STR_LIT>" , "<STR_LIT>" ) ) ; return false ; } return path . mkdirs ( ) ; } private static boolean isWriteable ( File path ) { File existParent = IoHelper . existingParent ( path ) ; if ( existParent == null ) { return false ; } if ( OsVersion . IS_WINDOWS ) { File tmpFile ; try { tmpFile = File . createTempFile ( "<STR_LIT>" , "<STR_LIT>" , existParent ) ; tmpFile . deleteOnExit ( ) ; } catch ( IOException e ) { logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; return false ; } return true ; } return existParent . canWrite ( ) ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; public class NotEmptyValidator implements Validator { public boolean validate ( ProcessingClient client ) { int numfields = client . getNumFields ( ) ; for ( int i = <NUM_LIT:0> ; i < numfields ; i ++ ) { String value = client . getFieldContents ( i ) ; if ( ( value == null ) || ( value . length ( ) == <NUM_LIT:0> ) ) { return false ; } } return true ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . PasswordGroup ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . util . Map ; import java . util . regex . Pattern ; public class RegularExpressionValidator implements Validator { public static final String STR_PATTERN_DEFAULT = "<STR_LIT>" ; private static final String PATTERN_PARAM = "<STR_LIT>" ; public boolean validate ( ProcessingClient client ) { String patternString ; if ( client . hasParams ( ) ) { Map < String , String > paramMap = client . getValidatorParams ( ) ; patternString = paramMap . get ( PATTERN_PARAM ) ; } else { patternString = STR_PATTERN_DEFAULT ; } Pattern pattern = Pattern . compile ( patternString ) ; return pattern . matcher ( getString ( client ) ) . matches ( ) ; } private String getString ( ProcessingClient client ) { String returnValue = "<STR_LIT>" ; if ( client instanceof PasswordGroup ) { int numFields = client . getNumFields ( ) ; if ( numFields > <NUM_LIT:0> ) { returnValue = client . getFieldContents ( <NUM_LIT:0> ) ; } else { returnValue = client . getText ( ) ; } } else { returnValue = client . getText ( ) ; } return returnValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; public class IsPortValidator implements Validator { public boolean validate ( ProcessingClient client ) { int port = <NUM_LIT:0> ; if ( "<STR_LIT>" . equals ( client . getFieldContents ( <NUM_LIT:0> ) ) ) { return false ; } try { port = Integer . parseInt ( client . getFieldContents ( <NUM_LIT:0> ) ) ; if ( port >= <NUM_LIT:0> && port <= <NUM_LIT> ) { return true ; } } catch ( Exception ex ) { return false ; } return false ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . net . InetAddress ; import java . net . ServerSocket ; public class PortValidator implements Validator { public boolean validate ( ProcessingClient client ) { InetAddress inet = null ; String host = "<STR_LIT:localhost>" ; boolean retValue = false ; int numfields = client . getNumFields ( ) ; for ( int i = <NUM_LIT:0> ; i < numfields ; i ++ ) { String value = client . getFieldContents ( i ) ; if ( ( value == null ) || ( value . length ( ) == <NUM_LIT:0> ) ) { return false ; } try { inet = InetAddress . getByName ( host ) ; ServerSocket socket = new ServerSocket ( Integer . parseInt ( value ) , <NUM_LIT:0> , inet ) ; retValue = socket . getLocalPort ( ) > <NUM_LIT:0> ; if ( ! retValue ) { break ; } socket . close ( ) ; } catch ( Exception ex ) { retValue = false ; } } return retValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . net . InetAddress ; import java . net . ServerSocket ; public class HostAddressValidator implements Validator { public boolean validate ( ProcessingClient client ) { InetAddress inet = null ; String host = "<STR_LIT>" ; int port = <NUM_LIT:0> ; boolean retValue = false ; try { host = client . getFieldContents ( <NUM_LIT:0> ) ; port = Integer . parseInt ( client . getFieldContents ( <NUM_LIT:1> ) ) ; } catch ( Exception e ) { return false ; } try { inet = InetAddress . getByName ( host ) ; ServerSocket socket = new ServerSocket ( port , <NUM_LIT:0> , inet ) ; retValue = socket . getLocalPort ( ) > <NUM_LIT:0> ; socket . close ( ) ; } catch ( Exception ex ) { retValue = false ; } return retValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; public interface Validator { public boolean validate ( ProcessingClient client ) ; } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . panels . userinput . PasswordGroup ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . util . Map ; public class PasswordEqualityValidator implements Validator { public boolean validate ( ProcessingClient client ) { boolean returnValue = false ; Map < String , String > params = getParams ( client ) ; try { returnValue = fieldsMatch ( client ) ; if ( returnValue ) { if ( params != null ) { System . out . println ( "<STR_LIT>" + params . size ( ) + "<STR_LIT>" ) ; } } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; } return ( returnValue ) ; } private Map < String , String > getParams ( ProcessingClient client ) { PasswordGroup group = null ; Map < String , String > params = null ; try { group = ( PasswordGroup ) client ; if ( group . hasParams ( ) ) { params = group . getValidatorParams ( ) ; } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; } return ( params ) ; } private boolean fieldsMatch ( ProcessingClient client ) { boolean returnValue = true ; int numFields = client . getNumFields ( ) ; if ( numFields < <NUM_LIT:2> ) { returnValue = true ; } else { String content = client . getFieldContents ( <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:1> ; i < numFields ; i ++ ) { if ( ! content . equals ( client . getFieldContents ( i ) ) ) { returnValue = false ; } } } return returnValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import java . security . SecureRandom ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . crypto . Cipher ; import javax . crypto . KeyGenerator ; import javax . crypto . spec . SecretKeySpec ; import com . izforge . izpack . panels . userinput . PasswordGroup ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import com . izforge . izpack . util . Base64 ; public class PasswordEncryptionValidator implements Validator { private static final Logger logger = Logger . getLogger ( PasswordEncryptionValidator . class . getName ( ) ) ; private Cipher encryptCipher ; @ Override public boolean validate ( ProcessingClient client ) { boolean returnValue = true ; String encryptedPassword = null ; String key = null ; String algorithm = null ; Map < String , String > params = getParams ( client ) ; try { key = params . get ( "<STR_LIT>" ) ; algorithm = params . get ( "<STR_LIT>" ) ; if ( key != null && algorithm != null ) { initialize ( key , algorithm ) ; encryptedPassword = encryptString ( client . getFieldContents ( <NUM_LIT:0> ) ) ; if ( encryptedPassword != null ) { PasswordGroup group = ( PasswordGroup ) client ; group . setModifiedPassword ( encryptedPassword ) ; } else { returnValue = false ; } } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; returnValue = false ; } return ( returnValue ) ; } private Map < String , String > getParams ( ProcessingClient client ) { PasswordGroup group = null ; Map < String , String > params = null ; try { group = ( PasswordGroup ) client ; if ( group . hasParams ( ) ) { params = group . getValidatorParams ( ) ; } } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; } return params ; } private void initialize ( String key , String algorithm ) throws Exception { try { KeyGenerator keygen = KeyGenerator . getInstance ( algorithm ) ; keygen . init ( new SecureRandom ( key . getBytes ( ) ) ) ; byte [ ] keyBytes = keygen . generateKey ( ) . getEncoded ( ) ; SecretKeySpec specKey = new SecretKeySpec ( keyBytes , algorithm ) ; encryptCipher = Cipher . getInstance ( algorithm ) ; encryptCipher . init ( Cipher . ENCRYPT_MODE , specKey ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; throw e ; } } public String encryptString ( String string ) throws Exception { String result = null ; try { byte [ ] cryptedbytes = null ; cryptedbytes = encryptCipher . doFinal ( string . getBytes ( "<STR_LIT:UTF-8>" ) ) ; result = Base64 . encodeBytes ( cryptedbytes ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , "<STR_LIT>" + e , e ) ; throw e ; } return result ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; import com . izforge . izpack . panels . userinput . PasswordGroup ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . io . FileInputStream ; import java . security . KeyStore ; import java . util . HashMap ; import java . util . Map ; public class PasswordKeystoreValidator implements Validator { private VariableSubstitutor variableSubstitutor ; public PasswordKeystoreValidator ( VariableSubstitutor variableSubstitutor ) { this . variableSubstitutor = variableSubstitutor ; } public boolean validate ( ProcessingClient client ) { boolean returnValue = false ; String keystorePassword = null ; String keystoreFile = null ; String keystoreType = "<STR_LIT>" ; String skipValidation = null ; String alias = null ; String aliasPassword = null ; Map < String , String > params = getParams ( client ) ; try { if ( params != null ) { skipValidation = params . get ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + skipValidation ) ; if ( skipValidation != null && skipValidation . equalsIgnoreCase ( "<STR_LIT:true>" ) ) { System . out . println ( "<STR_LIT>" ) ; return true ; } keystorePassword = params . get ( "<STR_LIT>" ) ; if ( keystorePassword == null ) { keystorePassword = getPassword ( client ) ; System . out . println ( "<STR_LIT>" ) ; } else if ( keystorePassword . equalsIgnoreCase ( "<STR_LIT>" ) ) { keystorePassword = getPassword ( client ) ; System . out . println ( "<STR_LIT>" ) ; } aliasPassword = params . get ( "<STR_LIT>" ) ; if ( aliasPassword == null ) { aliasPassword = getPassword ( client ) ; System . out . println ( "<STR_LIT>" ) ; } else if ( aliasPassword . equalsIgnoreCase ( "<STR_LIT>" ) ) { aliasPassword = getPassword ( client ) ; System . out . println ( "<STR_LIT>" ) ; } keystoreType = params . get ( "<STR_LIT>" ) ; if ( keystoreType == null ) { keystoreType = "<STR_LIT>" ; } System . out . println ( "<STR_LIT>" ) ; } else if ( keystoreType . equalsIgnoreCase ( "<STR_LIT>" ) ) { keystoreType = "<STR_LIT>" ; System . out . println ( "<STR_LIT>" ) ; } keystoreFile = params . get ( "<STR_LIT>" ) ; if ( keystoreFile != null ) { System . out . println ( "<STR_LIT>" + keystoreFile ) ; KeyStore keyStore = getKeyStore ( keystoreFile , keystoreType , keystorePassword . toCharArray ( ) ) ; if ( keyStore != null ) { returnValue = true ; System . out . println ( "<STR_LIT>" ) ; alias = params . get ( "<STR_LIT>" ) ; if ( alias != null ) { returnValue = keyStore . containsAlias ( alias ) ; if ( returnValue ) { System . out . println ( "<STR_LIT>" + alias + "<STR_LIT>" ) ; try { keyStore . getKey ( alias , aliasPassword . toCharArray ( ) ) ; System . out . println ( "<STR_LIT>" + alias + "<STR_LIT>" ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; returnValue = false ; } } else { System . out . println ( "<STR_LIT>" + alias + "<STR_LIT>" ) ; } } } } else { System . out . println ( "<STR_LIT>" ) ; } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; } return ( returnValue ) ; } private Map < String , String > getParams ( ProcessingClient client ) { Map < String , String > returnValue = null ; PasswordGroup group = null ; try { group = ( PasswordGroup ) client ; if ( group . hasParams ( ) ) { Map < String , String > params = group . getValidatorParams ( ) ; returnValue = new HashMap < String , String > ( ) ; for ( String key : params . keySet ( ) ) { String value = variableSubstitutor . substitute ( params . get ( key ) ) ; returnValue . put ( key , value ) ; } } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; } return returnValue ; } private String getPassword ( ProcessingClient client ) { return client . getFieldContents ( <NUM_LIT:0> ) ; } public static KeyStore getKeyStore ( String fileName , String type , char [ ] password ) { KeyStore keyStore = null ; try { keyStore = KeyStore . getInstance ( type ) ; keyStore . load ( new FileInputStream ( fileName ) , password ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" + e ) ; keyStore = null ; } return keyStore ; } } </s>
<s> package com . izforge . izpack . panels . userinput . validator ; import java . util . Map ; public class ValidatorContainer { private Validator validator = null ; private String message ; private boolean hasParams = false ; private Map < String , String > validatorParams = null ; public ValidatorContainer ( String validator , String message , Map < String , String > validatorParams ) { try { this . validator = ( Validator ) Class . forName ( validator ) . newInstance ( ) ; this . message = message ; this . validatorParams = validatorParams ; if ( validatorParams != null ) { if ( validatorParams . size ( ) > <NUM_LIT:0> ) { hasParams = true ; } } } catch ( Throwable e ) { System . out . println ( "<STR_LIT>" + e ) ; this . validator = null ; this . message = null ; hasParams = false ; validatorParams = null ; } } public boolean hasParams ( ) { return hasParams ; } public Map < String , String > getValidatorParams ( ) { return validatorParams ; } public Validator getValidator ( ) { return validator ; } public String getMessage ( ) { return message ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import java . util . List ; import java . util . Map ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . adaptator . impl . XMLElementImpl ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . installer . automation . PanelAutomation ; public class UserInputPanelAutomationHelper implements PanelAutomation { private static final Logger logger = Logger . getLogger ( UserInputPanelAutomationHelper . class . getName ( ) ) ; private static final String AUTO_KEY_USER_INPUT = "<STR_LIT>" ; private static final String AUTO_KEY_ENTRY = "<STR_LIT>" ; private static final String AUTO_ATTRIBUTE_KEY = "<STR_LIT:key>" ; private static final String AUTO_ATTRIBUTE_VALUE = "<STR_LIT:value>" ; private Map < String , String > entries ; public UserInputPanelAutomationHelper ( ) { this . entries = null ; } public UserInputPanelAutomationHelper ( Map < String , String > entries ) { this . entries = entries ; } @ Override public void makeXMLData ( InstallData idata , IXMLElement panelRoot ) { IXMLElement userInput ; IXMLElement dataElement ; userInput = new XMLElementImpl ( AUTO_KEY_USER_INPUT , panelRoot ) ; panelRoot . addChild ( userInput ) ; for ( String key : this . entries . keySet ( ) ) { String value = this . entries . get ( key ) ; dataElement = new XMLElementImpl ( AUTO_KEY_ENTRY , userInput ) ; dataElement . setAttribute ( AUTO_ATTRIBUTE_KEY , key ) ; dataElement . setAttribute ( AUTO_ATTRIBUTE_VALUE , value ) ; userInput . addChild ( dataElement ) ; } } @ Override public void runAutomated ( InstallData idata , IXMLElement panelRoot ) throws InstallerException { IXMLElement userInput ; String variable ; String value ; userInput = panelRoot . getFirstChildNamed ( AUTO_KEY_USER_INPUT ) ; if ( userInput == null ) { throw new InstallerException ( "<STR_LIT>" + panelRoot . getLineNr ( ) ) ; } List < IXMLElement > userEntries = userInput . getChildrenNamed ( AUTO_KEY_ENTRY ) ; if ( userEntries == null ) { throw new InstallerException ( "<STR_LIT>" + panelRoot . getLineNr ( ) ) ; } Variables variables = idata . getVariables ( ) ; for ( IXMLElement dataElement : userEntries ) { variable = dataElement . getAttribute ( AUTO_ATTRIBUTE_KEY ) ; value = dataElement . getAttribute ( AUTO_ATTRIBUTE_VALUE ) ; value = variables . replace ( value ) ; logger . fine ( "<STR_LIT>" + variable + "<STR_LIT:U+0020toU+0020>" + value ) ; idata . setVariable ( variable , value ) ; } } } </s>
<s> package com . izforge . izpack . panels . userinput . processor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import com . izforge . izpack . util . unix . UnixUsers ; public class UnixUserProcessor implements Processor { public String process ( ProcessingClient client ) { return UnixUsers . getUsersColonString ( ) ; } } </s>
<s> package com . izforge . izpack . panels . userinput . processor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; public interface Processor { public String process ( ProcessingClient client ) ; } </s>
<s> package com . izforge . izpack . panels . userinput . processor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . net . InetAddress ; import java . net . ServerSocket ; public class PortProcessor implements Processor { public String process ( ProcessingClient client ) { String retValue = "<STR_LIT>" ; String host = "<STR_LIT:localhost>" ; int port = <NUM_LIT:0> ; int oPort = <NUM_LIT:0> ; boolean found = false ; InetAddress inet = null ; ServerSocket socket = null ; try { if ( client . getNumFields ( ) > <NUM_LIT:1> ) { host = client . getFieldContents ( <NUM_LIT:0> ) ; oPort = Integer . parseInt ( client . getFieldContents ( <NUM_LIT:1> ) ) ; } else { oPort = Integer . parseInt ( client . getFieldContents ( <NUM_LIT:0> ) ) ; } } catch ( Exception ex ) { return getReturnValue ( client , null , null ) ; } port = oPort ; while ( ! found ) { try { inet = InetAddress . getByName ( host ) ; socket = new ServerSocket ( port , <NUM_LIT:0> , inet ) ; if ( socket . getLocalPort ( ) > <NUM_LIT:0> ) { found = true ; retValue = getReturnValue ( client , null , String . valueOf ( port ) ) ; } else { port ++ ; } } catch ( java . net . BindException ex ) { port ++ ; } catch ( Exception ex ) { return getReturnValue ( client , null , null ) ; } finally { try { socket . close ( ) ; } catch ( Exception ex ) { } } } return retValue ; } private String getReturnValue ( ProcessingClient client , String host , String port ) { String retValue = "<STR_LIT>" ; String _host = "<STR_LIT>" ; String _port = "<STR_LIT>" ; if ( client . getNumFields ( ) > <NUM_LIT:1> ) { _host = ( host == null ) ? client . getFieldContents ( <NUM_LIT:0> ) : host ; _port = ( port == null ) ? client . getFieldContents ( <NUM_LIT:1> ) : port ; retValue = _host + "<STR_LIT:*>" + _port ; } else { _port = ( port == null ) ? client . getFieldContents ( <NUM_LIT:0> ) : port ; retValue = _port ; } return retValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput . processor ; import com . izforge . izpack . panels . userinput . processorclient . ProcessingClient ; import java . io . BufferedReader ; import java . io . FileReader ; public class UnixGroupProcessor implements Processor { public String process ( ProcessingClient client ) { String retValue = "<STR_LIT>" ; String filepath = "<STR_LIT>" ; BufferedReader reader = null ; String line = "<STR_LIT>" ; try { reader = new BufferedReader ( new FileReader ( filepath ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { retValue += line . substring ( <NUM_LIT:0> , line . indexOf ( "<STR_LIT::>" ) ) + "<STR_LIT::>" ; } if ( retValue . endsWith ( "<STR_LIT::>" ) ) { retValue = retValue . substring ( <NUM_LIT:0> , retValue . length ( ) - <NUM_LIT:1> ) ; } } catch ( Exception ex ) { retValue = "<STR_LIT>" ; } return retValue ; } } </s>
<s> package com . izforge . izpack . panels . userinput ; import com . izforge . izpack . api . adaptator . IXMLElement ; import javax . swing . * ; import java . util . List ; public class UIElement { boolean displayed ; UIElementType type ; String associatedVariable ; JComponent component ; Object constraints ; List < IXMLElement > forPacks ; List < IXMLElement > forOs ; String trueValue ; String falseValue ; String message ; public UIElement ( ) { } public boolean hasVariableAssignment ( ) { return this . associatedVariable != null ; } public String getMessage ( ) { return message ; } public void setMessage ( String message ) { this . message = message ; } public UIElementType getType ( ) { return type ; } public void setType ( UIElementType type ) { this . type = type ; } public String getAssociatedVariable ( ) { return associatedVariable ; } public void setAssociatedVariable ( String associatedVariable ) { this . associatedVariable = associatedVariable ; } public JComponent getComponent ( ) { return component ; } public void setComponent ( JComponent component ) { this . component = component ; } public Object getConstraints ( ) { return constraints ; } public void setConstraints ( Object constraints ) { this . constraints = constraints ; } public List < IXMLElement > getForPacks ( ) { return forPacks ; } public void setForPacks ( List < IXMLElement > forPacks ) { this . forPacks = forPacks ; } public List < IXMLElement > getForOs ( ) { return forOs ; } public void setForOs ( List < IXMLElement > forOs ) { this . forOs = forOs ; } public String getTrueValue ( ) { return trueValue ; } public void setTrueValue ( String trueValue ) { this . trueValue = trueValue ; } public String getFalseValue ( ) { return falseValue ; } public void setFalseValue ( String falseValue ) { this . falseValue = falseValue ; } public boolean isDisplayed ( ) { return displayed ; } public void setDisplayed ( boolean displayed ) { this . displayed = displayed ; } } </s>