⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaupgrade.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            while(eachLines.hasMoreElements()) {                try                {                    String sqlCode  = (String) eachLines.nextElement();                    if(sqlCode.trim().length() > 0)                    {                        int      separatorPosition  = sqlCode.indexOf(SCRIPT_SEPARATOR);                        String   releaseNumber      = sqlCode.substring(SCRIPT_PREFIX.length(), separatorPosition).trim();                            try {                            int releaseNumberInt = Integer.parseInt(releaseNumber);                            if(releaseNumberInt > jahiaInstalledRelease) {                                try {                                    String completeSqlCode = sqlCode.substring(separatorPosition+1, sqlCode.length()).trim();                                    if((completeSqlCode.substring(0,6).equals("CREATE")) || (completeSqlCode.substring(0,4).equals("DROP"))) {                                        dbStatement.executeQuery( completeSqlCode );                                    } else {                                        dbStatement.executeUpdate( completeSqlCode );                                    }                                } catch (SQLException sqle) {                                } catch (IndexOutOfBoundsException ioobe) {                                }                            }                        } catch (NumberFormatException nfe) {                        }                    }                } catch (IndexOutOfBoundsException ioobe) {                }            }            dbStatement.close();            toConsole("Upgrade database is done.\n");        } catch (ClassNotFoundException cnfe) {            //System.out.println("\n");            toConsole(jahiaDBDriver + " driver class not found.");        } catch (SQLException sqle) {            //System.out.println("\n");            toConsole("Can't connect to database or connection refused.");            toConsole("Jahia must be configured if you want to make an upgrade.");        } catch (Throwable t) {            t.printStackTrace();        }    } // end executeDatabaseRuntime    /**     * Changes properties (add, modify, delete) in jahia.properties file.     *     * @author  AK     */    private static void changeJahiaPropertiesFile()    {        Enumeration eachLines = readLines(launchDirectoryPath + File.separator + "upgrade" + File.separator + "jahia_properties.upgrade");        while(eachLines.hasMoreElements()) {            try            {                String property  = (String) eachLines.nextElement();                if(property.trim().length() > 0)                {                    int      separatorPosition  = property.indexOf(SCRIPT_SEPARATOR);                    String   releaseNumber      = property.substring(SCRIPT_PREFIX.length(), separatorPosition).trim();                    try {                        int releaseNumberInt = Integer.parseInt(releaseNumber);                        if(releaseNumberInt > jahiaInstalledRelease) {                            String propertyName   = property.substring(separatorPosition+1, property.indexOf("=")).trim();                            String propvalue  = property.substring(property.indexOf("=")+1, property.length()).trim();                            //System.out.println("propertyName  = [" + propertyName + "]");                            //System.out.println("propvalue = [" + propvalue + "]");                        }                    } catch (NumberFormatException nfe) {                    }                }            } catch (IndexOutOfBoundsException ioobe) {            }        }    } // end changeJahiaPropertiesFile    /**     * Get and save new release number into Jahia properties file..     *     * @author  AK     */    private static void writeReleaseNumber()    {        try        {            String          releaseNumberFilePath    = launchDirectoryPath + File.separator + "upgrade" + File.separator + "release.upgrade";            Properties      releaseNumberProperties  = new Properties();            FileInputStream inputStream              = new FileInputStream(releaseNumberFilePath);            releaseNumberProperties.load(inputStream);            inputStream.close();            // get release.upgrade value...            newReleaseNumber  = releaseNumberProperties.getProperty("release");            // write new release number into jahia.properties file...            updatepropvalue( "release", newReleaseNumber, jahiaPropertiesFilePath );        } catch (IOException ioe) {        }    } // end writeReleaseNumber    /**     * Read a text file, line after line, and create an Enumeration.     *     * @author  AK     * @param   filePath    String containing the path to the file you want read.     *     * @return  Enumeration containing each separated line.     */    private static Enumeration readLines( String filePath )    {        Vector allLines  = new Vector();        try        {            BufferedReader buffered  = new BufferedReader( new FileReader(filePath) );            String         buffer    = "";                while((buffer = buffered.readLine()) != null) {                if(buffer.trim().length() > 0) {                    allLines.add(buffer);                }            }            buffered.close();        } catch (IOException ioe) {        }        return allLines.elements();    } // end readLine    /**     * Generates a path file for a gived entry name. Parses "/" and     * replaces them with File.separator.     * -> use unknown's genPathFile() method.     *     * @author  AK     */    private static String generatePathFile( String entryName )    {        StringBuffer thePath = new StringBuffer(entryName.length());        for(int i=0; i<entryName.length(); i++) {            if(entryName.charAt(i) == '/') {                thePath.append(File.separator);            } else {                thePath.append(entryName.charAt(i));            }        }        return(thePath.toString());    }    /**     * Copy an InputStream to an OutPutStream     *     * @author  AK     */    private static void copyStream( InputStream  inputStream,                                    OutputStream outputStream )    throws IOException    {        int    bufferRead;        int    bufferSize  = 1024;        byte[] writeBuffer = new byte[bufferSize];        BufferedOutputStream bufferedStream = new BufferedOutputStream(outputStream, bufferSize);        while((bufferRead = inputStream.read(writeBuffer)) != -1)        bufferedStream.write(writeBuffer, 0, bufferRead);        bufferedStream.flush();        bufferedStream.close();        outputStream.flush();        outputStream.close();    } // end copyStream    /**     * Delete a file or directory (and all its content).     * -> use NK's deleteFile() method.     *     * @author  AK     */    private static void deleteFile( File theFile )    {        if(theFile.isDirectory())        {			File[] filesInThisDirectory = theFile.listFiles();			for(int i=0; i<filesInThisDirectory.length; i++) {				if(filesInThisDirectory[i].isFile()) {					filesInThisDirectory[i].delete();				} else {					deleteFile(filesInThisDirectory[i]);				}			}		}		theFile.delete();	} // end deleteFile    /**	 * Update a property's value in a properties file	 * -> use NK's updatepropvalue() method.	 *	 * @author  AK	 * @param   propertyName   Property name	 * @param   propvalue  Property value	 * @param   path	       Full path to the properties file	 */    private static void updatepropvalue( String propertyName,                                             String propvalue,                                             String path )    {        Vector  bufferVector  = new Vector();        String  lineReaded    = null;        int     position      = 0;        boolean lineFound     = false;        try        {            // parse the file...            BufferedReader buffered  = new BufferedReader( new FileReader(path) );            while((lineReaded = buffered.readLine()) != null) {                if(lineReaded.indexOf(propertyName) >= 0) {                    position = lineReaded.lastIndexOf("=");                    if(position >= 0) {                        bufferVector.add( lineReaded.substring(0,position+1) + "   " + propvalue );                        lineFound = true;                    }                } else {                    bufferVector.add(lineReaded);                }            }            buffered.close();            // add property if it don't exists before...            if(!lineFound)            {                bufferVector.add( propertyName + " =   " + propvalue );            }            // rewrite the file...            File         thisFile      = new File(path);            FileWriter   fileWriter    = new FileWriter( thisFile );            StringBuffer outputBuffer  = new StringBuffer();            for(int i=0; i < bufferVector.size(); i++) {                outputBuffer.append((String) bufferVector.get(i));            }            fileWriter.write( outputBuffer.toString() );            fileWriter.close();        } catch (java.io.IOException ioe) {        }    } // end updatepropvalue    /**     * Format the message and output in the console.     *     * @author  AK     * @param   msg     Message to display in the console.     */    private static void toConsole( String msg )    {        //System.out.println("upgrade: " + msg);    } // end toConsole    /**     * Display a Jahia message to indicate the start of JahiaUpgrade :o)     *     * @author  AK     */    private static void startupConsole()    {        StringBuffer msg = new StringBuffer("\n\n\n");        msg.append("                                  ____.\n");        msg.append("                      __/\\ ______|    |__/\\.     _______\n");        msg.append("           __   .____|    |       \\   |    +----+       \\\n");        msg.append("   _______|  /--|    |    |    -   \\  _    |    :    -   \\_________\n");        msg.append("  \\\\______: :---|    :    :           |    :    |         \\________>\n");        msg.append("          |__\\---\\_____________:______:    :____|____:_____\\\n");        msg.append("                                     /_____|\n");        msg.append("\n");        msg.append("                 . . . j a h i a   u p g r a d e . . .\n");        msg.append("\n\n");        msg.append("     Copyright 2002 - Jahia Ltd http://www.jahia.org - all rights reserved\n");        msg.append("\n\n");        System.out.println(msg.toString());    } // end startupConsole    /**     * Say goodbye in the console :o)     *     * @author  AK     */    private static void shutdownConsole()    {        //System.out.println("\nupgrade: Upgrade is done! You now have the release " + newReleaseNumber + ".");    }} // end JahiaUpgrade

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -