FileDocCategorySizeDatePackage
SunACCTransfer.javaAPI DocGlassfish v2 API6686Fri May 04 22:35:08 BST 2007com.sun.enterprise.tools.upgrade.miscconfig

SunACCTransfer

public class SunACCTransfer extends Object
author
prakash

Fields Summary
private com.sun.enterprise.util.i18n.StringManager
stringManager
private Logger
logger
private String
docType
private String
secPolicyProperty
Constructors Summary
public SunACCTransfer()
Creates a new instance of SunACCTransfer

    
                 
      
    
Methods Summary
private java.lang.StringgetDOCTYPEString(java.io.File target)
Method to get DOCTYPE string from a xml file

        BufferedReader reader = new BufferedReader(new InputStreamReader
                (new FileInputStream(target)));
        String readLine = null;
        while((readLine = reader.readLine()) != null){
            if(readLine.indexOf("<!DOCTYPE") != -1){
                return readLine;
            }
        }
        return null;
    
private java.lang.StringgetSecurityConfigValue(java.io.File target)

        BufferedReader reader = new BufferedReader(new InputStreamReader
                (new FileInputStream(target)));
        String readLine = null;
        while((readLine = reader.readLine()) != null){
            if(readLine.indexOf("<property") != -1){
                if(readLine.indexOf("security.config") != -1) { 
                    return readLine;
                }
            }
        }
        return null;
    
private voidtransferFileContents(java.io.File source, java.io.File target)
Method to transfer contents of sun-acc.xml from source to target

        BufferedReader reader = new BufferedReader(new InputStreamReader
                (new FileInputStream(source)));
        PrintWriter writer = new PrintWriter(new FileOutputStream(target));
        String readLine = null;
        while((readLine = reader.readLine()) != null){
            if(readLine.indexOf("<!DOCTYPE") == -1 && 
                    readLine.indexOf("<property") == -1) { 
                writer.println(readLine);
            } else if(readLine.indexOf("<!DOCTYPE") != -1){ 
                if(docType != null)
                    writer.println(docType);
                else
                    writer.println();
            } else if(readLine.indexOf("<property") != -1) {
                if(readLine.indexOf("security.config") != -1) {
                    if(secPolicyProperty != null) 
                        writer.println(secPolicyProperty);
                    else
                        writer.println();
                } else {
                    writer.println(readLine);
                }
            }
        }
        writer.flush();
        writer.close();
        reader.close();
    
public voidtransform(java.lang.String sourceFileName, java.lang.String targetFileName)
Method to start transformation of sun-acc XML file

        logger.log(Level.INFO, stringManager.getString(
                "upgrade.configTransfers.sunacc.startMessage"));
        File sourceFile = new File(sourceFileName);
        File targetFile = new File(targetFileName);
        
        //Get the DOCTYPE and security-config of target file
        try {
            docType = this.getDOCTYPEString(targetFile);
            secPolicyProperty = this.getSecurityConfigValue(targetFile);
        } catch(Exception e) {}
        
        //Backup the target file before processing
        boolean renamed = targetFile.renameTo(new File(targetFileName+".bak"));
        if(!renamed){
            // This is possible if user is running the upgrade again 
            //and .bak is already created.
            renamed = targetFile.delete();
        }
        
        //Transfer file contents if backed up
        if(renamed){
            try{
                targetFile = new File(targetFileName);
                targetFile.createNewFile();
                this.transferFileContents(sourceFile, targetFile);
            }catch(Exception ex){
                // Log error message
                logger.log(Level.SEVERE, stringManager.getString(
                        "upgrade.configTransfers.sunacc.startFailureMessage"),ex);
            }  
        }else{
            // Log error message : rename failure
            logger.log(Level.SEVERE, stringManager.getString(
                    "upgrade.configTransfers.sunacc.renameFailureMessage"));
        }