text
stringlengths
30
1.67M
<s> package com . izforge . izpack . util ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintStream ; import java . io . PrintWriter ; import java . io . RandomAccessFile ; import java . lang . reflect . Method ; import java . lang . reflect . Modifier ; import java . net . URI ; import java . net . URL ; import java . text . CharacterIterator ; import java . text . SimpleDateFormat ; import java . text . StringCharacterIterator ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Date ; import java . util . Enumeration ; import java . util . List ; import java . util . jar . JarEntry ; import java . util . jar . JarFile ; import java . util . zip . ZipEntry ; import com . izforge . izpack . util . file . FileUtils ; public class SelfModifier { public static final String BASE_KEY = "<STR_LIT>" ; public static final String JAR_KEY = "<STR_LIT>" ; public static final String CLASS_KEY = "<STR_LIT>" ; public static final String METHOD_KEY = "<STR_LIT>" ; public static final String PHASE_KEY = "<STR_LIT>" ; private Method method = null ; private File logFile = null ; private File sandbox = null ; private File jarFile = null ; private int phase = <NUM_LIT:0> ; private SimpleDateFormat isoPoint = new SimpleDateFormat ( "<STR_LIT>" ) ; private Date date = new Date ( ) ; private int debugPort2 = Integer . getInteger ( DEBUG_PORT2_KEY , - <NUM_LIT:1> ) ; private int debugPort3 = Integer . getInteger ( DEBUG_PORT3_KEY , - <NUM_LIT:1> ) ; private static final String DEBUG_PORT2_KEY = "<STR_LIT>" ; private static final String DEBUG_PORT3_KEY = "<STR_LIT>" ; private static final String prefix = "<STR_LIT>" ; public static void test ( String [ ] args ) { try { File sandbox = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; File randFile = new File ( sandbox , "<STR_LIT>" ) ; RandomAccessFile rand = new RandomAccessFile ( randFile , "<STR_LIT>" ) ; rand . writeChars ( "<STR_LIT>" ) ; System . err . print ( "<STR_LIT>" ) ; deleteTree ( sandbox ) ; System . err . println ( sandbox . exists ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; } catch ( Exception x ) { System . err . println ( x . getMessage ( ) ) ; x . printStackTrace ( ) ; } } public static void main ( String [ ] args ) { try { SelfModifier selfModifier = new SelfModifier ( ) ; if ( selfModifier . phase == <NUM_LIT:2> ) { selfModifier . invoke2 ( args ) ; } else if ( selfModifier . phase == <NUM_LIT:3> ) { selfModifier . invoke3 ( args ) ; } } catch ( IOException ioe ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; ioe . printStackTrace ( ) ; } } private SelfModifier ( ) throws IOException { phase = Integer . parseInt ( System . getProperty ( PHASE_KEY ) ) ; String cName = System . getProperty ( CLASS_KEY ) ; String tName = System . getProperty ( METHOD_KEY ) ; jarFile = new File ( System . getProperty ( JAR_KEY ) ) ; logFile = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; sandbox = new File ( System . getProperty ( BASE_KEY ) + "<STR_LIT>" ) ; try { Class clazz = Class . forName ( cName ) ; Method method = clazz . getMethod ( tName , new Class [ ] { String [ ] . class } ) ; initMethod ( method ) ; } catch ( ClassNotFoundException x1 ) { log ( "<STR_LIT>" + cName ) ; } catch ( NoSuchMethodException x2 ) { log ( "<STR_LIT>" + tName + "<STR_LIT>" + cName ) ; } } public SelfModifier ( Method method ) throws IOException { phase = <NUM_LIT:1> ; initJavaExec ( ) ; initMethod ( method ) ; } @ Deprecated public SelfModifier ( Method method , long maxmemory , long maxpermgensize ) throws IOException { this ( method ) ; } private void initMethod ( Method method ) { int mod = method . getModifiers ( ) ; if ( ( mod & Modifier . PUBLIC ) == <NUM_LIT:0> || ( mod & Modifier . STATIC ) == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Class [ ] params = method . getParameterTypes ( ) ; if ( params . length != <NUM_LIT:1> || ! params [ <NUM_LIT:0> ] . isArray ( ) || ! "<STR_LIT>" . equals ( params [ <NUM_LIT:0> ] . getComponentType ( ) . getName ( ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Class clazz = method . getDeclaringClass ( ) ; mod = clazz . getModifiers ( ) ; if ( ( mod & Modifier . PUBLIC ) == <NUM_LIT:0> || ( mod & Modifier . INTERFACE ) != <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . method = method ; } private void initJavaExec ( ) throws IOException { try { Process process = Runtime . getRuntime ( ) . exec ( javaCommand ( ) ) ; new StreamProxy ( process . getErrorStream ( ) , "<STR_LIT>" ) . start ( ) ; new StreamProxy ( process . getInputStream ( ) , "<STR_LIT>" ) . start ( ) ; process . getOutputStream ( ) . close ( ) ; process . waitFor ( ) ; } catch ( InterruptedException ie ) { throw new IOException ( "<STR_LIT>" ) ; } } public void invoke ( String [ ] args ) throws IOException { while ( true ) { logFile = File . createTempFile ( prefix , "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + logFile . getAbsolutePath ( ) ) ; String fileName = logFile . toString ( ) ; sandbox = new File ( fileName . substring ( <NUM_LIT:0> , fileName . length ( ) - <NUM_LIT:4> ) + "<STR_LIT>" ) ; if ( ! sandbox . exists ( ) ) { break ; } logFile . delete ( ) ; } if ( ! sandbox . mkdir ( ) ) { throw new RuntimeException ( "<STR_LIT>" + sandbox ) ; } sandbox = sandbox . getCanonicalFile ( ) ; logFile = logFile . getCanonicalFile ( ) ; jarFile = findJarFile ( method . getDeclaringClass ( ) ) . getCanonicalFile ( ) ; if ( jarFile == null ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } log ( "<STR_LIT>" + jarFile ) ; extractJarFile ( ) ; if ( args == null ) { args = new String [ <NUM_LIT:0> ] ; } spawn ( args , <NUM_LIT:2> ) ; log ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } private Process spawn ( String [ ] args , int nextPhase ) throws IOException { String base = logFile . getAbsolutePath ( ) ; base = base . substring ( <NUM_LIT:0> , base . length ( ) - <NUM_LIT:4> ) ; String javaCommand = javaCommand ( ) ; List < String > command = new ArrayList < String > ( ) ; command . add ( javaCommand ) ; command . addAll ( new JVMHelper ( ) . getJVMArguments ( ) ) ; if ( nextPhase == <NUM_LIT:2> ) { if ( debugPort2 != - <NUM_LIT:1> ) { command . add ( getDebug ( debugPort2 ) ) ; } if ( debugPort3 != - <NUM_LIT:1> ) { command . add ( "<STR_LIT>" + DEBUG_PORT3_KEY + "<STR_LIT:=>" + debugPort3 ) ; } } else if ( nextPhase == <NUM_LIT:3> && debugPort3 != - <NUM_LIT:1> ) { command . add ( getDebug ( debugPort3 ) ) ; } command . add ( "<STR_LIT>" ) ; command . add ( sandbox . getAbsolutePath ( ) ) ; command . add ( "<STR_LIT>" + BASE_KEY + "<STR_LIT:=>" + base ) ; command . add ( "<STR_LIT>" + JAR_KEY + "<STR_LIT:=>" + jarFile . getPath ( ) + "<STR_LIT>" ) ; command . add ( "<STR_LIT>" + CLASS_KEY + "<STR_LIT:=>" + method . getDeclaringClass ( ) . getName ( ) ) ; command . add ( "<STR_LIT>" + METHOD_KEY + "<STR_LIT:=>" + method . getName ( ) ) ; command . add ( "<STR_LIT>" + PHASE_KEY + "<STR_LIT:=>" + nextPhase ) ; command . add ( getClass ( ) . getName ( ) ) ; Collections . addAll ( command , args ) ; StringBuilder buffer = new StringBuilder ( "<STR_LIT>" ) ; buffer . append ( nextPhase ) . append ( "<STR_LIT::U+0020>" ) ; for ( String anEntireCmd : command ) { buffer . append ( "<STR_LIT>" ) . append ( anEntireCmd ) ; } log ( buffer . toString ( ) ) ; return Runtime . getRuntime ( ) . exec ( command . toArray ( new String [ command . size ( ) ] ) , null , null ) ; } public static File findJarFile ( Class < ? > clazz ) { String resource = clazz . getName ( ) . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) + "<STR_LIT:.class>" ; URL url = ClassLoader . getSystemResource ( resource ) ; if ( ! "<STR_LIT>" . equals ( url . getProtocol ( ) ) ) { return null ; } String path = url . getFile ( ) ; path = path . substring ( <NUM_LIT:0> , path . lastIndexOf ( '<CHAR_LIT>' ) ) ; File file ; file = new File ( URI . create ( path ) ) ; return file ; } private void extractJarFile ( ) throws IOException { byte [ ] buf = new byte [ <NUM_LIT> ] ; int extracted = <NUM_LIT:0> ; InputStream in = null ; OutputStream out = null ; String MANIFEST = "<STR_LIT>" ; JarFile jar = new JarFile ( jarFile , true ) ; try { Enumeration < JarEntry > entries = jar . entries ( ) ; while ( entries . hasMoreElements ( ) ) { ZipEntry entry = entries . nextElement ( ) ; if ( entry . isDirectory ( ) ) { continue ; } String pathname = entry . getName ( ) ; if ( MANIFEST . equals ( pathname . toUpperCase ( ) ) ) { continue ; } in = jar . getInputStream ( entry ) ; File outFile = new File ( sandbox , pathname ) ; File parent = outFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } out = new BufferedOutputStream ( new FileOutputStream ( outFile ) ) ; int n ; while ( ( n = in . read ( buf , <NUM_LIT:0> , buf . length ) ) > <NUM_LIT:0> ) { out . write ( buf , <NUM_LIT:0> , n ) ; } FileUtils . close ( out ) ; FileUtils . close ( in ) ; extracted ++ ; } log ( "<STR_LIT>" + extracted + "<STR_LIT>" + ( extracted > <NUM_LIT:1> ? "<STR_LIT:s>" : "<STR_LIT>" ) + "<STR_LIT>" + sandbox . getPath ( ) ) ; } finally { FileUtils . close ( jar ) ; FileUtils . close ( out ) ; FileUtils . close ( in ) ; } } private void invoke2 ( String [ ] args ) { int retVal = - <NUM_LIT:1> ; try { try { Thread . sleep ( <NUM_LIT:1000> ) ; } catch ( Exception x ) { } Process process = spawn ( args , <NUM_LIT:3> ) ; new StreamProxy ( process . getErrorStream ( ) , "<STR_LIT>" , log ) . start ( ) ; new StreamProxy ( process . getInputStream ( ) , "<STR_LIT>" , log ) . start ( ) ; process . getOutputStream ( ) . close ( ) ; try { retVal = process . waitFor ( ) ; } catch ( InterruptedException e ) { log ( e ) ; } log ( "<STR_LIT>" ) ; deleteTree ( sandbox ) ; } catch ( Exception e ) { log ( e ) ; } log ( "<STR_LIT>" + retVal ) ; } public static boolean deleteTree ( File file ) { if ( file . isDirectory ( ) ) { File [ ] files = file . listFiles ( ) ; for ( File file1 : files ) { deleteTree ( file1 ) ; } } return file . delete ( ) ; } private void invoke3 ( String [ ] args ) { try { errlog ( "<STR_LIT>" + method . getDeclaringClass ( ) . getName ( ) + "<STR_LIT:.>" + method . getName ( ) + "<STR_LIT>" ) ; method . invoke ( null , new Object [ ] { args } ) ; } catch ( Throwable t ) { errlog ( t . getMessage ( ) ) ; t . printStackTrace ( ) ; errlog ( "<STR_LIT>" ) ; System . err . flush ( ) ; System . exit ( <NUM_LIT:31> ) ; } errlog ( "<STR_LIT>" ) ; System . err . flush ( ) ; } PrintStream log = null ; private void errlog ( String msg ) { date . setTime ( System . currentTimeMillis ( ) ) ; System . err . println ( isoPoint . format ( date ) + "<STR_LIT>" + phase + "<STR_LIT::U+0020>" + msg ) ; } private PrintStream checkLog ( ) { try { if ( log == null ) { log = new PrintStream ( new FileOutputStream ( logFile . toString ( ) , true ) ) ; } } catch ( IOException x ) { System . err . println ( "<STR_LIT>" + phase + "<STR_LIT>" + x . getMessage ( ) ) ; x . printStackTrace ( ) ; } date . setTime ( System . currentTimeMillis ( ) ) ; return log ; } private void log ( Throwable t ) { if ( checkLog ( ) != null ) { log . println ( isoPoint . format ( date ) + "<STR_LIT>" + phase + "<STR_LIT::U+0020>" + t . getMessage ( ) ) ; t . printStackTrace ( log ) ; } } private void log ( String msg ) { if ( checkLog ( ) != null ) { log . println ( isoPoint . format ( date ) + "<STR_LIT>" + phase + "<STR_LIT::U+0020>" + msg ) ; } } public static class StreamProxy extends Thread { InputStream in ; String name ; OutputStream out ; public StreamProxy ( InputStream in , String name ) { this ( in , name , null ) ; } public StreamProxy ( InputStream in , String name , OutputStream out ) { this . in = in ; this . name = name ; this . out = out ; } public void run ( ) { try { PrintWriter printWriter = null ; if ( out != null ) { printWriter = new PrintWriter ( out ) ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { if ( printWriter != null ) { printWriter . println ( line ) ; } } if ( printWriter != null ) { printWriter . flush ( ) ; } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } } private static final String JAVA_HOME = System . getProperty ( "<STR_LIT>" ) ; public static String fromURI ( String uri ) { if ( ! uri . startsWith ( "<STR_LIT>" ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( uri . startsWith ( "<STR_LIT>" ) ) { uri = uri . substring ( <NUM_LIT:7> ) ; } else { uri = uri . substring ( <NUM_LIT:5> ) ; } uri = uri . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ; if ( File . pathSeparatorChar == '<CHAR_LIT:;>' && uri . startsWith ( "<STR_LIT:\\>" ) && uri . length ( ) > <NUM_LIT:2> && Character . isLetter ( uri . charAt ( <NUM_LIT:1> ) ) && uri . lastIndexOf ( '<CHAR_LIT::>' ) > - <NUM_LIT:1> ) { uri = uri . substring ( <NUM_LIT:1> ) ; } StringBuilder buffer = new StringBuilder ( ) ; CharacterIterator iter = new StringCharacterIterator ( uri ) ; for ( char c = iter . first ( ) ; c != CharacterIterator . DONE ; c = iter . next ( ) ) { if ( c == '<CHAR_LIT>' ) { char c1 = iter . next ( ) ; if ( c1 != CharacterIterator . DONE ) { int i1 = Character . digit ( c1 , <NUM_LIT:16> ) ; char c2 = iter . next ( ) ; if ( c2 != CharacterIterator . DONE ) { int i2 = Character . digit ( c2 , <NUM_LIT:16> ) ; buffer . append ( ( char ) ( ( i1 << <NUM_LIT:4> ) + i2 ) ) ; } } } else { buffer . append ( c ) ; } } return buffer . toString ( ) ; } private static String addExtension ( String command ) { return command + ( OsVersion . IS_WINDOWS || OsVersion . IS_OS2 ? "<STR_LIT>" : "<STR_LIT>" ) ; } private static String javaCommand ( ) { String executable = addExtension ( "<STR_LIT>" ) ; String dir = new File ( JAVA_HOME + "<STR_LIT>" ) . getAbsolutePath ( ) ; File jExecutable = new File ( dir , executable ) ; if ( ! jExecutable . exists ( ) ) { return executable ; } return jExecutable . getAbsolutePath ( ) ; } private String getDebug ( int port ) { return "<STR_LIT>" + port ; } } </s>
<s> package com . izforge . izpack . util ; public class FreeThread extends Thread { private String name = "<STR_LIT>" ; private NativeLibraryClient client = null ; public FreeThread ( String name , NativeLibraryClient client ) { this . name = name ; this . client = client ; } public void run ( ) { client . freeLibrary ( name ) ; } } </s>
<s> package com . izforge . izpack . util ; import com . izforge . izpack . util . file . FileUtils ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . net . URISyntaxException ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; public class Librarian implements CleanupClient { private static final Logger logger = Logger . getLogger ( Librarian . class . getName ( ) ) ; private static final String JAR_PROTOCOL = "<STR_LIT>" ; private static final String FILE_PROTOCOL = "<STR_LIT:file>" ; private static final String NATIVE = "<STR_LIT>" ; private List < String > trackList = new ArrayList < String > ( ) ; private List < NativeLibraryClient > clients = new ArrayList < NativeLibraryClient > ( ) ; private List < String > temporaryFileNames = new ArrayList < String > ( ) ; private String extension = "<STR_LIT>" ; public Librarian ( TargetFactory factory , Housekeeper housekeeper ) { housekeeper . registerForCleanup ( this ) ; extension = '<CHAR_LIT:.>' + factory . getNativeLibraryExtension ( ) ; } public synchronized void loadLibrary ( String name , NativeLibraryClient client ) throws UnsatisfiedLinkError { name = strip ( name ) ; if ( ! trackList . contains ( name ) ) { boolean loaded = loadArchSpecificLibrary ( name , client ) ; if ( ! loaded ) { String name64 = name + "<STR_LIT>" ; loaded = loadArchSpecificLibrary ( name64 , client ) ; } if ( loaded ) { trackList . add ( name ) ; } else { throw new UnsatisfiedLinkError ( "<STR_LIT>" + name ) ; } } } @ Override public void cleanUp ( ) { try { LibraryRemover . invoke ( temporaryFileNames ) ; } catch ( IOException exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + exception . getMessage ( ) , exception ) ; } clients . clear ( ) ; } protected URL getResourcePath ( String name ) { String resource = "<STR_LIT:/>" + NATIVE + name + extension ; return getClass ( ) . getResource ( resource ) ; } private boolean loadArchSpecificLibrary ( String name , NativeLibraryClient client ) { boolean result = false ; if ( loadFromDLLPath ( name , client ) || loadSystemLibrary ( name , client ) || loadFromClassPath ( name , client ) ) { result = true ; } return result ; } private boolean loadFromDLLPath ( String name , NativeLibraryClient client ) { String property = System . getProperty ( "<STR_LIT>" ) ; if ( property != null ) { String path = property + "<STR_LIT:/>" + name + extension ; path = path . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ; return load ( path , client ) ; } return false ; } private boolean loadFromClassPath ( String name , NativeLibraryClient client ) { boolean result = false ; URL url = getResourcePath ( name ) ; if ( url != null ) { String protocol = url . getProtocol ( ) ; if ( protocol . equalsIgnoreCase ( FILE_PROTOCOL ) ) { try { String path = new File ( url . toURI ( ) ) . getPath ( ) ; result = load ( path , client ) ; } catch ( URISyntaxException exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + name + "<STR_LIT::U+0020>" + exception . getMessage ( ) , exception ) ; } } else if ( protocol . equalsIgnoreCase ( JAR_PROTOCOL ) ) { result = loadJarLibrary ( name , url , client ) ; } } return result ; } private boolean loadJarLibrary ( String name , URL url , NativeLibraryClient client ) { boolean result = false ; File file = null ; InputStream in = null ; FileOutputStream out = null ; String path = null ; try { file = FileUtils . createTempFile ( name , extension ) ; in = url . openStream ( ) ; out = new FileOutputStream ( file ) ; IoHelper . copyStream ( in , out ) ; path = file . getAbsolutePath ( ) ; } catch ( IOException exception ) { logger . log ( Level . WARNING , "<STR_LIT>" + name + "<STR_LIT::U+0020>" + exception . getMessage ( ) , exception ) ; } finally { FileUtils . close ( in ) ; FileUtils . close ( out ) ; } if ( path != null ) { result = load ( path , client ) ; } if ( ! result ) { FileUtils . delete ( file ) ; } else { temporaryFileNames . add ( path ) ; file . deleteOnExit ( ) ; } return result ; } private boolean loadSystemLibrary ( String name , NativeLibraryClient client ) { try { System . loadLibrary ( name ) ; clients . add ( client ) ; return true ; } catch ( Throwable exception ) { logger . log ( Level . FINE , "<STR_LIT>" + name + "<STR_LIT::U+0020>" + exception . getMessage ( ) , exception ) ; } return false ; } private boolean load ( String path , NativeLibraryClient client ) { boolean result = false ; try { System . load ( path ) ; clients . add ( client ) ; result = true ; } catch ( Throwable exception ) { logger . log ( Level . FINE , "<STR_LIT>" + path + "<STR_LIT::U+0020>" + exception . getMessage ( ) , exception ) ; } return result ; } private String strip ( String name ) { int extensionStart = name . lastIndexOf ( '<CHAR_LIT:.>' ) ; int nameStart = name . lastIndexOf ( '<CHAR_LIT:/>' ) ; if ( nameStart < <NUM_LIT:0> ) { nameStart = name . lastIndexOf ( '<STR_LIT:\\>' ) ; } nameStart ++ ; String shortName ; if ( extensionStart > <NUM_LIT:0> ) { shortName = name . substring ( nameStart , extensionStart ) ; } else { shortName = name . substring ( nameStart , name . length ( ) ) ; } return ( shortName ) ; } } </s>
<s> package com . izforge . izpack . util ; import java . util . logging . Formatter ; import java . util . logging . Level ; import java . util . logging . LogManager ; import java . util . logging . LogRecord ; import java . util . logging . StreamHandler ; public class LogHandler extends StreamHandler { private void configure ( ) { LogManager manager = LogManager . getLogManager ( ) ; String cname = getClass ( ) . getName ( ) ; String formatterName = manager . getProperty ( cname + "<STR_LIT>" ) ; Formatter formatter = null ; try { if ( formatterName != null ) { Class < Formatter > formatterClass = ( Class < Formatter > ) ClassLoader . getSystemClassLoader ( ) . loadClass ( formatterName ) ; formatter = ( Formatter ) formatterClass . newInstance ( ) ; } } catch ( Exception ex ) { } if ( formatter == null ) { formatter = new LogFormatter ( ) ; } setFormatter ( formatter ) ; if ( Debug . isDEBUG ( ) ) { setLevel ( Level . FINE ) ; } else { setLevel ( Level . INFO ) ; } } public LogHandler ( ) { configure ( ) ; setOutputStream ( System . err ) ; } public void publish ( LogRecord record ) { super . publish ( record ) ; flush ( ) ; } public void close ( ) { flush ( ) ; } } </s>
<s> package com . izforge . izpack . util . file ; public interface FileNameMapper { void setFrom ( String from ) ; void setTo ( String to ) ; String [ ] mapFileName ( String sourceFileName ) ; } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; import java . util . Vector ; import com . izforge . izpack . util . file . types . Resource ; import com . izforge . izpack . util . file . types . ResourceFactory ; public class SourceFileScanner implements ResourceFactory { private FileUtils fileUtils ; private File destDir ; public SourceFileScanner ( ) { fileUtils = FileUtils . getFileUtils ( ) ; } public String [ ] restrict ( String [ ] files , File srcDir , File destDir , FileNameMapper mapper ) throws Exception { return restrict ( files , srcDir , destDir , mapper , fileUtils . getFileTimestampGranularity ( ) ) ; } public String [ ] restrict ( String [ ] files , File srcDir , File destDir , FileNameMapper mapper , long granularity ) throws Exception { this . destDir = destDir ; Vector < Resource > v = new Vector < Resource > ( ) ; for ( String file : files ) { File src = fileUtils . resolveFile ( srcDir , file ) ; v . addElement ( new Resource ( file , src . exists ( ) , src . lastModified ( ) , src . isDirectory ( ) ) ) ; } Resource [ ] sourceresources = new Resource [ v . size ( ) ] ; v . copyInto ( sourceresources ) ; Resource [ ] outofdate = ResourceUtils . selectOutOfDateSources ( sourceresources , mapper , this , granularity ) ; String [ ] result = new String [ outofdate . length ] ; for ( int counter = <NUM_LIT:0> ; counter < outofdate . length ; counter ++ ) { result [ counter ] = outofdate [ counter ] . getName ( ) ; } return result ; } public File [ ] restrictAsFiles ( String [ ] files , File srcDir , File destDir , FileNameMapper mapper ) throws Exception { return restrictAsFiles ( files , srcDir , destDir , mapper , fileUtils . getFileTimestampGranularity ( ) ) ; } public File [ ] restrictAsFiles ( String [ ] files , File srcDir , File destDir , FileNameMapper mapper , long granularity ) throws Exception { String [ ] res = restrict ( files , srcDir , destDir , mapper , granularity ) ; File [ ] result = new File [ res . length ] ; for ( int i = <NUM_LIT:0> ; i < res . length ; i ++ ) { result [ i ] = new File ( srcDir , res [ i ] ) ; } return result ; } public Resource getResource ( String name ) throws Exception { File src = fileUtils . resolveFile ( destDir , name ) ; return new Resource ( name , src . exists ( ) , src . lastModified ( ) , src . isDirectory ( ) ) ; } } </s>
<s> package com . izforge . izpack . util . file ; import java . util . Arrays ; import java . util . HashSet ; public class CompositeMapper extends ContainerMapper { public String [ ] mapFileName ( String sourceFileName ) { HashSet < String > results = new HashSet < String > ( ) ; for ( FileNameMapper mapper : getMappers ( ) ) { if ( mapper != null ) { String [ ] mapped = mapper . mapFileName ( sourceFileName ) ; if ( mapped != null ) { results . addAll ( Arrays . asList ( mapped ) ) ; } } } return ( results . size ( ) == <NUM_LIT:0> ) ? null : results . toArray ( new String [ results . size ( ) ] ) ; } } </s>
<s> package com . izforge . izpack . util . file ; public class MergingMapper implements FileNameMapper { protected String [ ] mergedFile = null ; public void setFrom ( String from ) { } public void setTo ( String to ) { mergedFile = new String [ ] { to } ; } public String [ ] mapFileName ( String sourceFileName ) { return mergedFile ; } } </s>
<s> package com . izforge . izpack . util . file ; import com . izforge . izpack . util . OsVersion ; import java . io . BufferedInputStream ; import java . io . BufferedReader ; import java . io . Closeable ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . Reader ; import java . net . MalformedURLException ; import java . net . URL ; import java . text . CharacterIterator ; import java . text . DecimalFormat ; import java . text . StringCharacterIterator ; import java . util . Random ; import java . util . Stack ; import java . util . StringTokenizer ; import java . util . zip . ZipFile ; public class FileUtils { private static final FileUtils PRIMARY_INSTANCE = new FileUtils ( ) ; private static Random rand = new Random ( System . currentTimeMillis ( ) + Runtime . getRuntime ( ) . freeMemory ( ) ) ; private static final int BUF_SIZE = <NUM_LIT> ; private static boolean [ ] isSpecial = new boolean [ <NUM_LIT> ] ; private static char [ ] escapedChar1 = new char [ <NUM_LIT> ] ; private static char [ ] escapedChar2 = new char [ <NUM_LIT> ] ; public static final long FAT_FILE_TIMESTAMP_GRANULARITY = <NUM_LIT> ; public static final long UNIX_FILE_TIMESTAMP_GRANULARITY = <NUM_LIT:1000> ; static { for ( int i = <NUM_LIT:0> ; i <= <NUM_LIT> ; i ++ ) { isSpecial [ i ] = true ; escapedChar1 [ i ] = Character . forDigit ( i > > <NUM_LIT:4> , <NUM_LIT:16> ) ; escapedChar2 [ i ] = Character . forDigit ( i & <NUM_LIT> , <NUM_LIT:16> ) ; } isSpecial [ <NUM_LIT> ] = true ; escapedChar1 [ <NUM_LIT> ] = '<CHAR_LIT>' ; escapedChar2 [ <NUM_LIT> ] = '<CHAR_LIT>' ; char [ ] escChs = { '<CHAR_LIT>' , '<CHAR_LIT:>>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT:">' , '<CHAR_LIT>' , '<CHAR_LIT:}>' , '<CHAR_LIT>' , '<STR_LIT:\\>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT:[>' , '<CHAR_LIT:]>' , '<CHAR_LIT>' } ; int len = escChs . length ; char ch ; for ( int i = <NUM_LIT:0> ; i < len ; i ++ ) { ch = escChs [ i ] ; isSpecial [ ch ] = true ; escapedChar1 [ ch ] = Character . forDigit ( ch > > <NUM_LIT:4> , <NUM_LIT:16> ) ; escapedChar2 [ ch ] = Character . forDigit ( ch & <NUM_LIT> , <NUM_LIT:16> ) ; } } public static File createTempFile ( String prefix , String suffix ) throws IOException { if ( OsVersion . IS_OSX ) { return File . createTempFile ( prefix , suffix , new File ( "<STR_LIT>" ) ) ; } else { return File . createTempFile ( prefix , suffix ) ; } } public static FileUtils getFileUtils ( ) { return PRIMARY_INSTANCE ; } protected FileUtils ( ) { } public URL getFileURL ( File file ) throws MalformedURLException { return new URL ( toURI ( file . getAbsolutePath ( ) ) ) ; } public void copyFile ( String sourceFile , String destFile , boolean overwrite , boolean preserveLastModified ) throws IOException { copyFile ( new File ( sourceFile ) , new File ( destFile ) , overwrite , preserveLastModified ) ; } public void copyFile ( File sourceFile , File destFile ) throws IOException { copyFile ( sourceFile , destFile , false , false ) ; } public void copyFile ( File sourceFile , File destFile , boolean overwrite , boolean preserveLastModified ) throws IOException { if ( overwrite || ! destFile . exists ( ) || destFile . lastModified ( ) < sourceFile . lastModified ( ) ) { if ( destFile . exists ( ) && destFile . isFile ( ) ) { destFile . delete ( ) ; } File parent = destFile . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) ) { parent . mkdirs ( ) ; } FileInputStream in = null ; FileOutputStream out = null ; try { in = new FileInputStream ( sourceFile ) ; out = new FileOutputStream ( destFile ) ; byte [ ] buffer = new byte [ BUF_SIZE ] ; int count = <NUM_LIT:0> ; do { out . write ( buffer , <NUM_LIT:0> , count ) ; count = in . read ( buffer , <NUM_LIT:0> , buffer . length ) ; } while ( count != - <NUM_LIT:1> ) ; } finally { close ( out ) ; close ( in ) ; } if ( preserveLastModified ) { setFileLastModified ( destFile , sourceFile . lastModified ( ) ) ; } } } public void setFileLastModified ( File file , long time ) { file . setLastModified ( ( time < <NUM_LIT:0> ) ? System . currentTimeMillis ( ) : time ) ; } public File resolveFile ( File file , String filename ) throws Exception { filename = filename . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; if ( isAbsolutePath ( filename ) ) { return normalize ( filename ) ; } if ( file == null ) { return new File ( filename ) ; } File helpFile = new File ( file . getAbsolutePath ( ) ) ; StringTokenizer tok = new StringTokenizer ( filename , File . separator ) ; while ( tok . hasMoreTokens ( ) ) { String part = tok . nextToken ( ) ; if ( part . equals ( "<STR_LIT>" ) ) { helpFile = helpFile . getParentFile ( ) ; if ( helpFile == null ) { String msg = "<STR_LIT>" + filename + "<STR_LIT>" + file . getPath ( ) ; throw new Exception ( msg ) ; } } else if ( part . equals ( "<STR_LIT:.>" ) ) { } else { helpFile = new File ( helpFile , part ) ; } } return new File ( helpFile . getAbsolutePath ( ) ) ; } public static boolean isAbsolutePath ( String filename ) { if ( filename . startsWith ( File . separator ) ) { return true ; } if ( OsVersion . IS_WINDOWS && filename . length ( ) >= <NUM_LIT:2> && Character . isLetter ( filename . charAt ( <NUM_LIT:0> ) ) && filename . charAt ( <NUM_LIT:1> ) == '<CHAR_LIT::>' ) { return true ; } return false ; } public File normalize ( String path ) throws Exception { String orig = path ; path = path . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; int colon = path . indexOf ( "<STR_LIT::>" ) ; if ( ! isAbsolutePath ( path ) ) { String msg = path + "<STR_LIT>" ; throw new Exception ( msg ) ; } boolean dosWithDrive = false ; String root = null ; if ( ( OsVersion . IS_WINDOWS && path . length ( ) >= <NUM_LIT:2> && Character . isLetter ( path . charAt ( <NUM_LIT:0> ) ) && path . charAt ( <NUM_LIT:1> ) == '<CHAR_LIT::>' ) ) { dosWithDrive = true ; char [ ] ca = path . replace ( '<CHAR_LIT:/>' , '<STR_LIT:\\>' ) . toCharArray ( ) ; StringBuffer sbRoot = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < colon ; i ++ ) { sbRoot . append ( Character . toUpperCase ( ca [ i ] ) ) ; } sbRoot . append ( '<CHAR_LIT::>' ) ; if ( colon + <NUM_LIT:1> < path . length ( ) ) { sbRoot . append ( File . separatorChar ) ; } root = sbRoot . toString ( ) ; StringBuffer sbPath = new StringBuffer ( ) ; for ( int i = colon + <NUM_LIT:1> ; i < ca . length ; i ++ ) { if ( ( ca [ i ] != '<STR_LIT:\\>' ) || ( ca [ i ] == '<STR_LIT:\\>' && ca [ i - <NUM_LIT:1> ] != '<STR_LIT:\\>' ) ) { sbPath . append ( ca [ i ] ) ; } } path = sbPath . toString ( ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; } else { if ( path . length ( ) == <NUM_LIT:1> ) { root = File . separator ; path = "<STR_LIT>" ; } else if ( path . charAt ( <NUM_LIT:1> ) == File . separatorChar ) { root = File . separator + File . separator ; path = path . substring ( <NUM_LIT:2> ) ; } else { root = File . separator ; path = path . substring ( <NUM_LIT:1> ) ; } } Stack < String > s = new Stack < String > ( ) ; s . push ( root ) ; StringTokenizer tok = new StringTokenizer ( path , File . separator ) ; while ( tok . hasMoreTokens ( ) ) { String thisToken = tok . nextToken ( ) ; if ( "<STR_LIT:.>" . equals ( thisToken ) ) { continue ; } else if ( "<STR_LIT>" . equals ( thisToken ) ) { if ( s . size ( ) < <NUM_LIT:2> ) { throw new Exception ( "<STR_LIT>" + orig ) ; } else { s . pop ( ) ; } } else { s . push ( thisToken ) ; } } StringBuffer sb = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < s . size ( ) ; i ++ ) { if ( i > <NUM_LIT:1> ) { sb . append ( File . separatorChar ) ; } sb . append ( s . elementAt ( i ) ) ; } path = sb . toString ( ) ; if ( dosWithDrive ) { path = path . replace ( '<CHAR_LIT:/>' , '<STR_LIT:\\>' ) ; } return new File ( path ) ; } public String toVMSPath ( File f ) throws Exception { String osPath ; String path = normalize ( f . getAbsolutePath ( ) ) . getPath ( ) ; String name = f . getName ( ) ; boolean isAbsolute = path . charAt ( <NUM_LIT:0> ) == File . separatorChar ; boolean isDirectory = f . isDirectory ( ) && ! name . regionMatches ( true , name . length ( ) - <NUM_LIT:4> , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:4> ) ; String device = null ; StringBuffer directory = null ; String file = null ; int index = <NUM_LIT:0> ; if ( isAbsolute ) { index = path . indexOf ( File . separatorChar , <NUM_LIT:1> ) ; if ( index == - <NUM_LIT:1> ) { return path . substring ( <NUM_LIT:1> ) + "<STR_LIT>" ; } else { device = path . substring ( <NUM_LIT:1> , index ++ ) ; } } if ( isDirectory ) { directory = new StringBuffer ( path . substring ( index ) . replace ( File . separatorChar , '<CHAR_LIT:.>' ) ) ; } else { int dirEnd = path . lastIndexOf ( File . separatorChar , path . length ( ) ) ; if ( dirEnd == - <NUM_LIT:1> || dirEnd < index ) { file = path . substring ( index ) ; } else { directory = new StringBuffer ( path . substring ( index , dirEnd ) . replace ( File . separatorChar , '<CHAR_LIT:.>' ) ) ; index = dirEnd + <NUM_LIT:1> ; if ( path . length ( ) > index ) { file = path . substring ( index ) ; } } } if ( ! isAbsolute && directory != null ) { directory . insert ( <NUM_LIT:0> , '<CHAR_LIT:.>' ) ; } osPath = ( ( device != null ) ? device + "<STR_LIT::>" : "<STR_LIT>" ) + ( ( directory != null ) ? "<STR_LIT:[>" + directory + "<STR_LIT:]>" : "<STR_LIT>" ) + ( ( file != null ) ? file : "<STR_LIT>" ) ; return osPath ; } public File createTempFile ( String prefix , String suffix , File parentDir ) { File result = null ; String parent = ( parentDir == null ) ? System . getProperty ( "<STR_LIT>" ) : parentDir . getPath ( ) ; DecimalFormat fmt = new DecimalFormat ( "<STR_LIT>" ) ; synchronized ( rand ) { do { result = new File ( parent , prefix + fmt . format ( Math . abs ( rand . nextInt ( ) ) ) + suffix ) ; } while ( result . exists ( ) ) ; } return result ; } public boolean contentEquals ( File f1 , File f2 ) throws Exception { return contentEquals ( f1 , f2 , false ) ; } public boolean contentEquals ( File f1 , File f2 , boolean textfile ) throws Exception { if ( f1 . exists ( ) != f2 . exists ( ) ) { return false ; } if ( ! f1 . exists ( ) ) { return true ; } if ( f1 . isDirectory ( ) || f2 . isDirectory ( ) ) { return false ; } if ( fileNameEquals ( f1 , f2 ) ) { return true ; } return textfile ? textEquals ( f1 , f2 ) : binaryEquals ( f1 , f2 ) ; } private boolean binaryEquals ( File f1 , File f2 ) throws IOException { if ( f1 . length ( ) != f2 . length ( ) ) { return false ; } InputStream in1 = null ; InputStream in2 = null ; try { in1 = new BufferedInputStream ( new FileInputStream ( f1 ) ) ; in2 = new BufferedInputStream ( new FileInputStream ( f2 ) ) ; int expectedByte = in1 . read ( ) ; while ( expectedByte != - <NUM_LIT:1> ) { if ( expectedByte != in2 . read ( ) ) { return false ; } expectedByte = in1 . read ( ) ; } if ( in2 . read ( ) != - <NUM_LIT:1> ) { return false ; } return true ; } finally { close ( in1 ) ; close ( in2 ) ; } } private boolean textEquals ( File f1 , File f2 ) throws IOException { BufferedReader in1 = null ; BufferedReader in2 = null ; try { in1 = new BufferedReader ( new FileReader ( f1 ) ) ; in2 = new BufferedReader ( new FileReader ( f2 ) ) ; String expected = in1 . readLine ( ) ; while ( expected != null ) { if ( ! expected . equals ( in2 . readLine ( ) ) ) { return false ; } expected = in1 . readLine ( ) ; } if ( in2 . readLine ( ) != null ) { return false ; } return true ; } finally { close ( in1 ) ; close ( in2 ) ; } } public File getParentFile ( File f ) { return ( f == null ) ? null : f . getParentFile ( ) ; } public static final String readFully ( Reader rdr ) throws IOException { return readFully ( rdr , BUF_SIZE ) ; } public static final String readFully ( Reader rdr , int bufferSize ) throws IOException { if ( bufferSize <= <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + "<STR_LIT>" ) ; } final char [ ] buffer = new char [ bufferSize ] ; int bufferLength = <NUM_LIT:0> ; StringBuffer textBuffer = null ; while ( bufferLength != - <NUM_LIT:1> ) { bufferLength = rdr . read ( buffer ) ; if ( bufferLength > <NUM_LIT:0> ) { textBuffer = ( textBuffer == null ) ? new StringBuffer ( ) : textBuffer ; textBuffer . append ( new String ( buffer , <NUM_LIT:0> , bufferLength ) ) ; } } return ( textBuffer == null ) ? null : textBuffer . toString ( ) ; } public boolean createNewFile ( File f ) throws IOException { return f . createNewFile ( ) ; } public boolean createNewFile ( File f , boolean mkdirs ) throws IOException { File parent = f . getParentFile ( ) ; if ( mkdirs && ! ( parent . exists ( ) ) ) { parent . mkdirs ( ) ; } return f . createNewFile ( ) ; } public boolean isSymbolicLink ( File parent , String name ) throws IOException { if ( parent == null ) { File f = new File ( name ) ; parent = f . getParentFile ( ) ; name = f . getName ( ) ; } File toTest = new File ( parent . getCanonicalPath ( ) , name ) ; return ! toTest . getAbsolutePath ( ) . equals ( toTest . getCanonicalPath ( ) ) ; } public String removeLeadingPath ( File leading , File path ) throws Exception { String l = normalize ( leading . getAbsolutePath ( ) ) . getAbsolutePath ( ) ; String p = normalize ( path . getAbsolutePath ( ) ) . getAbsolutePath ( ) ; if ( l . equals ( p ) ) { return "<STR_LIT>" ; } if ( ! l . endsWith ( File . separator ) ) { l += File . separator ; } return ( p . startsWith ( l ) ) ? p . substring ( l . length ( ) ) : p ; } public String toURI ( String path ) { boolean isDir = ( new File ( path ) ) . isDirectory ( ) ; StringBuffer sb = new StringBuffer ( "<STR_LIT>" ) ; try { path = normalize ( path ) . getAbsolutePath ( ) ; sb . append ( "<STR_LIT>" ) ; if ( ! path . startsWith ( File . separator ) ) { sb . append ( "<STR_LIT:/>" ) ; } } catch ( Exception e ) { } path = path . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; CharacterIterator iter = new StringCharacterIterator ( path ) ; for ( char c = iter . first ( ) ; c != CharacterIterator . DONE ; c = iter . next ( ) ) { if ( c < <NUM_LIT> && isSpecial [ c ] ) { sb . append ( '<CHAR_LIT>' ) ; sb . append ( escapedChar1 [ c ] ) ; sb . append ( escapedChar2 [ c ] ) ; } else { sb . append ( c ) ; } } if ( isDir && ! path . endsWith ( "<STR_LIT:/>" ) ) { sb . append ( '<CHAR_LIT:/>' ) ; } return sb . toString ( ) ; } public boolean fileNameEquals ( File f1 , File f2 ) throws Exception { return normalize ( f1 . getAbsolutePath ( ) ) . equals ( normalize ( f2 . getAbsolutePath ( ) ) ) ; } public void rename ( File from , File to ) throws IOException { if ( to . exists ( ) && ! to . delete ( ) ) { throw new IOException ( "<STR_LIT>" + to + "<STR_LIT>" + from ) ; } File parent = to . getParentFile ( ) ; if ( parent != null && ! parent . exists ( ) && ! parent . mkdirs ( ) ) { throw new IOException ( "<STR_LIT>" + parent + "<STR_LIT>" + from ) ; } if ( ! from . renameTo ( to ) ) { copyFile ( from , to ) ; if ( ! from . delete ( ) ) { throw new IOException ( "<STR_LIT>" + from + "<STR_LIT>" ) ; } } } public long getFileTimestampGranularity ( ) { return OsVersion . IS_WINDOWS ? FAT_FILE_TIMESTAMP_GRANULARITY : UNIX_FILE_TIMESTAMP_GRANULARITY ; } public boolean isUpToDate ( File source , File dest , long granularity ) { if ( ! dest . exists ( ) ) { return false ; } long sourceTime = source . lastModified ( ) ; long destTime = dest . lastModified ( ) ; return isUpToDate ( sourceTime , destTime , granularity ) ; } public boolean isUpToDate ( File source , File dest ) { return isUpToDate ( source , dest , getFileTimestampGranularity ( ) ) ; } public boolean isUpToDate ( long sourceTime , long destTime , long granularity ) { if ( destTime == - <NUM_LIT:1> ) { return false ; } return destTime >= sourceTime + granularity ; } public boolean isUpToDate ( long sourceTime , long destTime ) { return isUpToDate ( sourceTime , destTime , getFileTimestampGranularity ( ) ) ; } public static void close ( Closeable closeable ) { if ( closeable != null ) { try { closeable . close ( ) ; } catch ( IOException ignore ) { } } } public static void close ( ZipFile file ) { if ( file != null ) { try { file . close ( ) ; } catch ( IOException ignore ) { } } } public static void delete ( File file ) { if ( file != null ) { file . delete ( ) ; } } public static boolean deleteRecursively ( File fileToDelete ) { boolean retval = true ; if ( fileToDelete . isDirectory ( ) ) { for ( File fileInDir : fileToDelete . listFiles ( ) ) { retval &= deleteRecursively ( fileInDir ) ; } } retval &= fileToDelete . delete ( ) ; return retval ; } } </s>
<s> package com . izforge . izpack . util . file ; public class IdentityMapper implements FileNameMapper { public void setFrom ( String from ) { } public void setTo ( String to ) { } public String [ ] mapFileName ( String sourceFileName ) { return new String [ ] { sourceFileName } ; } } </s>
<s> package com . izforge . izpack . util . file ; public class FlatFileNameMapper implements FileNameMapper { public void setFrom ( String from ) { } public void setTo ( String to ) { } public String [ ] mapFileName ( String sourceFileName ) { return new String [ ] { new java . io . File ( sourceFileName ) . getName ( ) } ; } } </s>
<s> package com . izforge . izpack . util . file ; public class GlobPatternMapper implements FileNameMapper { protected String fromPrefix = null ; protected String fromPostfix = null ; protected int prefixLength ; protected int postfixLength ; protected String toPrefix = null ; protected String toPostfix = null ; private boolean handleDirSep = false ; private boolean caseSensitive = true ; public void setHandleDirSep ( boolean handleDirSep ) { this . handleDirSep = handleDirSep ; } public void setCaseSensitive ( boolean caseSensitive ) { this . caseSensitive = caseSensitive ; } public void setFrom ( String from ) { int index = from . lastIndexOf ( "<STR_LIT:*>" ) ; if ( index == - <NUM_LIT:1> ) { fromPrefix = from ; fromPostfix = "<STR_LIT>" ; } else { fromPrefix = from . substring ( <NUM_LIT:0> , index ) ; fromPostfix = from . substring ( index + <NUM_LIT:1> ) ; } prefixLength = fromPrefix . length ( ) ; postfixLength = fromPostfix . length ( ) ; } public void setTo ( String to ) { int index = to . lastIndexOf ( "<STR_LIT:*>" ) ; if ( index == - <NUM_LIT:1> ) { toPrefix = to ; toPostfix = "<STR_LIT>" ; } else { toPrefix = to . substring ( <NUM_LIT:0> , index ) ; toPostfix = to . substring ( index + <NUM_LIT:1> ) ; } } public String [ ] mapFileName ( String sourceFileName ) { if ( fromPrefix == null || ! modifyName ( sourceFileName ) . startsWith ( modifyName ( fromPrefix ) ) || ! modifyName ( sourceFileName ) . endsWith ( modifyName ( fromPostfix ) ) ) { return null ; } return new String [ ] { toPrefix + extractVariablePart ( sourceFileName ) + toPostfix } ; } protected String extractVariablePart ( String name ) { return name . substring ( prefixLength , name . length ( ) - postfixLength ) ; } private String modifyName ( String name ) { if ( ! caseSensitive ) { name = name . toLowerCase ( ) ; } if ( handleDirSep ) { if ( name . indexOf ( '<STR_LIT:\\>' ) != - <NUM_LIT:1> ) { name = name . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; } } return name ; } } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; import java . util . NoSuchElementException ; import java . util . StringTokenizer ; import org . apache . tools . ant . taskdefs . condition . Os ; public class PathTokenizer { private StringTokenizer tokenizer ; private String lookahead = null ; private boolean onNetWare = Os . isFamily ( "<STR_LIT>" ) ; private boolean dosStyleFilesystem ; public PathTokenizer ( String path ) { if ( onNetWare ) { tokenizer = new StringTokenizer ( path , "<STR_LIT>" , true ) ; } else { tokenizer = new StringTokenizer ( path , "<STR_LIT>" , false ) ; } dosStyleFilesystem = File . pathSeparatorChar == '<CHAR_LIT:;>' ; } public boolean hasMoreTokens ( ) { if ( lookahead != null ) { return true ; } return tokenizer . hasMoreTokens ( ) ; } public String nextToken ( ) throws NoSuchElementException { String token = null ; if ( lookahead != null ) { token = lookahead ; lookahead = null ; } else { token = tokenizer . nextToken ( ) . trim ( ) ; } if ( ! onNetWare ) { if ( token . length ( ) == <NUM_LIT:1> && Character . isLetter ( token . charAt ( <NUM_LIT:0> ) ) && dosStyleFilesystem && tokenizer . hasMoreTokens ( ) ) { String nextToken = tokenizer . nextToken ( ) . trim ( ) ; if ( nextToken . startsWith ( "<STR_LIT:\\>" ) || nextToken . startsWith ( "<STR_LIT:/>" ) ) { token += "<STR_LIT::>" + nextToken ; } else { lookahead = nextToken ; } } } else { if ( token . equals ( File . pathSeparator ) || token . equals ( "<STR_LIT::>" ) ) { token = tokenizer . nextToken ( ) . trim ( ) ; } if ( tokenizer . hasMoreTokens ( ) ) { String nextToken = tokenizer . nextToken ( ) . trim ( ) ; if ( ! nextToken . equals ( File . pathSeparator ) ) { if ( nextToken . equals ( "<STR_LIT::>" ) ) { if ( ! token . startsWith ( "<STR_LIT:/>" ) && ! token . startsWith ( "<STR_LIT:\\>" ) && ! token . startsWith ( "<STR_LIT:.>" ) && ! token . startsWith ( "<STR_LIT>" ) ) { String oneMore = tokenizer . nextToken ( ) . trim ( ) ; if ( ! oneMore . equals ( File . pathSeparator ) ) { token += "<STR_LIT::>" + oneMore ; } else { token += "<STR_LIT::>" ; lookahead = oneMore ; } } } else { lookahead = nextToken ; } } } } return token ; } } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; public interface FileScanner { void addDefaultExcludes ( ) ; File getBasedir ( ) ; String [ ] getExcludedDirectories ( ) throws Exception ; String [ ] getExcludedFiles ( ) throws Exception ; String [ ] getIncludedDirectories ( ) throws Exception ; String [ ] getIncludedFiles ( ) throws Exception ; String [ ] getNotIncludedDirectories ( ) throws Exception ; String [ ] getNotIncludedFiles ( ) throws Exception ; void scan ( ) throws Exception ; void setBasedir ( String basedir ) ; void setBasedir ( File basedir ) ; void setExcludes ( String [ ] excludes ) ; void setIncludes ( String [ ] includes ) ; void setCaseSensitive ( boolean isCaseSensitive ) ; } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; import java . io . IOException ; import java . util . Enumeration ; import java . util . Hashtable ; import java . util . Vector ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . util . file . types . FileSet ; import com . izforge . izpack . util . file . types . Mapper ; public class FileCopyTask { private static final Logger logger = Logger . getLogger ( FileCopyTask . class . getName ( ) ) ; protected File file = null ; protected File destFile = null ; protected File destDir = null ; protected Vector < FileSet > filesets = new Vector < FileSet > ( ) ; private boolean enableMultipleMappings = false ; protected boolean preserveLastModified = false ; protected boolean forceOverwrite = false ; protected boolean flatten = false ; protected boolean includeEmpty = true ; protected boolean failonerror = true ; protected Hashtable < String , String [ ] > fileCopyMap = new Hashtable < String , String [ ] > ( ) ; protected Hashtable < String , String [ ] > dirCopyMap = new Hashtable < String , String [ ] > ( ) ; protected Hashtable < File , File > completeDirMap = new Hashtable < File , File > ( ) ; protected Mapper mapperElement = null ; protected FileUtils fileUtils ; private long granularity = <NUM_LIT:0> ; public FileCopyTask ( ) { fileUtils = FileUtils . getFileUtils ( ) ; granularity = fileUtils . getFileTimestampGranularity ( ) ; } protected FileUtils getFileUtils ( ) { return fileUtils ; } public void setFile ( File file ) { this . file = file ; } public void setToFile ( File destFile ) { this . destFile = destFile ; } public void setToDir ( File destDir ) { this . destDir = destDir ; } public void setPreserveLastModified ( boolean preserve ) { preserveLastModified = preserve ; } public boolean getPreserveLastModified ( ) { return preserveLastModified ; } public void setOverwrite ( boolean overwrite ) { this . forceOverwrite = overwrite ; } public void setFlatten ( boolean flatten ) { this . flatten = flatten ; } public void setIncludeEmptyDirs ( boolean includeEmpty ) { this . includeEmpty = includeEmpty ; } public void setEnableMultipleMappings ( boolean enableMultipleMappings ) { this . enableMultipleMappings = enableMultipleMappings ; } public boolean isEnableMultipleMapping ( ) { return enableMultipleMappings ; } public void setFailOnError ( boolean failonerror ) { this . failonerror = failonerror ; } public void addFileSet ( FileSet set ) { filesets . addElement ( set ) ; } public Mapper createMapper ( ) throws Exception { if ( mapperElement != null ) { throw new Exception ( "<STR_LIT>" ) ; } mapperElement = new Mapper ( ) ; return mapperElement ; } public void add ( FileNameMapper fileNameMapper ) throws Exception { createMapper ( ) . add ( fileNameMapper ) ; } public void setGranularity ( long granularity ) { this . granularity = granularity ; } public void execute ( ) throws Exception { File savedFile = file ; File savedDestFile = destFile ; File savedDestDir = destDir ; FileSet savedFileSet = null ; if ( file == null && destFile != null && filesets . size ( ) == <NUM_LIT:1> ) { savedFileSet = filesets . elementAt ( <NUM_LIT:0> ) ; } validateAttributes ( ) ; try { if ( file != null ) { if ( file . exists ( ) ) { if ( destFile == null ) { destFile = new File ( destDir , file . getName ( ) ) ; } if ( forceOverwrite || ! destFile . exists ( ) || ( file . lastModified ( ) - granularity > destFile . lastModified ( ) ) ) { fileCopyMap . put ( file . getAbsolutePath ( ) , new String [ ] { destFile . getAbsolutePath ( ) } ) ; } else { logger . fine ( file + "<STR_LIT>" + destFile + "<STR_LIT>" ) ; } } else { String message = "<STR_LIT>" + file . getAbsolutePath ( ) + "<STR_LIT>" ; if ( ! failonerror ) { logger . fine ( message ) ; } else { throw new Exception ( message ) ; } } } for ( int i = <NUM_LIT:0> ; i < filesets . size ( ) ; i ++ ) { FileSet fs = filesets . elementAt ( i ) ; DirectoryScanner ds = null ; try { ds = fs . getDirectoryScanner ( ) ; } catch ( Exception e ) { if ( failonerror || ! e . getMessage ( ) . endsWith ( "<STR_LIT>" ) ) { throw e ; } else { logger . log ( Level . WARNING , "<STR_LIT>" + e . getMessage ( ) , e ) ; continue ; } } File fromDir = fs . getDir ( ) ; String [ ] srcFiles = ds . getIncludedFiles ( ) ; String [ ] srcDirs = ds . getIncludedDirectories ( ) ; boolean isEverythingIncluded = ds . isEverythingIncluded ( ) && ( ! fs . hasSelectors ( ) && ! fs . hasPatterns ( ) ) ; if ( isEverythingIncluded && ! flatten && mapperElement == null ) { completeDirMap . put ( fromDir , destDir ) ; } scan ( fromDir , destDir , srcFiles , srcDirs ) ; } try { doFileOperations ( ) ; } catch ( Exception e ) { if ( ! failonerror ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } else { throw e ; } } } finally { file = savedFile ; destFile = savedDestFile ; destDir = savedDestDir ; if ( savedFileSet != null ) { filesets . insertElementAt ( savedFileSet , <NUM_LIT:0> ) ; } fileCopyMap . clear ( ) ; dirCopyMap . clear ( ) ; completeDirMap . clear ( ) ; } } protected void validateAttributes ( ) throws Exception { if ( file == null && filesets . size ( ) == <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } if ( destFile != null && destDir != null ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } if ( destFile == null && destDir == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( file != null && file . exists ( ) && file . isDirectory ( ) ) { throw new Exception ( "<STR_LIT>" ) ; } if ( destFile != null && filesets . size ( ) > <NUM_LIT:0> ) { if ( filesets . size ( ) > <NUM_LIT:1> ) { throw new Exception ( "<STR_LIT>" ) ; } else { FileSet fs = filesets . elementAt ( <NUM_LIT:0> ) ; DirectoryScanner ds = fs . getDirectoryScanner ( ) ; String [ ] srcFiles = ds . getIncludedFiles ( ) ; if ( srcFiles . length == <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } else if ( srcFiles . length == <NUM_LIT:1> ) { if ( file == null ) { file = new File ( ds . getBasedir ( ) , srcFiles [ <NUM_LIT:0> ] ) ; filesets . removeElementAt ( <NUM_LIT:0> ) ; } else { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } } else { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } } } if ( destFile != null ) { destDir = fileUtils . getParentFile ( destFile ) ; } } protected void scan ( File fromDir , File toDir , String [ ] files , String [ ] dirs ) throws Exception { FileNameMapper mapper = null ; if ( mapperElement != null ) { mapper = mapperElement . getImplementation ( ) ; } else if ( flatten ) { mapper = new FlatFileNameMapper ( ) ; } else { mapper = new IdentityMapper ( ) ; } buildMap ( fromDir , toDir , files , mapper , fileCopyMap ) ; if ( includeEmpty ) { buildMap ( fromDir , toDir , dirs , mapper , dirCopyMap ) ; } } protected void buildMap ( File fromDir , File toDir , String [ ] names , FileNameMapper mapper , Hashtable < String , String [ ] > map ) throws Exception { String [ ] toCopy = null ; if ( forceOverwrite ) { Vector < String > v = new Vector < String > ( ) ; for ( String name : names ) { if ( mapper . mapFileName ( name ) != null ) { v . addElement ( name ) ; } } toCopy = new String [ v . size ( ) ] ; v . copyInto ( toCopy ) ; } else { SourceFileScanner ds = new SourceFileScanner ( ) ; toCopy = ds . restrict ( names , fromDir , toDir , mapper , granularity ) ; } for ( String elementToCopy : toCopy ) { File src = new File ( fromDir , elementToCopy ) ; String [ ] mappedFiles = mapper . mapFileName ( elementToCopy ) ; if ( ! enableMultipleMappings ) { map . put ( src . getAbsolutePath ( ) , new String [ ] { new File ( toDir , mappedFiles [ <NUM_LIT:0> ] ) . getAbsolutePath ( ) } ) ; } else { for ( int k = <NUM_LIT:0> ; k < mappedFiles . length ; k ++ ) { mappedFiles [ k ] = new File ( toDir , mappedFiles [ k ] ) . getAbsolutePath ( ) ; } map . put ( src . getAbsolutePath ( ) , mappedFiles ) ; } } } protected void doFileOperations ( ) throws Exception { if ( fileCopyMap . size ( ) > <NUM_LIT:0> ) { logger . fine ( "<STR_LIT>" + fileCopyMap . size ( ) + "<STR_LIT>" + ( fileCopyMap . size ( ) == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT:s>" ) + "<STR_LIT:U+0020toU+0020>" + destDir . getAbsolutePath ( ) ) ; Enumeration < String > e = fileCopyMap . keys ( ) ; while ( e . hasMoreElements ( ) ) { String fromFile = e . nextElement ( ) ; String [ ] toFiles = fileCopyMap . get ( fromFile ) ; for ( String toFile : toFiles ) { if ( fromFile . equals ( toFile ) ) { logger . warning ( "<STR_LIT>" + fromFile ) ; continue ; } try { logger . fine ( "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile ) ; fileUtils . copyFile ( fromFile , toFile , forceOverwrite , preserveLastModified ) ; } catch ( IOException ioe ) { String msg = "<STR_LIT>" + fromFile + "<STR_LIT:U+0020toU+0020>" + toFile + "<STR_LIT>" + ioe . getMessage ( ) ; File targetFile = new File ( toFile ) ; if ( targetFile . exists ( ) && ! targetFile . delete ( ) ) { msg += "<STR_LIT>" + toFile ; } throw new Exception ( msg , ioe ) ; } } } } if ( includeEmpty ) { Enumeration < String [ ] > e = dirCopyMap . elements ( ) ; int createCount = <NUM_LIT:0> ; while ( e . hasMoreElements ( ) ) { String [ ] dirs = e . nextElement ( ) ; for ( String dir : dirs ) { File d = new File ( dir ) ; if ( ! d . exists ( ) ) { if ( ! d . mkdirs ( ) ) { System . err . println ( "<STR_LIT>" + d . getAbsolutePath ( ) ) ; } else { createCount ++ ; } } } } if ( createCount > <NUM_LIT:0> ) { logger . fine ( "<STR_LIT>" + dirCopyMap . size ( ) + "<STR_LIT>" + ( dirCopyMap . size ( ) == <NUM_LIT:1> ? "<STR_LIT:y>" : "<STR_LIT>" ) + "<STR_LIT:U+0020toU+0020>" + createCount + "<STR_LIT>" + ( createCount == <NUM_LIT:1> ? "<STR_LIT:y>" : "<STR_LIT>" ) + "<STR_LIT>" + destDir . getAbsolutePath ( ) ) ; } } } } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; import java . util . Vector ; import java . util . logging . Logger ; import com . izforge . izpack . util . file . types . Resource ; import com . izforge . izpack . util . file . types . ResourceFactory ; import com . izforge . izpack . util . file . types . selectors . SelectorUtils ; public class ResourceUtils { private static final Logger logger = Logger . getLogger ( ResourceUtils . class . getName ( ) ) ; public static Resource [ ] selectOutOfDateSources ( Resource [ ] source , FileNameMapper mapper , ResourceFactory targets ) throws Exception { return selectOutOfDateSources ( source , mapper , targets , FileUtils . getFileUtils ( ) . getFileTimestampGranularity ( ) ) ; } public static Resource [ ] selectOutOfDateSources ( Resource [ ] resources , FileNameMapper mapper , ResourceFactory targets , long granularity ) throws Exception { long now = ( new java . util . Date ( ) ) . getTime ( ) + granularity ; Vector < Resource > vresult = new Vector < Resource > ( ) ; for ( Resource resource : resources ) { if ( resource . getLastModified ( ) > now ) { logger . warning ( resource . getName ( ) + "<STR_LIT>" ) ; } String [ ] targetnames = mapper . mapFileName ( resource . getName ( ) . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ) ; if ( targetnames != null ) { boolean added = false ; StringBuffer targetList = new StringBuffer ( ) ; for ( int ctarget = <NUM_LIT:0> ; ! added && ctarget < targetnames . length ; ctarget ++ ) { Resource atarget = targets . getResource ( targetnames [ ctarget ] . replace ( File . separatorChar , '<CHAR_LIT:/>' ) ) ; if ( ! atarget . isExists ( ) ) { logger . warning ( resource . getName ( ) + "<STR_LIT>" + atarget . getName ( ) + "<STR_LIT>" ) ; vresult . addElement ( resource ) ; added = true ; } else if ( ! atarget . isDirectory ( ) && SelectorUtils . isOutOfDate ( resource , atarget , ( int ) granularity ) ) { logger . warning ( resource . getName ( ) + "<STR_LIT>" + atarget . getName ( ) + "<STR_LIT>" ) ; vresult . addElement ( resource ) ; added = true ; } else { if ( targetList . length ( ) > <NUM_LIT:0> ) { targetList . append ( "<STR_LIT:U+002CU+0020>" ) ; } targetList . append ( atarget . getName ( ) ) ; } } if ( ! added ) { logger . fine ( resource . getName ( ) + "<STR_LIT>" + targetList . toString ( ) + ( targetnames . length == <NUM_LIT:1> ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" ) ; } } else { logger . warning ( resource . getName ( ) + "<STR_LIT>" ) ; } } Resource [ ] result = new Resource [ vresult . size ( ) ] ; vresult . copyInto ( result ) ; return result ; } } </s>
<s> package com . izforge . izpack . util . file . types ; import java . io . File ; import java . util . Vector ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . file . PathTokenizer ; public class Path extends DataType implements Cloneable { private static final Logger logger = Logger . getLogger ( Path . class . getName ( ) ) ; private static FileUtils fileUtils = FileUtils . getFileUtils ( ) ; private Vector < Object > elements ; public class PathElement { private String [ ] parts ; public void setLocation ( File loc ) { parts = new String [ ] { translateFile ( loc . getAbsolutePath ( ) ) } ; } public void setPath ( InstallData idata , String path ) { parts = Path . translatePath ( idata , path ) ; } public String [ ] getParts ( ) { return parts ; } } public Path ( InstallData idata , String path ) throws Exception { createPathElement ( ) . setPath ( idata , path ) ; } public Path ( ) { elements = new Vector < Object > ( ) ; } public void setLocation ( File location ) throws Exception { createPathElement ( ) . setLocation ( location ) ; } public void setPath ( InstallData idata , String path ) throws Exception { createPathElement ( ) . setPath ( idata , path ) ; } public PathElement createPathElement ( ) throws Exception { PathElement pe = new PathElement ( ) ; elements . addElement ( pe ) ; return pe ; } public void addFileset ( FileSet fs ) throws Exception { elements . addElement ( fs ) ; setChecked ( false ) ; } public void addFilelist ( FileList fl ) throws Exception { elements . addElement ( fl ) ; setChecked ( false ) ; } public void addDirset ( DirSet dset ) throws Exception { elements . addElement ( dset ) ; setChecked ( false ) ; } public void add ( Path path ) throws Exception { elements . addElement ( path ) ; setChecked ( false ) ; } public Path createPath ( ) throws Exception { Path p = new Path ( ) ; elements . addElement ( p ) ; setChecked ( false ) ; return p ; } public void append ( Path other ) throws Exception { if ( other == null ) { return ; } String [ ] pathElements = other . list ( ) ; for ( String pathElement : pathElements ) { if ( elements . indexOf ( pathElement ) == - <NUM_LIT:1> ) { elements . addElement ( pathElement ) ; } } } public void addExisting ( Path source ) throws Exception { addExisting ( source , false ) ; } public void addExisting ( Path source , boolean tryUserDir ) throws Exception { String [ ] pathElements = source . list ( ) ; File userDir = ( tryUserDir ) ? new File ( System . getProperty ( "<STR_LIT>" ) ) : null ; for ( String pathElement : pathElements ) { File f = null ; f = new File ( pathElement ) ; if ( tryUserDir && ! f . exists ( ) ) { f = new File ( userDir , pathElement ) ; } if ( f . exists ( ) ) { setLocation ( f ) ; } else { logger . warning ( "<STR_LIT>" + f + "<STR_LIT>" ) ; } } } public String [ ] list ( ) throws Exception { Vector < String > result = new Vector < String > ( <NUM_LIT:2> * elements . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < elements . size ( ) ; i ++ ) { Object o = elements . elementAt ( i ) ; if ( o instanceof String ) { addUnlessPresent ( result , ( String ) o ) ; } else if ( o instanceof PathElement ) { String [ ] parts = ( ( PathElement ) o ) . getParts ( ) ; if ( parts == null ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } for ( String part : parts ) { addUnlessPresent ( result , part ) ; } } else if ( o instanceof Path ) { Path p = ( Path ) o ; String [ ] parts = p . list ( ) ; for ( String part : parts ) { addUnlessPresent ( result , part ) ; } } else if ( o instanceof DirSet ) { DirSet dset = ( DirSet ) o ; addUnlessPresent ( result , dset . getDir ( ) , dset . getDirectoryScanner ( ) . getIncludedDirectories ( ) ) ; } else if ( o instanceof FileSet ) { FileSet fs = ( FileSet ) o ; addUnlessPresent ( result , fs . getDir ( ) , fs . getDirectoryScanner ( ) . getIncludedFiles ( ) ) ; } else if ( o instanceof FileList ) { FileList fl = ( FileList ) o ; addUnlessPresent ( result , fl . getDir ( ) , fl . getFiles ( ) ) ; } } String [ ] res = new String [ result . size ( ) ] ; result . copyInto ( res ) ; return res ; } @ Override public String toString ( ) { try { final String [ ] list = list ( ) ; if ( list . length == <NUM_LIT:0> ) { return "<STR_LIT>" ; } final StringBuffer result = new StringBuffer ( list [ <NUM_LIT:0> ] . toString ( ) ) ; for ( int i = <NUM_LIT:1> ; i < list . length ; i ++ ) { result . append ( File . pathSeparatorChar ) ; result . append ( list [ i ] ) ; } return result . toString ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public static String [ ] translatePath ( InstallData idata , String source ) { final Vector < String > result = new Vector < String > ( ) ; if ( source == null ) { return new String [ <NUM_LIT:0> ] ; } PathTokenizer tok = new PathTokenizer ( source ) ; StringBuffer element = new StringBuffer ( ) ; while ( tok . hasMoreTokens ( ) ) { String pathElement = tok . nextToken ( ) ; try { element . append ( resolveFile ( idata , pathElement ) ) ; } catch ( Exception e ) { logger . warning ( "<STR_LIT>" + pathElement + "<STR_LIT>" ) ; } for ( int i = <NUM_LIT:0> ; i < element . length ( ) ; i ++ ) { translateFileSep ( element , i ) ; } result . addElement ( element . toString ( ) ) ; element = new StringBuffer ( ) ; } String [ ] res = new String [ result . size ( ) ] ; result . copyInto ( res ) ; return res ; } public static String translateFile ( String source ) { if ( source == null ) { return "<STR_LIT>" ; } final StringBuffer result = new StringBuffer ( source ) ; for ( int i = <NUM_LIT:0> ; i < result . length ( ) ; i ++ ) { translateFileSep ( result , i ) ; } return result . toString ( ) ; } protected static boolean translateFileSep ( StringBuffer buffer , int pos ) { if ( buffer . charAt ( pos ) == '<CHAR_LIT:/>' || buffer . charAt ( pos ) == '<STR_LIT:\\>' ) { buffer . setCharAt ( pos , File . separatorChar ) ; return true ; } return false ; } public int size ( ) throws Exception { return list ( ) . length ; } @ Override public Object clone ( ) { try { Path p = ( Path ) super . clone ( ) ; p . elements = ( Vector < Object > ) elements . clone ( ) ; return p ; } catch ( CloneNotSupportedException e ) { throw new RuntimeException ( e ) ; } } private static String resolveFile ( InstallData idata , String relativeName ) throws Exception { File f = fileUtils . resolveFile ( new File ( idata . getInstallPath ( ) ) , relativeName ) ; return f . getAbsolutePath ( ) ; } private static void addUnlessPresent ( Vector < String > v , String s ) { if ( v . indexOf ( s ) == - <NUM_LIT:1> ) { v . addElement ( s ) ; } } private static void addUnlessPresent ( Vector < String > v , File dir , String [ ] s ) { for ( String value : s ) { File d = new File ( dir , value ) ; String absolutePath = d . getAbsolutePath ( ) ; addUnlessPresent ( v , translateFile ( absolutePath ) ) ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import com . izforge . izpack . api . data . InstallData ; public class AndSelector extends BaseSelectorContainer { public AndSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; Enumeration < FileSelector > e = selectorElements ( ) ; boolean result ; while ( e . hasMoreElements ( ) ) { result = e . nextElement ( ) . isSelected ( idata , basedir , filename , file ) ; if ( ! result ) { return false ; } } return true ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . StringTokenizer ; import java . util . Vector ; import com . izforge . izpack . util . file . types . Resource ; public final class SelectorUtils { private static SelectorUtils instance = new SelectorUtils ( ) ; private SelectorUtils ( ) { } public static SelectorUtils getInstance ( ) { return instance ; } public static boolean matchPatternStart ( String pattern , String str ) { return matchPatternStart ( pattern , str , true ) ; } public static boolean matchPatternStart ( String pattern , String str , boolean isCaseSensitive ) { if ( str . startsWith ( File . separator ) != pattern . startsWith ( File . separator ) ) { return false ; } String [ ] patDirs = tokenizePathAsArray ( pattern ) ; String [ ] strDirs = tokenizePathAsArray ( str ) ; int patIdxStart = <NUM_LIT:0> ; int patIdxEnd = patDirs . length - <NUM_LIT:1> ; int strIdxStart = <NUM_LIT:0> ; int strIdxEnd = strDirs . length - <NUM_LIT:1> ; while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd ) { String patDir = patDirs [ patIdxStart ] ; if ( patDir . equals ( "<STR_LIT>" ) ) { break ; } if ( ! match ( patDir , strDirs [ strIdxStart ] , isCaseSensitive ) ) { return false ; } patIdxStart ++ ; strIdxStart ++ ; } if ( strIdxStart > strIdxEnd ) { return true ; } else if ( patIdxStart > patIdxEnd ) { return false ; } else { return true ; } } public static boolean matchPath ( String pattern , String str ) { return matchPath ( pattern , str , true ) ; } public static boolean matchPath ( String pattern , String str , boolean isCaseSensitive ) { if ( str . startsWith ( File . separator ) != pattern . startsWith ( File . separator ) ) { return false ; } String [ ] patDirs = tokenizePathAsArray ( pattern ) ; String [ ] strDirs = tokenizePathAsArray ( str ) ; int patIdxStart = <NUM_LIT:0> ; int patIdxEnd = patDirs . length - <NUM_LIT:1> ; int strIdxStart = <NUM_LIT:0> ; int strIdxEnd = strDirs . length - <NUM_LIT:1> ; while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd ) { String patDir = patDirs [ patIdxStart ] ; if ( patDir . equals ( "<STR_LIT>" ) ) { break ; } if ( ! match ( patDir , strDirs [ strIdxStart ] , isCaseSensitive ) ) { patDirs = null ; strDirs = null ; return false ; } patIdxStart ++ ; strIdxStart ++ ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! patDirs [ i ] . equals ( "<STR_LIT>" ) ) { patDirs = null ; strDirs = null ; return false ; } } return true ; } else { if ( patIdxStart > patIdxEnd ) { patDirs = null ; strDirs = null ; return false ; } } while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd ) { String patDir = patDirs [ patIdxEnd ] ; if ( patDir . equals ( "<STR_LIT>" ) ) { break ; } if ( ! match ( patDir , strDirs [ strIdxEnd ] , isCaseSensitive ) ) { patDirs = null ; strDirs = null ; return false ; } patIdxEnd -- ; strIdxEnd -- ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! patDirs [ i ] . equals ( "<STR_LIT>" ) ) { patDirs = null ; strDirs = null ; return false ; } } return true ; } while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd ) { int patIdxTmp = - <NUM_LIT:1> ; for ( int i = patIdxStart + <NUM_LIT:1> ; i <= patIdxEnd ; i ++ ) { if ( patDirs [ i ] . equals ( "<STR_LIT>" ) ) { patIdxTmp = i ; break ; } } if ( patIdxTmp == patIdxStart + <NUM_LIT:1> ) { patIdxStart ++ ; continue ; } int patLength = ( patIdxTmp - patIdxStart - <NUM_LIT:1> ) ; int strLength = ( strIdxEnd - strIdxStart + <NUM_LIT:1> ) ; int foundIdx = - <NUM_LIT:1> ; strLoop : for ( int i = <NUM_LIT:0> ; i <= strLength - patLength ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < patLength ; j ++ ) { String subPat = patDirs [ patIdxStart + j + <NUM_LIT:1> ] ; String subStr = strDirs [ strIdxStart + i + j ] ; if ( ! match ( subPat , subStr , isCaseSensitive ) ) { continue strLoop ; } } foundIdx = strIdxStart + i ; break ; } if ( foundIdx == - <NUM_LIT:1> ) { patDirs = null ; strDirs = null ; return false ; } patIdxStart = patIdxTmp ; strIdxStart = foundIdx + patLength ; } for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( ! patDirs [ i ] . equals ( "<STR_LIT>" ) ) { patDirs = null ; strDirs = null ; return false ; } } return true ; } public static boolean match ( String pattern , String str ) { return match ( pattern , str , true ) ; } public static boolean match ( String pattern , String str , boolean isCaseSensitive ) { char [ ] patArr = pattern . toCharArray ( ) ; char [ ] strArr = str . toCharArray ( ) ; int patIdxStart = <NUM_LIT:0> ; int patIdxEnd = patArr . length - <NUM_LIT:1> ; int strIdxStart = <NUM_LIT:0> ; int strIdxEnd = strArr . length - <NUM_LIT:1> ; char ch ; boolean containsStar = false ; for ( int i = <NUM_LIT:0> ; i < patArr . length ; i ++ ) { if ( patArr [ i ] == '<CHAR_LIT>' ) { containsStar = true ; break ; } } if ( ! containsStar ) { if ( patIdxEnd != strIdxEnd ) { return false ; } for ( int i = <NUM_LIT:0> ; i <= patIdxEnd ; i ++ ) { ch = patArr [ i ] ; if ( ch != '<CHAR_LIT>' ) { if ( isCaseSensitive && ch != strArr [ i ] ) { return false ; } if ( ! isCaseSensitive && Character . toUpperCase ( ch ) != Character . toUpperCase ( strArr [ i ] ) ) { return false ; } } } return true ; } if ( patIdxEnd == <NUM_LIT:0> ) { return true ; } while ( ( ch = patArr [ patIdxStart ] ) != '<CHAR_LIT>' && strIdxStart <= strIdxEnd ) { if ( ch != '<CHAR_LIT>' ) { if ( isCaseSensitive && ch != strArr [ strIdxStart ] ) { return false ; } if ( ! isCaseSensitive && Character . toUpperCase ( ch ) != Character . toUpperCase ( strArr [ strIdxStart ] ) ) { return false ; } } patIdxStart ++ ; strIdxStart ++ ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( patArr [ i ] != '<CHAR_LIT>' ) { return false ; } } return true ; } while ( ( ch = patArr [ patIdxEnd ] ) != '<CHAR_LIT>' && strIdxStart <= strIdxEnd ) { if ( ch != '<CHAR_LIT>' ) { if ( isCaseSensitive && ch != strArr [ strIdxEnd ] ) { return false ; } if ( ! isCaseSensitive && Character . toUpperCase ( ch ) != Character . toUpperCase ( strArr [ strIdxEnd ] ) ) { return false ; } } patIdxEnd -- ; strIdxEnd -- ; } if ( strIdxStart > strIdxEnd ) { for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( patArr [ i ] != '<CHAR_LIT>' ) { return false ; } } return true ; } while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd ) { int patIdxTmp = - <NUM_LIT:1> ; for ( int i = patIdxStart + <NUM_LIT:1> ; i <= patIdxEnd ; i ++ ) { if ( patArr [ i ] == '<CHAR_LIT>' ) { patIdxTmp = i ; break ; } } if ( patIdxTmp == patIdxStart + <NUM_LIT:1> ) { patIdxStart ++ ; continue ; } int patLength = ( patIdxTmp - patIdxStart - <NUM_LIT:1> ) ; int strLength = ( strIdxEnd - strIdxStart + <NUM_LIT:1> ) ; int foundIdx = - <NUM_LIT:1> ; strLoop : for ( int i = <NUM_LIT:0> ; i <= strLength - patLength ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < patLength ; j ++ ) { ch = patArr [ patIdxStart + j + <NUM_LIT:1> ] ; if ( ch != '<CHAR_LIT>' ) { if ( isCaseSensitive && ch != strArr [ strIdxStart + i + j ] ) { continue strLoop ; } if ( ! isCaseSensitive && Character . toUpperCase ( ch ) != Character . toUpperCase ( strArr [ strIdxStart + i + j ] ) ) { continue strLoop ; } } } foundIdx = strIdxStart + i ; break ; } if ( foundIdx == - <NUM_LIT:1> ) { return false ; } patIdxStart = patIdxTmp ; strIdxStart = foundIdx + patLength ; } for ( int i = patIdxStart ; i <= patIdxEnd ; i ++ ) { if ( patArr [ i ] != '<CHAR_LIT>' ) { return false ; } } return true ; } public static Vector < String > tokenizePath ( String path ) { return tokenizePath ( path , File . separator ) ; } public static Vector < String > tokenizePath ( String path , String separator ) { Vector < String > ret = new Vector < String > ( ) ; StringTokenizer st = new StringTokenizer ( path , separator ) ; while ( st . hasMoreTokens ( ) ) { ret . addElement ( st . nextToken ( ) ) ; } return ret ; } private static String [ ] tokenizePathAsArray ( String path ) { char sep = File . separatorChar ; int start = <NUM_LIT:0> ; int len = path . length ( ) ; int count = <NUM_LIT:0> ; for ( int pos = <NUM_LIT:0> ; pos < len ; pos ++ ) { if ( path . charAt ( pos ) == sep ) { if ( pos != start ) { count ++ ; } start = pos + <NUM_LIT:1> ; } } if ( len != start ) { count ++ ; } String [ ] l = new String [ count ] ; count = <NUM_LIT:0> ; start = <NUM_LIT:0> ; for ( int pos = <NUM_LIT:0> ; pos < len ; pos ++ ) { if ( path . charAt ( pos ) == sep ) { if ( pos != start ) { String tok = path . substring ( start , pos ) ; l [ count ++ ] = tok ; } start = pos + <NUM_LIT:1> ; } } if ( len != start ) { String tok = path . substring ( start ) ; l [ count ] = tok ; } return l ; } public static boolean isOutOfDate ( File src , File target , int granularity ) { if ( ! src . exists ( ) ) { return false ; } if ( ! target . exists ( ) ) { return true ; } if ( ( src . lastModified ( ) - granularity ) > target . lastModified ( ) ) { return true ; } return false ; } public static boolean isOutOfDate ( Resource src , Resource target , int granularity ) { if ( ! src . isExists ( ) ) { return false ; } if ( ! target . isExists ( ) ) { return true ; } if ( ( src . getLastModified ( ) - granularity ) > target . getLastModified ( ) ) { return true ; } return false ; } public static String removeWhitespace ( String input ) { StringBuffer result = new StringBuffer ( ) ; if ( input != null ) { StringTokenizer st = new StringTokenizer ( input ) ; while ( st . hasMoreTokens ( ) ) { result . append ( st . nextToken ( ) ) ; } } return result . toString ( ) ; } public static boolean hasWildcards ( String input ) { return ( input . indexOf ( '<CHAR_LIT>' ) != - <NUM_LIT:1> || input . indexOf ( '<CHAR_LIT>' ) != - <NUM_LIT:1> ) ; } public static String rtrimWildcardTokens ( String input ) { Vector < String > v = tokenizePath ( input , File . separator ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int counter = <NUM_LIT:0> ; counter < v . size ( ) ; counter ++ ) { if ( hasWildcards ( v . elementAt ( counter ) ) ) { break ; } if ( counter > <NUM_LIT:0> ) { sb . append ( File . separator ) ; } sb . append ( v . elementAt ( counter ) ) ; } return sb . toString ( ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public class ContainsSelector extends BaseExtendSelector { private String contains = null ; private boolean casesensitive = true ; private boolean ignorewhitespace = false ; public static final String EXPRESSION_KEY = "<STR_LIT>" ; public static final String CONTAINS_KEY = "<STR_LIT:text>" ; public static final String CASE_KEY = "<STR_LIT>" ; public static final String WHITESPACE_KEY = "<STR_LIT>" ; public ContainsSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( contains ) ; buf . append ( "<STR_LIT>" ) ; if ( casesensitive ) { buf . append ( "<STR_LIT:true>" ) ; } else { buf . append ( "<STR_LIT:false>" ) ; } buf . append ( "<STR_LIT>" ) ; if ( ignorewhitespace ) { buf . append ( "<STR_LIT:true>" ) ; } else { buf . append ( "<STR_LIT:false>" ) ; } buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setText ( String contains ) { this . contains = contains ; } public void setCasesensitive ( boolean casesensitive ) { this . casesensitive = casesensitive ; } public void setIgnorewhitespace ( boolean ignorewhitespace ) { this . ignorewhitespace = ignorewhitespace ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( CONTAINS_KEY . equalsIgnoreCase ( paramname ) ) { setText ( parameter . getValue ( ) ) ; } else if ( CASE_KEY . equalsIgnoreCase ( paramname ) ) { setCasesensitive ( Boolean . parseBoolean ( parameter . getValue ( ) ) ) ; } else if ( WHITESPACE_KEY . equalsIgnoreCase ( paramname ) ) { setIgnorewhitespace ( Boolean . parseBoolean ( parameter . getValue ( ) ) ) ; } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( contains == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( file . isDirectory ( ) ) { return true ; } String userstr = contains ; if ( ! casesensitive ) { userstr = contains . toLowerCase ( ) ; } if ( ignorewhitespace ) { userstr = SelectorUtils . removeWhitespace ( userstr ) ; } BufferedReader in = null ; try { in = new BufferedReader ( new InputStreamReader ( new FileInputStream ( file ) ) ) ; String teststr = in . readLine ( ) ; while ( teststr != null ) { if ( ! casesensitive ) { teststr = teststr . toLowerCase ( ) ; } if ( ignorewhitespace ) { teststr = SelectorUtils . removeWhitespace ( teststr ) ; } if ( teststr . indexOf ( userstr ) > - <NUM_LIT:1> ) { return true ; } teststr = in . readLine ( ) ; } return false ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + filename ) ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( Exception e ) { throw new Exception ( "<STR_LIT>" + filename ) ; } } } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . DataType ; public abstract class BaseSelector extends DataType implements FileSelector { private String errmsg = null ; public BaseSelector ( ) { } public void setError ( String msg ) { if ( errmsg == null ) { errmsg = msg ; } } public String getError ( ) { return errmsg ; } public void verifySettings ( ) throws Exception { } public void validate ( ) throws Exception { if ( getError ( ) == null ) { verifySettings ( ) ; } if ( getError ( ) != null ) { throw new Exception ( errmsg ) ; } } public abstract boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception ; } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import com . izforge . izpack . util . file . types . DataType ; import java . util . Enumeration ; import java . util . Vector ; public abstract class AbstractSelectorContainer extends DataType implements SelectorContainer { private Vector < FileSelector > selectorsList = new Vector < FileSelector > ( ) ; public boolean hasSelectors ( ) { return ! ( selectorsList . isEmpty ( ) ) ; } public int selectorCount ( ) { return selectorsList . size ( ) ; } public FileSelector [ ] getSelectors ( ) { FileSelector [ ] result = new FileSelector [ selectorsList . size ( ) ] ; selectorsList . copyInto ( result ) ; return result ; } public Enumeration < FileSelector > selectorElements ( ) { return selectorsList . elements ( ) ; } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; Enumeration < FileSelector > e = selectorElements ( ) ; if ( e . hasMoreElements ( ) ) { while ( e . hasMoreElements ( ) ) { buf . append ( e . nextElement ( ) . toString ( ) ) ; if ( e . hasMoreElements ( ) ) { buf . append ( "<STR_LIT:U+002CU+0020>" ) ; } } } return buf . toString ( ) ; } public void appendSelector ( FileSelector selector ) { selectorsList . addElement ( selector ) ; } public void validate ( ) throws Exception { Enumeration < FileSelector > e = selectorElements ( ) ; while ( e . hasMoreElements ( ) ) { Object o = e . nextElement ( ) ; if ( o instanceof BaseSelector ) { ( ( BaseSelector ) o ) . validate ( ) ; } } } public void addSelector ( SelectSelector selector ) { appendSelector ( selector ) ; } public void addAnd ( AndSelector selector ) { appendSelector ( selector ) ; } public void addOr ( OrSelector selector ) { appendSelector ( selector ) ; } public void addNot ( NotSelector selector ) { appendSelector ( selector ) ; } public void addNone ( NoneSelector selector ) { appendSelector ( selector ) ; } public void addMajority ( MajoritySelector selector ) { appendSelector ( selector ) ; } public void addDate ( DateSelector selector ) { appendSelector ( selector ) ; } public void addSize ( SizeSelector selector ) { appendSelector ( selector ) ; } public void addFilename ( FilenameSelector selector ) { appendSelector ( selector ) ; } public void addCustom ( ExtendSelector selector ) { appendSelector ( selector ) ; } public void addContains ( ContainsSelector selector ) { appendSelector ( selector ) ; } public void addPresent ( PresentSelector selector ) { appendSelector ( selector ) ; } public void addDepth ( DepthSelector selector ) { appendSelector ( selector ) ; } public void addDepend ( DependSelector selector ) { appendSelector ( selector ) ; } public void addDifferent ( DifferentSelector selector ) { appendSelector ( selector ) ; } public void addType ( TypeSelector selector ) { appendSelector ( selector ) ; } public void addContainsRegexp ( ContainsRegexpSelector selector ) { appendSelector ( selector ) ; } public void add ( FileSelector selector ) { appendSelector ( selector ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import com . izforge . izpack . api . data . InstallData ; public class MajoritySelector extends BaseSelectorContainer { private boolean allowtie = true ; public MajoritySelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public void setAllowtie ( boolean tiebreaker ) { allowtie = tiebreaker ; } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; int yesvotes = <NUM_LIT:0> ; int novotes = <NUM_LIT:0> ; Enumeration < FileSelector > e = selectorElements ( ) ; boolean result ; while ( e . hasMoreElements ( ) ) { result = e . nextElement ( ) . isSelected ( idata , basedir , filename , file ) ; if ( result ) { yesvotes = yesvotes + <NUM_LIT:1> ; } else { novotes = novotes + <NUM_LIT:1> ; } } if ( yesvotes > novotes ) { return true ; } else if ( novotes > yesvotes ) { return false ; } return allowtie ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . util . Enumeration ; public interface SelectorContainer { boolean hasSelectors ( ) ; int selectorCount ( ) ; FileSelector [ ] getSelectors ( ) ; Enumeration < FileSelector > selectorElements ( ) ; void appendSelector ( FileSelector selector ) ; void addSelector ( SelectSelector selector ) ; void addAnd ( AndSelector selector ) ; void addOr ( OrSelector selector ) ; void addNot ( NotSelector selector ) ; void addNone ( NoneSelector selector ) ; void addMajority ( MajoritySelector selector ) ; void addDate ( DateSelector selector ) ; void addSize ( SizeSelector selector ) ; void addFilename ( FilenameSelector selector ) ; void addCustom ( ExtendSelector selector ) ; void addContains ( ContainsSelector selector ) ; void addPresent ( PresentSelector selector ) ; void addDepth ( DepthSelector selector ) ; void addDepend ( DependSelector selector ) ; void addContainsRegexp ( ContainsRegexpSelector selector ) ; void addType ( TypeSelector selector ) ; void addDifferent ( DifferentSelector selector ) ; void add ( FileSelector selector ) ; } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; public class DependSelector extends MappingSelector { public DependSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; if ( targetdir == null ) { buf . append ( "<STR_LIT>" ) ; } else { buf . append ( targetdir . getName ( ) ) ; } buf . append ( "<STR_LIT>" ) ; buf . append ( granularity ) ; if ( map != null ) { buf . append ( "<STR_LIT>" ) ; buf . append ( map . toString ( ) ) ; } else if ( mapperElement != null ) { buf . append ( "<STR_LIT>" ) ; buf . append ( mapperElement . toString ( ) ) ; } buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public boolean selectionTest ( File srcfile , File destfile ) { boolean selected = SelectorUtils . isOutOfDate ( srcfile , destfile , granularity ) ; return selected ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . StringTokenizer ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public class DepthSelector extends BaseExtendSelector { public int min = - <NUM_LIT:1> ; public int max = - <NUM_LIT:1> ; public static final String MIN_KEY = "<STR_LIT>" ; public static final String MAX_KEY = "<STR_LIT>" ; public DepthSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( min ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( max ) ; buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setMin ( int min ) { this . min = min ; } public void setMax ( int max ) { this . max = max ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( MIN_KEY . equalsIgnoreCase ( paramname ) ) { try { setMin ( Integer . parseInt ( parameter . getValue ( ) ) ) ; } catch ( NumberFormatException nfe1 ) { setError ( "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( MAX_KEY . equalsIgnoreCase ( paramname ) ) { try { setMax ( Integer . parseInt ( parameter . getValue ( ) ) ) ; } catch ( NumberFormatException nfe1 ) { setError ( "<STR_LIT>" + parameter . getValue ( ) ) ; } } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( min < <NUM_LIT:0> && max < <NUM_LIT:0> ) { setError ( "<STR_LIT>" + "<STR_LIT>" ) ; } if ( max < min && max > - <NUM_LIT:1> ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; int depth = - <NUM_LIT:1> ; String absBase = basedir . getAbsolutePath ( ) ; String absFile = file . getAbsolutePath ( ) ; StringTokenizer tokBase = new StringTokenizer ( absBase , File . separator ) ; StringTokenizer tokFile = new StringTokenizer ( absFile , File . separator ) ; while ( tokFile . hasMoreTokens ( ) ) { String filetoken = tokFile . nextToken ( ) ; if ( tokBase . hasMoreTokens ( ) ) { String basetoken = tokBase . nextToken ( ) ; if ( ! basetoken . equals ( filetoken ) ) { throw new Exception ( "<STR_LIT>" + filename + "<STR_LIT>" + absBase + "<STR_LIT>" ) ; } } else { depth += <NUM_LIT:1> ; if ( max > - <NUM_LIT:1> && depth > max ) { return false ; } } } if ( tokBase . hasMoreTokens ( ) ) { throw new Exception ( "<STR_LIT>" + filename + "<STR_LIT>" + absBase + "<STR_LIT>" ) ; } if ( min > - <NUM_LIT:1> && depth < min ) { return false ; } return true ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import com . izforge . izpack . api . data . InstallData ; public class NoneSelector extends BaseSelectorContainer { public NoneSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; Enumeration < FileSelector > e = selectorElements ( ) ; boolean result ; while ( e . hasMoreElements ( ) ) { result = e . nextElement ( ) . isSelected ( idata , basedir , filename , file ) ; if ( result ) { return false ; } } return true ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; public class NotSelector extends NoneSelector { public NotSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public void verifySettings ( ) { if ( selectorCount ( ) != <NUM_LIT:1> ) { setError ( "<STR_LIT>" + "<STR_LIT>" ) ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Map ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public class SizeSelector extends BaseExtendSelector { private long size = - <NUM_LIT:1> ; private long multiplier = <NUM_LIT:1> ; private long sizelimit = - <NUM_LIT:1> ; private SizeComparisons cmp = SizeComparisons . EQUAL ; public static final String SIZE_KEY = "<STR_LIT:value>" ; public static final String UNITS_KEY = "<STR_LIT>" ; public static final String WHEN_KEY = "<STR_LIT>" ; public SizeSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( sizelimit ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( cmp . getAttribute ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setValue ( long size ) { this . size = size ; if ( ( multiplier != <NUM_LIT:0> ) && ( size > - <NUM_LIT:1> ) ) { sizelimit = size * multiplier ; } } public void setUnits ( ByteUnits units ) { multiplier = <NUM_LIT:0> ; switch ( units ) { case K : case k : case kilo : case KILO : multiplier = <NUM_LIT:1000> ; break ; case Ki : case KI : case ki : case kibi : case KIBI : multiplier = <NUM_LIT> ; break ; case M : case m : case mega : case MEGA : multiplier = <NUM_LIT> ; break ; case Mi : case MI : case mi : case mebi : case MEBI : multiplier = <NUM_LIT> ; break ; case G : case g : case giga : case GIGA : multiplier = <NUM_LIT> ; break ; case Gi : case GI : case gi : case gibi : case GIBI : multiplier = <NUM_LIT> ; break ; case T : case t : case tera : case TERA : multiplier = <NUM_LIT> ; break ; case Ti : case TI : case ti : case tebi : case TEBI : multiplier = <NUM_LIT> ; break ; default : break ; } if ( ( multiplier > <NUM_LIT:0> ) && ( size > - <NUM_LIT:1> ) ) { sizelimit = size * multiplier ; } } public void setWhen ( SizeComparisons scmp ) { this . cmp = scmp ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( SIZE_KEY . equalsIgnoreCase ( paramname ) ) { try { setValue ( new Long ( parameter . getValue ( ) ) . longValue ( ) ) ; } catch ( NumberFormatException nfe ) { setError ( "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( UNITS_KEY . equalsIgnoreCase ( paramname ) ) { ByteUnits units = ByteUnits . getFromAttribute ( parameter . getValue ( ) ) ; if ( units != null ) { setUnits ( units ) ; } else { setError ( "<STR_LIT>" + UNITS_KEY + "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( WHEN_KEY . equalsIgnoreCase ( paramname ) ) { SizeComparisons cmp = SizeComparisons . getFromAttribute ( parameter . getValue ( ) ) ; if ( cmp != null ) { setWhen ( cmp ) ; } else { setError ( "<STR_LIT>" + WHEN_KEY + "<STR_LIT>" + parameter . getValue ( ) ) ; } } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( size < <NUM_LIT:0> ) { setError ( "<STR_LIT>" ) ; } else if ( multiplier < <NUM_LIT:1> ) { setError ( "<STR_LIT>" ) ; } else if ( sizelimit < <NUM_LIT:0> ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( file . isDirectory ( ) ) { return true ; } switch ( cmp ) { case LESS : return ( file . length ( ) < sizelimit ) ; case MORE : return ( file . length ( ) > sizelimit ) ; default : return ( file . length ( ) == sizelimit ) ; } } public enum ByteUnits { K ( "<STR_LIT>" ) , k ( "<STR_LIT>" ) , kilo ( "<STR_LIT>" ) , KILO ( "<STR_LIT>" ) , Ki ( "<STR_LIT>" ) , KI ( "<STR_LIT>" ) , ki ( "<STR_LIT>" ) , kibi ( "<STR_LIT>" ) , KIBI ( "<STR_LIT>" ) , M ( "<STR_LIT:M>" ) , m ( "<STR_LIT:m>" ) , mega ( "<STR_LIT>" ) , MEGA ( "<STR_LIT>" ) , Mi ( "<STR_LIT>" ) , MI ( "<STR_LIT>" ) , mi ( "<STR_LIT>" ) , mebi ( "<STR_LIT>" ) , MEBI ( "<STR_LIT>" ) , G ( "<STR_LIT>" ) , g ( "<STR_LIT>" ) , giga ( "<STR_LIT>" ) , GIGA ( "<STR_LIT>" ) , Gi ( "<STR_LIT>" ) , GI ( "<STR_LIT>" ) , gi ( "<STR_LIT>" ) , gibi ( "<STR_LIT>" ) , GIBI ( "<STR_LIT>" ) , T ( "<STR_LIT:T>" ) , t ( "<STR_LIT:t>" ) , tera ( "<STR_LIT>" ) , TERA ( "<STR_LIT>" ) , Ti ( "<STR_LIT>" ) , TI ( "<STR_LIT>" ) , ti ( "<STR_LIT>" ) , tebi ( "<STR_LIT>" ) , TEBI ( "<STR_LIT>" ) ; private static Map < String , ByteUnits > lookup ; private String attribute ; ByteUnits ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , ByteUnits > ( ) ; for ( ByteUnits mapperType : EnumSet . allOf ( ByteUnits . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } } public String getAttribute ( ) { return attribute ; } public static ByteUnits getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } public enum SizeComparisons { LESS ( "<STR_LIT>" ) , MORE ( "<STR_LIT>" ) , EQUAL ( "<STR_LIT>" ) ; private static Map < String , SizeComparisons > lookup ; private String attribute ; SizeComparisons ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , SizeComparisons > ( ) ; for ( SizeComparisons mapperType : EnumSet . allOf ( SizeComparisons . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } } public String getAttribute ( ) { return attribute ; } public static SizeComparisons getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import com . izforge . izpack . util . file . types . Parameterizable ; public interface ExtendFileSelector extends FileSelector , Parameterizable { } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import com . izforge . izpack . api . data . InstallData ; public class OrSelector extends BaseSelectorContainer { public OrSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; Enumeration < FileSelector > e = selectorElements ( ) ; boolean result ; while ( e . hasMoreElements ( ) ) { result = e . nextElement ( ) . isSelected ( idata , basedir , filename , file ) ; if ( result ) { return true ; } } return false ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Vector ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; import com . izforge . izpack . util . file . types . Path ; public class ExtendSelector extends BaseSelector { private String classname = null ; private FileSelector dynselector = null ; private Vector < Parameter > paramVec = new Vector < Parameter > ( ) ; private Path classpath = null ; public ExtendSelector ( ) { } public void setClassname ( String classname ) { this . classname = classname ; } public void selectorCreate ( ) { if ( classname != null && classname . length ( ) > <NUM_LIT:0> ) { try { Class c = Class . forName ( classname ) ; dynselector = ( FileSelector ) c . newInstance ( ) ; } catch ( ClassNotFoundException cnfexcept ) { setError ( "<STR_LIT>" + classname + "<STR_LIT>" ) ; } catch ( InstantiationException iexcept ) { setError ( "<STR_LIT>" + classname + "<STR_LIT>" ) ; } catch ( IllegalAccessException iaexcept ) { setError ( "<STR_LIT>" + classname + "<STR_LIT>" ) ; } } else { setError ( "<STR_LIT>" ) ; } } public void addParam ( Parameter p ) { paramVec . addElement ( p ) ; } public final void setClasspath ( Path classpath ) throws Exception { if ( this . classpath == null ) { this . classpath = classpath ; } else { this . classpath . append ( classpath ) ; } } public final Path createClasspath ( ) throws Exception { if ( this . classpath == null ) { this . classpath = new Path ( ) ; } return this . classpath . createPath ( ) ; } public final Path getClasspath ( ) { return classpath ; } public void verifySettings ( ) { if ( dynselector == null ) { selectorCreate ( ) ; } if ( classname == null || classname . length ( ) < <NUM_LIT:1> ) { setError ( "<STR_LIT>" ) ; } else if ( dynselector == null ) { setError ( "<STR_LIT>" ) ; } else if ( ! ( dynselector instanceof ExtendFileSelector ) && ( paramVec . size ( ) > <NUM_LIT:0> ) ) { setError ( "<STR_LIT>" + "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( paramVec . size ( ) > <NUM_LIT:0> && dynselector instanceof ExtendFileSelector ) { Parameter [ ] paramArray = new Parameter [ paramVec . size ( ) ] ; paramVec . copyInto ( paramArray ) ; ( ( ExtendFileSelector ) dynselector ) . setParameters ( paramArray ) ; } return dynselector . isSelected ( idata , basedir , filename , file ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Map ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public class TypeSelector extends BaseExtendSelector { private FileType type ; public static final String TYPE_KEY = "<STR_LIT:type>" ; public TypeSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( type . getAttribute ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setType ( FileType fileType ) { this . type = fileType ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( TYPE_KEY . equalsIgnoreCase ( paramname ) ) { FileType type = FileType . getFromAttribute ( parameter . getValue ( ) ) ; if ( type != null ) { setType ( type ) ; } else { setError ( "<STR_LIT>" + TYPE_KEY + "<STR_LIT>" + parameter . getValue ( ) ) ; } } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( type == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( file . isDirectory ( ) ) { return type . equals ( FileType . DIR ) ; } else { return type . equals ( FileType . FILE ) ; } } public enum FileType { FILE ( "<STR_LIT:file>" ) , DIR ( "<STR_LIT>" ) ; private static Map < String , FileType > lookup ; private String attribute ; FileType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , FileType > ( ) ; for ( FileType mapperType : EnumSet . allOf ( FileType . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } } public String getAttribute ( ) { return attribute ; } public static FileType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Map ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . FileNameMapper ; import com . izforge . izpack . util . file . IdentityMapper ; import com . izforge . izpack . util . file . types . Mapper ; public class PresentSelector extends BaseSelector { private File targetdir = null ; private Mapper mapperElement = null ; private FileNameMapper map = null ; private boolean destmustexist = true ; public PresentSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; if ( targetdir == null ) { buf . append ( "<STR_LIT>" ) ; } else { buf . append ( targetdir . getName ( ) ) ; } buf . append ( "<STR_LIT>" ) ; if ( destmustexist ) { buf . append ( "<STR_LIT>" ) ; } else { buf . append ( "<STR_LIT>" ) ; } if ( map != null ) { buf . append ( map . toString ( ) ) ; } else if ( mapperElement != null ) { buf . append ( mapperElement . toString ( ) ) ; } buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setTargetdir ( File targetdir ) { this . targetdir = targetdir ; } public Mapper createMapper ( ) throws Exception { if ( mapperElement != null ) { throw new Exception ( "<STR_LIT>" ) ; } mapperElement = new Mapper ( ) ; return mapperElement ; } public void setPresent ( FilePresence fp ) { if ( fp . equals ( FilePresence . SRCONLY ) ) { destmustexist = false ; } } public void verifySettings ( ) throws Exception { if ( targetdir == null ) { setError ( "<STR_LIT>" ) ; } if ( mapperElement == null ) { map = new IdentityMapper ( ) ; } else { map = mapperElement . getImplementation ( ) ; } if ( map == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; String [ ] destfiles = map . mapFileName ( filename ) ; if ( destfiles == null ) { return false ; } if ( destfiles . length != <NUM_LIT:1> || destfiles [ <NUM_LIT:0> ] == null ) { throw new Exception ( "<STR_LIT>" + targetdir + "<STR_LIT>" + filename ) ; } String destname = destfiles [ <NUM_LIT:0> ] ; File destfile = new File ( targetdir , destname ) ; return destfile . exists ( ) == destmustexist ; } public enum FilePresence { SRCONLY ( "<STR_LIT>" ) , BOTH ( "<STR_LIT>" ) ; private static Map < String , FilePresence > lookup ; private String attribute ; FilePresence ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , FilePresence > ( ) ; for ( FilePresence mapperType : EnumSet . allOf ( FilePresence . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } } public String getAttribute ( ) { return attribute ; } public static FilePresence getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . text . DateFormat ; import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Locale ; import java . util . Map ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . OsVersion ; import com . izforge . izpack . util . file . types . Parameter ; public class DateSelector extends BaseExtendSelector { private long millis = - <NUM_LIT:1> ; private String dateTime = null ; private boolean includeDirs = false ; private int granularity = <NUM_LIT:0> ; private TimeComparisons cmp = TimeComparisons . EQUAL ; private String pattern ; public static final String MILLIS_KEY = "<STR_LIT>" ; public static final String DATETIME_KEY = "<STR_LIT>" ; public static final String CHECKDIRS_KEY = "<STR_LIT>" ; public static final String GRANULARITY_KEY = "<STR_LIT>" ; public static final String WHEN_KEY = "<STR_LIT>" ; public static final String PATTERN_KEY = "<STR_LIT>" ; public DateSelector ( ) { if ( OsVersion . IS_WINDOWS ) { granularity = <NUM_LIT> ; } } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( dateTime ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( cmp . getAttribute ( ) ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( granularity ) ; if ( pattern != null ) { buf . append ( "<STR_LIT>" ) . append ( pattern ) ; } buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setMillis ( long millis ) { this . millis = millis ; } public long getMillis ( ) throws Exception { if ( dateTime != null ) { validate ( ) ; } return millis ; } public void setDatetime ( String dateTime ) { this . dateTime = dateTime ; } public void setCheckdirs ( boolean includeDirs ) { this . includeDirs = includeDirs ; } public void setGranularity ( int granularity ) { this . granularity = granularity ; } public void setWhen ( TimeComparisons cmp ) { this . cmp = cmp ; } public void setPattern ( String pattern ) { this . pattern = pattern ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( MILLIS_KEY . equalsIgnoreCase ( paramname ) ) { try { setMillis ( new Long ( parameter . getValue ( ) ) . longValue ( ) ) ; } catch ( NumberFormatException nfe ) { setError ( "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( DATETIME_KEY . equalsIgnoreCase ( paramname ) ) { setDatetime ( parameter . getValue ( ) ) ; } else if ( CHECKDIRS_KEY . equalsIgnoreCase ( paramname ) ) { setCheckdirs ( Boolean . parseBoolean ( parameter . getValue ( ) ) ) ; } else if ( GRANULARITY_KEY . equalsIgnoreCase ( paramname ) ) { try { setGranularity ( new Integer ( parameter . getValue ( ) ) . intValue ( ) ) ; } catch ( NumberFormatException nfe ) { setError ( "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( WHEN_KEY . equalsIgnoreCase ( paramname ) ) { TimeComparisons cmp = TimeComparisons . getFromAttribute ( parameter . getValue ( ) ) ; if ( cmp != null ) { setWhen ( cmp ) ; } else { setError ( "<STR_LIT>" + WHEN_KEY + "<STR_LIT>" + parameter . getValue ( ) ) ; } } else if ( PATTERN_KEY . equalsIgnoreCase ( paramname ) ) { setPattern ( parameter . getValue ( ) ) ; } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( dateTime == null && millis < <NUM_LIT:0> ) { setError ( "<STR_LIT>" + "<STR_LIT>" ) ; } else if ( millis < <NUM_LIT:0> && dateTime != null ) { DateFormat df = ( ( pattern == null ) ? DateFormat . getDateTimeInstance ( DateFormat . SHORT , DateFormat . SHORT , Locale . US ) : new SimpleDateFormat ( pattern ) ) ; try { setMillis ( df . parse ( dateTime ) . getTime ( ) ) ; if ( millis < <NUM_LIT:0> ) { setError ( "<STR_LIT>" + dateTime + "<STR_LIT>" + "<STR_LIT>" ) ; } } catch ( ParseException pe ) { setError ( "<STR_LIT>" + dateTime + "<STR_LIT>" + ( ( pattern == null ) ? "<STR_LIT>" : pattern ) + "<STR_LIT>" ) ; } } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( file . isDirectory ( ) && ( ! includeDirs ) ) { return true ; } switch ( cmp ) { case BEFORE : return ( ( file . lastModified ( ) - granularity ) < millis ) ; case AFTER : return ( ( file . lastModified ( ) + granularity ) > millis ) ; default : return ( Math . abs ( file . lastModified ( ) - millis ) <= granularity ) ; } } public enum TimeComparisons { BEFORE ( "<STR_LIT>" ) , AFTER ( "<STR_LIT>" ) , EQUAL ( "<STR_LIT>" ) ; private static Map < String , TimeComparisons > lookup ; private String attribute ; TimeComparisons ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , TimeComparisons > ( ) ; for ( TimeComparisons mapperType : EnumSet . allOf ( TimeComparisons . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } } public String getAttribute ( ) { return attribute ; } public static TimeComparisons getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import com . izforge . izpack . api . data . InstallData ; public class SelectSelector extends BaseSelectorContainer { private String ifProperty ; private String unlessProperty ; public SelectSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; if ( hasSelectors ( ) ) { buf . append ( "<STR_LIT>" ) ; if ( ifProperty != null ) { buf . append ( "<STR_LIT>" ) ; buf . append ( ifProperty ) ; } if ( unlessProperty != null ) { buf . append ( "<STR_LIT>" ) ; buf . append ( unlessProperty ) ; } buf . append ( "<STR_LIT:U+0020>" ) ; buf . append ( super . toString ( ) ) ; buf . append ( "<STR_LIT:}>" ) ; } return buf . toString ( ) ; } public void verifySettings ( ) { int cnt = selectorCount ( ) ; if ( cnt < <NUM_LIT:0> || cnt > <NUM_LIT:1> ) { setError ( "<STR_LIT>" + "<STR_LIT>" ) ; } } public boolean passesConditions ( InstallData idata ) { if ( ifProperty != null && idata . getVariable ( ifProperty ) == null ) { return false ; } else if ( unlessProperty != null && idata . getVariable ( unlessProperty ) != null ) { return false ; } return true ; } public void setIf ( String ifProperty ) { this . ifProperty = ifProperty ; } public void setUnless ( String unlessProperty ) { this . unlessProperty = unlessProperty ; } @ Override public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; if ( ! ( passesConditions ( idata ) ) ) { return false ; } Enumeration < FileSelector > e = selectorElements ( ) ; if ( ! ( e . hasMoreElements ( ) ) ) { return true ; } FileSelector f = e . nextElement ( ) ; return f . isSelected ( idata , basedir , filename , file ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import com . izforge . izpack . api . data . InstallData ; public interface FileSelector { boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception ; } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public class FilenameSelector extends BaseExtendSelector { private String pattern = null ; private boolean casesensitive = true ; private boolean negated = false ; public static final String NAME_KEY = "<STR_LIT:name>" ; public static final String CASE_KEY = "<STR_LIT>" ; public static final String NEGATE_KEY = "<STR_LIT>" ; public FilenameSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( pattern ) ; buf . append ( "<STR_LIT>" ) ; if ( negated ) { buf . append ( "<STR_LIT:true>" ) ; } else { buf . append ( "<STR_LIT:false>" ) ; } buf . append ( "<STR_LIT>" ) ; if ( casesensitive ) { buf . append ( "<STR_LIT:true>" ) ; } else { buf . append ( "<STR_LIT:false>" ) ; } buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setName ( String pattern ) { pattern = pattern . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; if ( pattern . endsWith ( File . separator ) ) { pattern += "<STR_LIT>" ; } this . pattern = pattern ; } public void setCasesensitive ( boolean casesensitive ) { this . casesensitive = casesensitive ; } public void setNegate ( boolean negated ) { this . negated = negated ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( NAME_KEY . equalsIgnoreCase ( paramname ) ) { setName ( parameter . getValue ( ) ) ; } else if ( CASE_KEY . equalsIgnoreCase ( paramname ) ) { setCasesensitive ( Boolean . parseBoolean ( parameter . getValue ( ) ) ) ; } else if ( NEGATE_KEY . equalsIgnoreCase ( paramname ) ) { setNegate ( Boolean . parseBoolean ( parameter . getValue ( ) ) ) ; } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( pattern == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; return ( SelectorUtils . matchPath ( pattern , filename , casesensitive ) == ! ( negated ) ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; public interface SelectorScanner { void setSelectors ( FileSelector [ ] selectors ) ; String [ ] getDeselectedDirectories ( ) throws Exception ; String [ ] getDeselectedFiles ( ) throws Exception ; } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import com . izforge . izpack . api . exception . IzPackException ; import com . izforge . izpack . util . file . FileUtils ; public class DifferentSelector extends MappingSelector { private FileUtils fileUtils = FileUtils . getFileUtils ( ) ; private boolean ignoreFileTimes = true ; private boolean ignoreContents = false ; public void setIgnoreFileTimes ( boolean ignoreFileTimes ) { this . ignoreFileTimes = ignoreFileTimes ; } public void setIgnoreContents ( boolean ignoreContents ) { this . ignoreContents = ignoreContents ; } protected boolean selectionTest ( File srcfile , File destfile ) { if ( srcfile . exists ( ) != destfile . exists ( ) ) { return true ; } if ( srcfile . length ( ) != destfile . length ( ) ) { return true ; } if ( ! ignoreFileTimes ) { boolean sameDate ; sameDate = destfile . lastModified ( ) >= srcfile . lastModified ( ) - granularity && destfile . lastModified ( ) <= srcfile . lastModified ( ) + granularity ; if ( ! sameDate ) { return true ; } } if ( ! ignoreContents ) { try { return ! fileUtils . contentEquals ( srcfile , destfile ) ; } catch ( Exception e ) { throw new IzPackException ( "<STR_LIT>" + srcfile + "<STR_LIT:U+0020andU+0020>" + destfile , e ) ; } } else { return false ; } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; import com . izforge . izpack . util . regex . Regexp ; import com . izforge . izpack . util . regex . RegularExpression ; public class ContainsRegexpSelector extends BaseExtendSelector { private String userProvidedExpression = null ; private RegularExpression myRegExp = null ; private Regexp myExpression = null ; public static final String EXPRESSION_KEY = "<STR_LIT>" ; public ContainsRegexpSelector ( ) { } public String toString ( ) { StringBuffer buf = new StringBuffer ( "<STR_LIT>" ) ; buf . append ( userProvidedExpression ) ; buf . append ( "<STR_LIT:}>" ) ; return buf . toString ( ) ; } public void setExpression ( String theexpression ) { this . userProvidedExpression = theexpression ; } public void setParameters ( Parameter [ ] parameters ) { super . setParameters ( parameters ) ; if ( parameters != null ) { for ( Parameter parameter : parameters ) { String paramname = parameter . getName ( ) ; if ( EXPRESSION_KEY . equalsIgnoreCase ( paramname ) ) { setExpression ( parameter . getValue ( ) ) ; } else { setError ( "<STR_LIT>" + paramname ) ; } } } } public void verifySettings ( ) { if ( userProvidedExpression == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { String teststr = null ; BufferedReader in = null ; validate ( ) ; if ( file . isDirectory ( ) ) { return true ; } if ( myRegExp == null ) { myRegExp = new RegularExpression ( ) ; myRegExp . setPattern ( userProvidedExpression ) ; myExpression = myRegExp . getRegexp ( ) ; } try { in = new BufferedReader ( new InputStreamReader ( new FileInputStream ( file ) ) ) ; teststr = in . readLine ( ) ; while ( teststr != null ) { if ( myExpression . matches ( teststr ) ) { return true ; } teststr = in . readLine ( ) ; } return false ; } catch ( IOException ioe ) { throw new Exception ( "<STR_LIT>" + filename ) ; } finally { if ( in != null ) { try { in . close ( ) ; } catch ( Exception e ) { throw new Exception ( "<STR_LIT>" + filename ) ; } } } } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import java . util . Enumeration ; import java . util . Vector ; import com . izforge . izpack . api . data . InstallData ; public abstract class BaseSelectorContainer extends BaseSelector implements SelectorContainer { private Vector < FileSelector > selectorsList = new Vector < FileSelector > ( ) ; public BaseSelectorContainer ( ) { } public boolean hasSelectors ( ) { return ! ( selectorsList . isEmpty ( ) ) ; } public int selectorCount ( ) { return selectorsList . size ( ) ; } public FileSelector [ ] getSelectors ( ) { FileSelector [ ] result = new FileSelector [ selectorsList . size ( ) ] ; selectorsList . copyInto ( result ) ; return result ; } public Enumeration < FileSelector > selectorElements ( ) { return selectorsList . elements ( ) ; } public String toString ( ) { StringBuffer buf = new StringBuffer ( ) ; Enumeration < FileSelector > e = selectorElements ( ) ; if ( e . hasMoreElements ( ) ) { while ( e . hasMoreElements ( ) ) { buf . append ( e . nextElement ( ) . toString ( ) ) ; if ( e . hasMoreElements ( ) ) { buf . append ( "<STR_LIT:U+002CU+0020>" ) ; } } } return buf . toString ( ) ; } public void appendSelector ( FileSelector selector ) { selectorsList . addElement ( selector ) ; } public void validate ( ) throws Exception { verifySettings ( ) ; String errmsg = getError ( ) ; if ( errmsg != null ) { throw new Exception ( errmsg ) ; } Enumeration < FileSelector > e = selectorElements ( ) ; while ( e . hasMoreElements ( ) ) { Object o = e . nextElement ( ) ; if ( o instanceof BaseSelector ) { ( ( BaseSelector ) o ) . validate ( ) ; } } } public abstract boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception ; public void addSelector ( SelectSelector selector ) { appendSelector ( selector ) ; } public void addAnd ( AndSelector selector ) { appendSelector ( selector ) ; } public void addOr ( OrSelector selector ) { appendSelector ( selector ) ; } public void addNot ( NotSelector selector ) { appendSelector ( selector ) ; } public void addNone ( NoneSelector selector ) { appendSelector ( selector ) ; } public void addMajority ( MajoritySelector selector ) { appendSelector ( selector ) ; } public void addDate ( DateSelector selector ) { appendSelector ( selector ) ; } public void addSize ( SizeSelector selector ) { appendSelector ( selector ) ; } public void addFilename ( FilenameSelector selector ) { appendSelector ( selector ) ; } public void addCustom ( ExtendSelector selector ) { appendSelector ( selector ) ; } public void addContains ( ContainsSelector selector ) { appendSelector ( selector ) ; } public void addPresent ( PresentSelector selector ) { appendSelector ( selector ) ; } public void addDepth ( DepthSelector selector ) { appendSelector ( selector ) ; } public void addDepend ( DependSelector selector ) { appendSelector ( selector ) ; } public void addDifferent ( DifferentSelector selector ) { appendSelector ( selector ) ; } public void addType ( TypeSelector selector ) { appendSelector ( selector ) ; } public void addContainsRegexp ( ContainsRegexpSelector selector ) { appendSelector ( selector ) ; } public void add ( FileSelector selector ) { appendSelector ( selector ) ; } } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Parameter ; public abstract class BaseExtendSelector extends BaseSelector implements ExtendFileSelector { protected Parameter [ ] parameters = null ; public BaseExtendSelector ( ) { } public void setParameters ( Parameter [ ] parameters ) { this . parameters = parameters ; } protected Parameter [ ] getParameters ( ) { return parameters ; } public abstract boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception ; } </s>
<s> package com . izforge . izpack . util . file . types . selectors ; import java . io . File ; import org . apache . tools . ant . BuildException ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . FileNameMapper ; import com . izforge . izpack . util . file . FileUtils ; import com . izforge . izpack . util . file . IdentityMapper ; import com . izforge . izpack . util . file . types . Mapper ; public abstract class MappingSelector extends BaseSelector { protected File targetdir = null ; protected Mapper mapperElement = null ; protected FileNameMapper map = null ; protected int granularity = <NUM_LIT:0> ; public MappingSelector ( ) { granularity = ( int ) FileUtils . getFileUtils ( ) . getFileTimestampGranularity ( ) ; } public void setTargetdir ( File targetdir ) { this . targetdir = targetdir ; } public Mapper createMapper ( ) throws Exception { if ( mapperElement != null ) { throw new Exception ( "<STR_LIT>" ) ; } mapperElement = new Mapper ( ) ; return mapperElement ; } public void verifySettings ( ) throws Exception { if ( targetdir == null ) { setError ( "<STR_LIT>" ) ; } if ( mapperElement == null ) { map = new IdentityMapper ( ) ; } else { map = mapperElement . getImplementation ( ) ; } if ( map == null ) { setError ( "<STR_LIT>" ) ; } } public boolean isSelected ( InstallData idata , File basedir , String filename , File file ) throws Exception { validate ( ) ; String [ ] destfiles = map . mapFileName ( filename ) ; if ( destfiles == null ) { return false ; } if ( destfiles . length != <NUM_LIT:1> || destfiles [ <NUM_LIT:0> ] == null ) { throw new Exception ( "<STR_LIT>" + targetdir . getName ( ) + "<STR_LIT>" + filename ) ; } String destname = destfiles [ <NUM_LIT:0> ] ; File destfile = new File ( targetdir , destname ) ; boolean selected = selectionTest ( file , destfile ) ; return selected ; } protected abstract boolean selectionTest ( File srcfile , File destfile ) ; public void setGranularity ( int granularity ) { this . granularity = granularity ; } } </s>
<s> package com . izforge . izpack . util . file . types ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Enumeration ; import java . util . Vector ; import java . util . logging . Logger ; import com . izforge . izpack . util . file . DirectoryScanner ; import com . izforge . izpack . util . file . FileScanner ; import com . izforge . izpack . util . file . types . selectors . * ; public class FileSet extends DataType implements Cloneable , SelectorContainer { private static final Logger logger = Logger . getLogger ( FileSet . class . getName ( ) ) ; private PatternSet defaultPatterns = new PatternSet ( ) ; private Vector < PatternSet > additionalPatterns = new Vector < PatternSet > ( ) ; private Vector < FileSelector > selectors = new Vector < FileSelector > ( ) ; private File dir ; private boolean useDefaultExcludes = true ; private boolean isCaseSensitive = true ; private boolean followSymlinks = true ; public FileSet ( ) { super ( ) ; } public void setDir ( File dir ) throws Exception { this . dir = dir ; } public File getDir ( ) { return dir ; } public PatternSet . NameEntry createInclude ( ) { return defaultPatterns . createInclude ( ) ; } public PatternSet . NameEntry createExclude ( ) { return defaultPatterns . createExclude ( ) ; } public void setFile ( File file ) throws Exception { if ( ! file . exists ( ) ) { throw new FileNotFoundException ( "<STR_LIT>" + file + "<STR_LIT>" ) ; } setDir ( file . getParentFile ( ) ) ; createInclude ( ) . setName ( file . getName ( ) ) ; } public void setIncludes ( String includes ) { defaultPatterns . setIncludes ( includes ) ; } public void setExcludes ( String excludes ) { defaultPatterns . setExcludes ( excludes ) ; } public void setDefaultexcludes ( boolean useDefaultExcludes ) { this . useDefaultExcludes = useDefaultExcludes ; } public boolean getDefaultexcludes ( ) { return useDefaultExcludes ; } public void setCaseSensitive ( boolean isCaseSensitive ) { this . isCaseSensitive = isCaseSensitive ; } public void setFollowSymlinks ( boolean followSymlinks ) { this . followSymlinks = followSymlinks ; } public boolean isFollowSymlinks ( ) { return followSymlinks ; } public DirectoryScanner getDirectoryScanner ( ) throws Exception { if ( dir == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( ! dir . exists ( ) ) { throw new Exception ( dir . getAbsolutePath ( ) + "<STR_LIT>" ) ; } if ( ! dir . isDirectory ( ) ) { throw new Exception ( dir . getAbsolutePath ( ) + "<STR_LIT>" ) ; } DirectoryScanner ds = new DirectoryScanner ( ) ; setupDirectoryScanner ( ds ) ; ds . setFollowSymlinks ( followSymlinks ) ; ds . scan ( ) ; return ds ; } public void setupDirectoryScanner ( FileScanner ds ) { if ( ds == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } ds . setBasedir ( dir ) ; final int count = additionalPatterns . size ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { Object o = additionalPatterns . elementAt ( i ) ; defaultPatterns . append ( ( PatternSet ) o ) ; } logger . fine ( "<STR_LIT>" + dir + "<STR_LIT>" + defaultPatterns ) ; ds . setIncludes ( defaultPatterns . getIncludePatterns ( ) ) ; ds . setExcludes ( defaultPatterns . getExcludePatterns ( ) ) ; if ( ds instanceof SelectorScanner ) { SelectorScanner ss = ( SelectorScanner ) ds ; ss . setSelectors ( getSelectors ( ) ) ; } if ( useDefaultExcludes ) { ds . addDefaultExcludes ( ) ; } ds . setCaseSensitive ( isCaseSensitive ) ; } @ Override public boolean hasSelectors ( ) { return ! ( selectors . isEmpty ( ) ) ; } public boolean hasPatterns ( ) { if ( defaultPatterns . hasPatterns ( ) ) { return true ; } Enumeration < PatternSet > e = additionalPatterns . elements ( ) ; while ( e . hasMoreElements ( ) ) { PatternSet ps = e . nextElement ( ) ; if ( ps . hasPatterns ( ) ) { return true ; } } return false ; } @ Override public int selectorCount ( ) { return selectors . size ( ) ; } @ Override public FileSelector [ ] getSelectors ( ) { return selectors . toArray ( new FileSelector [ selectors . size ( ) ] ) ; } @ Override public Enumeration < FileSelector > selectorElements ( ) { return selectors . elements ( ) ; } @ Override public void appendSelector ( FileSelector selector ) { selectors . addElement ( selector ) ; } @ Override public void addSelector ( SelectSelector selector ) { appendSelector ( selector ) ; } @ Override public void addAnd ( AndSelector selector ) { appendSelector ( selector ) ; } @ Override public void addOr ( OrSelector selector ) { appendSelector ( selector ) ; } @ Override public void addNot ( NotSelector selector ) { appendSelector ( selector ) ; } @ Override public void addNone ( NoneSelector selector ) { appendSelector ( selector ) ; } @ Override public void addMajority ( MajoritySelector selector ) { appendSelector ( selector ) ; } @ Override public void addDate ( DateSelector selector ) { appendSelector ( selector ) ; } @ Override public void addSize ( SizeSelector selector ) { appendSelector ( selector ) ; } @ Override public void addDifferent ( DifferentSelector selector ) { appendSelector ( selector ) ; } @ Override public void addFilename ( FilenameSelector selector ) { appendSelector ( selector ) ; } @ Override public void addType ( TypeSelector selector ) { appendSelector ( selector ) ; } @ Override public void addCustom ( ExtendSelector selector ) { appendSelector ( selector ) ; } @ Override public void addContains ( ContainsSelector selector ) { appendSelector ( selector ) ; } @ Override public void addPresent ( PresentSelector selector ) { appendSelector ( selector ) ; } @ Override public void addDepth ( DepthSelector selector ) { appendSelector ( selector ) ; } @ Override public void addDepend ( DependSelector selector ) { appendSelector ( selector ) ; } @ Override public void addContainsRegexp ( ContainsRegexpSelector selector ) { appendSelector ( selector ) ; } @ Override public void add ( FileSelector selector ) { appendSelector ( selector ) ; } } </s>
<s> package com . izforge . izpack . util . file . types ; public class Resource implements Cloneable , Comparable < Object > { public static final long UNKNOWN_SIZE = - <NUM_LIT:1> ; private String name = null ; private boolean exists = true ; private long lastmodified = <NUM_LIT:0> ; private boolean directory = false ; private long size = UNKNOWN_SIZE ; public Resource ( ) { } public Resource ( String name ) { this ( name , false , <NUM_LIT:0> , false ) ; } public Resource ( String name , boolean exists , long lastmodified ) { this ( name , exists , lastmodified , false ) ; } public Resource ( String name , boolean exists , long lastmodified , boolean directory ) { this ( name , exists , lastmodified , directory , UNKNOWN_SIZE ) ; } public Resource ( String name , boolean exists , long lastmodified , boolean directory , long size ) { this . name = name ; setName ( name ) ; setExists ( exists ) ; setLastModified ( lastmodified ) ; setDirectory ( directory ) ; setSize ( size ) ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public boolean isExists ( ) { return exists ; } public void setExists ( boolean exists ) { this . exists = exists ; } public long getLastModified ( ) { return ! exists || lastmodified < <NUM_LIT:0> ? <NUM_LIT> : lastmodified ; } public void setLastModified ( long lastmodified ) { this . lastmodified = lastmodified ; } public boolean isDirectory ( ) { return directory ; } public void setDirectory ( boolean directory ) { this . directory = directory ; } public void setSize ( long size ) { this . size = ( size > UNKNOWN_SIZE ) ? size : UNKNOWN_SIZE ; } public long getSize ( ) { return ( exists ) ? size : <NUM_LIT> ; } public Object clone ( ) { try { return super . clone ( ) ; } catch ( CloneNotSupportedException e ) { throw new Error ( "<STR_LIT>" + "<STR_LIT>" ) ; } } public int compareTo ( Object other ) { if ( ! ( other instanceof Resource ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Resource r = ( Resource ) other ; return getName ( ) . compareTo ( r . getName ( ) ) ; } } </s>
<s> package com . izforge . izpack . util . file . types ; public abstract class DataType { private String description ; private boolean checked = true ; public void setDescription ( final String desc ) { description = desc ; } public String getDescription ( ) { return description ; } protected Exception tooManyAttributes ( ) { return new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } protected Exception noChildrenAllowed ( ) { return new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } protected boolean isChecked ( ) { return checked ; } protected void setChecked ( final boolean checked ) { this . checked = checked ; } } </s>
<s> package com . izforge . izpack . util . file . types ; public interface Parameterizable { void setParameters ( Parameter [ ] parameters ) ; } </s>
<s> package com . izforge . izpack . util . file . types ; import java . util . StringTokenizer ; import java . util . Vector ; public class PatternSet extends DataType implements Cloneable { private Vector < NameEntry > includeList = new Vector < NameEntry > ( ) ; private Vector < NameEntry > excludeList = new Vector < NameEntry > ( ) ; public class NameEntry { private String name ; private String ifCond ; private String unlessCond ; public void setName ( String name ) { this . name = name ; } public void setIf ( String cond ) { ifCond = cond ; } public void setUnless ( String cond ) { unlessCond = cond ; } public String getName ( ) { return name ; } public String toString ( ) { if ( name == null ) { throw new RuntimeException ( "<STR_LIT>" ) ; } StringBuffer buf = new StringBuffer ( name ) ; if ( ( ifCond != null ) || ( unlessCond != null ) ) { buf . append ( "<STR_LIT::>" ) ; String connector = "<STR_LIT>" ; if ( ifCond != null ) { buf . append ( "<STR_LIT>" ) ; buf . append ( ifCond ) ; connector = "<STR_LIT:;>" ; } if ( unlessCond != null ) { buf . append ( connector ) ; buf . append ( "<STR_LIT>" ) ; buf . append ( unlessCond ) ; } } return buf . toString ( ) ; } } public PatternSet ( ) { super ( ) ; } public void addConfiguredPatternset ( PatternSet p ) { String [ ] nestedIncludes = p . getIncludePatterns ( ) ; String [ ] nestedExcludes = p . getExcludePatterns ( ) ; if ( nestedIncludes != null ) { for ( String nestedInclude : nestedIncludes ) { createInclude ( ) . setName ( nestedInclude ) ; } } if ( nestedExcludes != null ) { for ( String nestedExclude : nestedExcludes ) { createExclude ( ) . setName ( nestedExclude ) ; } } } public NameEntry createInclude ( ) { return addPatternToList ( includeList ) ; } public NameEntry createExclude ( ) { return addPatternToList ( excludeList ) ; } public void setIncludes ( String includes ) { if ( includes != null && includes . length ( ) > <NUM_LIT:0> ) { StringTokenizer tok = new StringTokenizer ( includes , "<STR_LIT:U+002CU+0020>" , false ) ; while ( tok . hasMoreTokens ( ) ) { createInclude ( ) . setName ( tok . nextToken ( ) ) ; } } } public void setExcludes ( String excludes ) { if ( excludes != null && excludes . length ( ) > <NUM_LIT:0> ) { StringTokenizer tok = new StringTokenizer ( excludes , "<STR_LIT:U+002CU+0020>" , false ) ; while ( tok . hasMoreTokens ( ) ) { createExclude ( ) . setName ( tok . nextToken ( ) ) ; } } } private NameEntry addPatternToList ( Vector < NameEntry > list ) { NameEntry result = new NameEntry ( ) ; list . addElement ( result ) ; return result ; } public void append ( PatternSet other ) { String [ ] incl = other . getIncludePatterns ( ) ; if ( incl != null ) { for ( String anIncl : incl ) { createInclude ( ) . setName ( anIncl ) ; } } String [ ] excl = other . getExcludePatterns ( ) ; if ( excl != null ) { for ( String anExcl : excl ) { createExclude ( ) . setName ( anExcl ) ; } } } public String [ ] getIncludePatterns ( ) { return makeArray ( includeList ) ; } public String [ ] getExcludePatterns ( ) { return makeArray ( excludeList ) ; } boolean hasPatterns ( ) { return includeList . size ( ) > <NUM_LIT:0> || excludeList . size ( ) > <NUM_LIT:0> ; } private String [ ] makeArray ( Vector < NameEntry > list ) { if ( list . size ( ) == <NUM_LIT:0> ) { return null ; } Vector < String > tmpNames = new Vector < String > ( ) ; for ( NameEntry ne : list ) { String pattern = ne . getName ( ) ; if ( pattern != null && pattern . length ( ) > <NUM_LIT:0> ) { tmpNames . addElement ( pattern ) ; } } String [ ] result = new String [ tmpNames . size ( ) ] ; tmpNames . copyInto ( result ) ; return result ; } public String toString ( ) { return "<STR_LIT>" + includeList + "<STR_LIT>" + excludeList + "<STR_LIT>" ; } } </s>
<s> package com . izforge . izpack . util . file . types ; public interface ResourceFactory { Resource getResource ( String name ) throws Exception ; } </s>
<s> package com . izforge . izpack . util . file . types ; import java . io . File ; import java . util . StringTokenizer ; import java . util . Vector ; public class FileList extends DataType { private Vector < String > filenames = new Vector < String > ( ) ; private File dir ; public FileList ( ) { super ( ) ; } protected FileList ( FileList filelist ) { this . dir = filelist . dir ; this . filenames = filelist . filenames ; } public void setDir ( File dir ) throws Exception { this . dir = dir ; } public File getDir ( ) { return dir ; } public void setFiles ( String filenames ) { if ( filenames != null && filenames . length ( ) > <NUM_LIT:0> ) { StringTokenizer tok = new StringTokenizer ( filenames , "<STR_LIT>" , false ) ; while ( tok . hasMoreTokens ( ) ) { this . filenames . addElement ( tok . nextToken ( ) ) ; } } } public String [ ] getFiles ( ) throws Exception { if ( dir == null ) { throw new Exception ( "<STR_LIT>" ) ; } if ( filenames . size ( ) == <NUM_LIT:0> ) { throw new Exception ( "<STR_LIT>" ) ; } String [ ] result = new String [ filenames . size ( ) ] ; filenames . copyInto ( result ) ; return result ; } public static class FileName { private String name ; public void setName ( String name ) { this . name = name ; } public String getName ( ) { return name ; } } public void addConfiguredFile ( FileName name ) throws Exception { if ( name . getName ( ) == null ) { throw new Exception ( "<STR_LIT>" ) ; } filenames . addElement ( name . getName ( ) ) ; } } </s>
<s> package com . izforge . izpack . util . file . types ; public final class Parameter { private String name ; private String type ; private String value ; public final void setName ( final String name ) { this . name = name ; } public final void setType ( final String type ) { this . type = type ; } public final void setValue ( final String value ) { this . value = value ; } public final String getName ( ) { return name ; } public final String getType ( ) { return type ; } public final String getValue ( ) { return value ; } } </s>
<s> package com . izforge . izpack . util . file . types ; import java . util . EnumSet ; import java . util . HashMap ; import java . util . Hashtable ; import java . util . Map ; import com . izforge . izpack . util . file . CompositeMapper ; import com . izforge . izpack . util . file . ContainerMapper ; import com . izforge . izpack . util . file . FileNameMapper ; public class Mapper extends DataType implements Cloneable { protected MapperType type = null ; protected String classname = null ; protected Path classpath = null ; protected String from = null ; protected String to = null ; private ContainerMapper container = null ; public void setType ( MapperType type ) { this . type = type ; } public void add ( FileNameMapper fileNameMapper ) throws Exception { if ( container == null ) { if ( type == null && classname == null ) { container = new CompositeMapper ( ) ; } else { FileNameMapper m = getImplementation ( ) ; if ( m instanceof ContainerMapper ) { container = ( ContainerMapper ) m ; } else { throw new Exception ( String . valueOf ( m ) + "<STR_LIT>" ) ; } } } container . add ( fileNameMapper ) ; } public void addConfiguredMapper ( Mapper mapper ) throws Exception { add ( mapper . getImplementation ( ) ) ; } public void setClassname ( String classname ) { this . classname = classname ; } public void setFrom ( String from ) { this . from = from ; } public void setTo ( String to ) { this . to = to ; } public FileNameMapper getImplementation ( ) throws Exception { if ( type == null && classname == null && container == null ) { throw new Exception ( "<STR_LIT>" + "<STR_LIT>" ) ; } if ( container != null ) { return container ; } if ( type != null && classname != null ) { throw new Exception ( "<STR_LIT>" ) ; } try { FileNameMapper m = ( FileNameMapper ) ( getImplementationClass ( ) . newInstance ( ) ) ; m . setFrom ( from ) ; m . setTo ( to ) ; return m ; } catch ( Exception be ) { throw be ; } catch ( Throwable t ) { throw new Exception ( t ) ; } } protected Class getImplementationClass ( ) throws ClassNotFoundException { String classname = this . classname ; if ( type != null ) { classname = type . getImplementation ( ) ; } ClassLoader loader = getClass ( ) . getClassLoader ( ) ; return Class . forName ( classname , true , loader ) ; } public enum MapperType { IDENTITY ( "<STR_LIT>" ) , FLATTEN ( "<STR_LIT>" ) , GLOB ( "<STR_LIT>" ) , MERGE ( "<STR_LIT>" ) , REGEXP ( "<STR_LIT>" ) , PACKAGE ( "<STR_LIT>" ) , UNPACKAGE ( "<STR_LIT>" ) ; private static Map < String , MapperType > lookup ; private static Hashtable < MapperType , String > implementations ; private String attribute ; MapperType ( String attribute ) { this . attribute = attribute ; } static { lookup = new HashMap < String , MapperType > ( ) ; for ( MapperType mapperType : EnumSet . allOf ( MapperType . class ) ) { lookup . put ( mapperType . getAttribute ( ) , mapperType ) ; } implementations = new Hashtable < MapperType , String > ( ) ; implementations . put ( IDENTITY , "<STR_LIT>" ) ; implementations . put ( FLATTEN , "<STR_LIT>" ) ; implementations . put ( GLOB , "<STR_LIT>" ) ; implementations . put ( MERGE , "<STR_LIT>" ) ; implementations . put ( REGEXP , "<STR_LIT>" ) ; implementations . put ( PACKAGE , "<STR_LIT>" ) ; implementations . put ( UNPACKAGE , "<STR_LIT>" ) ; } public String getAttribute ( ) { return attribute ; } public static MapperType getFromAttribute ( String attribute ) { if ( attribute != null && lookup . containsKey ( attribute ) ) { return lookup . get ( attribute ) ; } return null ; } public String getImplementation ( ) { return implementations . get ( this ) ; } } } </s>
<s> package com . izforge . izpack . util . file . types ; public class DirSet extends FileSet { public DirSet ( ) { super ( ) ; } } </s>
<s> package com . izforge . izpack . util . file ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Iterator ; import java . util . List ; import com . izforge . izpack . util . file . types . Mapper ; public abstract class ContainerMapper implements FileNameMapper { private List < FileNameMapper > mappers = new ArrayList < FileNameMapper > ( ) ; public void addConfiguredMapper ( Mapper mapper ) throws Exception { add ( mapper . getImplementation ( ) ) ; } public synchronized void add ( FileNameMapper fileNameMapper ) { if ( this == fileNameMapper || ( fileNameMapper instanceof ContainerMapper && ( ( ContainerMapper ) fileNameMapper ) . contains ( this ) ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } else { mappers . add ( fileNameMapper ) ; } } protected synchronized boolean contains ( FileNameMapper fileNameMapper ) { boolean foundit = false ; for ( Iterator < FileNameMapper > iter = mappers . iterator ( ) ; iter . hasNext ( ) && ! foundit ; ) { FileNameMapper next = iter . next ( ) ; foundit |= ( next == fileNameMapper || ( next instanceof ContainerMapper && ( ( ContainerMapper ) next ) . contains ( fileNameMapper ) ) ) ; } return foundit ; } public synchronized List < FileNameMapper > getMappers ( ) { return Collections . unmodifiableList ( mappers ) ; } public void setFrom ( String ignore ) { } public void setTo ( String ignore ) { } } </s>
<s> package com . izforge . izpack . util . file ; import java . io . File ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Enumeration ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Hashtable ; import java . util . Map ; import java . util . Set ; import java . util . Vector ; import com . izforge . izpack . api . data . InstallData ; import com . izforge . izpack . util . file . types . Resource ; import com . izforge . izpack . util . file . types . ResourceFactory ; import com . izforge . izpack . util . file . types . selectors . FileSelector ; import com . izforge . izpack . util . file . types . selectors . SelectorUtils ; public class DirectoryScanner implements FileScanner , ResourceFactory { protected InstallData idata ; protected static final String [ ] DEFAULTEXCLUDES = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private static final FileUtils FILE_UTILS = FileUtils . getFileUtils ( ) ; private static final boolean [ ] CS_SCAN_ONLY = new boolean [ ] { true } ; private static final boolean [ ] CS_THEN_NON_CS = new boolean [ ] { true , false } ; private static Vector < String > defaultExcludes = new Vector < String > ( ) ; static { resetDefaultExcludes ( ) ; } protected File basedir ; protected String [ ] includes ; protected String [ ] excludes ; protected FileSelector [ ] selectors = null ; protected Vector < String > filesIncluded ; protected Vector < String > filesNotIncluded ; protected Vector < String > filesExcluded ; protected Vector < String > dirsIncluded ; protected Vector < String > dirsNotIncluded ; protected Vector < String > dirsExcluded ; protected Vector < String > filesDeselected ; protected Vector < String > dirsDeselected ; protected boolean haveSlowResults = false ; protected boolean isCaseSensitive = true ; private boolean followSymlinks = true ; protected boolean everythingIncluded = true ; private Map < File , String [ ] > fileListMap = new HashMap < File , String [ ] > ( ) ; private Set < String > scannedDirs = new HashSet < String > ( ) ; private Set < String > includeNonPatterns = new HashSet < String > ( ) ; private Set < String > excludeNonPatterns = new HashSet < String > ( ) ; private String [ ] includePatterns ; private String [ ] excludePatterns ; private boolean areNonPatternSetsReady = false ; private boolean scanning = false ; private Object scanLock = new Object ( ) ; private boolean slowScanning = false ; private Object slowScanLock = new Object ( ) ; private Exception illegal = null ; public DirectoryScanner ( ) { } protected static boolean matchPatternStart ( String pattern , String str ) { return SelectorUtils . matchPatternStart ( pattern , str ) ; } protected static boolean matchPatternStart ( String pattern , String str , boolean isCaseSensitive ) { return SelectorUtils . matchPatternStart ( pattern , str , isCaseSensitive ) ; } protected static boolean matchPath ( String pattern , String str ) { return SelectorUtils . matchPath ( pattern , str ) ; } protected static boolean matchPath ( String pattern , String str , boolean isCaseSensitive ) { return SelectorUtils . matchPath ( pattern , str , isCaseSensitive ) ; } public static boolean match ( String pattern , String str ) { return SelectorUtils . match ( pattern , str ) ; } protected static boolean match ( String pattern , String str , boolean isCaseSensitive ) { return SelectorUtils . match ( pattern , str , isCaseSensitive ) ; } public static String [ ] getDefaultExcludes ( ) { return defaultExcludes . toArray ( new String [ defaultExcludes . size ( ) ] ) ; } public static boolean addDefaultExclude ( String s ) { if ( defaultExcludes . indexOf ( s ) == - <NUM_LIT:1> ) { defaultExcludes . add ( s ) ; return true ; } return false ; } public static boolean removeDefaultExclude ( String s ) { return defaultExcludes . remove ( s ) ; } public static void resetDefaultExcludes ( ) { defaultExcludes = new Vector < String > ( ) ; defaultExcludes . addAll ( Arrays . asList ( DEFAULTEXCLUDES ) ) ; } public void setBasedir ( String basedir ) { setBasedir ( new File ( basedir . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ) ) ; } public synchronized void setBasedir ( File basedir ) { this . basedir = basedir ; } public synchronized File getBasedir ( ) { return basedir ; } public synchronized boolean isCaseSensitive ( ) { return isCaseSensitive ; } public synchronized void setCaseSensitive ( boolean isCaseSensitive ) { this . isCaseSensitive = isCaseSensitive ; } public synchronized boolean isFollowSymlinks ( ) { return followSymlinks ; } public synchronized void setFollowSymlinks ( boolean followSymlinks ) { this . followSymlinks = followSymlinks ; } public synchronized void setIncludes ( String [ ] includes ) { if ( includes == null ) { this . includes = null ; } else { this . includes = new String [ includes . length ] ; for ( int i = <NUM_LIT:0> ; i < includes . length ; i ++ ) { this . includes [ i ] = normalizePattern ( includes [ i ] ) ; } } } public synchronized void setExcludes ( String [ ] excludes ) { if ( excludes == null ) { this . excludes = null ; } else { this . excludes = new String [ excludes . length ] ; for ( int i = <NUM_LIT:0> ; i < excludes . length ; i ++ ) { this . excludes [ i ] = normalizePattern ( excludes [ i ] ) ; } } } public synchronized void addExcludes ( String [ ] excludes ) { if ( excludes != null && excludes . length > <NUM_LIT:0> ) { if ( this . excludes != null && this . excludes . length > <NUM_LIT:0> ) { String [ ] tmp = new String [ excludes . length + this . excludes . length ] ; System . arraycopy ( this . excludes , <NUM_LIT:0> , tmp , <NUM_LIT:0> , this . excludes . length ) ; for ( int i = <NUM_LIT:0> ; i < excludes . length ; i ++ ) { tmp [ this . excludes . length + i ] = normalizePattern ( excludes [ i ] ) ; } this . excludes = tmp ; } else { setExcludes ( excludes ) ; } } } private static String normalizePattern ( String p ) { String pattern = p . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; if ( pattern . endsWith ( File . separator ) ) { pattern += "<STR_LIT>" ; } return pattern ; } public synchronized boolean isEverythingIncluded ( ) { return everythingIncluded ; } public void scan ( ) throws Exception { synchronized ( scanLock ) { if ( scanning ) { while ( scanning ) { try { scanLock . wait ( ) ; } catch ( InterruptedException e ) { continue ; } } if ( illegal != null ) { throw illegal ; } return ; } scanning = true ; } try { synchronized ( this ) { illegal = null ; clearResults ( ) ; boolean nullIncludes = ( includes == null ) ; includes = nullIncludes ? new String [ ] { "<STR_LIT>" } : includes ; boolean nullExcludes = ( excludes == null ) ; excludes = nullExcludes ? new String [ <NUM_LIT:0> ] : excludes ; if ( basedir == null ) { illegal = new Exception ( "<STR_LIT>" ) ; } else { if ( ! basedir . exists ( ) ) { illegal = new Exception ( "<STR_LIT>" + basedir + "<STR_LIT>" ) ; } if ( ! basedir . isDirectory ( ) ) { illegal = new Exception ( "<STR_LIT>" + basedir + "<STR_LIT>" ) ; } } if ( illegal != null ) { throw illegal ; } if ( isIncluded ( "<STR_LIT>" ) ) { if ( ! isExcluded ( "<STR_LIT>" ) ) { if ( isSelected ( "<STR_LIT>" , basedir ) ) { dirsIncluded . addElement ( "<STR_LIT>" ) ; } else { dirsDeselected . addElement ( "<STR_LIT>" ) ; } } else { dirsExcluded . addElement ( "<STR_LIT>" ) ; } } else { dirsNotIncluded . addElement ( "<STR_LIT>" ) ; } checkIncludePatterns ( ) ; clearCaches ( ) ; includes = nullIncludes ? null : includes ; excludes = nullExcludes ? null : excludes ; } } finally { synchronized ( scanLock ) { scanning = false ; scanLock . notifyAll ( ) ; } } } private void checkIncludePatterns ( ) throws Exception { Hashtable < String , String > newroots = new Hashtable < String , String > ( ) ; for ( String include : includes ) { newroots . put ( SelectorUtils . rtrimWildcardTokens ( include ) , include ) ; } if ( newroots . containsKey ( "<STR_LIT>" ) ) { scandir ( basedir , "<STR_LIT>" , true ) ; } else { Enumeration < String > enum2 = newroots . keys ( ) ; File canonBase = null ; try { canonBase = basedir . getCanonicalFile ( ) ; } catch ( IOException ex ) { throw new Exception ( ex ) ; } while ( enum2 . hasMoreElements ( ) ) { String currentelement = enum2 . nextElement ( ) ; String originalpattern = newroots . get ( currentelement ) ; File myfile = new File ( basedir , currentelement ) ; if ( myfile . exists ( ) ) { try { File canonFile = myfile . getCanonicalFile ( ) ; String path = FILE_UTILS . removeLeadingPath ( canonBase , canonFile ) ; if ( ! path . equals ( currentelement ) ) { myfile = findFile ( basedir , currentelement , true ) ; if ( myfile != null ) { currentelement = FILE_UTILS . removeLeadingPath ( basedir , myfile ) ; } } } catch ( IOException ex ) { throw new Exception ( ex ) ; } } if ( ( myfile == null || ! myfile . exists ( ) ) && ! isCaseSensitive ( ) ) { File f = findFile ( basedir , currentelement , false ) ; if ( f != null && f . exists ( ) ) { currentelement = FILE_UTILS . removeLeadingPath ( basedir , f ) ; myfile = f ; } } if ( myfile != null && myfile . exists ( ) ) { if ( ! followSymlinks && isSymlink ( basedir , currentelement ) ) { continue ; } if ( myfile . isDirectory ( ) ) { if ( isIncluded ( currentelement ) && currentelement . length ( ) > <NUM_LIT:0> ) { accountForIncludedDir ( currentelement , myfile , true ) ; } else { if ( currentelement . length ( ) > <NUM_LIT:0> ) { if ( currentelement . charAt ( currentelement . length ( ) - <NUM_LIT:1> ) != File . separatorChar ) { currentelement = currentelement + File . separatorChar ; } } scandir ( myfile , currentelement , true ) ; } } else { boolean included = isCaseSensitive ( ) ? originalpattern . equals ( currentelement ) : originalpattern . equalsIgnoreCase ( currentelement ) ; if ( included ) { accountForIncludedFile ( currentelement , myfile ) ; } } } } } } protected synchronized void clearResults ( ) { filesIncluded = new Vector < String > ( ) ; filesNotIncluded = new Vector < String > ( ) ; filesExcluded = new Vector < String > ( ) ; filesDeselected = new Vector < String > ( ) ; dirsIncluded = new Vector < String > ( ) ; dirsNotIncluded = new Vector < String > ( ) ; dirsExcluded = new Vector < String > ( ) ; dirsDeselected = new Vector < String > ( ) ; everythingIncluded = ( basedir != null ) ; scannedDirs . clear ( ) ; } protected void slowScan ( ) throws Exception { synchronized ( slowScanLock ) { if ( haveSlowResults ) { return ; } if ( slowScanning ) { while ( slowScanning ) { try { slowScanLock . wait ( ) ; } catch ( InterruptedException e ) { } } return ; } slowScanning = true ; } try { synchronized ( this ) { boolean nullIncludes = ( includes == null ) ; includes = nullIncludes ? new String [ ] { "<STR_LIT>" } : includes ; boolean nullExcludes = ( excludes == null ) ; excludes = nullExcludes ? new String [ <NUM_LIT:0> ] : excludes ; String [ ] excl = new String [ dirsExcluded . size ( ) ] ; dirsExcluded . copyInto ( excl ) ; String [ ] notIncl = new String [ dirsNotIncluded . size ( ) ] ; dirsNotIncluded . copyInto ( notIncl ) ; for ( String anExcl : excl ) { if ( ! couldHoldIncluded ( anExcl ) ) { scandir ( new File ( basedir , anExcl ) , anExcl + File . separator , false ) ; } } for ( String aNotIncl : notIncl ) { if ( ! couldHoldIncluded ( aNotIncl ) ) { scandir ( new File ( basedir , aNotIncl ) , aNotIncl + File . separator , false ) ; } } clearCaches ( ) ; includes = nullIncludes ? null : includes ; excludes = nullExcludes ? null : excludes ; } } finally { synchronized ( slowScanLock ) { haveSlowResults = true ; slowScanning = false ; slowScanLock . notifyAll ( ) ; } } } protected void scandir ( File dir , String vpath , boolean fast ) throws Exception { if ( dir == null ) { throw new Exception ( "<STR_LIT>" ) ; } else if ( ! dir . exists ( ) ) { throw new Exception ( dir + "<STR_LIT>" ) ; } else if ( ! dir . isDirectory ( ) ) { throw new Exception ( dir + "<STR_LIT>" ) ; } if ( fast && hasBeenScanned ( vpath ) ) { return ; } String [ ] newfiles = dir . list ( ) ; if ( newfiles == null ) { throw new Exception ( "<STR_LIT>" + dir . getAbsolutePath ( ) ) ; } if ( ! followSymlinks ) { Vector < String > noLinks = new Vector < String > ( ) ; for ( String newfile : newfiles ) { try { if ( FILE_UTILS . isSymbolicLink ( dir , newfile ) ) { String name = vpath + newfile ; File file = new File ( dir , newfile ) ; ( file . isDirectory ( ) ? dirsExcluded : filesExcluded ) . addElement ( name ) ; } else { noLinks . addElement ( newfile ) ; } } catch ( IOException ioe ) { String msg = "<STR_LIT>" + "<STR_LIT>" ; System . err . println ( msg ) ; noLinks . addElement ( newfile ) ; } } newfiles = new String [ noLinks . size ( ) ] ; noLinks . copyInto ( newfiles ) ; } for ( String newfile : newfiles ) { String name = vpath + newfile ; File file = new File ( dir , newfile ) ; if ( file . isDirectory ( ) ) { if ( isIncluded ( name ) ) { accountForIncludedDir ( name , file , fast ) ; } else { everythingIncluded = false ; dirsNotIncluded . addElement ( name ) ; if ( fast && couldHoldIncluded ( name ) ) { scandir ( file , name + File . separator , fast ) ; } } if ( ! fast ) { scandir ( file , name + File . separator , fast ) ; } } else if ( file . isFile ( ) ) { if ( isIncluded ( name ) ) { accountForIncludedFile ( name , file ) ; } else { everythingIncluded = false ; filesNotIncluded . addElement ( name ) ; } } } } private void accountForIncludedFile ( String name , File file ) throws Exception { if ( filesIncluded . contains ( name ) || filesExcluded . contains ( name ) || filesDeselected . contains ( name ) ) { return ; } boolean included = false ; if ( isExcluded ( name ) ) { filesExcluded . addElement ( name ) ; } else if ( isSelected ( name , file ) ) { included = true ; filesIncluded . addElement ( name ) ; } else { filesDeselected . addElement ( name ) ; } everythingIncluded &= included ; } private void accountForIncludedDir ( String name , File file , boolean fast ) throws Exception { if ( dirsIncluded . contains ( name ) || dirsExcluded . contains ( name ) || dirsDeselected . contains ( name ) ) { return ; } boolean included = false ; if ( isExcluded ( name ) ) { dirsExcluded . addElement ( name ) ; } else if ( isSelected ( name , file ) ) { included = true ; dirsIncluded . addElement ( name ) ; } else { dirsDeselected . addElement ( name ) ; } everythingIncluded &= included ; if ( fast && couldHoldIncluded ( name ) && ! contentsExcluded ( name ) ) { scandir ( file , name + File . separator , fast ) ; } } protected boolean isIncluded ( String name ) { ensureNonPatternSetsReady ( ) ; if ( isCaseSensitive ( ) ? includeNonPatterns . contains ( name ) : includeNonPatterns . contains ( name . toUpperCase ( ) ) ) { return true ; } for ( String includePattern : includePatterns ) { if ( matchPath ( includePattern , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } protected boolean couldHoldIncluded ( String name ) { for ( String include : includes ) { if ( matchPatternStart ( include , name , isCaseSensitive ( ) ) && isMorePowerfulThanExcludes ( name , include ) && isDeeper ( include , name ) ) { return true ; } } return false ; } private boolean isDeeper ( String pattern , String name ) { Vector < ? > p = SelectorUtils . tokenizePath ( pattern ) ; Vector < ? > n = SelectorUtils . tokenizePath ( name ) ; return p . contains ( "<STR_LIT>" ) || p . size ( ) > n . size ( ) ; } private boolean isMorePowerfulThanExcludes ( String name , String includepattern ) { String soughtexclude = name + File . separator + "<STR_LIT>" ; for ( String exclude : excludes ) { if ( exclude . equals ( soughtexclude ) ) { return false ; } } return true ; } private boolean contentsExcluded ( String name ) { name = ( name . endsWith ( File . separator ) ) ? name : name + File . separator ; for ( String e : excludes ) { if ( e . endsWith ( "<STR_LIT>" ) && SelectorUtils . matchPath ( e . substring ( <NUM_LIT:0> , e . length ( ) - <NUM_LIT:2> ) , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } protected boolean isExcluded ( String name ) { ensureNonPatternSetsReady ( ) ; if ( isCaseSensitive ( ) ? excludeNonPatterns . contains ( name ) : excludeNonPatterns . contains ( name . toUpperCase ( ) ) ) { return true ; } for ( String excludePattern : excludePatterns ) { if ( matchPath ( excludePattern , name , isCaseSensitive ( ) ) ) { return true ; } } return false ; } protected boolean isSelected ( String name , File file ) throws Exception { if ( selectors != null ) { for ( FileSelector selector : selectors ) { if ( ! selector . isSelected ( idata , basedir , name , file ) ) { return false ; } } } return true ; } public synchronized String [ ] getIncludedFiles ( ) throws Exception { if ( filesIncluded == null ) { throw new Exception ( ) ; } String [ ] files = new String [ filesIncluded . size ( ) ] ; filesIncluded . copyInto ( files ) ; Arrays . sort ( files ) ; return files ; } public synchronized int getIncludedFilesCount ( ) throws Exception { if ( filesIncluded == null ) { throw new Exception ( ) ; } return filesIncluded . size ( ) ; } public synchronized String [ ] getNotIncludedFiles ( ) throws Exception { slowScan ( ) ; String [ ] files = new String [ filesNotIncluded . size ( ) ] ; filesNotIncluded . copyInto ( files ) ; return files ; } public synchronized String [ ] getExcludedFiles ( ) throws Exception { slowScan ( ) ; String [ ] files = new String [ filesExcluded . size ( ) ] ; filesExcluded . copyInto ( files ) ; return files ; } public synchronized String [ ] getDeselectedFiles ( ) throws Exception { slowScan ( ) ; String [ ] files = new String [ filesDeselected . size ( ) ] ; filesDeselected . copyInto ( files ) ; return files ; } public synchronized String [ ] getIncludedDirectories ( ) throws Exception { if ( dirsIncluded == null ) { throw new Exception ( ) ; } String [ ] directories = new String [ dirsIncluded . size ( ) ] ; dirsIncluded . copyInto ( directories ) ; Arrays . sort ( directories ) ; return directories ; } public synchronized int getIncludedDirsCount ( ) throws Exception { if ( dirsIncluded == null ) { throw new Exception ( ) ; } return dirsIncluded . size ( ) ; } public synchronized String [ ] getNotIncludedDirectories ( ) throws Exception { slowScan ( ) ; String [ ] directories = new String [ dirsNotIncluded . size ( ) ] ; dirsNotIncluded . copyInto ( directories ) ; return directories ; } public synchronized String [ ] getExcludedDirectories ( ) throws Exception { slowScan ( ) ; String [ ] directories = new String [ dirsExcluded . size ( ) ] ; dirsExcluded . copyInto ( directories ) ; return directories ; } public synchronized String [ ] getDeselectedDirectories ( ) throws Exception { slowScan ( ) ; String [ ] directories = new String [ dirsDeselected . size ( ) ] ; dirsDeselected . copyInto ( directories ) ; return directories ; } public synchronized void addDefaultExcludes ( ) { int excludesLength = excludes == null ? <NUM_LIT:0> : excludes . length ; String [ ] newExcludes ; newExcludes = new String [ excludesLength + defaultExcludes . size ( ) ] ; if ( excludesLength > <NUM_LIT:0> ) { System . arraycopy ( excludes , <NUM_LIT:0> , newExcludes , <NUM_LIT:0> , excludesLength ) ; } String [ ] defaultExcludesTemp = getDefaultExcludes ( ) ; for ( int i = <NUM_LIT:0> ; i < defaultExcludesTemp . length ; i ++ ) { newExcludes [ i + excludesLength ] = defaultExcludesTemp [ i ] . replace ( '<CHAR_LIT:/>' , File . separatorChar ) . replace ( '<STR_LIT:\\>' , File . separatorChar ) ; } excludes = newExcludes ; } public synchronized Resource getResource ( String name ) throws Exception { File f = FILE_UTILS . resolveFile ( basedir , name ) ; return new Resource ( name , f . exists ( ) , f . lastModified ( ) , f . isDirectory ( ) , f . length ( ) ) ; } private String [ ] list ( File file ) { String [ ] files = fileListMap . get ( file ) ; if ( files == null ) { files = file . list ( ) ; if ( files != null ) { fileListMap . put ( file , files ) ; } } return files ; } private File findFile ( File base , String path , boolean cs ) throws Exception { return findFile ( base , SelectorUtils . tokenizePath ( path ) , cs ) ; } private File findFile ( File base , Vector < String > pathElements , boolean cs ) throws Exception { if ( pathElements . size ( ) == <NUM_LIT:0> ) { return base ; } if ( ! base . isDirectory ( ) ) { return null ; } String [ ] files = list ( base ) ; if ( files == null ) { throw new Exception ( "<STR_LIT>" + base . getAbsolutePath ( ) ) ; } String current = pathElements . remove ( <NUM_LIT:0> ) ; boolean [ ] matchCase = cs ? CS_SCAN_ONLY : CS_THEN_NON_CS ; for ( boolean aMatchCase : matchCase ) { for ( String file : files ) { if ( aMatchCase ? file . equals ( current ) : file . equalsIgnoreCase ( current ) ) { return findFile ( new File ( base , file ) , pathElements , cs ) ; } } } return null ; } private boolean isSymlink ( File base , String path ) { return isSymlink ( base , SelectorUtils . tokenizePath ( path ) ) ; } private boolean isSymlink ( File base , Vector < String > pathElements ) { if ( pathElements . size ( ) > <NUM_LIT:0> ) { String current = pathElements . remove ( <NUM_LIT:0> ) ; try { return FILE_UTILS . isSymbolicLink ( base , current ) || isSymlink ( new File ( base , current ) , pathElements ) ; } catch ( IOException ioe ) { String msg = "<STR_LIT>" + "<STR_LIT>" ; System . err . println ( msg ) ; } } return false ; } private boolean hasBeenScanned ( String vpath ) { return ! scannedDirs . add ( vpath ) ; } Set < String > getScannedDirs ( ) { return scannedDirs ; } private synchronized void clearCaches ( ) { fileListMap . clear ( ) ; includeNonPatterns . clear ( ) ; excludeNonPatterns . clear ( ) ; includePatterns = null ; excludePatterns = null ; areNonPatternSetsReady = false ; } private synchronized void ensureNonPatternSetsReady ( ) { if ( ! areNonPatternSetsReady ) { includePatterns = fillNonPatternSet ( includeNonPatterns , includes ) ; excludePatterns = fillNonPatternSet ( excludeNonPatterns , excludes ) ; areNonPatternSetsReady = true ; } } private String [ ] fillNonPatternSet ( Set < String > set , String [ ] patterns ) { ArrayList < String > al = new ArrayList < String > ( patterns . length ) ; for ( String pattern : patterns ) { if ( ! SelectorUtils . hasWildcards ( pattern ) ) { set . add ( isCaseSensitive ( ) ? pattern : pattern . toUpperCase ( ) ) ; } else { al . add ( pattern ) ; } } return set . size ( ) == <NUM_LIT:0> ? patterns : al . toArray ( new String [ al . size ( ) ] ) ; } } </s>
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Name . UNIX ; import java . io . File ; import java . io . FilenameFilter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . StringWriter ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Iterator ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . handler . AbstractUIHandler ; import com . izforge . izpack . data . ExecutableFile ; public class FileExecutor { private static final Logger logger = Logger . getLogger ( FileExecutor . class . getName ( ) ) ; private static final String JAR_FILE_SUFFIX = "<STR_LIT>" ; private boolean stopThread ( Thread t , MonitorInputStream monitorInputStream ) { monitorInputStream . doStop ( ) ; long softTimeout = <NUM_LIT:1000> ; try { t . join ( softTimeout ) ; } catch ( InterruptedException e ) { } if ( ! t . isAlive ( ) ) { return true ; } t . interrupt ( ) ; long hardTimeout = <NUM_LIT:1000> ; try { t . join ( hardTimeout ) ; } catch ( InterruptedException e ) { } return ! t . isAlive ( ) ; } public FileExecutor ( Collection < ExecutableFile > files ) { this . files = files ; } public FileExecutor ( ) { this . files = null ; } public static String getExecOutput ( String [ ] aCommandLine ) { return getExecOutput ( aCommandLine , null , false ) ; } public static String getExecOutput ( String [ ] aCommandLine , String dir ) { return getExecOutput ( aCommandLine , dir , false ) ; } public static String getExecOutput ( String [ ] aCommandLine , boolean forceToGetStdOut ) { return getExecOutput ( aCommandLine , null , forceToGetStdOut ) ; } public static String getExecOutput ( String [ ] aCommandLine , String dir , boolean forceToGetStdOut ) { FileExecutor fileExecutor = new FileExecutor ( ) ; String [ ] execOut = new String [ <NUM_LIT:2> ] ; int execResult = fileExecutor . executeCommand ( aCommandLine , execOut , dir ) ; if ( execResult == <NUM_LIT:0> ) { return execOut [ <NUM_LIT:0> ] ; } else if ( forceToGetStdOut ) { return execOut [ <NUM_LIT:0> ] ; } else { return execOut [ <NUM_LIT:1> ] ; } } public int executeCommand ( String [ ] params , String [ ] output ) { return executeCommand ( params , output , null ) ; } public int executeCommand ( String [ ] params , String [ ] output , String dir ) { StringBuilder retval = new StringBuilder ( ) ; retval . append ( "<STR_LIT>" ) ; if ( params != null ) { for ( String param : params ) { retval . append ( "<STR_LIT>" ) . append ( param ) ; retval . append ( "<STR_LIT:n>" ) ; } } if ( dir != null ) { retval . append ( "<STR_LIT>" ) . append ( dir ) . append ( "<STR_LIT:n>" ) ; } Process process = null ; MonitorInputStream outMonitor = null ; MonitorInputStream errMonitor = null ; Thread outMonitorThread = null ; Thread errMonitorThread = null ; int exitStatus = - <NUM_LIT:1> ; logger . fine ( retval . toString ( ) ) ; try { if ( params [ <NUM_LIT:0> ] . matches ( "<STR_LIT>" ) ) { params [ <NUM_LIT:0> ] = new File ( params [ <NUM_LIT:0> ] ) . getCanonicalPath ( ) ; } if ( dir != null ) { if ( dir . matches ( "<STR_LIT>" ) ) { dir = new File ( dir ) . getCanonicalPath ( ) ; } process = Runtime . getRuntime ( ) . exec ( params , null , new File ( dir ) ) ; } else { process = Runtime . getRuntime ( ) . exec ( params ) ; } StringWriter outWriter = new StringWriter ( ) ; StringWriter errWriter = new StringWriter ( ) ; InputStreamReader outStreamReader = new InputStreamReader ( process . getInputStream ( ) ) ; InputStreamReader errStreamReader = new InputStreamReader ( process . getErrorStream ( ) ) ; outMonitor = new MonitorInputStream ( outStreamReader , outWriter ) ; errMonitor = new MonitorInputStream ( errStreamReader , errWriter ) ; outMonitorThread = new Thread ( outMonitor ) ; errMonitorThread = new Thread ( errMonitor ) ; outMonitorThread . setDaemon ( true ) ; errMonitorThread . setDaemon ( true ) ; outMonitorThread . start ( ) ; errMonitorThread . start ( ) ; exitStatus = process . waitFor ( ) ; outMonitorThread . join ( ) ; errMonitorThread . join ( ) ; output [ <NUM_LIT:0> ] = outWriter . toString ( ) ; logger . fine ( "<STR_LIT>" ) ; logger . fine ( output [ <NUM_LIT:0> ] ) ; output [ <NUM_LIT:1> ] = errWriter . toString ( ) ; logger . fine ( "<STR_LIT>" ) ; logger . fine ( output [ <NUM_LIT:1> ] ) ; logger . fine ( "<STR_LIT>" + Integer . toString ( exitStatus ) ) ; } catch ( InterruptedException e ) { logger . log ( Level . FINE , e . toString ( ) , e ) ; stopThread ( outMonitorThread , outMonitor ) ; stopThread ( errMonitorThread , errMonitor ) ; output [ <NUM_LIT:0> ] = "<STR_LIT>" ; output [ <NUM_LIT:1> ] = e . getMessage ( ) + "<STR_LIT:n>" ; } catch ( IOException e ) { logger . log ( Level . WARNING , e . toString ( ) , e ) ; output [ <NUM_LIT:0> ] = "<STR_LIT>" ; output [ <NUM_LIT:1> ] = e . getMessage ( ) + "<STR_LIT:n>" ; } finally { if ( process != null ) { process . destroy ( ) ; } } return exitStatus ; } public int executeFiles ( int currentStage , PlatformModelMatcher matcher , AbstractUIHandler handler ) { int exitStatus = <NUM_LIT:0> ; String [ ] output = new String [ <NUM_LIT:2> ] ; String permissions = "<STR_LIT>" ; boolean isUnix = matcher . getCurrentPlatform ( ) . isA ( UNIX ) ; Iterator < ExecutableFile > efileIterator = this . files . iterator ( ) ; while ( exitStatus == <NUM_LIT:0> && efileIterator . hasNext ( ) ) { ExecutableFile efile = efileIterator . next ( ) ; boolean deleteAfterwards = ! efile . keepFile ; File file = new File ( efile . path ) ; logger . fine ( "<STR_LIT>" + efile ) ; if ( ! matcher . matchesCurrentPlatform ( efile . osList ) ) { continue ; } if ( ExecutableFile . BIN == efile . type && currentStage != ExecutableFile . UNINSTALL && isUnix ) { logger . fine ( "<STR_LIT>" ) ; String [ ] params = { "<STR_LIT>" , permissions , file . toString ( ) } ; exitStatus = executeCommand ( params , output ) ; if ( exitStatus != <NUM_LIT:0> ) { handler . emitWarning ( "<STR_LIT>" , "<STR_LIT>" + params [ <NUM_LIT:0> ] + "<STR_LIT:U+0020>" + params [ <NUM_LIT:1> ] + "<STR_LIT:U+0020>" + params [ <NUM_LIT:2> ] ) ; continue ; } } if ( ( exitStatus == <NUM_LIT:0> ) && ( ( currentStage == ExecutableFile . POSTINSTALL && efile . executionStage == ExecutableFile . POSTINSTALL ) || ( currentStage == ExecutableFile . UNINSTALL && efile . executionStage == ExecutableFile . UNINSTALL ) ) ) { List < String > paramList = new ArrayList < String > ( ) ; if ( ExecutableFile . BIN == efile . type ) { paramList . add ( file . toString ( ) ) ; } else if ( ExecutableFile . JAR == efile . type && null == efile . mainClass ) { paramList . add ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; paramList . add ( "<STR_LIT>" ) ; paramList . add ( file . toString ( ) ) ; } else if ( ExecutableFile . JAR == efile . type && null != efile . mainClass ) { paramList . add ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; paramList . add ( "<STR_LIT>" ) ; try { paramList . add ( buildClassPath ( file . toString ( ) ) ) ; } catch ( Exception e ) { exitStatus = - <NUM_LIT:1> ; logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; } paramList . add ( efile . mainClass ) ; } if ( null != efile . argList && ! efile . argList . isEmpty ( ) ) { paramList . addAll ( efile . argList ) ; } String [ ] params = new String [ paramList . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < paramList . size ( ) ; i ++ ) { params [ i ] = paramList . get ( i ) ; } exitStatus = executeCommand ( params , output ) ; if ( exitStatus != <NUM_LIT:0> ) { deleteAfterwards = false ; String message = output [ <NUM_LIT:0> ] + "<STR_LIT:n>" + output [ <NUM_LIT:1> ] ; if ( message . length ( ) == <NUM_LIT:1> ) { message = "<STR_LIT>" + file . toString ( ) + "<STR_LIT:.>" ; } if ( efile . onFailure == ExecutableFile . ABORT ) { handler . emitError ( "<STR_LIT>" + exitStatus , message ) ; } else if ( efile . onFailure == ExecutableFile . WARN ) { handler . emitWarning ( "<STR_LIT>" + exitStatus , message ) ; exitStatus = <NUM_LIT:0> ; } else if ( efile . onFailure == ExecutableFile . IGNORE ) { exitStatus = <NUM_LIT:0> ; } else { if ( handler . askQuestion ( "<STR_LIT>" , message + "<STR_LIT>" , AbstractUIHandler . CHOICES_YES_NO ) == AbstractUIHandler . ANSWER_YES ) { exitStatus = <NUM_LIT:0> ; } } } } if ( efile . executionStage == ExecutableFile . POSTINSTALL && deleteAfterwards ) { if ( file . canWrite ( ) ) { file . delete ( ) ; } } } return exitStatus ; } private String buildClassPath ( String targetFile ) throws Exception { StringBuilder classPath = new StringBuilder ( ) ; List < String > jars = new ArrayList < String > ( ) ; String rawClassPath = targetFile . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:;>" , "<STR_LIT:#>" ) . replaceAll ( "<STR_LIT::>" , "<STR_LIT:#>" ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ; String [ ] rawJars = rawClassPath . split ( "<STR_LIT:#>" ) ; for ( String rawJar : rawJars ) { File file = new File ( rawJar ) ; jars . add ( rawJar ) ; if ( file . isDirectory ( ) ) { String [ ] subDirJars = FileUtil . getFileNames ( rawJar , new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String name ) { return name . toLowerCase ( ) . endsWith ( JAR_FILE_SUFFIX ) ; } } ) ; if ( subDirJars != null ) { for ( String subDirJar : subDirJars ) { jars . add ( rawJar + File . separator + subDirJar ) ; } } } } Iterator < String > iter = jars . iterator ( ) ; if ( iter . hasNext ( ) ) { classPath . append ( iter . next ( ) ) ; } while ( iter . hasNext ( ) ) { classPath . append ( File . pathSeparatorChar ) . append ( iter . next ( ) ) ; } return classPath . toString ( ) ; } private Collection < ExecutableFile > files ; } </s>
<s> package com . izforge . izpack . util ; public class Base64 { public final static int NO_OPTIONS = <NUM_LIT:0> ; public final static int ENCODE = <NUM_LIT:1> ; public final static int DECODE = <NUM_LIT:0> ; public final static int GZIP = <NUM_LIT:2> ; public final static int DONT_GUNZIP = <NUM_LIT:4> ; public final static int DO_BREAK_LINES = <NUM_LIT:8> ; public final static int URL_SAFE = <NUM_LIT:16> ; public final static int ORDERED = <NUM_LIT:32> ; private final static int MAX_LINE_LENGTH = <NUM_LIT> ; private final static byte EQUALS_SIGN = ( byte ) '<CHAR_LIT:=>' ; private final static byte NEW_LINE = ( byte ) '<STR_LIT:\n>' ; private final static String PREFERRED_ENCODING = "<STR_LIT>" ; private final static byte WHITE_SPACE_ENC = - <NUM_LIT:5> ; private final static byte EQUALS_SIGN_ENC = - <NUM_LIT:1> ; private final static byte [ ] _STANDARD_ALPHABET = { ( byte ) '<CHAR_LIT:A>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:Z>' , ( byte ) '<CHAR_LIT:a>' , ( byte ) '<CHAR_LIT:b>' , ( byte ) '<CHAR_LIT:c>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:e>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:0>' , ( byte ) '<CHAR_LIT:1>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:9>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:/>' } ; private final static byte [ ] _STANDARD_DECODABET = { - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:1> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:31> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> } ; private final static byte [ ] _URL_SAFE_ALPHABET = { ( byte ) '<CHAR_LIT:A>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:Z>' , ( byte ) '<CHAR_LIT:a>' , ( byte ) '<CHAR_LIT:b>' , ( byte ) '<CHAR_LIT:c>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:e>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:0>' , ( byte ) '<CHAR_LIT:1>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:9>' , ( byte ) '<CHAR_LIT:->' , ( byte ) '<CHAR_LIT:_>' } ; private final static byte [ ] _URL_SAFE_DECODABET = { - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:1> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , - <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:31> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> } ; private final static byte [ ] _ORDERED_ALPHABET = { ( byte ) '<CHAR_LIT:->' , ( byte ) '<CHAR_LIT:0>' , ( byte ) '<CHAR_LIT:1>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:9>' , ( byte ) '<CHAR_LIT:A>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:Z>' , ( byte ) '<CHAR_LIT:_>' , ( byte ) '<CHAR_LIT:a>' , ( byte ) '<CHAR_LIT:b>' , ( byte ) '<CHAR_LIT:c>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT:e>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' , ( byte ) '<CHAR_LIT>' } ; private final static byte [ ] _ORDERED_DECODABET = { - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:5> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT:0> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:1> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:31> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , <NUM_LIT> , - <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> , - <NUM_LIT:9> } ; private final static byte [ ] getAlphabet ( int options ) { if ( ( options & URL_SAFE ) == URL_SAFE ) { return _URL_SAFE_ALPHABET ; } else if ( ( options & ORDERED ) == ORDERED ) { return _ORDERED_ALPHABET ; } else { return _STANDARD_ALPHABET ; } } private final static byte [ ] getDecodabet ( int options ) { if ( ( options & URL_SAFE ) == URL_SAFE ) { return _URL_SAFE_DECODABET ; } else if ( ( options & ORDERED ) == ORDERED ) { return _ORDERED_DECODABET ; } else { return _STANDARD_DECODABET ; } } private Base64 ( ) { } private static byte [ ] encode3to4 ( byte [ ] b4 , byte [ ] threeBytes , int numSigBytes , int options ) { encode3to4 ( threeBytes , <NUM_LIT:0> , numSigBytes , b4 , <NUM_LIT:0> , options ) ; return b4 ; } private static byte [ ] encode3to4 ( byte [ ] source , int srcOffset , int numSigBytes , byte [ ] destination , int destOffset , int options ) { byte [ ] ALPHABET = getAlphabet ( options ) ; int inBuff = ( numSigBytes > <NUM_LIT:0> ? ( ( source [ srcOffset ] << <NUM_LIT:24> ) > > > <NUM_LIT:8> ) : <NUM_LIT:0> ) | ( numSigBytes > <NUM_LIT:1> ? ( ( source [ srcOffset + <NUM_LIT:1> ] << <NUM_LIT:24> ) > > > <NUM_LIT:16> ) : <NUM_LIT:0> ) | ( numSigBytes > <NUM_LIT:2> ? ( ( source [ srcOffset + <NUM_LIT:2> ] << <NUM_LIT:24> ) > > > <NUM_LIT:24> ) : <NUM_LIT:0> ) ; switch ( numSigBytes ) { case <NUM_LIT:3> : destination [ destOffset ] = ALPHABET [ ( inBuff > > > <NUM_LIT> ) ] ; destination [ destOffset + <NUM_LIT:1> ] = ALPHABET [ ( inBuff > > > <NUM_LIT:12> ) & <NUM_LIT> ] ; destination [ destOffset + <NUM_LIT:2> ] = ALPHABET [ ( inBuff > > > <NUM_LIT:6> ) & <NUM_LIT> ] ; destination [ destOffset + <NUM_LIT:3> ] = ALPHABET [ ( inBuff ) & <NUM_LIT> ] ; return destination ; case <NUM_LIT:2> : destination [ destOffset ] = ALPHABET [ ( inBuff > > > <NUM_LIT> ) ] ; destination [ destOffset + <NUM_LIT:1> ] = ALPHABET [ ( inBuff > > > <NUM_LIT:12> ) & <NUM_LIT> ] ; destination [ destOffset + <NUM_LIT:2> ] = ALPHABET [ ( inBuff > > > <NUM_LIT:6> ) & <NUM_LIT> ] ; destination [ destOffset + <NUM_LIT:3> ] = EQUALS_SIGN ; return destination ; case <NUM_LIT:1> : destination [ destOffset ] = ALPHABET [ ( inBuff > > > <NUM_LIT> ) ] ; destination [ destOffset + <NUM_LIT:1> ] = ALPHABET [ ( inBuff > > > <NUM_LIT:12> ) & <NUM_LIT> ] ; destination [ destOffset + <NUM_LIT:2> ] = EQUALS_SIGN ; destination [ destOffset + <NUM_LIT:3> ] = EQUALS_SIGN ; return destination ; default : return destination ; } } public static void encode ( java . nio . ByteBuffer raw , java . nio . ByteBuffer encoded ) { byte [ ] raw3 = new byte [ <NUM_LIT:3> ] ; byte [ ] enc4 = new byte [ <NUM_LIT:4> ] ; while ( raw . hasRemaining ( ) ) { int rem = Math . min ( <NUM_LIT:3> , raw . remaining ( ) ) ; raw . get ( raw3 , <NUM_LIT:0> , rem ) ; Base64 . encode3to4 ( enc4 , raw3 , rem , Base64 . NO_OPTIONS ) ; encoded . put ( enc4 ) ; } } public static void encode ( java . nio . ByteBuffer raw , java . nio . CharBuffer encoded ) { byte [ ] raw3 = new byte [ <NUM_LIT:3> ] ; byte [ ] enc4 = new byte [ <NUM_LIT:4> ] ; while ( raw . hasRemaining ( ) ) { int rem = Math . min ( <NUM_LIT:3> , raw . remaining ( ) ) ; raw . get ( raw3 , <NUM_LIT:0> , rem ) ; Base64 . encode3to4 ( enc4 , raw3 , rem , Base64 . NO_OPTIONS ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { encoded . put ( ( char ) ( enc4 [ i ] & <NUM_LIT> ) ) ; } } } public static String encodeObject ( java . io . Serializable serializableObject ) throws java . io . IOException { return encodeObject ( serializableObject , NO_OPTIONS ) ; } public static String encodeObject ( java . io . Serializable serializableObject , int options ) throws java . io . IOException { if ( serializableObject == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } java . io . ByteArrayOutputStream baos = null ; java . io . OutputStream b64os = null ; java . util . zip . GZIPOutputStream gzos = null ; java . io . ObjectOutputStream oos = null ; try { baos = new java . io . ByteArrayOutputStream ( ) ; b64os = new Base64 . OutputStream ( baos , ENCODE | options ) ; if ( ( options & GZIP ) != <NUM_LIT:0> ) { gzos = new java . util . zip . GZIPOutputStream ( b64os ) ; oos = new java . io . ObjectOutputStream ( gzos ) ; } else { oos = new java . io . ObjectOutputStream ( b64os ) ; } oos . writeObject ( serializableObject ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { oos . close ( ) ; } catch ( Exception e ) { } try { gzos . close ( ) ; } catch ( Exception e ) { } try { b64os . close ( ) ; } catch ( Exception e ) { } try { baos . close ( ) ; } catch ( Exception e ) { } } try { return new String ( baos . toByteArray ( ) , PREFERRED_ENCODING ) ; } catch ( java . io . UnsupportedEncodingException uue ) { return new String ( baos . toByteArray ( ) ) ; } } public static String encodeBytes ( byte [ ] source ) { String encoded = null ; try { encoded = encodeBytes ( source , <NUM_LIT:0> , source . length , NO_OPTIONS ) ; } catch ( java . io . IOException ex ) { assert false : ex . getMessage ( ) ; } assert encoded != null ; return encoded ; } public static String encodeBytes ( byte [ ] source , int options ) throws java . io . IOException { return encodeBytes ( source , <NUM_LIT:0> , source . length , options ) ; } public static String encodeBytes ( byte [ ] source , int off , int len ) { String encoded = null ; try { encoded = encodeBytes ( source , off , len , NO_OPTIONS ) ; } catch ( java . io . IOException ex ) { assert false : ex . getMessage ( ) ; } assert encoded != null ; return encoded ; } public static String encodeBytes ( byte [ ] source , int off , int len , int options ) throws java . io . IOException { byte [ ] encoded = encodeBytesToBytes ( source , off , len , options ) ; try { return new String ( encoded , PREFERRED_ENCODING ) ; } catch ( java . io . UnsupportedEncodingException uue ) { return new String ( encoded ) ; } } public static byte [ ] encodeBytesToBytes ( byte [ ] source ) { byte [ ] encoded = null ; try { encoded = encodeBytesToBytes ( source , <NUM_LIT:0> , source . length , Base64 . NO_OPTIONS ) ; } catch ( java . io . IOException ex ) { assert false : "<STR_LIT>" + ex . getMessage ( ) ; } return encoded ; } public static byte [ ] encodeBytesToBytes ( byte [ ] source , int off , int len , int options ) throws java . io . IOException { if ( source == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( off < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + off ) ; } if ( len < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + len ) ; } if ( off + len > source . length ) { throw new IllegalArgumentException ( String . format ( "<STR_LIT>" , off , len , source . length ) ) ; } if ( ( options & GZIP ) != <NUM_LIT:0> ) { java . io . ByteArrayOutputStream baos = null ; java . util . zip . GZIPOutputStream gzos = null ; Base64 . OutputStream b64os = null ; try { baos = new java . io . ByteArrayOutputStream ( ) ; b64os = new Base64 . OutputStream ( baos , ENCODE | options ) ; gzos = new java . util . zip . GZIPOutputStream ( b64os ) ; gzos . write ( source , off , len ) ; gzos . close ( ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { gzos . close ( ) ; } catch ( Exception e ) { } try { b64os . close ( ) ; } catch ( Exception e ) { } try { baos . close ( ) ; } catch ( Exception e ) { } } return baos . toByteArray ( ) ; } else { boolean breakLines = ( options & DO_BREAK_LINES ) > <NUM_LIT:0> ; int encLen = ( len / <NUM_LIT:3> ) * <NUM_LIT:4> + ( len % <NUM_LIT:3> > <NUM_LIT:0> ? <NUM_LIT:4> : <NUM_LIT:0> ) ; if ( breakLines ) { encLen += encLen / MAX_LINE_LENGTH ; } byte [ ] outBuff = new byte [ encLen ] ; int d = <NUM_LIT:0> ; int e = <NUM_LIT:0> ; int len2 = len - <NUM_LIT:2> ; int lineLength = <NUM_LIT:0> ; for ( ; d < len2 ; d += <NUM_LIT:3> , e += <NUM_LIT:4> ) { encode3to4 ( source , d + off , <NUM_LIT:3> , outBuff , e , options ) ; lineLength += <NUM_LIT:4> ; if ( breakLines && lineLength >= MAX_LINE_LENGTH ) { outBuff [ e + <NUM_LIT:4> ] = NEW_LINE ; e ++ ; lineLength = <NUM_LIT:0> ; } } if ( d < len ) { encode3to4 ( source , d + off , len - d , outBuff , e , options ) ; e += <NUM_LIT:4> ; } if ( e < outBuff . length - <NUM_LIT:1> ) { byte [ ] finalOut = new byte [ e ] ; System . arraycopy ( outBuff , <NUM_LIT:0> , finalOut , <NUM_LIT:0> , e ) ; return finalOut ; } else { return outBuff ; } } } private static int decode4to3 ( byte [ ] source , int srcOffset , byte [ ] destination , int destOffset , int options ) { if ( source == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( destination == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( srcOffset < <NUM_LIT:0> || srcOffset + <NUM_LIT:3> >= source . length ) { throw new IllegalArgumentException ( String . format ( "<STR_LIT>" , source . length , srcOffset ) ) ; } if ( destOffset < <NUM_LIT:0> || destOffset + <NUM_LIT:2> >= destination . length ) { throw new IllegalArgumentException ( String . format ( "<STR_LIT>" , destination . length , destOffset ) ) ; } byte [ ] DECODABET = getDecodabet ( options ) ; if ( source [ srcOffset + <NUM_LIT:2> ] == EQUALS_SIGN ) { int outBuff = ( ( DECODABET [ source [ srcOffset ] ] & <NUM_LIT> ) << <NUM_LIT> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:1> ] ] & <NUM_LIT> ) << <NUM_LIT:12> ) ; destination [ destOffset ] = ( byte ) ( outBuff > > > <NUM_LIT:16> ) ; return <NUM_LIT:1> ; } else if ( source [ srcOffset + <NUM_LIT:3> ] == EQUALS_SIGN ) { int outBuff = ( ( DECODABET [ source [ srcOffset ] ] & <NUM_LIT> ) << <NUM_LIT> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:1> ] ] & <NUM_LIT> ) << <NUM_LIT:12> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:2> ] ] & <NUM_LIT> ) << <NUM_LIT:6> ) ; destination [ destOffset ] = ( byte ) ( outBuff > > > <NUM_LIT:16> ) ; destination [ destOffset + <NUM_LIT:1> ] = ( byte ) ( outBuff > > > <NUM_LIT:8> ) ; return <NUM_LIT:2> ; } else { int outBuff = ( ( DECODABET [ source [ srcOffset ] ] & <NUM_LIT> ) << <NUM_LIT> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:1> ] ] & <NUM_LIT> ) << <NUM_LIT:12> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:2> ] ] & <NUM_LIT> ) << <NUM_LIT:6> ) | ( ( DECODABET [ source [ srcOffset + <NUM_LIT:3> ] ] & <NUM_LIT> ) ) ; destination [ destOffset ] = ( byte ) ( outBuff > > <NUM_LIT:16> ) ; destination [ destOffset + <NUM_LIT:1> ] = ( byte ) ( outBuff > > <NUM_LIT:8> ) ; destination [ destOffset + <NUM_LIT:2> ] = ( byte ) ( outBuff ) ; return <NUM_LIT:3> ; } } public static byte [ ] decode ( byte [ ] source ) { byte [ ] decoded = null ; try { decoded = decode ( source , <NUM_LIT:0> , source . length , Base64 . NO_OPTIONS ) ; } catch ( java . io . IOException ex ) { assert false : "<STR_LIT>" + ex . getMessage ( ) ; } return decoded ; } public static byte [ ] decode ( byte [ ] source , int off , int len , int options ) throws java . io . IOException { if ( source == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } if ( off < <NUM_LIT:0> || off + len > source . length ) { throw new IllegalArgumentException ( String . format ( "<STR_LIT>" , source . length , off , len ) ) ; } if ( len == <NUM_LIT:0> ) { return new byte [ <NUM_LIT:0> ] ; } else if ( len < <NUM_LIT:4> ) { throw new IllegalArgumentException ( "<STR_LIT>" + len ) ; } byte [ ] DECODABET = getDecodabet ( options ) ; int len34 = len * <NUM_LIT:3> / <NUM_LIT:4> ; byte [ ] outBuff = new byte [ len34 ] ; int outBuffPosn = <NUM_LIT:0> ; byte [ ] b4 = new byte [ <NUM_LIT:4> ] ; int b4Posn = <NUM_LIT:0> ; int i = <NUM_LIT:0> ; byte sbiCrop = <NUM_LIT:0> ; byte sbiDecode = <NUM_LIT:0> ; for ( i = off ; i < off + len ; i ++ ) { sbiCrop = ( byte ) ( source [ i ] & <NUM_LIT> ) ; sbiDecode = DECODABET [ sbiCrop ] ; if ( sbiDecode >= WHITE_SPACE_ENC ) { if ( sbiDecode >= EQUALS_SIGN_ENC ) { b4 [ b4Posn ++ ] = sbiCrop ; if ( b4Posn > <NUM_LIT:3> ) { outBuffPosn += decode4to3 ( b4 , <NUM_LIT:0> , outBuff , outBuffPosn , options ) ; b4Posn = <NUM_LIT:0> ; if ( sbiCrop == EQUALS_SIGN ) { break ; } } } } else { throw new java . io . IOException ( String . format ( "<STR_LIT>" , source [ i ] , i ) ) ; } } byte [ ] out = new byte [ outBuffPosn ] ; System . arraycopy ( outBuff , <NUM_LIT:0> , out , <NUM_LIT:0> , outBuffPosn ) ; return out ; } public static byte [ ] decode ( String s ) throws java . io . IOException { return decode ( s , NO_OPTIONS ) ; } public static byte [ ] decode ( String s , int options ) throws java . io . IOException { if ( s == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } byte [ ] bytes ; try { bytes = s . getBytes ( PREFERRED_ENCODING ) ; } catch ( java . io . UnsupportedEncodingException uee ) { bytes = s . getBytes ( ) ; } bytes = decode ( bytes , <NUM_LIT:0> , bytes . length , options ) ; boolean dontGunzip = ( options & DONT_GUNZIP ) != <NUM_LIT:0> ; if ( ( bytes != null ) && ( bytes . length >= <NUM_LIT:4> ) && ( ! dontGunzip ) ) { int head = ( ( int ) bytes [ <NUM_LIT:0> ] & <NUM_LIT> ) | ( ( bytes [ <NUM_LIT:1> ] << <NUM_LIT:8> ) & <NUM_LIT> ) ; if ( java . util . zip . GZIPInputStream . GZIP_MAGIC == head ) { java . io . ByteArrayInputStream bais = null ; java . util . zip . GZIPInputStream gzis = null ; java . io . ByteArrayOutputStream baos = null ; byte [ ] buffer = new byte [ <NUM_LIT> ] ; int length = <NUM_LIT:0> ; try { baos = new java . io . ByteArrayOutputStream ( ) ; bais = new java . io . ByteArrayInputStream ( bytes ) ; gzis = new java . util . zip . GZIPInputStream ( bais ) ; while ( ( length = gzis . read ( buffer ) ) >= <NUM_LIT:0> ) { baos . write ( buffer , <NUM_LIT:0> , length ) ; } bytes = baos . toByteArray ( ) ; } catch ( java . io . IOException e ) { e . printStackTrace ( ) ; } finally { try { baos . close ( ) ; } catch ( Exception e ) { } try { gzis . close ( ) ; } catch ( Exception e ) { } try { bais . close ( ) ; } catch ( Exception e ) { } } } } return bytes ; } public static Object decodeToObject ( String encodedObject ) throws java . io . IOException , java . lang . ClassNotFoundException { return decodeToObject ( encodedObject , NO_OPTIONS , null ) ; } public static Object decodeToObject ( String encodedObject , int options , final ClassLoader loader ) throws java . io . IOException , java . lang . ClassNotFoundException { byte [ ] objBytes = decode ( encodedObject , options ) ; java . io . ByteArrayInputStream bais = null ; java . io . ObjectInputStream ois = null ; Object obj = null ; try { bais = new java . io . ByteArrayInputStream ( objBytes ) ; if ( loader == null ) { ois = new java . io . ObjectInputStream ( bais ) ; } else { ois = new java . io . ObjectInputStream ( bais ) { @ Override public Class < ? > resolveClass ( java . io . ObjectStreamClass streamClass ) throws java . io . IOException , ClassNotFoundException { Class < ? > c = Class . forName ( streamClass . getName ( ) , false , loader ) ; if ( c == null ) { return super . resolveClass ( streamClass ) ; } else { return c ; } } } ; } obj = ois . readObject ( ) ; } catch ( java . io . IOException e ) { throw e ; } catch ( java . lang . ClassNotFoundException e ) { throw e ; } finally { try { bais . close ( ) ; } catch ( Exception e ) { } try { ois . close ( ) ; } catch ( Exception e ) { } } return obj ; } public static void encodeToFile ( byte [ ] dataToEncode , String filename ) throws java . io . IOException { if ( dataToEncode == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } Base64 . OutputStream bos = null ; try { bos = new Base64 . OutputStream ( new java . io . FileOutputStream ( filename ) , Base64 . ENCODE ) ; bos . write ( dataToEncode ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { bos . close ( ) ; } catch ( Exception e ) { } } } public static void decodeToFile ( String dataToDecode , String filename ) throws java . io . IOException { Base64 . OutputStream bos = null ; try { bos = new Base64 . OutputStream ( new java . io . FileOutputStream ( filename ) , Base64 . DECODE ) ; bos . write ( dataToDecode . getBytes ( PREFERRED_ENCODING ) ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { bos . close ( ) ; } catch ( Exception e ) { } } } public static byte [ ] decodeFromFile ( String filename ) throws java . io . IOException { byte [ ] decodedData = null ; Base64 . InputStream bis = null ; try { java . io . File file = new java . io . File ( filename ) ; byte [ ] buffer = null ; int length = <NUM_LIT:0> ; int numBytes = <NUM_LIT:0> ; if ( file . length ( ) > Integer . MAX_VALUE ) { throw new java . io . IOException ( "<STR_LIT>" + file . length ( ) + "<STR_LIT>" ) ; } buffer = new byte [ ( int ) file . length ( ) ] ; bis = new Base64 . InputStream ( new java . io . BufferedInputStream ( new java . io . FileInputStream ( file ) ) , Base64 . DECODE ) ; while ( ( numBytes = bis . read ( buffer , length , <NUM_LIT> ) ) >= <NUM_LIT:0> ) { length += numBytes ; } decodedData = new byte [ length ] ; System . arraycopy ( buffer , <NUM_LIT:0> , decodedData , <NUM_LIT:0> , length ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { bis . close ( ) ; } catch ( Exception e ) { } } return decodedData ; } public static String encodeFromFile ( String filename ) throws java . io . IOException { String encodedData = null ; Base64 . InputStream bis = null ; try { java . io . File file = new java . io . File ( filename ) ; byte [ ] buffer = new byte [ Math . max ( ( int ) ( file . length ( ) * <NUM_LIT> + <NUM_LIT:1> ) , <NUM_LIT> ) ] ; int length = <NUM_LIT:0> ; int numBytes = <NUM_LIT:0> ; bis = new Base64 . InputStream ( new java . io . BufferedInputStream ( new java . io . FileInputStream ( file ) ) , Base64 . ENCODE ) ; while ( ( numBytes = bis . read ( buffer , length , <NUM_LIT> ) ) >= <NUM_LIT:0> ) { length += numBytes ; } encodedData = new String ( buffer , <NUM_LIT:0> , length , Base64 . PREFERRED_ENCODING ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { bis . close ( ) ; } catch ( Exception e ) { } } return encodedData ; } public static void encodeFileToFile ( String infile , String outfile ) throws java . io . IOException { String encoded = Base64 . encodeFromFile ( infile ) ; java . io . OutputStream out = null ; try { out = new java . io . BufferedOutputStream ( new java . io . FileOutputStream ( outfile ) ) ; out . write ( encoded . getBytes ( "<STR_LIT>" ) ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { out . close ( ) ; } catch ( Exception ex ) { } } } public static void decodeFileToFile ( String infile , String outfile ) throws java . io . IOException { byte [ ] decoded = Base64 . decodeFromFile ( infile ) ; java . io . OutputStream out = null ; try { out = new java . io . BufferedOutputStream ( new java . io . FileOutputStream ( outfile ) ) ; out . write ( decoded ) ; } catch ( java . io . IOException e ) { throw e ; } finally { try { out . close ( ) ; } catch ( Exception ex ) { } } } public static class InputStream extends java . io . FilterInputStream { private boolean encode ; private int position ; private byte [ ] buffer ; private int bufferLength ; private int numSigBytes ; private int lineLength ; private boolean breakLines ; private int options ; private byte [ ] decodabet ; public InputStream ( java . io . InputStream in ) { this ( in , DECODE ) ; } public InputStream ( java . io . InputStream in , int options ) { super ( in ) ; this . options = options ; this . breakLines = ( options & DO_BREAK_LINES ) > <NUM_LIT:0> ; this . encode = ( options & ENCODE ) > <NUM_LIT:0> ; this . bufferLength = encode ? <NUM_LIT:4> : <NUM_LIT:3> ; this . buffer = new byte [ bufferLength ] ; this . position = - <NUM_LIT:1> ; this . lineLength = <NUM_LIT:0> ; this . decodabet = getDecodabet ( options ) ; } @ Override public int read ( ) throws java . io . IOException { if ( position < <NUM_LIT:0> ) { if ( encode ) { byte [ ] b3 = new byte [ <NUM_LIT:3> ] ; int numBinaryBytes = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { int b = in . read ( ) ; if ( b >= <NUM_LIT:0> ) { b3 [ i ] = ( byte ) b ; numBinaryBytes ++ ; } else { break ; } } if ( numBinaryBytes > <NUM_LIT:0> ) { encode3to4 ( b3 , <NUM_LIT:0> , numBinaryBytes , buffer , <NUM_LIT:0> , options ) ; position = <NUM_LIT:0> ; numSigBytes = <NUM_LIT:4> ; } else { return - <NUM_LIT:1> ; } } else { byte [ ] b4 = new byte [ <NUM_LIT:4> ] ; int i = <NUM_LIT:0> ; for ( i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { int b = <NUM_LIT:0> ; do { b = in . read ( ) ; } while ( b >= <NUM_LIT:0> && decodabet [ b & <NUM_LIT> ] <= WHITE_SPACE_ENC ) ; if ( b < <NUM_LIT:0> ) { break ; } b4 [ i ] = ( byte ) b ; } if ( i == <NUM_LIT:4> ) { numSigBytes = decode4to3 ( b4 , <NUM_LIT:0> , buffer , <NUM_LIT:0> , options ) ; position = <NUM_LIT:0> ; } else if ( i == <NUM_LIT:0> ) { return - <NUM_LIT:1> ; } else { throw new java . io . IOException ( "<STR_LIT>" ) ; } } } if ( position >= <NUM_LIT:0> ) { if ( position >= numSigBytes ) { return - <NUM_LIT:1> ; } if ( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) { lineLength = <NUM_LIT:0> ; return '<STR_LIT:\n>' ; } else { lineLength ++ ; int b = buffer [ position ++ ] ; if ( position >= bufferLength ) { position = - <NUM_LIT:1> ; } return b & <NUM_LIT> ; } } else { throw new java . io . IOException ( "<STR_LIT>" ) ; } } @ Override public int read ( byte [ ] dest , int off , int len ) throws java . io . IOException { int i ; int b ; for ( i = <NUM_LIT:0> ; i < len ; i ++ ) { b = read ( ) ; if ( b >= <NUM_LIT:0> ) { dest [ off + i ] = ( byte ) b ; } else if ( i == <NUM_LIT:0> ) { return - <NUM_LIT:1> ; } else { break ; } } return i ; } } public static class OutputStream extends java . io . FilterOutputStream { private boolean encode ; private int position ; private byte [ ] buffer ; private int bufferLength ; private int lineLength ; private boolean breakLines ; private byte [ ] b4 ; private boolean suspendEncoding ; private int options ; private byte [ ] decodabet ; public OutputStream ( java . io . OutputStream out ) { this ( out , ENCODE ) ; } public OutputStream ( java . io . OutputStream out , int options ) { super ( out ) ; this . breakLines = ( options & DO_BREAK_LINES ) != <NUM_LIT:0> ; this . encode = ( options & ENCODE ) != <NUM_LIT:0> ; this . bufferLength = encode ? <NUM_LIT:3> : <NUM_LIT:4> ; this . buffer = new byte [ bufferLength ] ; this . position = <NUM_LIT:0> ; this . lineLength = <NUM_LIT:0> ; this . suspendEncoding = false ; this . b4 = new byte [ <NUM_LIT:4> ] ; this . options = options ; this . decodabet = getDecodabet ( options ) ; } @ Override public void write ( int theByte ) throws java . io . IOException { if ( suspendEncoding ) { this . out . write ( theByte ) ; return ; } if ( encode ) { buffer [ position ++ ] = ( byte ) theByte ; if ( position >= bufferLength ) { this . out . write ( encode3to4 ( b4 , buffer , bufferLength , options ) ) ; lineLength += <NUM_LIT:4> ; if ( breakLines && lineLength >= MAX_LINE_LENGTH ) { this . out . write ( NEW_LINE ) ; lineLength = <NUM_LIT:0> ; } position = <NUM_LIT:0> ; } } else { if ( decodabet [ theByte & <NUM_LIT> ] > WHITE_SPACE_ENC ) { buffer [ position ++ ] = ( byte ) theByte ; if ( position >= bufferLength ) { int len = Base64 . decode4to3 ( buffer , <NUM_LIT:0> , b4 , <NUM_LIT:0> , options ) ; out . write ( b4 , <NUM_LIT:0> , len ) ; position = <NUM_LIT:0> ; } } else if ( decodabet [ theByte & <NUM_LIT> ] != WHITE_SPACE_ENC ) { throw new java . io . IOException ( "<STR_LIT>" ) ; } } } @ Override public void write ( byte [ ] theBytes , int off , int len ) throws java . io . IOException { if ( suspendEncoding ) { this . out . write ( theBytes , off , len ) ; return ; } for ( int i = <NUM_LIT:0> ; i < len ; i ++ ) { write ( theBytes [ off + i ] ) ; } } public void flushBase64 ( ) throws java . io . IOException { if ( position > <NUM_LIT:0> ) { if ( encode ) { out . write ( encode3to4 ( b4 , buffer , position , options ) ) ; position = <NUM_LIT:0> ; } else { throw new java . io . IOException ( "<STR_LIT>" ) ; } } } @ Override public void close ( ) throws java . io . IOException { flushBase64 ( ) ; super . close ( ) ; buffer = null ; out = null ; } public void suspendEncoding ( ) throws java . io . IOException { flushBase64 ( ) ; this . suspendEncoding = true ; } public void resumeEncoding ( ) { this . suspendEncoding = false ; } } } </s>
<s> package com . izforge . izpack . util ; public interface NativeLibraryClient { public void freeLibrary ( String name ) ; } </s>
<s> package com . izforge . izpack . util ; import static com . izforge . izpack . util . Platform . Name . MAC_OSX ; import static com . izforge . izpack . util . Platform . Name . UNIX ; import static com . izforge . izpack . util . Platform . Name . WINDOWS ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . net . URI ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; public class PrivilegedRunner { private final Platform platform ; private static final Logger logger = Logger . getLogger ( PrivilegedRunner . class . getName ( ) ) ; public PrivilegedRunner ( Platform platform ) { this . platform = platform ; } public boolean isPlatformSupported ( ) { return platform . isA ( UNIX ) || platform . isA ( WINDOWS ) ; } public boolean isElevationNeeded ( ) { return isElevationNeeded ( null ) ; } public boolean isElevationNeeded ( String path ) { boolean result ; if ( platform . isA ( WINDOWS ) ) { if ( path != null ) { path = new File ( path ) . getParent ( ) ; } if ( path == null || path . trim ( ) . length ( ) == <NUM_LIT:0> ) { path = getProgramFiles ( ) ; } result = ! isPrivilegedMode ( ) && ! canWrite ( path ) ; } else { if ( path != null ) { result = ! canWrite ( path ) ; } else { result = ! System . getProperty ( "<STR_LIT>" ) . equals ( "<STR_LIT:root>" ) ; } } return result ; } public int relaunchWithElevatedRights ( ) throws IOException , InterruptedException { String javaCommand = getJavaCommand ( ) ; String installer = getInstallerJar ( ) ; ProcessBuilder builder = new ProcessBuilder ( getElevator ( javaCommand , installer ) ) ; if ( logger . isLoggable ( Level . INFO ) ) { logger . info ( "<STR_LIT>" + StringTool . listToString ( builder . command ( ) , "<STR_LIT:U+0020>" ) ) ; } builder . environment ( ) . put ( "<STR_LIT>" , "<STR_LIT>" ) ; Process process = builder . start ( ) ; return process . waitFor ( ) ; } public static boolean isPrivilegedMode ( ) { return "<STR_LIT>" . equals ( System . getenv ( "<STR_LIT>" ) ) || "<STR_LIT>" . equals ( System . getProperty ( "<STR_LIT>" ) ) ; } protected List < String > getElevator ( String javaCommand , String installer ) throws IOException { List < String > jvmArgs = new JVMHelper ( ) . getJVMArguments ( ) ; List < String > elevator = new ArrayList < String > ( ) ; if ( platform . isA ( MAC_OSX ) ) { elevator . add ( extractMacElevator ( ) . getCanonicalPath ( ) ) ; elevator . add ( javaCommand ) ; elevator . addAll ( jvmArgs ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( installer ) ; } else if ( platform . isA ( UNIX ) ) { elevator . add ( "<STR_LIT>" ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( javaCommand ) ; elevator . addAll ( jvmArgs ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( installer ) ; } else if ( platform . isA ( WINDOWS ) ) { elevator . add ( "<STR_LIT>" ) ; elevator . add ( extractVistaElevator ( ) . getCanonicalPath ( ) ) ; elevator . add ( javaCommand ) ; elevator . addAll ( jvmArgs ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( "<STR_LIT>" ) ; elevator . add ( installer ) ; } return elevator ; } protected File extractVistaElevator ( ) throws IOException { String path = System . getProperty ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" ; File elevator = new File ( path ) ; FileOutputStream out = new FileOutputStream ( elevator ) ; InputStream in = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; copyStream ( out , in ) ; in . close ( ) ; out . close ( ) ; elevator . deleteOnExit ( ) ; return elevator ; } protected File extractMacElevator ( ) throws IOException { String path = System . getProperty ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" ; File elevator = new File ( path ) ; FileOutputStream out = new FileOutputStream ( elevator ) ; InputStream in = getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ; copyStream ( out , in ) ; in . close ( ) ; out . close ( ) ; if ( ! elevator . setExecutable ( true ) ) { throw new IOException ( "<STR_LIT>" + path ) ; } elevator . deleteOnExit ( ) ; return elevator ; } private void copyStream ( OutputStream out , InputStream in ) throws IOException { byte [ ] buffer = new byte [ <NUM_LIT> ] ; int bytesRead ; while ( ( bytesRead = in . read ( buffer ) ) >= <NUM_LIT:0> ) { out . write ( buffer , <NUM_LIT:0> , bytesRead ) ; } } private String getInstallerJar ( ) { try { URI uri = getClass ( ) . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . toURI ( ) ; if ( ! "<STR_LIT:file>" . equals ( uri . getScheme ( ) ) ) { throw new Exception ( "<STR_LIT>" + uri ) ; } return new File ( uri . getSchemeSpecificPart ( ) ) . getCanonicalPath ( ) ; } catch ( Exception e ) { logger . log ( Level . INFO , e . getMessage ( ) , e ) ; } return null ; } private String getJavaCommand ( ) { return System . getProperty ( "<STR_LIT>" ) + File . separator + "<STR_LIT>" + File . separator + getJavaExecutable ( ) ; } private String getJavaExecutable ( ) { if ( platform . isA ( WINDOWS ) ) { return "<STR_LIT>" ; } else { return "<STR_LIT>" ; } } private boolean canWrite ( String path ) { File file = new File ( path ) ; boolean canWrite = file . canWrite ( ) ; if ( canWrite ) { try { File test = File . createTempFile ( "<STR_LIT>" , null , file ) ; if ( ! test . delete ( ) ) { test . deleteOnExit ( ) ; } } catch ( IOException exception ) { canWrite = false ; } } return canWrite ; } private String getProgramFiles ( ) { String path = System . getenv ( "<STR_LIT>" ) ; if ( path == null ) { path = "<STR_LIT>" ; } return path ; } } </s>
<s> package com . izforge . izpack . util ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import com . izforge . izpack . api . data . binding . OsModel ; public class PlatformModelMatcher { private final Platforms platforms ; private final Platform platform ; private static final Logger logger = Logger . getLogger ( PlatformModelMatcher . class . getName ( ) ) ; public PlatformModelMatcher ( Platforms platforms , Platform platform ) { this . platforms = platforms ; this . platform = platform ; } public Platform getCurrentPlatform ( ) { return platform ; } public boolean matchesCurrentPlatform ( OsModel model ) { return match ( platform , model ) ; } public boolean match ( Platform platform , OsModel model ) { boolean match = true ; if ( model . getArch ( ) != null && model . getArch ( ) . length ( ) != <NUM_LIT:0> ) { Platform . Arch arch = platforms . getArch ( model . getArch ( ) ) ; match = arch . equals ( platform . getArch ( ) ) ; } if ( match && ( model . getVersion ( ) != null ) && ( model . getVersion ( ) . length ( ) != <NUM_LIT:0> ) ) { match = platform . getVersion ( ) != null && platform . getVersion ( ) . equals ( model . getVersion ( ) ) ; } if ( match && ( model . getName ( ) != null ) && ( model . getName ( ) . length ( ) != <NUM_LIT:0> ) ) { Platform . Name name = platforms . getName ( model . getName ( ) ) ; match = name . equals ( platform . getName ( ) ) ; } if ( match && ( model . getFamily ( ) != null ) ) { Platform . Name family = platforms . getName ( model . getFamily ( ) ) ; match = platform . getName ( ) . isA ( family ) ; } if ( match && ( model . getJre ( ) != null ) && ( model . getJre ( ) . length ( ) > <NUM_LIT:0> ) ) { match = platform . getJavaVersion ( ) != null && platform . getJavaVersion ( ) . startsWith ( model . getJre ( ) ) ; } return match && ( ( model . getFamily ( ) != null ) || ( model . getName ( ) != null ) || ( model . getVersion ( ) != null ) || ( model . getArch ( ) != null ) || ( model . getJre ( ) != null ) ) ; } public boolean matchesCurrentPlatform ( List < OsModel > models ) { return matches ( platform , models ) ; } public boolean matches ( Platform platform , List < OsModel > models ) { if ( models == null || models . isEmpty ( ) ) { return true ; } boolean log = logger . isLoggable ( Level . FINE ) ; for ( OsModel model : models ) { if ( log ) { logger . fine ( "<STR_LIT>" + model + "<STR_LIT>" + platform ) ; } if ( match ( platform , model ) ) { if ( log ) { logger . fine ( "<STR_LIT>" ) ; } return true ; } } if ( log ) { logger . fine ( "<STR_LIT>" + platform ) ; } return false ; } } </s>
<s> package com . izforge . izpack . util ; import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . FilterOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; import java . util . StringTokenizer ; import java . util . zip . ZipEntry ; import java . util . zip . ZipException ; import java . util . zip . ZipInputStream ; import org . apache . tools . zip . ZipOutputStream ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . substitutor . SubstitutionType ; import com . izforge . izpack . api . substitutor . VariableSubstitutor ; public class IoHelper { private static final String MASKED_SLASH_PLACEHOLDER = "<STR_LIT>" ; private static Properties envVars = null ; private IoHelper ( ) { } public static void copyFile ( String inFile , String outFile ) throws IOException { copyFile ( new File ( inFile ) , new File ( outFile ) ) ; } public static void copyFile ( File inFile , File outFile ) throws IOException { copyFile ( inFile , outFile , null , null ) ; } public static void copyFile ( File inFile , File outFile , String permissions ) throws IOException { copyFile ( inFile , outFile , permissions , null ) ; } public static void copyFile ( File inFile , File outFile , VariableSubstitutor vss ) throws IOException { copyFile ( inFile , outFile , null , vss ) ; } public static void copyFile ( File inFile , File outFile , String permissions , VariableSubstitutor vs ) throws IOException { copyFile ( inFile , outFile , permissions , vs , null ) ; } public static void copyFile ( File inFile , File outFile , String permissions , VariableSubstitutor vs , SubstitutionType type ) throws IOException { FileOutputStream out = new FileOutputStream ( outFile ) ; FileInputStream in = new FileInputStream ( inFile ) ; copyStream ( in , out , vs , type ) ; if ( permissions != null && IoHelper . supported ( "<STR_LIT>" ) ) { chmod ( outFile . getAbsolutePath ( ) , permissions ) ; } } public static void copyStream ( InputStream in , OutputStream out , VariableSubstitutor vs , SubstitutionType type ) throws IOException { if ( vs == null ) { byte [ ] buffer = new byte [ <NUM_LIT> ] ; long bytesCopied = <NUM_LIT:0> ; int bytesInBuffer ; while ( ( bytesInBuffer = in . read ( buffer ) ) != - <NUM_LIT:1> ) { out . write ( buffer , <NUM_LIT:0> , bytesInBuffer ) ; bytesCopied += bytesInBuffer ; } in . close ( ) ; out . close ( ) ; } else { BufferedInputStream bin = new BufferedInputStream ( in , <NUM_LIT> ) ; BufferedOutputStream bout = new BufferedOutputStream ( out , <NUM_LIT> ) ; try { vs . substitute ( bin , bout , type , null ) ; } catch ( Exception e ) { throw new IOException ( "<STR_LIT>" + e . getMessage ( ) + "<STR_LIT:)>" ) ; } bin . close ( ) ; bout . close ( ) ; } } public static File copyToTempFile ( File template , String defaultExtension ) throws IOException { return copyToTempFile ( template , defaultExtension , null ) ; } public static File copyToTempFile ( InputStream is , String ext , VariableSubstitutor vss ) throws IOException { File tmpFile = File . createTempFile ( "<STR_LIT>" , ext ) ; tmpFile . deleteOnExit ( ) ; IoHelper . copyStream ( is , new FileOutputStream ( tmpFile ) , vss , null ) ; return tmpFile ; } public static File copyToTempFile ( File template , String defaultExtension , VariableSubstitutor vss ) throws IOException { String path = template . getCanonicalPath ( ) ; int pos = path . lastIndexOf ( '<CHAR_LIT:.>' ) ; String ext = path . substring ( pos ) ; if ( ext == null ) { ext = defaultExtension ; } File tmpFile = File . createTempFile ( "<STR_LIT>" , ext ) ; tmpFile . deleteOnExit ( ) ; IoHelper . copyFile ( template , tmpFile , vss ) ; return tmpFile ; } public static File copyToTempFile ( String template , String defaultExtension ) throws IOException { return copyToTempFile ( new File ( template ) , defaultExtension ) ; } public static void chmod ( File file , String permissions ) throws IOException { chmod ( file . getAbsolutePath ( ) , permissions ) ; } public static void chmod ( String path , String permissions ) throws IOException { if ( OsVersion . IS_UNIX ) { String [ ] params = { "<STR_LIT>" , permissions , path } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; } else { throw new IOException ( "<STR_LIT>" + OsVersion . OS_NAME + "<STR_LIT:.>" ) ; } } public static long getFreeSpace ( String path ) { long retval = - <NUM_LIT:1> ; if ( OsVersion . IS_WINDOWS ) { String command = "<STR_LIT>" ; if ( System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . contains ( "<STR_LIT>" ) ) { return ( - <NUM_LIT:1> ) ; } String [ ] params = { command , "<STR_LIT>" , "<STR_LIT>" + path + "<STR_LIT>" } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; retval = extractLong ( output [ <NUM_LIT:0> ] , - <NUM_LIT:3> , <NUM_LIT:3> , "<STR_LIT:%>" ) ; } else if ( OsVersion . IS_SUNOS ) { String [ ] params = { "<STR_LIT>" , "<STR_LIT>" , path } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; retval = extractLong ( output [ <NUM_LIT:0> ] , - <NUM_LIT:3> , <NUM_LIT:3> , "<STR_LIT:%>" ) * <NUM_LIT> ; } else if ( OsVersion . IS_HPUX ) { String [ ] params = { "<STR_LIT>" , path } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; retval = extractLong ( output [ <NUM_LIT:0> ] , - <NUM_LIT:3> , <NUM_LIT:3> , "<STR_LIT:%>" ) * <NUM_LIT> ; } else if ( OsVersion . IS_UNIX ) { String [ ] params = { "<STR_LIT>" , "<STR_LIT>" , path } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; retval = extractLong ( output [ <NUM_LIT:0> ] , - <NUM_LIT:3> , <NUM_LIT:3> , "<STR_LIT:%>" ) * <NUM_LIT> ; } return retval ; } public static boolean supported ( String method ) { if ( "<STR_LIT>" . equals ( method ) ) { if ( OsVersion . IS_UNIX ) { return true ; } if ( OsVersion . IS_WINDOWS ) { if ( System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . contains ( "<STR_LIT>" ) ) { return ( false ) ; } return ( true ) ; } } else if ( "<STR_LIT>" . equals ( method ) ) { if ( OsVersion . IS_UNIX ) { return true ; } } else if ( "<STR_LIT>" . equals ( method ) ) { return true ; } else if ( "<STR_LIT>" . equals ( method ) ) { if ( OsVersion . IS_UNIX ) { return true ; } } else if ( "<STR_LIT>" . equals ( method ) ) { return true ; } else { throw new RuntimeException ( "<STR_LIT>" + method + "<STR_LIT>" ) ; } return false ; } public static File existingParent ( File path ) { File result = path ; while ( ! result . exists ( ) ) { if ( result . getParent ( ) == null ) { return result ; } result = result . getParentFile ( ) ; } return result ; } private static long extractLong ( String in , int assumedPlace , int halfRange , String useNotIdentifier ) { long retval = - <NUM_LIT:1> ; StringTokenizer st = new StringTokenizer ( in ) ; int length = st . countTokens ( ) ; int i ; int currentRange = <NUM_LIT:0> ; String [ ] interestedEntries = new String [ halfRange + halfRange ] ; for ( i = <NUM_LIT:0> ; i < length - halfRange + assumedPlace ; ++ i ) { st . nextToken ( ) ; } for ( i = <NUM_LIT:0> ; i < halfRange + halfRange ; ++ i ) { if ( st . hasMoreTokens ( ) ) { interestedEntries [ i ] = st . nextToken ( ) ; currentRange ++ ; } } for ( i = currentRange - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; -- i ) { if ( useNotIdentifier != null && interestedEntries [ i ] . contains ( useNotIdentifier ) ) { continue ; } try { retval = Long . parseLong ( interestedEntries [ i ] ) ; } catch ( NumberFormatException nfe ) { continue ; } break ; } return retval ; } public static String getPrimaryGroup ( ) { if ( supported ( "<STR_LIT>" ) ) { if ( OsVersion . IS_SUNOS ) { String [ ] params = { "<STR_LIT:id>" } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fileExecutor = new FileExecutor ( ) ; fileExecutor . executeCommand ( params , output ) ; if ( output [ <NUM_LIT:0> ] != null ) { StringTokenizer tokenizer = new StringTokenizer ( output [ <NUM_LIT:0> ] , "<STR_LIT>" ) ; int length = tokenizer . countTokens ( ) ; if ( length >= <NUM_LIT:4> ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; ++ i ) { tokenizer . nextToken ( ) ; } return ( tokenizer . nextToken ( ) ) ; } } return ( null ) ; } else { String [ ] params = { "<STR_LIT:id>" , "<STR_LIT>" } ; String [ ] output = new String [ <NUM_LIT:2> ] ; FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; return output [ <NUM_LIT:0> ] ; } } else { return null ; } } public static String replaceString ( String destination , String what , String with ) { if ( destination . contains ( what ) ) { StringBuffer buf = new StringBuffer ( ) ; int last = <NUM_LIT:0> ; int current = destination . indexOf ( what ) ; int whatLength = what . length ( ) ; while ( current >= <NUM_LIT:0> ) { if ( current > <NUM_LIT:0> ) { buf . append ( destination . substring ( last , current ) ) ; } buf . append ( with ) ; last = current + whatLength ; current = destination . indexOf ( what , last ) ; } if ( destination . length ( ) > last ) { buf . append ( destination . substring ( last ) ) ; } return buf . toString ( ) ; } return destination ; } public static String translatePath ( String destination , Variables variables ) { destination = variables . replace ( destination ) ; return translatePath ( destination ) ; } @ Deprecated public static String translatePath ( String destination , VariableSubstitutor vs ) { try { destination = vs . substitute ( destination ) ; } catch ( Exception e ) { } return translatePath ( destination ) ; } private static String translatePath ( String destination ) { if ( destination . contains ( "<STR_LIT>" ) && ! destination . contains ( MASKED_SLASH_PLACEHOLDER ) ) { destination = replaceString ( destination , "<STR_LIT>" , MASKED_SLASH_PLACEHOLDER ) ; destination = destination . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ; destination = replaceString ( destination , MASKED_SLASH_PLACEHOLDER , "<STR_LIT:/>" ) ; } else { destination = destination . replace ( '<CHAR_LIT:/>' , File . separatorChar ) ; } return destination ; } public static String getenv ( String key ) { if ( envVars == null ) { loadEnv ( ) ; } if ( envVars == null ) { return ( null ) ; } if ( OsVersion . IS_WINDOWS ) { key = key . toUpperCase ( ) ; } return ( String ) ( envVars . get ( key ) ) ; } private static void loadEnv ( ) { String [ ] output = new String [ <NUM_LIT:2> ] ; String [ ] params ; if ( OsVersion . IS_WINDOWS ) { String command = "<STR_LIT>" ; if ( System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . contains ( "<STR_LIT>" ) ) { command = "<STR_LIT>" ; } String [ ] paramst = { command , "<STR_LIT>" , "<STR_LIT>" } ; params = paramst ; } else { String [ ] paramst = { "<STR_LIT>" } ; params = paramst ; } FileExecutor fe = new FileExecutor ( ) ; fe . executeCommand ( params , output ) ; if ( output [ <NUM_LIT:0> ] . length ( ) <= <NUM_LIT:0> ) { return ; } String lineSep = System . getProperty ( "<STR_LIT>" ) ; StringTokenizer tokenizer = new StringTokenizer ( output [ <NUM_LIT:0> ] , lineSep ) ; envVars = new Properties ( ) ; String var = null ; while ( tokenizer . hasMoreTokens ( ) ) { String line = tokenizer . nextToken ( ) ; if ( line . indexOf ( '<CHAR_LIT:=>' ) == - <NUM_LIT:1> ) { if ( var == null ) { var = lineSep + line ; } else { var += lineSep + line ; } } else { setEnvVar ( var ) ; var = line ; } } setEnvVar ( var ) ; } private static void setEnvVar ( String var ) { if ( var == null ) { return ; } int index = var . indexOf ( '<CHAR_LIT:=>' ) ; if ( index < <NUM_LIT:0> ) { return ; } String key = var . substring ( <NUM_LIT:0> , index ) ; if ( OsVersion . IS_WINDOWS ) { key = key . toUpperCase ( ) ; } envVars . setProperty ( key , var . substring ( index + <NUM_LIT:1> ) ) ; } public static void copyZip ( ZipInputStream zin , org . apache . tools . zip . ZipOutputStream out , List < String > files , Map < FilterOutputStream , Set < String > > alreadyWrittenFiles ) throws IOException { ZipEntry zentry ; if ( ! alreadyWrittenFiles . containsKey ( out ) ) { alreadyWrittenFiles . put ( out , new HashSet < String > ( ) ) ; } Set < String > currentSet = alreadyWrittenFiles . get ( out ) ; while ( ( zentry = zin . getNextEntry ( ) ) != null ) { String currentName = zentry . getName ( ) ; String testName = currentName . replace ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) ; testName = testName . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:.>' ) ; if ( files != null ) { boolean founded = false ; for ( String doInclude : files ) { if ( testName . matches ( doInclude ) ) { founded = true ; break ; } } if ( ! founded ) { continue ; } } if ( currentSet . contains ( currentName ) ) { continue ; } try { long fileTime = zentry . getTime ( ) ; copyStreamToJar ( zin , out , currentName , fileTime ) ; zin . closeEntry ( ) ; currentSet . add ( currentName ) ; } catch ( ZipException x ) { } } } public static void copyStreamToJar ( InputStream zin , ZipOutputStream out , String currentName , long fileTime ) throws IOException { org . apache . tools . zip . ZipEntry newEntry = new org . apache . tools . zip . ZipEntry ( currentName ) ; if ( fileTime != - <NUM_LIT:1> ) { newEntry . setTime ( fileTime ) ; } out . putNextEntry ( newEntry ) ; if ( zin != null ) { copyStream ( zin , out ) ; } out . closeEntry ( ) ; } public static void copyStreamToJar ( InputStream zin , java . util . zip . ZipOutputStream out , String currentName , long fileTime ) throws IOException { org . apache . tools . zip . ZipEntry newEntry = new org . apache . tools . zip . ZipEntry ( currentName ) ; if ( fileTime != - <NUM_LIT:1> ) { newEntry . setTime ( fileTime ) ; } out . putNextEntry ( newEntry ) ; if ( zin != null ) { copyStream ( zin , out ) ; } out . closeEntry ( ) ; } public static long copyStream ( InputStream in , OutputStream out ) throws IOException { byte [ ] buffer = new byte [ <NUM_LIT> ] ; long bytesCopied = <NUM_LIT:0> ; int bytesInBuffer ; while ( ( bytesInBuffer = in . read ( buffer ) ) != - <NUM_LIT:1> ) { out . write ( buffer , <NUM_LIT:0> , bytesInBuffer ) ; bytesCopied += bytesInBuffer ; } return bytesCopied ; } } </s>
<s> package com . izforge . izpack . util ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . logging . Level ; import java . util . logging . LogManager ; import java . util . logging . Logger ; public class Debug { public static final String SYSPROP_NAME_STACKTRACE = "<STR_LIT>" ; public static final String SYSPROP_NAME_TRACE = "<STR_LIT>" ; public static final String SYSPROP_NAME_DEBUG = "<STR_LIT>" ; private static boolean TRACE ; private static boolean STACKTRACE ; private static boolean DEBUG ; static { STACKTRACE = Boolean . getBoolean ( SYSPROP_NAME_STACKTRACE ) ; TRACE = Boolean . getBoolean ( SYSPROP_NAME_TRACE ) ; DEBUG = Boolean . getBoolean ( SYSPROP_NAME_DEBUG ) ; } public static boolean isTRACE ( ) { return TRACE ; } public static boolean isSTACKTRACE ( ) { return STACKTRACE ; } public static boolean isDEBUG ( ) { return DEBUG ; } } </s>
<s> package com . izforge . izpack . util . regex ; public class RegularExpression { private boolean alreadyInit = false ; private static final RegexpFactory FACTORY = new RegexpFactory ( ) ; private Regexp regexp = null ; private String myPattern ; private boolean setPatternPending = false ; private void init ( ) { if ( ! alreadyInit ) { this . regexp = FACTORY . newRegexp ( ) ; alreadyInit = true ; } } private void setPattern ( ) { if ( setPatternPending ) { regexp . setPattern ( myPattern ) ; setPatternPending = false ; } } public void setPattern ( String pattern ) { if ( regexp == null ) { myPattern = pattern ; setPatternPending = true ; } else { regexp . setPattern ( pattern ) ; } } public String getPattern ( ) { init ( ) ; setPattern ( ) ; return regexp . getPattern ( ) ; } public Regexp getRegexp ( ) { init ( ) ; setPattern ( ) ; return this . regexp ; } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; public class RegexpMatcherFactory { public RegexpMatcher newRegexpMatcher ( ) throws Exception { String systemDefault = System . getProperty ( "<STR_LIT>" ) ; if ( systemDefault != null ) { return createInstance ( systemDefault ) ; } try { testAvailability ( "<STR_LIT>" ) ; return createInstance ( "<STR_LIT>" ) ; } catch ( Exception be ) { } throw new Exception ( "<STR_LIT>" ) ; } protected RegexpMatcher createInstance ( String className ) throws RuntimeException { try { Class < ? > implClass = Class . forName ( className ) ; return ( RegexpMatcher ) implClass . newInstance ( ) ; } catch ( Throwable t ) { throw new RuntimeException ( t ) ; } } protected void testAvailability ( String className ) throws Exception { try { Class . forName ( className ) ; } catch ( Throwable t ) { throw new Exception ( t ) ; } } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class JavaRegexp extends JavaRegexpMatcher implements Regexp { public JavaRegexp ( ) { super ( ) ; } protected int getSubsOptions ( int options ) { int subsOptions = REPLACE_FIRST ; if ( RegexUtil . hasFlag ( options , REPLACE_ALL ) ) { subsOptions = REPLACE_ALL ; } return subsOptions ; } public String substitute ( String input , String argument , int options ) throws RuntimeException { StringBuffer subst = new StringBuffer ( ) ; for ( int i = <NUM_LIT:0> ; i < argument . length ( ) ; i ++ ) { char c = argument . charAt ( i ) ; if ( c == '<CHAR_LIT>' ) { subst . append ( '<STR_LIT:\\>' ) ; subst . append ( '<CHAR_LIT>' ) ; } else if ( c == '<STR_LIT:\\>' ) { if ( ++ i < argument . length ( ) ) { c = argument . charAt ( i ) ; int value = Character . digit ( c , <NUM_LIT:10> ) ; if ( value > - <NUM_LIT:1> ) { subst . append ( "<STR_LIT:$>" ) . append ( value ) ; } else { subst . append ( c ) ; } } else { subst . append ( '<STR_LIT:\\>' ) ; } } else { subst . append ( c ) ; } } argument = subst . toString ( ) ; int sOptions = getSubsOptions ( options ) ; Pattern p = getCompiledPattern ( options ) ; StringBuffer sb = new StringBuffer ( ) ; Matcher m = p . matcher ( input ) ; if ( RegexUtil . hasFlag ( sOptions , REPLACE_ALL ) ) { sb . append ( m . replaceAll ( argument ) ) ; } else { boolean res = m . find ( ) ; if ( res ) { m . appendReplacement ( sb , argument ) ; m . appendTail ( sb ) ; } else { sb . append ( input ) ; } } return sb . toString ( ) ; } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; public interface Regexp extends RegexpMatcher { int REPLACE_FIRST = <NUM_LIT> ; int REPLACE_ALL = <NUM_LIT> ; String substitute ( String input , String argument , int options ) throws RuntimeException ; } </s>
<s> package com . izforge . izpack . util . regex ; import java . util . Enumeration ; import java . util . Vector ; public class RegexUtil { private static interface SelectNode { public String select ( Vector < String > groups ) ; } private static class GroupSelectNode implements SelectNode { private int groupNumber ; public GroupSelectNode ( int groupNumber ) { this . groupNumber = groupNumber ; } public String select ( Vector < String > groups ) { if ( groupNumber < groups . size ( ) ) { return groups . elementAt ( groupNumber ) ; } else { return "<STR_LIT:\\>" + groupNumber ; } } public String toString ( ) { return "<STR_LIT>" + groupNumber ; } } private static class StringSelectNode implements SelectNode { private String text ; public StringSelectNode ( String text ) { this . text = text ; } public String select ( Vector < String > groups ) { return text ; } public String toString ( ) { return "<STR_LIT>" + text ; } } private static Vector < SelectNode > parseSelectString ( String input ) { Vector < SelectNode > nodes = new Vector < SelectNode > ( ) ; StringBuffer buf = new StringBuffer ( ) ; char c [ ] = input . toCharArray ( ) ; for ( int i = <NUM_LIT:0> ; i < c . length ; i ++ ) { if ( c [ i ] == '<STR_LIT:\\>' ) { if ( buf . length ( ) > <NUM_LIT:0> ) { nodes . addElement ( new StringSelectNode ( buf . toString ( ) ) ) ; buf . setLength ( <NUM_LIT:0> ) ; } while ( i + <NUM_LIT:1> < c . length && Character . isDigit ( c [ i + <NUM_LIT:1> ] ) ) { buf . append ( c [ i + <NUM_LIT:1> ] ) ; i ++ ; } int groupNum = Integer . parseInt ( buf . toString ( ) ) ; buf . setLength ( <NUM_LIT:0> ) ; nodes . addElement ( new GroupSelectNode ( groupNum ) ) ; } else { buf . append ( c [ i ] ) ; } } if ( buf . length ( ) > <NUM_LIT:0> ) { nodes . addElement ( new StringSelectNode ( buf . toString ( ) ) ) ; buf . setLength ( <NUM_LIT:0> ) ; } return nodes ; } public static String select ( String select , Vector < String > groups ) { Vector < SelectNode > nodes = parseSelectString ( select ) ; StringBuffer buf = new StringBuffer ( ) ; Enumeration < SelectNode > e = nodes . elements ( ) ; SelectNode node = null ; while ( e . hasMoreElements ( ) ) { node = e . nextElement ( ) ; buf . append ( node . select ( groups ) ) ; } return buf . toString ( ) ; } public static boolean hasFlag ( int options , int flag ) { return ( ( options & flag ) > <NUM_LIT:0> ) ; } public static int removeFlag ( int options , int flag ) { return ( options & ( <NUM_LIT> - flag ) ) ; } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; import java . util . Vector ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import java . util . regex . PatternSyntaxException ; public class JavaRegexpMatcher implements RegexpMatcher { private String pattern ; public JavaRegexpMatcher ( ) { } public void setPattern ( String pattern ) { this . pattern = pattern ; } public String getPattern ( ) { return pattern ; } protected Pattern getCompiledPattern ( int options ) throws RuntimeException { int cOptions = getCompilerOptions ( options ) ; try { Pattern p = Pattern . compile ( this . pattern , cOptions ) ; return p ; } catch ( PatternSyntaxException e ) { throw new RuntimeException ( e ) ; } } public boolean matches ( String argument ) throws RuntimeException { return matches ( argument , MATCH_DEFAULT ) ; } public boolean matches ( String input , int options ) throws RuntimeException { try { Pattern p = getCompiledPattern ( options ) ; return p . matcher ( input ) . find ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public Vector < String > getGroups ( String argument ) throws RuntimeException { return getGroups ( argument , MATCH_DEFAULT ) ; } public Vector < String > getGroups ( String input , int options ) throws RuntimeException { Pattern p = getCompiledPattern ( options ) ; Matcher matcher = p . matcher ( input ) ; if ( ! matcher . find ( ) ) { return null ; } Vector < String > v = new Vector < String > ( ) ; int cnt = matcher . groupCount ( ) ; for ( int i = <NUM_LIT:0> ; i <= cnt ; i ++ ) { String match = matcher . group ( i ) ; if ( match == null ) { match = "<STR_LIT>" ; } v . addElement ( match ) ; } return v ; } protected int getCompilerOptions ( int options ) { int cOptions = Pattern . UNIX_LINES ; if ( RegexUtil . hasFlag ( options , MATCH_CASE_INSENSITIVE ) ) { cOptions |= Pattern . CASE_INSENSITIVE ; } if ( RegexUtil . hasFlag ( options , MATCH_MULTILINE ) ) { cOptions |= Pattern . MULTILINE ; } if ( RegexUtil . hasFlag ( options , MATCH_SINGLELINE ) ) { cOptions |= Pattern . DOTALL ; } return cOptions ; } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; public class RegexpFactory extends RegexpMatcherFactory { public Regexp newRegexp ( ) throws RuntimeException { String systemDefault = System . getProperty ( "<STR_LIT>" ) ; if ( systemDefault != null ) { return createRegexpInstance ( systemDefault ) ; } try { testAvailability ( "<STR_LIT>" ) ; return createRegexpInstance ( "<STR_LIT>" ) ; } catch ( Exception be ) { } throw new RuntimeException ( "<STR_LIT>" ) ; } protected Regexp createRegexpInstance ( String classname ) throws RuntimeException { RegexpMatcher m = createInstance ( classname ) ; if ( m instanceof Regexp ) { return ( Regexp ) m ; } else { throw new RuntimeException ( classname + "<STR_LIT>" ) ; } } } </s>
<s> package com . izforge . izpack . util . regex ; import org . apache . tools . ant . BuildException ; import java . util . Vector ; public interface RegexpMatcher { int MATCH_DEFAULT = <NUM_LIT> ; int MATCH_CASE_INSENSITIVE = <NUM_LIT> ; int MATCH_MULTILINE = <NUM_LIT> ; int MATCH_SINGLELINE = <NUM_LIT> ; void setPattern ( String pattern ) throws RuntimeException ; String getPattern ( ) throws RuntimeException ; boolean matches ( String argument ) throws RuntimeException ; Vector < String > getGroups ( String argument ) throws RuntimeException ; boolean matches ( String input , int options ) throws RuntimeException ; Vector < String > getGroups ( String input , int options ) throws RuntimeException ; } </s>
<s> package com . izforge . izpack . util ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; public class Housekeeper { private List < CleanupClient > cleanupClients = new ArrayList < CleanupClient > ( ) ; private static final Logger logger = Logger . getLogger ( Housekeeper . class . getName ( ) ) ; public Housekeeper ( ) { } public void registerForCleanup ( CleanupClient client ) { if ( client instanceof Librarian ) { cleanupClients . add ( <NUM_LIT:0> , client ) ; } else { cleanupClients . add ( client ) ; } } public void shutDown ( int exitCode ) { shutDown ( exitCode , false ) ; } public void shutDown ( int exitCode , boolean reboot ) { for ( int i = cleanupClients . size ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { try { ( cleanupClients . get ( i ) ) . cleanUp ( ) ; } catch ( Throwable exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } terminate ( exitCode , reboot ) ; } protected void terminate ( int exitCode , boolean reboot ) { if ( reboot ) { try { systemReboot ( ) ; } catch ( IOException exception ) { logger . log ( Level . WARNING , exception . getMessage ( ) , exception ) ; } } System . exit ( exitCode ) ; } private void systemReboot ( ) throws IOException { final int waitseconds = <NUM_LIT:2> ; if ( OsVersion . IS_UNIX ) { Runtime . getRuntime ( ) . exec ( "<STR_LIT>" + waitseconds + "<STR_LIT>" ) ; } else if ( OsVersion . IS_WINDOWS ) { Runtime . getRuntime ( ) . exec ( "<STR_LIT>" + waitseconds ) ; } else { throw new IOException ( "<STR_LIT>" ) ; } } } </s>
<s> package com . izforge . izpack . util ; import java . io . BufferedReader ; import java . io . File ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . util . logging . Level ; import java . util . logging . Logger ; public class TargetFactory { private static final Logger logger = Logger . getLogger ( TargetFactory . class . getName ( ) ) ; public static final int WINDOWS = <NUM_LIT:0> ; public static final int UNIX = <NUM_LIT:2> ; public static final int GENERIC = <NUM_LIT:3> ; public static final int STANDARD = <NUM_LIT:0> ; public static final int NT = <NUM_LIT:1> ; public static final int X = <NUM_LIT:2> ; public static final int X86 = <NUM_LIT:0> ; public static final int OTHER = <NUM_LIT:1> ; static final String [ ] LIBRARY_EXTENSION = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; static final String [ ] CLASS_PREFIX = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; static final String [ ] CLASS_FLAVOR_PREFIX = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; static final String [ ] CLASS_ARCHITECTURE_PREFIX = { "<STR_LIT>" , "<STR_LIT>" } ; static final String [ ] INSTALL_PATH_FRAGMENT = { "<STR_LIT>" + File . separator , "<STR_LIT>" + File . separator , "<STR_LIT>" + File . separator , File . separator + "<STR_LIT>" + File . separator } ; static final String [ ] [ ] INSTALL_PATH_RESOURCE_KEY = { { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } , { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } } ; private static final String VERSION_DELIMITER = "<STR_LIT>" ; private final TargetPlatformFactory factory ; private int os = - <NUM_LIT:1> ; private int osFlavor = - <NUM_LIT:1> ; private int architecture = - <NUM_LIT:1> ; private String version = "<STR_LIT>" ; public TargetFactory ( TargetPlatformFactory factory ) { this . factory = factory ; version = System . getProperty ( "<STR_LIT>" ) ; if ( OsVersion . IS_WINDOWS ) { os = WINDOWS ; osFlavor = STANDARD ; architecture = X86 ; String osName = OsVersion . OS_NAME . toLowerCase ( ) ; if ( osName . contains ( "<STR_LIT>" ) ) { osFlavor = NT ; } else if ( osName . contains ( "<STR_LIT>" ) ) { osFlavor = NT ; } else if ( osName . contains ( "<STR_LIT>" ) ) { osFlavor = NT ; } } else if ( OsVersion . IS_OSX ) { os = X ; osFlavor = STANDARD ; architecture = OTHER ; } else { os = UNIX ; osFlavor = STANDARD ; architecture = OTHER ; String osName = OsVersion . OS_NAME . toLowerCase ( ) ; if ( osName . contains ( "<STR_LIT>" ) ) { architecture = X86 ; } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public < T > T makeObject ( Class < T > clazz ) throws Exception { T result ; try { result = factory . create ( clazz ) ; } catch ( Exception e ) { logger . log ( Level . WARNING , e . getMessage ( ) , e ) ; result = ( T ) makeObject ( clazz . getName ( ) ) ; } return result ; } public Object makeObject ( String name ) throws Exception { int nameStart = name . lastIndexOf ( '<CHAR_LIT:.>' ) + <NUM_LIT:1> ; String packageName = name . substring ( <NUM_LIT:0> , nameStart ) ; String className = name . substring ( nameStart , name . length ( ) ) ; String actualName ; try { actualName = packageName + CLASS_PREFIX [ os ] + CLASS_FLAVOR_PREFIX [ osFlavor ] + className ; Class < ? > temp = Class . forName ( actualName ) ; return temp . newInstance ( ) ; } catch ( Throwable exception1 ) { try { Class < ? > temp = Class . forName ( packageName + CLASS_PREFIX [ os ] + className ) ; return temp . newInstance ( ) ; } catch ( Throwable exception2 ) { try { actualName = name ; Class < ? > temp = Class . forName ( actualName ) ; return temp . newInstance ( ) ; } catch ( Throwable exception3 ) { throw new Exception ( "<STR_LIT>" + name ) ; } } } } public boolean versionIsHigher ( String version ) throws Exception { StringTokenizer targetVersion = new StringTokenizer ( this . version , VERSION_DELIMITER ) ; StringTokenizer compareVersion = new StringTokenizer ( version , VERSION_DELIMITER ) ; int target ; int compare ; while ( targetVersion . hasMoreTokens ( ) && compareVersion . hasMoreTokens ( ) ) { try { target = Integer . parseInt ( targetVersion . nextToken ( ) ) ; compare = Integer . parseInt ( compareVersion . nextToken ( ) ) ; } catch ( Throwable exception ) { throw new Exception ( "<STR_LIT>" ) ; } if ( compare > target ) { return true ; } else if ( target > compare ) { return false ; } } return false ; } public int getOS ( ) { return os ; } public int getOSFlavor ( ) { return osFlavor ; } public int getArchitecture ( ) { return architecture ; } public String getNativeLibraryExtension ( ) { return LIBRARY_EXTENSION [ os ] ; } public String getDefaultInstallPath ( String appName ) { String path = null ; InputStream input ; String keyFragment = "<STR_LIT>" + INSTALL_PATH_RESOURCE_KEY [ GENERIC ] [ STANDARD ] ; input = getClass ( ) . getResourceAsStream ( "<STR_LIT>" + INSTALL_PATH_RESOURCE_KEY [ os ] [ osFlavor ] ) ; if ( input == null ) { String key = OsVersion . OS_NAME . toLowerCase ( ) . replace ( '<CHAR_LIT:U+0020>' , '<CHAR_LIT:_>' ) ; key = keyFragment + key . toLowerCase ( ) ; input = TargetFactory . class . getResourceAsStream ( key ) ; } if ( input == null ) { input = TargetFactory . class . getResourceAsStream ( keyFragment ) ; } if ( input != null ) { InputStreamReader streamReader ; BufferedReader reader = null ; String line ; try { streamReader = new InputStreamReader ( input ) ; reader = new BufferedReader ( streamReader ) ; line = reader . readLine ( ) ; while ( line != null ) { line = line . trim ( ) ; if ( ! "<STR_LIT>" . equals ( line ) ) { break ; } line = reader . readLine ( ) ; } path = line ; } catch ( Throwable exception ) { } finally { try { if ( reader != null ) { reader . close ( ) ; } } catch ( Throwable exception ) { } } } if ( path == null || "<STR_LIT>" . equals ( path ) ) { path = "<STR_LIT>" ; if ( os == WINDOWS ) { String home = System . getProperty ( "<STR_LIT>" ) ; path = home . substring ( <NUM_LIT:0> , home . indexOf ( File . separatorChar ) + <NUM_LIT:1> ) ; } path = path + INSTALL_PATH_FRAGMENT [ os ] + appName ; } return path ; } public static String getCurrentOSPrefix ( ) { String OSName = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) ; String OSArch = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) ; int OS = <NUM_LIT:0> ; int OSFlavor = <NUM_LIT:0> ; int OSarchitecture = <NUM_LIT:0> ; if ( OSName . contains ( "<STR_LIT>" ) ) { OS = WINDOWS ; OSFlavor = STANDARD ; OSarchitecture = X86 ; if ( OSName . contains ( "<STR_LIT>" ) ) { OSFlavor = NT ; } else if ( OSName . contains ( "<STR_LIT>" ) ) { OSFlavor = NT ; } else if ( OSName . contains ( "<STR_LIT>" ) ) { OSFlavor = NT ; } } else if ( OSName . contains ( "<STR_LIT>" ) ) { OS = GENERIC ; OSFlavor = STANDARD ; OSarchitecture = OTHER ; if ( OSName . contains ( "<STR_LIT>" ) ) { OSFlavor = X ; } } else { OS = UNIX ; OSFlavor = STANDARD ; OSarchitecture = OTHER ; if ( OSArch . contains ( "<STR_LIT>" ) ) { OSarchitecture = X86 ; } } return ( CLASS_PREFIX [ OS ] + CLASS_FLAVOR_PREFIX [ OSFlavor ] ) ; } } </s>
<s> package com . izforge . izpack . util ; import java . util . ArrayList ; import java . util . List ; import java . util . logging . Logger ; import com . izforge . izpack . api . adaptator . IXMLElement ; import com . izforge . izpack . api . data . binding . OsModel ; public class OsConstraintHelper { private static final Logger logger = Logger . getLogger ( OsConstraintHelper . class . getName ( ) ) ; @ Deprecated public static boolean matchCurrentSystem ( OsModel osModel ) { boolean match = true ; String osName = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) ; if ( ( osModel . getArch ( ) != null ) && ( osModel . getArch ( ) . length ( ) != <NUM_LIT:0> ) ) { match = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . equals ( osModel . getArch ( ) ) ; } if ( match && ( osModel . getVersion ( ) != null ) && ( osModel . getVersion ( ) . length ( ) != <NUM_LIT:0> ) ) { match = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . equals ( osModel . getVersion ( ) ) ; } if ( match && ( osModel . getName ( ) != null ) && ( osModel . getName ( ) . length ( ) != <NUM_LIT:0> ) ) { match = osName . equals ( osModel . getName ( ) ) ; } if ( match && ( osModel . getFamily ( ) != null ) ) { if ( "<STR_LIT>" . equals ( osModel . getFamily ( ) ) ) { match = OsVersion . IS_WINDOWS ; } else if ( "<STR_LIT>" . equals ( osModel . getFamily ( ) ) || "<STR_LIT>" . equals ( osModel . getFamily ( ) ) ) { match = OsVersion . IS_OSX ; } else if ( "<STR_LIT>" . equals ( osModel . getFamily ( ) ) ) { match = OsVersion . IS_UNIX ; } } if ( match && ( osModel . getJre ( ) != null ) && ( osModel . getJre ( ) . length ( ) > <NUM_LIT:0> ) ) { match = System . getProperty ( "<STR_LIT>" ) . toLowerCase ( ) . startsWith ( osModel . getJre ( ) ) ; } return match && ( ( osModel . getFamily ( ) != null ) || ( osModel . getName ( ) != null ) || ( osModel . getVersion ( ) != null ) || ( osModel . getArch ( ) != null ) || ( osModel . getJre ( ) != null ) ) ; } public static List < OsModel > getOsList ( IXMLElement element ) { ArrayList < OsModel > osList = new ArrayList < OsModel > ( ) ; for ( IXMLElement osElement : element . getChildrenNamed ( "<STR_LIT>" ) ) { osList . add ( new OsModel ( osElement . getAttribute ( "<STR_LIT>" , null ) , osElement . getAttribute ( "<STR_LIT>" , null ) , osElement . getAttribute ( "<STR_LIT>" , null ) , osElement . getAttribute ( "<STR_LIT:name>" , null ) , osElement . getAttribute ( "<STR_LIT:version>" , null ) ) ) ; } String osattr = element . getAttribute ( "<STR_LIT>" ) ; if ( ( osattr != null ) && ( osattr . length ( ) > <NUM_LIT:0> ) ) { osList . add ( new OsModel ( null , osattr , null , null , null ) ) ; } return osList ; } @ Deprecated public static boolean oneMatchesCurrentSystem ( List < OsModel > constraint_list ) { if ( constraint_list == null || constraint_list . isEmpty ( ) ) { return true ; } for ( OsModel osModel : constraint_list ) { logger . fine ( "<STR_LIT>" + osModel + "<STR_LIT>" ) ; if ( matchCurrentSystem ( osModel ) ) { logger . fine ( "<STR_LIT>" ) ; return true ; } } logger . fine ( "<STR_LIT>" ) ; return false ; } @ Deprecated public static boolean oneMatchesCurrentSystem ( IXMLElement el ) { return oneMatchesCurrentSystem ( getOsList ( el ) ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . config ; import java . io . File ; import java . io . InputStream ; import org . w3c . dom . Document ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; import com . izforge . izpack . util . xmlmerge . Configurer ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . MergeAction ; import com . izforge . izpack . util . xmlmerge . XmlMerge ; import com . izforge . izpack . util . xmlmerge . merge . DefaultXmlMerge ; public class ConfigurableXmlMerge implements XmlMerge { XmlMerge m_wrappedXmlMerge ; public ConfigurableXmlMerge ( Configurer configurer ) throws ConfigurationException { this ( new DefaultXmlMerge ( ) , configurer ) ; } public ConfigurableXmlMerge ( XmlMerge wrappedXmlMerge , Configurer configurer ) throws ConfigurationException { configurer . configure ( wrappedXmlMerge ) ; this . m_wrappedXmlMerge = wrappedXmlMerge ; } @ Override public InputStream merge ( InputStream [ ] sources ) throws AbstractXmlMergeException { return m_wrappedXmlMerge . merge ( sources ) ; } @ Override public void merge ( File [ ] sources , File target ) throws AbstractXmlMergeException { m_wrappedXmlMerge . merge ( sources , target ) ; } @ Override public Document merge ( Document [ ] sources ) throws AbstractXmlMergeException { return m_wrappedXmlMerge . merge ( sources ) ; } @ Override public String merge ( String [ ] sources ) throws AbstractXmlMergeException { return m_wrappedXmlMerge . merge ( sources ) ; } @ Override public void setRootMapper ( Mapper rootMapper ) { m_wrappedXmlMerge . setRootMapper ( rootMapper ) ; } @ Override public void setRootMergeAction ( MergeAction rootMergeAction ) { m_wrappedXmlMerge . setRootMergeAction ( rootMergeAction ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . config ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . util . Enumeration ; import java . util . LinkedHashSet ; import java . util . Map ; import java . util . Properties ; import java . util . Set ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; public class PropertyXPathConfigurer extends AbstractXPathConfigurer { public static final String DEFAULT_ACTION_KEY = "<STR_LIT>" ; public static final String DEFAULT_MAPPER_KEY = "<STR_LIT>" ; public static final String DEFAULT_MATCHER_KEY = "<STR_LIT>" ; public static final String PATH_PREFIX = "<STR_LIT>" ; public static final String MAPPER_PREFIX = "<STR_LIT>" ; public static final String MATCHER_PREFIX = "<STR_LIT>" ; public static final String ACTION_PREFIX = "<STR_LIT>" ; Properties m_props ; Set < String > m_paths = new LinkedHashSet < String > ( ) ; public PropertyXPathConfigurer ( String propString ) throws ConfigurationException { m_props = new Properties ( ) ; try { m_props . load ( new ByteArrayInputStream ( propString . getBytes ( ) ) ) ; } catch ( IOException ioe ) { throw new ConfigurationException ( ioe ) ; } } public PropertyXPathConfigurer ( Map < String , String > map ) { m_props = new Properties ( ) ; m_props . putAll ( map ) ; } public PropertyXPathConfigurer ( Properties properties ) { m_props = properties ; } @ Override protected void readConfiguration ( ) throws ConfigurationException { String token ; token = m_props . getProperty ( DEFAULT_ACTION_KEY ) ; if ( token != null ) { setDefaultAction ( token ) ; } token = m_props . getProperty ( DEFAULT_MAPPER_KEY ) ; if ( token != null ) { setDefaultMapper ( token ) ; } token = m_props . getProperty ( DEFAULT_MATCHER_KEY ) ; if ( token != null ) { setDefaultMatcher ( token ) ; } Enumeration < Object > keys = m_props . keys ( ) ; while ( keys . hasMoreElements ( ) ) { String key = ( String ) keys . nextElement ( ) ; if ( key . startsWith ( PATH_PREFIX ) ) { m_paths . add ( key . substring ( PATH_PREFIX . length ( ) ) ) ; } } for ( String path : m_paths ) { token = m_props . getProperty ( ACTION_PREFIX + path ) ; if ( token != null ) { addAction ( m_props . getProperty ( PATH_PREFIX + path ) , token ) ; } token = m_props . getProperty ( MAPPER_PREFIX + path ) ; if ( token != null ) { addMapper ( m_props . getProperty ( PATH_PREFIX + path ) , token ) ; } token = m_props . getProperty ( MATCHER_PREFIX + path ) ; if ( token != null ) { addMatcher ( m_props . getProperty ( PATH_PREFIX + path ) , token ) ; } } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . config ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; import com . izforge . izpack . util . xmlmerge . Configurer ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . Matcher ; import com . izforge . izpack . util . xmlmerge . MergeAction ; import com . izforge . izpack . util . xmlmerge . XmlMerge ; import com . izforge . izpack . util . xmlmerge . action . FullMergeAction ; import com . izforge . izpack . util . xmlmerge . action . StandardActions ; import com . izforge . izpack . util . xmlmerge . factory . AttributeOperationFactory ; import com . izforge . izpack . util . xmlmerge . factory . OperationResolver ; import com . izforge . izpack . util . xmlmerge . factory . StaticOperationFactory ; import com . izforge . izpack . util . xmlmerge . mapper . NamespaceFilterMapper ; import com . izforge . izpack . util . xmlmerge . matcher . AttributeMatcher ; import com . izforge . izpack . util . xmlmerge . matcher . StandardMatchers ; public class AttributeMergeConfigurer implements Configurer { public static final String ATTRIBUTE_NAMESPACE = "<STR_LIT>" ; public static final String ACTION_ATTRIBUTE = "<STR_LIT>" ; public static final String MATCHER_ATTRIBUTE = "<STR_LIT>" ; @ Override public void configure ( XmlMerge xmlMerge ) throws ConfigurationException { MergeAction defaultMergeAction = new FullMergeAction ( ) ; Mapper mapper = new NamespaceFilterMapper ( ATTRIBUTE_NAMESPACE ) ; defaultMergeAction . setMapperFactory ( new StaticOperationFactory ( mapper ) ) ; OperationResolver actionResolver = new OperationResolver ( StandardActions . class ) ; defaultMergeAction . setActionFactory ( new AttributeOperationFactory ( defaultMergeAction , actionResolver , ACTION_ATTRIBUTE , ATTRIBUTE_NAMESPACE ) ) ; Matcher defaultMatcher = new AttributeMatcher ( ) ; OperationResolver matcherResolver = new OperationResolver ( StandardMatchers . class ) ; defaultMergeAction . setMatcherFactory ( new AttributeOperationFactory ( defaultMatcher , matcherResolver , MATCHER_ATTRIBUTE , ATTRIBUTE_NAMESPACE ) ) ; xmlMerge . setRootMapper ( mapper ) ; xmlMerge . setRootMergeAction ( defaultMergeAction ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . config ; import java . util . LinkedHashMap ; import java . util . Map ; import com . izforge . izpack . util . xmlmerge . Action ; import com . izforge . izpack . util . xmlmerge . ConfigurationException ; import com . izforge . izpack . util . xmlmerge . Configurer ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . Matcher ; import com . izforge . izpack . util . xmlmerge . MergeAction ; import com . izforge . izpack . util . xmlmerge . Operation ; import com . izforge . izpack . util . xmlmerge . XmlMerge ; import com . izforge . izpack . util . xmlmerge . action . FullMergeAction ; import com . izforge . izpack . util . xmlmerge . action . StandardActions ; import com . izforge . izpack . util . xmlmerge . factory . OperationResolver ; import com . izforge . izpack . util . xmlmerge . factory . XPathOperationFactory ; import com . izforge . izpack . util . xmlmerge . mapper . IdentityMapper ; import com . izforge . izpack . util . xmlmerge . mapper . StandardMappers ; import com . izforge . izpack . util . xmlmerge . matcher . AttributeMatcher ; import com . izforge . izpack . util . xmlmerge . matcher . StandardMatchers ; public abstract class AbstractXPathConfigurer implements Configurer { OperationResolver m_matcherResolver = new OperationResolver ( StandardMatchers . class ) ; OperationResolver m_actionResolver = new OperationResolver ( StandardActions . class ) ; OperationResolver m_mapperResolver = new OperationResolver ( StandardMappers . class ) ; MergeAction m_rootMergeAction = new FullMergeAction ( ) ; Matcher m_defaultMatcher = new AttributeMatcher ( ) ; Mapper m_defaultMapper = new IdentityMapper ( ) ; Action m_defaultAction = new FullMergeAction ( ) ; Map < String , Operation > m_matchers = new LinkedHashMap < String , Operation > ( ) ; Map < String , Operation > m_actions = new LinkedHashMap < String , Operation > ( ) ; Map < String , Operation > m_mappers = new LinkedHashMap < String , Operation > ( ) ; protected final void setDefaultMatcher ( String matcherName ) throws ConfigurationException { m_defaultMatcher = ( Matcher ) m_matcherResolver . resolve ( matcherName ) ; } protected final void setDefaultMapper ( String mapperName ) throws ConfigurationException { m_defaultMapper = ( Mapper ) m_mapperResolver . resolve ( mapperName ) ; } protected final void setDefaultAction ( String actionName ) throws ConfigurationException { m_defaultAction = ( Action ) m_actionResolver . resolve ( actionName ) ; } protected final void setRootMergeAction ( String actionName ) throws ConfigurationException { m_rootMergeAction = ( MergeAction ) m_actionResolver . resolve ( actionName ) ; } protected final void addMatcher ( String xPath , String matcherName ) throws ConfigurationException { m_matchers . put ( xPath , m_matcherResolver . resolve ( matcherName ) ) ; } protected final void addAction ( String xPath , String actionName ) throws ConfigurationException { m_actions . put ( xPath , m_actionResolver . resolve ( actionName ) ) ; } protected final void addMapper ( String xPath , String mapperName ) throws ConfigurationException { m_mappers . put ( xPath , m_mapperResolver . resolve ( mapperName ) ) ; } @ Override public final void configure ( XmlMerge xmlMerge ) throws ConfigurationException { readConfiguration ( ) ; XPathOperationFactory matcherFactory = new XPathOperationFactory ( ) ; matcherFactory . setDefaultOperation ( m_defaultMatcher ) ; matcherFactory . setOperationMap ( m_matchers ) ; m_rootMergeAction . setMatcherFactory ( matcherFactory ) ; XPathOperationFactory mapperFactory = new XPathOperationFactory ( ) ; mapperFactory . setDefaultOperation ( m_defaultMapper ) ; mapperFactory . setOperationMap ( m_mappers ) ; m_rootMergeAction . setMapperFactory ( mapperFactory ) ; XPathOperationFactory actionFactory = new XPathOperationFactory ( ) ; actionFactory . setDefaultOperation ( m_defaultAction ) ; actionFactory . setOperationMap ( m_actions ) ; m_rootMergeAction . setActionFactory ( actionFactory ) ; xmlMerge . setRootMergeAction ( m_rootMergeAction ) ; } protected abstract void readConfiguration ( ) throws ConfigurationException ; public void setActionResolver ( OperationResolver actionResolver ) { this . m_actionResolver = actionResolver ; } public void setMapperResolver ( OperationResolver mapperResolver ) { this . m_mapperResolver = mapperResolver ; } public void setMatcherResolver ( OperationResolver matcherResolver ) { this . m_matcherResolver = matcherResolver ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public interface OperationFactory { public Operation getOperation ( Element originalElement , Element modifiedElement ) throws AbstractXmlMergeException ; } </s>
<s> package com . izforge . izpack . util . xmlmerge . merge ; import java . io . ByteArrayInputStream ; import java . io . ByteArrayOutputStream ; import java . io . File ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import org . jdom . DocType ; import org . jdom . Document ; import org . jdom . Element ; import org . jdom . JDOMException ; import org . jdom . input . DOMBuilder ; import org . jdom . input . SAXBuilder ; import org . jdom . output . DOMOutputter ; import org . jdom . output . Format ; import org . jdom . output . XMLOutputter ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . DocumentException ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . Matcher ; import com . izforge . izpack . util . xmlmerge . MergeAction ; import com . izforge . izpack . util . xmlmerge . ParseException ; import com . izforge . izpack . util . xmlmerge . XmlMerge ; import com . izforge . izpack . util . xmlmerge . action . FullMergeAction ; import com . izforge . izpack . util . xmlmerge . factory . StaticOperationFactory ; import com . izforge . izpack . util . xmlmerge . mapper . IdentityMapper ; import com . izforge . izpack . util . xmlmerge . matcher . AttributeMatcher ; public class DefaultXmlMerge implements XmlMerge { private MergeAction m_rootMergeAction = new FullMergeAction ( ) ; public DefaultXmlMerge ( ) { setRootMergeAction ( new FullMergeAction ( ) ) ; setRootMatcher ( new AttributeMatcher ( ) ) ; setRootMapper ( new IdentityMapper ( ) ) ; } @ Override public void setRootMergeAction ( MergeAction rootMergeAction ) { this . m_rootMergeAction . setActionFactory ( new StaticOperationFactory ( rootMergeAction ) ) ; } public void setRootMatcher ( Matcher matcher ) { m_rootMergeAction . setMatcherFactory ( new StaticOperationFactory ( matcher ) ) ; } @ Override public void setRootMapper ( Mapper mapper ) { m_rootMergeAction . setMapperFactory ( new StaticOperationFactory ( mapper ) ) ; } @ Override public String merge ( String [ ] sources ) throws AbstractXmlMergeException { InputStream [ ] inputStreams = new InputStream [ sources . length ] ; for ( int i = <NUM_LIT:0> ; i < sources . length ; i ++ ) { inputStreams [ i ] = new ByteArrayInputStream ( sources [ i ] . getBytes ( ) ) ; } InputStream merged = merge ( inputStreams ) ; ByteArrayOutputStream result = new ByteArrayOutputStream ( ) ; try { byte [ ] buffer = new byte [ <NUM_LIT> ] ; int len ; while ( ( len = merged . read ( buffer ) ) != - <NUM_LIT:1> ) { result . write ( buffer , <NUM_LIT:0> , len ) ; } } catch ( IOException ioe ) { throw new RuntimeException ( ioe ) ; } return result . toString ( ) ; } @ Override public org . w3c . dom . Document merge ( org . w3c . dom . Document [ ] sources ) throws AbstractXmlMergeException { DOMBuilder domb = new DOMBuilder ( ) ; Document [ ] docs = new Document [ sources . length ] ; for ( int i = <NUM_LIT:0> ; i < sources . length ; i ++ ) { docs [ i ] = domb . build ( sources [ i ] ) ; } Document result = doMerge ( docs ) ; DOMOutputter outputter = new DOMOutputter ( ) ; try { return outputter . output ( result ) ; } catch ( JDOMException e ) { throw new DocumentException ( result , e ) ; } } @ Override public InputStream merge ( InputStream [ ] sources ) throws AbstractXmlMergeException { SAXBuilder sxb = new SAXBuilder ( ) ; Document [ ] docs = new Document [ sources . length ] ; for ( int i = <NUM_LIT:0> ; i < sources . length ; i ++ ) { try { docs [ i ] = sxb . build ( sources [ i ] ) ; } catch ( JDOMException e ) { throw new ParseException ( e ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; throw new ParseException ( ioe ) ; } } Document result = doMerge ( docs ) ; Format prettyFormatter = Format . getPrettyFormat ( ) ; prettyFormatter . setLineSeparator ( System . getProperty ( "<STR_LIT>" ) ) ; XMLOutputter sortie = new XMLOutputter ( prettyFormatter ) ; ByteArrayOutputStream buffer = new ByteArrayOutputStream ( ) ; try { sortie . output ( result , buffer ) ; } catch ( IOException ex ) { throw new DocumentException ( result , ex ) ; } return new ByteArrayInputStream ( buffer . toByteArray ( ) ) ; } @ Override public void merge ( File [ ] sources , File target ) throws AbstractXmlMergeException { SAXBuilder sxb = new SAXBuilder ( ) ; Document [ ] docs = new Document [ sources . length ] ; for ( int i = <NUM_LIT:0> ; i < sources . length ; i ++ ) { try { docs [ i ] = sxb . build ( sources [ i ] ) ; } catch ( JDOMException e ) { throw new ParseException ( e ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; throw new ParseException ( ioe ) ; } } Document result = doMerge ( docs ) ; Format prettyFormatter = Format . getPrettyFormat ( ) ; prettyFormatter . setLineSeparator ( System . getProperty ( "<STR_LIT>" ) ) ; XMLOutputter sortie = new XMLOutputter ( prettyFormatter ) ; try { sortie . output ( result , new FileOutputStream ( target ) ) ; } catch ( IOException ex ) { throw new DocumentException ( result , ex ) ; } } private Document doMerge ( Document [ ] docs ) throws AbstractXmlMergeException { Document originalDoc = docs [ <NUM_LIT:0> ] ; Element origRootElement = originalDoc . getRootElement ( ) ; for ( int i = <NUM_LIT:1> ; i < docs . length ; i ++ ) { Element comparedRootElement = docs [ i ] . getRootElement ( ) ; Document output = new Document ( ) ; if ( originalDoc . getDocType ( ) != null ) { output . setDocType ( ( DocType ) originalDoc . getDocType ( ) . clone ( ) ) ; } output . setRootElement ( new Element ( "<STR_LIT:root>" ) ) ; Element outputRootElement = output . getRootElement ( ) ; m_rootMergeAction . perform ( origRootElement , comparedRootElement , outputRootElement ) ; Element root = ( Element ) outputRootElement . getChildren ( ) . get ( <NUM_LIT:0> ) ; root . detach ( ) ; originalDoc . setRootElement ( root ) ; } return originalDoc ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import java . util . ArrayList ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . logging . Logger ; import org . jdom . Attribute ; import org . jdom . Comment ; import org . jdom . Content ; import org . jdom . Element ; import org . jdom . Text ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . Action ; import com . izforge . izpack . util . xmlmerge . DocumentException ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . Matcher ; import com . izforge . izpack . util . xmlmerge . MergeAction ; public class FullMergeAction extends AbstractMergeAction { private static final Logger logger = Logger . getLogger ( FullMergeAction . class . getName ( ) ) ; @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) throws AbstractXmlMergeException { logger . fine ( "<STR_LIT>" + originalElement + "<STR_LIT>" + patchElement + "<STR_LIT>" ) ; Mapper mapper = ( Mapper ) m_mapperFactory . getOperation ( originalElement , patchElement ) ; if ( originalElement == null ) { outputParentElement . addContent ( mapper . map ( patchElement ) ) ; } else if ( patchElement == null ) { outputParentElement . addContent ( ( Content ) originalElement . clone ( ) ) ; } else { Element workingElement = new Element ( originalElement . getName ( ) , originalElement . getNamespacePrefix ( ) , originalElement . getNamespaceURI ( ) ) ; addAttributes ( workingElement , originalElement ) ; logger . fine ( "<STR_LIT>" + workingElement ) ; outputParentElement . addContent ( workingElement ) ; doIt ( workingElement , originalElement , patchElement ) ; } } private void doIt ( Element parentOut , Element origElement , Element patchElement ) throws AbstractXmlMergeException { addAttributes ( parentOut , patchElement ) ; List < Content > origContentList = origElement . getContent ( ) ; List < Content > patchContentList = patchElement . getContent ( ) ; List < Content > unmatchedPatchContentList = new ArrayList < Content > ( ) ; List < Content > matchedPatchContentList = new ArrayList < Content > ( ) ; for ( Content origContent : origContentList ) { logger . fine ( "<STR_LIT>" + origContent + "<STR_LIT>" ) ; if ( origContent instanceof Element ) { boolean patchMatched = false ; for ( Content patchContent : patchContentList ) { logger . fine ( "<STR_LIT>" + patchContent ) ; if ( patchContent instanceof Comment || patchContent instanceof Text ) { logger . fine ( "<STR_LIT>" + patchContent ) ; } else if ( ! ( patchContent instanceof Element ) ) { throw new DocumentException ( patchContent . getDocument ( ) , "<STR_LIT>" + patchContent . getClass ( ) . getName ( ) + "<STR_LIT>" ) ; } else { if ( ( ( Matcher ) m_matcherFactory . getOperation ( ( Element ) patchContent , ( Element ) origContent ) ) . matches ( ( Element ) patchContent , ( Element ) origContent ) ) { logger . fine ( "<STR_LIT>" + patchContent + "<STR_LIT>" + origContent ) ; applyAction ( parentOut , ( Element ) origContent , ( Element ) patchContent ) ; patchMatched = true ; if ( ! matchedPatchContentList . contains ( patchContent ) ) { matchedPatchContentList . add ( patchContent ) ; } } else { if ( ! unmatchedPatchContentList . contains ( patchContent ) ) { unmatchedPatchContentList . add ( patchContent ) ; } } } } if ( ! patchMatched ) { logger . fine ( "<STR_LIT>" + origContent ) ; applyAction ( parentOut , ( Element ) origContent , null ) ; } } else if ( origContent instanceof Comment || origContent instanceof Text ) { parentOut . addContent ( ( Content ) origContent . clone ( ) ) ; } else { throw new DocumentException ( origContent . getDocument ( ) , "<STR_LIT>" + origContent . getClass ( ) . getName ( ) + "<STR_LIT>" ) ; } } for ( Content unmatchedPatchContent : unmatchedPatchContentList ) { if ( ! matchedPatchContentList . contains ( unmatchedPatchContent ) ) { logger . fine ( "<STR_LIT>" + unmatchedPatchContent ) ; applyAction ( parentOut , null , ( Element ) unmatchedPatchContent ) ; } } } private void applyAction ( Element workingParent , Element originalElement , Element patchElement ) throws AbstractXmlMergeException { Action action = ( Action ) m_actionFactory . getOperation ( originalElement , patchElement ) ; Mapper mapper = ( Mapper ) m_mapperFactory . getOperation ( originalElement , patchElement ) ; if ( action instanceof MergeAction ) { MergeAction mergeAction = ( MergeAction ) action ; mergeAction . setActionFactory ( m_actionFactory ) ; mergeAction . setMapperFactory ( m_mapperFactory ) ; mergeAction . setMatcherFactory ( m_matcherFactory ) ; } action . perform ( originalElement , mapper . map ( patchElement ) , workingParent ) ; } private void addAttributes ( Element out , Element in ) { LinkedHashMap < String , Attribute > allAttributes = new LinkedHashMap < String , Attribute > ( ) ; List < Attribute > outAttributes = new ArrayList < Attribute > ( out . getAttributes ( ) ) ; List < Attribute > inAttributes = new ArrayList < Attribute > ( in . getAttributes ( ) ) ; for ( Attribute attr : outAttributes ) { attr . detach ( ) ; allAttributes . put ( attr . getQualifiedName ( ) , attr ) ; logger . fine ( "<STR_LIT>" + attr ) ; } for ( Attribute attr : inAttributes ) { attr . detach ( ) ; allAttributes . put ( attr . getQualifiedName ( ) , attr ) ; logger . fine ( "<STR_LIT>" + attr ) ; } out . setAttributes ( new ArrayList < Attribute > ( allAttributes . values ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . jdom . Content ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class InsertAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( patchElement == null && originalElement != null ) { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } else { List < Content > outputContent = outputParentElement . getContent ( ) ; Iterator < Content > it = outputContent . iterator ( ) ; int lastIndex = outputContent . size ( ) ; while ( it . hasNext ( ) ) { Content content = it . next ( ) ; if ( content instanceof Element ) { Element element = ( Element ) content ; if ( element . getQualifiedName ( ) . equals ( patchElement . getQualifiedName ( ) ) ) { lastIndex = outputParentElement . indexOf ( element ) ; } } } List < Content > toAdd = new ArrayList < Content > ( ) ; toAdd . add ( patchElement ) ; outputContent . addAll ( Math . min ( lastIndex + <NUM_LIT:1> , outputContent . size ( ) ) , toAdd ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class CompleteAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( originalElement != null ) { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } else { if ( patchElement != null ) { outputParentElement . addContent ( ( Element ) patchElement . clone ( ) ) ; } } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import java . util . ArrayList ; import java . util . LinkedHashMap ; import java . util . List ; import java . util . logging . Logger ; import org . jdom . Attribute ; import org . jdom . Comment ; import org . jdom . Content ; import org . jdom . Element ; import org . jdom . Text ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . Action ; import com . izforge . izpack . util . xmlmerge . DocumentException ; import com . izforge . izpack . util . xmlmerge . Mapper ; import com . izforge . izpack . util . xmlmerge . Matcher ; import com . izforge . izpack . util . xmlmerge . MergeAction ; public class OrderedMergeAction extends AbstractMergeAction { private static final Logger logger = Logger . getLogger ( OrderedMergeAction . class . getName ( ) ) ; @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) throws AbstractXmlMergeException { logger . fine ( "<STR_LIT>" + originalElement + "<STR_LIT>" + patchElement + "<STR_LIT>" ) ; Mapper mapper = ( Mapper ) m_mapperFactory . getOperation ( originalElement , patchElement ) ; if ( originalElement == null ) { outputParentElement . addContent ( mapper . map ( patchElement ) ) ; } else if ( patchElement == null ) { outputParentElement . addContent ( ( Content ) originalElement . clone ( ) ) ; } else { Element workingElement = new Element ( originalElement . getName ( ) , originalElement . getNamespacePrefix ( ) , originalElement . getNamespaceURI ( ) ) ; addAttributes ( workingElement , originalElement ) ; logger . fine ( "<STR_LIT>" + workingElement ) ; outputParentElement . addContent ( workingElement ) ; doIt ( workingElement , originalElement , patchElement ) ; } } private void doIt ( Element parentOut , Element parentIn1 , Element parentIn2 ) throws AbstractXmlMergeException { addAttributes ( parentOut , parentIn2 ) ; Content [ ] list1 = ( Content [ ] ) parentIn1 . getContent ( ) . toArray ( new Content [ ] { } ) ; Content [ ] list2 = ( Content [ ] ) parentIn2 . getContent ( ) . toArray ( new Content [ ] { } ) ; int offsetTreated1 = <NUM_LIT:0> ; int offsetTreated2 = <NUM_LIT:0> ; for ( Content content1 : list1 ) { logger . fine ( "<STR_LIT>" + content1 ) ; if ( content1 instanceof Comment || content1 instanceof Text ) { parentOut . addContent ( ( Content ) content1 . clone ( ) ) ; offsetTreated1 ++ ; } else if ( ! ( content1 instanceof Element ) ) { throw new DocumentException ( content1 . getDocument ( ) , "<STR_LIT>" + content1 . getClass ( ) . getName ( ) + "<STR_LIT>" ) ; } else { Element e1 = ( Element ) content1 ; int posInList2 = - <NUM_LIT:1> ; for ( int j = offsetTreated2 ; j < list2 . length ; j ++ ) { logger . fine ( "<STR_LIT>" + list2 [ j ] ) ; if ( list2 [ j ] instanceof Element ) { if ( ( ( Matcher ) m_matcherFactory . getOperation ( e1 , ( Element ) list2 [ j ] ) ) . matches ( e1 , ( Element ) list2 [ j ] ) ) { logger . fine ( "<STR_LIT>" + e1 + "<STR_LIT:U+0020andU+0020>" + list2 [ j ] ) ; posInList2 = j ; break ; } } else if ( list2 [ j ] instanceof Comment || list2 [ j ] instanceof Text ) { } else { throw new DocumentException ( list2 [ j ] . getDocument ( ) , "<STR_LIT>" + list2 [ j ] . getClass ( ) . getName ( ) + "<STR_LIT>" ) ; } } while ( posInList2 != - <NUM_LIT:1> && offsetTreated2 < posInList2 ) { Content contentToAdd ; if ( list2 [ offsetTreated2 ] instanceof Element ) { applyAction ( parentOut , null , ( Element ) list2 [ offsetTreated2 ] ) ; } else { if ( ! ( list2 [ offsetTreated2 ] instanceof Comment ) ) { contentToAdd = ( Content ) list2 [ offsetTreated2 ] . clone ( ) ; parentOut . addContent ( contentToAdd ) ; } } offsetTreated2 ++ ; } if ( posInList2 != - <NUM_LIT:1> ) { applyAction ( parentOut , ( Element ) list1 [ offsetTreated1 ] , ( Element ) list2 [ offsetTreated2 ] ) ; offsetTreated1 ++ ; offsetTreated2 ++ ; } else { applyAction ( parentOut , ( Element ) list1 [ offsetTreated1 ] , null ) ; offsetTreated1 ++ ; } } } while ( offsetTreated2 < list2 . length ) { Content contentToAdd ; if ( list2 [ offsetTreated2 ] instanceof Element ) { applyAction ( parentOut , null , ( Element ) list2 [ offsetTreated2 ] ) ; } else { if ( ! ( list2 [ offsetTreated2 ] instanceof Comment ) ) { contentToAdd = ( Content ) list2 [ offsetTreated2 ] . clone ( ) ; parentOut . addContent ( contentToAdd ) ; } } offsetTreated2 ++ ; } } private void applyAction ( Element workingParent , Element originalElement , Element patchElement ) throws AbstractXmlMergeException { Action action = ( Action ) m_actionFactory . getOperation ( originalElement , patchElement ) ; Mapper mapper = ( Mapper ) m_mapperFactory . getOperation ( originalElement , patchElement ) ; if ( action instanceof MergeAction ) { MergeAction mergeAction = ( MergeAction ) action ; mergeAction . setActionFactory ( m_actionFactory ) ; mergeAction . setMapperFactory ( m_mapperFactory ) ; mergeAction . setMatcherFactory ( m_matcherFactory ) ; } action . perform ( originalElement , mapper . map ( patchElement ) , workingParent ) ; } private void addAttributes ( Element out , Element in ) { LinkedHashMap < String , Attribute > allAttributes = new LinkedHashMap < String , Attribute > ( ) ; List < Attribute > outAttributes = new ArrayList < Attribute > ( out . getAttributes ( ) ) ; List < Attribute > inAttributes = new ArrayList < Attribute > ( in . getAttributes ( ) ) ; for ( Attribute attr : outAttributes ) { attr . detach ( ) ; allAttributes . put ( attr . getQualifiedName ( ) , attr ) ; logger . fine ( "<STR_LIT>" + attr ) ; } for ( Attribute attr : inAttributes ) { attr . detach ( ) ; allAttributes . put ( attr . getQualifiedName ( ) , attr ) ; logger . fine ( "<STR_LIT>" + attr ) ; } out . setAttributes ( new ArrayList < Attribute > ( allAttributes . values ( ) ) ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import com . izforge . izpack . util . xmlmerge . MergeAction ; import com . izforge . izpack . util . xmlmerge . OperationFactory ; import com . izforge . izpack . util . xmlmerge . factory . StaticOperationFactory ; import com . izforge . izpack . util . xmlmerge . mapper . IdentityMapper ; import com . izforge . izpack . util . xmlmerge . matcher . AttributeMatcher ; public abstract class AbstractMergeAction implements MergeAction { protected OperationFactory m_actionFactory = new StaticOperationFactory ( this ) ; protected OperationFactory m_mapperFactory = new StaticOperationFactory ( new IdentityMapper ( ) ) ; protected OperationFactory m_matcherFactory = new StaticOperationFactory ( new AttributeMatcher ( ) ) ; @ Override public void setMapperFactory ( OperationFactory factory ) { m_mapperFactory = factory ; } @ Override public void setMatcherFactory ( OperationFactory factory ) { m_matcherFactory = factory ; } @ Override public void setActionFactory ( OperationFactory factory ) { m_actionFactory = factory ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class DeleteAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( originalElement != null && patchElement == null ) { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class KeepAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( originalElement != null && patchElement != null ) { outputParentElement . addContent ( ( Element ) patchElement . clone ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . Reader ; import java . net . MalformedURLException ; import java . net . URL ; import java . util . ArrayList ; import java . util . Hashtable ; import java . util . List ; import java . util . Map ; import java . util . logging . Logger ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . AbstractXmlMergeException ; import com . izforge . izpack . util . xmlmerge . Action ; import com . izforge . izpack . util . xmlmerge . DocumentException ; import com . izforge . izpack . util . xmlmerge . ElementException ; import com . wutka . dtd . DTD ; import com . wutka . dtd . DTDAny ; import com . wutka . dtd . DTDContainer ; import com . wutka . dtd . DTDElement ; import com . wutka . dtd . DTDItem ; import com . wutka . dtd . DTDName ; import com . wutka . dtd . DTDParser ; public class DtdInsertAction implements Action { private static final Logger logger = Logger . getLogger ( DtdInsertAction . class . getName ( ) ) ; static Map < String , DTD > s_dtdMap = new Hashtable < String , DTD > ( ) ; @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) throws AbstractXmlMergeException { Element element ; if ( originalElement != null ) { element = ( Element ) originalElement . clone ( ) ; } else { element = ( Element ) patchElement . clone ( ) ; } DTD dtd = getDTD ( outputParentElement ) ; List < DTDElement > dtdElements = dtd . getItemsByType ( DTDElement . class ) ; DTDElement parentDtdElement = null ; for ( DTDElement dtdElement : dtdElements ) { if ( dtdElement . getName ( ) . equals ( outputParentElement . getName ( ) ) ) { parentDtdElement = dtdElement ; } } if ( parentDtdElement == null ) { throw new ElementException ( element , "<STR_LIT>" + outputParentElement . getName ( ) + "<STR_LIT>" ) ; } else { DTDItem item = parentDtdElement . getContent ( ) ; if ( item instanceof DTDAny ) { outputParentElement . addContent ( element ) ; } else if ( item instanceof DTDContainer ) { List < Element > existingChildren = outputParentElement . getChildren ( ) ; if ( existingChildren . size ( ) == <NUM_LIT:0> ) { outputParentElement . addContent ( element ) ; } else { List < String > orderedDtdElements = getOrderedDtdElements ( ( DTDContainer ) item ) ; int indexOfNewElementInDtd = orderedDtdElements . indexOf ( element . getName ( ) ) ; logger . fine ( "<STR_LIT>" + element . getName ( ) + "<STR_LIT::U+0020>" + indexOfNewElementInDtd ) ; int pos = existingChildren . size ( ) ; for ( int i = <NUM_LIT:0> ; i < existingChildren . size ( ) ; i ++ ) { String elementName = ( existingChildren . get ( i ) ) . getName ( ) ; logger . fine ( "<STR_LIT>" + elementName + "<STR_LIT::U+0020>" + orderedDtdElements . indexOf ( elementName ) ) ; if ( orderedDtdElements . indexOf ( elementName ) > indexOfNewElementInDtd ) { pos = i ; break ; } } logger . fine ( "<STR_LIT>" + element . getName ( ) + "<STR_LIT>" + pos ) ; outputParentElement . addContent ( pos , element ) ; } } } } public DTD getDTD ( Element element ) throws DocumentException { if ( element . getDocument ( ) . getDocType ( ) != null ) { String systemId = element . getDocument ( ) . getDocType ( ) . getSystemID ( ) ; DTD dtd = s_dtdMap . get ( systemId ) ; if ( dtd == null ) { Reader reader ; URL url ; try { url = new URL ( systemId ) ; reader = new InputStreamReader ( url . openStream ( ) ) ; } catch ( MalformedURLException e ) { throw new DocumentException ( element . getDocument ( ) , e ) ; } catch ( IOException ioe ) { throw new DocumentException ( element . getDocument ( ) , ioe ) ; } try { dtd = new DTDParser ( reader ) . parse ( ) ; } catch ( IOException ioe ) { throw new DocumentException ( element . getDocument ( ) , ioe ) ; } s_dtdMap . put ( systemId , dtd ) ; } return dtd ; } else { throw new DocumentException ( element . getDocument ( ) , "<STR_LIT>" + element . getDocument ( ) ) ; } } public List < String > getOrderedDtdElements ( DTDContainer container ) { List < String > result = new ArrayList < String > ( ) ; DTDItem [ ] items = container . getItems ( ) ; for ( DTDItem item : items ) { if ( item instanceof DTDContainer ) { result . addAll ( getOrderedDtdElements ( ( DTDContainer ) item ) ) ; } else if ( item instanceof DTDName ) { result . add ( ( ( DTDName ) item ) . getValue ( ) ) ; } } return result ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class ReplaceAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( patchElement != null ) { outputParentElement . addContent ( ( Element ) patchElement . clone ( ) ) ; } else { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; public final class StandardActions { public static final FullMergeAction FULLMERGE = new FullMergeAction ( ) ; public static final OrderedMergeAction ORDEREDMERGE = new OrderedMergeAction ( ) ; public static final ReplaceAction REPLACE = new ReplaceAction ( ) ; public static final OverrideAction OVERRIDE = new OverrideAction ( ) ; public static final KeepAction KEEP = new KeepAction ( ) ; public static final CompleteAction COMPLETE = new CompleteAction ( ) ; public static final DeleteAction DELETE = new DeleteAction ( ) ; public static final PreserveAction PRESERVE = new PreserveAction ( ) ; public static final InsertAction INSERT = new InsertAction ( ) ; public static final DtdInsertAction DTD = new DtdInsertAction ( ) ; } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class PreserveAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( originalElement != null ) { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge . action ; import org . jdom . Element ; import com . izforge . izpack . util . xmlmerge . Action ; public class OverrideAction implements Action { @ Override public void perform ( Element originalElement , Element patchElement , Element outputParentElement ) { if ( originalElement != null && patchElement != null ) { outputParentElement . addContent ( ( Element ) patchElement . clone ( ) ) ; } else if ( originalElement != null ) { outputParentElement . addContent ( ( Element ) originalElement . clone ( ) ) ; } } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public class MatchException extends AbstractXmlMergeException { Element m_element ; public MatchException ( Element element , String message ) { super ( message ) ; this . m_element = element ; } public MatchException ( Element element , Throwable cause ) { super ( cause ) ; this . m_element = element ; } public Element getElement ( ) { return m_element ; } public void setElement ( Element element ) { m_element = element ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Document ; public class DocumentException extends AbstractXmlMergeException { Document m_document ; public DocumentException ( Document document , String message ) { super ( message ) ; m_document = document ; } public DocumentException ( Document document , Throwable cause ) { super ( makeMessage ( document ) , cause ) ; m_document = document ; } private static String makeMessage ( Document document ) { return "<STR_LIT>" + document ; } public Document getDocument ( ) { return m_document ; } public void setDocument ( Document document ) { m_document = document ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; public class ConfigurationException extends AbstractXmlMergeException { public ConfigurationException ( ) { super ( ) ; } public ConfigurationException ( String message ) { super ( message ) ; } public ConfigurationException ( String message , Throwable cause ) { super ( message , cause ) ; } public ConfigurationException ( Throwable cause ) { super ( cause ) ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public interface Matcher extends Operation { boolean matches ( Element originalElement , Element patchElement ) ; } </s>
<s> package com . izforge . izpack . util . xmlmerge ; import org . jdom . Element ; public class ElementException extends AbstractXmlMergeException { Element m_element ; public ElementException ( Element element ) { super ( makeMessage ( element ) ) ; this . m_element = element ; } public ElementException ( Element element , String message ) { super ( message ) ; this . m_element = element ; } public ElementException ( Element element , Throwable cause ) { super ( makeMessage ( element ) , cause ) ; } public Element getElement ( ) { return m_element ; } public void setElement ( Element element ) { m_element = element ; } private static String makeMessage ( Element element ) { return "<STR_LIT>" + element ; } } </s>
<s> package com . izforge . izpack . util . xmlmerge ; public interface Operation { } </s>
<s> package com . izforge . izpack . util . xmlmerge ; public interface Configurer { public void configure ( XmlMerge xmlMerge ) throws ConfigurationException ; } </s>
<s> package com . izforge . izpack . util . xmlmerge ; public abstract class AbstractXmlMergeException extends Exception { public AbstractXmlMergeException ( ) { super ( ) ; } public AbstractXmlMergeException ( String message ) { super ( message ) ; } public AbstractXmlMergeException ( String message , Throwable cause ) { super ( message , cause ) ; } public AbstractXmlMergeException ( Throwable cause ) { super ( cause ) ; } } </s>