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

📄 jahiawebappsdeployerservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if ( warPackage != null && warPackage.getWebApps().size()>0 ){                pack = new JahiaWebAppsPackage(warPackage.getContextRoot());                pack.addWebAppDef(warPackage.getWebApps());                pack.setFileName(fileItem.getName());                pack.setFilePath(path);            }        } else if ( fileItem != null && fileItem.getName().endsWith(".ear") ) {            JahiaWebAppsEarPackage earPackage = loadWebAppInfoFromEar(fileItem.getAbsolutePath());            if ( earPackage != null && earPackage.getWebApps().size()>0 ){                pack = new JahiaWebAppsPackage(earPackage.getContextRoot());                pack.addWebAppDef(earPackage.getWebApps());                pack.setFileName(fileItem.getName());                pack.setFilePath(path);            }        }        return pack;    }    /**     * read the informations contained in a war file     *     * @param path , the full path to the file     * @return a JahiaWebAppsWarPackage or null     */    protected JahiaWebAppsWarPackage loadWebAppInfoFromWar(String path) throws JahiaException {        File fileItem = new File(path);        if ( fileItem != null && fileItem.getName().endsWith(".war") ){            // Create a war file Handler            JahiaWebAppsWarHandler wah = null;            try {                wah = new JahiaWebAppsWarHandler(path);                JahiaWebAppsWarPackage warPackage = wah.getWebAppsPackage();                return warPackage;            } finally {                if ( wah != null ){                    wah.closeArchiveFile();                }            }        }        return null;    }    /**     * read the informations contained in a ear file     *     * @param path , the full path to the file     * @return a JahiaWebAppsEarPackage or null     */    protected JahiaWebAppsEarPackage loadWebAppInfoFromEar(String path) throws JahiaException {        File fileItem = new File(path);        if ( fileItem != null && fileItem.getName().endsWith(".ear") ){            // Create a Ear Handler            JahiaEarFileHandler earh = null;            try {                earh = new JahiaEarFileHandler(path);                JahiaWebAppsEarPackage earPackage = new JahiaWebAppsEarPackage(JahiaTools.removeFileExtension(fileItem.getName(),".ear"));                // Get WebComponents ( list of war files )                Vector webComponents = earh.getWebComponents();                int size = webComponents.size();                Web_Component webComp   = null;                String webURI           = null;     // name of the war file                JahiaWebAppsWarPackage warPackage = null;                for ( int i=0 ; i<size ; i++ ){                    webComp = (Web_Component)webComponents.get(i);                    webURI = webComp.getWebURI();                    if ( webURI != null && (webURI.length()>0) ){                        //JahiaConsole.println("JahiaWebAppsDeployerService.loadWebAppInfoFromEar","start extracting entry " + webURI);                        // extract the war file                        earh.extractEntry(webURI,m_TempFolderDiskPath);                        // get the extracted war file                        File warFile = new File(m_TempFolderDiskPath + File.separator + webURI);                        // load info from war                        warPackage = loadWebAppInfoFromWar(warFile.getAbsolutePath());                        if ( warPackage != null && (warPackage.getWebApps().size()>0) ){                            earPackage.addWebAppDefs((Vector)warPackage.getWebApps());                        }                        warFile.delete();                    }                }                return earPackage;            } catch ( JahiaException e ) {                String errMsg = "Failed handling webApps file " ;                JahiaConsole.println("JahiaWebAppsDeployerBaseService::loadWebAppInfoFromEar()", errMsg + "\n" + e.toString());                if ( earh != null ){                    earh.closeArchiveFile();                }                throw new JahiaException ( "JahiaWebAppsDeployerBaseService::loadWebAppInfoFromEar()",                                    "JahiaWebAppsDeployerBaseService" + errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR);            } finally {                // Important to close the JarFile object !!!!                // cannot delete it otherwise                if ( earh != null ){                    earh.closeArchiveFile();                }            }        }        return null;    }    /**     * return a reference to the DTD entity resolver     *     */    public EntityResolver getDtdEntityResolver(){        return (EntityResolver)m_Resolver;    }    /************************************************************************     * Web Application Packages ( .war , .ear or unzipped directory )     * handling.     *     * The directory jahiafiles/new_webapps is periodically scanned for new component     * packages. A package can be a war or ear file.     *     * If the informations contained in their deployment descriptor     * files ( META-INF/applications.xml, WEB-INF/web.xml ) is scanned successfully     * a JahiaWebAppsPackage object that holds all informations needed by Jahia     * to deploy them is created.     *     * If the deployment mode is automatic, they are automatically deployed and     * registered in Jahia. If not, they are added in the HashTable of packages     * waiting to be deployed manually throught the JahiaAdministration interface.     *     * The Key in the hashtable of packages used to identify each package is     * the filename of the package.     *     ************************************************************************/    /**     * delete a package reference in the hashtable of detected packages     * and delete it physically from disk.     *     * @param (JahiaSite) the site in which the webapp package belong to     * @param (String) full path to a file or directory     * @return true if successful     */    public boolean deletePackage(JahiaSite site, String path) {        synchronized(m_WebAppsPackage){            File tmpFile = new File(path);            StringBuffer filename = new StringBuffer(site.getSiteKey());            filename.append("_");            filename.append(tmpFile.getName());            //System.out.println(" deletePackage key is =" + filename );            if ( tmpFile != null && tmpFile.isFile() ){                if (tmpFile.delete()){                    m_WebAppsPackage.remove(filename.toString());                    return true;                } else {                    return false;                }            } else if ( tmpFile != null && tmpFile.isDirectory() ){                StringBuffer buff = new StringBuffer(m_TempFolderDiskPath);                buff.append(File.separator);                buff.append(m_TempFolderPrefix);                buff.append(filename.toString());                buff.append(JahiaTools.getUniqueDirName());                File tmpFolder = new File( buff.toString() );                //System.out.println(" try to move to " + tmpFolder.getAbsolutePath() );                if (tmpFile.renameTo(tmpFolder) ){                    m_WebAppsPackage.remove(filename.toString());                    // delete folder                    JahiaTools.deleteFile( tmpFolder );                    return true;                }            } else {                m_WebAppsPackage.remove(filename.toString());                return true;            }            return false;        }    }    /**     * add a new file or directory only if it is recognized     * as a valid component package.     * And only if it is not registered yet.     *     * @param (JahiaSite) the site for which to register the webapp     * @param (String) full path to a file or directory     */    public void addNewFile(JahiaSite site, String path) {        synchronized(m_WebAppsPackage){            File tmpFile = new File(path);            StringBuffer filename = new StringBuffer(site.getSiteKey());            filename.append("_");            filename.append(tmpFile.getName());            if ( tmpFile != null ){                JahiaWebAppsPackage pack = null;                if ( m_WebAppsPackage.get(filename.toString())==null ) {                    pack = loadWebAppInfo(path);                    if ( pack != null ){                        m_WebAppsPackage.remove(filename.toString());                        m_WebAppsPackage.put(filename.toString(),pack);                    }                }            }        }    }    /***     * return an Enumerations of the keys of the Hashtable of package     *     * @return (Enumeration) the enumeration of all keys     */    public Enumeration getWebAppsPackageKeys(){        synchronized(m_WebAppsPackage){            return m_WebAppsPackage.keys();        }    }    /***     * return an Enumerations of the keys of the Hashtable of package for a gived site     *     * @return (String) the site key identifier     * @return (Enumeration) the enumeration of all keys     */    public Enumeration getWebAppsPackageKeys(String siteKey){        Enumeration enum = null;        Vector result = new Vector();        synchronized(m_WebAppsPackage){            enum = m_WebAppsPackage.keys();            String name = null;            String siteIdent = siteKey + "_";            while ( enum.hasMoreElements() ){                name = (String)enum.nextElement();                if ( name.startsWith(siteIdent) ){                    result.add(siteIdent);                }            }            return result.elements();        }    }    /***     * return an enumeration of the web apps package Hashtable     *     * @return (Enumeration) the enumeration of the packages     */    public Enumeration getWebAppsPackages(){        return m_WebAppsPackage.elements();    }    /***     * return an enumeration of the web apps package Hashtable     *     * @return (String) the site key identifier     * @return (Enumeration) the enumeration of the packages     */    public Enumeration getWebAppsPackages(String siteKey){        Enumeration enum = null;        Vector result = new Vector();        synchronized(m_WebAppsPackage){            enum = m_WebAppsPackage.keys();            String name = null;            String siteIdent = siteKey + "_";            while ( enum.hasMoreElements() ){                name = (String)enum.nextElement();                if ( name.startsWith(siteIdent) ){                    result.add(m_WebAppsPackage.get(name));                }            }            return result.elements();        }    }    /***     * return a web app package in the Hashtable m_WebAppsPackage     * looking at the key     * @param (String) the key     * @return (Object) a webapps package or null     */    public Object getWebAppsPackage(String theKey){        synchronized(m_WebAppsPackage){            return m_WebAppsPackage.get(theKey);        }    }    /***     * scan a directory for web apps package.     * Add them to the HashTable of WebAppsPackage.     *     * @param the full path to a directory     * @return an Hashtable     */    public void scanDirectory(String path)    throws JahiaException {        synchronized(m_WebAppsPackage){            JahiaWebAppsPackage pack = null;            File dir = new File(path);            if ( dir != null && dir.isDirectory() ){                File[] files = dir.listFiles();                int size = files.length;                for ( int i=0; i<size ; i++ ){                    if ( files[i].canWrite() ){                        pack = loadWebAppInfo(files[i].getAbsolutePath());                        if ( pack != null ){                            //System.out.println("added package in hashtable " + files[i].getAbsolutePath() );                            // remove old map                            m_WebAppsPackage.remove(files[i].getName());                            // set the new map                            m_WebAppsPackage.put(files[i].getName(),pack);                        }                    }                }            }        }    }    //-------------------------------------------------------------------------    /**     * Search and remove the Meta-Inf folder     * @param String parentPath, the path of the parent Folder     * @return (boolean) true if successfull     */    protected boolean removeMetaInfFolder(String parentPath){        if ( parentPath == null ){            return false;        }        File f = new File(parentPath);        File[] files = f.listFiles();        for (int i=0 ; i<files.length ; i++){            if ( files[i].getName().equalsIgnoreCase(m_META_INF) ){                try {                    return JahiaTools.deleteFile(files[i],false);                }catch ( Throwable t ){                    t.printStackTrace();                    return false;                }            }        }        return false;    }} // end JahiaWebAppsDeployerService

⌨️ 快捷键说明

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