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

📄 jahiatemplatespackagehandler.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////////  JahiaTemplatePackageHandler////  NK      13.01.2001////package org.jahia.data.templates;import java.io.*;import java.util.*;import java.util.jar.*;import java.util.zip.*;import org.w3c.dom.*;import org.jahia.exceptions.*;import org.jahia.utils.zip.*;               // JahiaarHandlerimport org.jahia.utils.*;                   // JahiaCmdExecimport org.jahia.utils.xml.*;               // JahiaConsole, XMLParser/** * This class is responsible for loading data from a Template Jar File * The Format of the XML Template Descriptor File is : * * <pre> *    Format of XML document is as follows: *    <?xml version="1.0" encoding="ISO-8859-1"?> * *	<tpml> *		<parameter name="package-name">DigitalCortexDHTML</parameter> *		<parameter name="root-folder">DigitalCortexDHTML</parameter> *		<parameter name="classes-file">digicorp.jar</parameter> *		<parameter name="provider">www.jahia.org</parameter> *		<parameter name="thumbnail">thumbnail.gif</parameter> *		<template id="1" visible="1" homepage="1"> *			<parameter name="name">DigitalCortexDHTML</parameter> *			<parameter name="filename">digicorp.jsp</parameter> *			<parameter name="display-name">Digital Cortex DHTML</parameter> *		</template> *	</tpml> * * </pre> * * ----------------------------------------------------------------- * IMPORTANT !!!!! Must call the method closeArchiveFile() * to be able to delete the file later !!! * ----------------------------------------------------------------- * * * @author Khue ng * @version 1.0 * */public class JahiaTemplatesPackageHandler {    private static final String CLASS_NAME = JahiaTemplatesPackageHandler.class.getName();   /** The root folder **/   private String m_TemplateRootFolder;   /** The full path to the Template Jar File **/   private String m_FilePath;   /** The Jar File Handler of the Template Jar File **/   private JahiaArchiveFileHandler m_ArchFile;   /** The JahiaTemplatesPackage Object created with data from the templates.xml file **/   private JahiaTemplatesPackage m_Package;   /** the XML Document **/   private Templates_Xml m_XMLDocument;   /** The classes_file.jar provided within the templates package **/   private File m_ClassesFile;   /** The thumbnail image file **/   private File m_ThumbnailFile;   /** The Jar File Handler of the classes_file.jar provided within the templates package **/   private JahiaArchiveFileHandler m_JarClassesFile;    /** the entry to the templates.xml file **/    private static String TEMPLATES_XML_FILE = "templates.xml";   /**    * Constructor is initialized with the template File    *    */   public JahiaTemplatesPackageHandler (String filePath)   throws JahiaException {        m_FilePath = filePath;        File tmpFile = new File(filePath);        boolean isFile = true;        if (  tmpFile.isFile() && tmpFile.canWrite()){            try {                m_ArchFile = new JahiaArchiveFileHandler( filePath );            } catch (IOException e ) {                String errMsg = "Failed creating an Archive File Handler "  ;                JahiaConsole.println("JahiaTemplatesPackageHandler::Constructor", errMsg + "\n" + e.toString());                throw new JahiaException ("JahiaTemplatesPackageHandler", errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR, e);            }        } else {            isFile = false;        }        try {            buildTemplatesPackage(isFile);        }  catch ( JahiaException je ) {            if ( m_ArchFile != null ){                m_ArchFile.closeArchiveFile();            }            JahiaConsole.println("JahiaTemplatesPackageHandler::Constructor", "error building the TemplatesPackageHandler" + je.toString());            throw new JahiaException ("JahiaTemplatesPackageHandler", "error building the TemplatesPackageHandler" ,                                   JahiaException.SERVICE_ERROR, JahiaException.ERROR, je);        }    }    /**     * Extract data from the templates.xml file and build the JahiaTemplatesPackage object     *     * @param isFile , are we handling a file or instead a directory ?     */    protected void buildTemplatesPackage(boolean isFile) throws JahiaException {        // extract data from the templates.xml file        try {            if ( isFile ) {                File tmpFile = m_ArchFile.extractFile(TEMPLATES_XML_FILE);                m_XMLDocument = new Templates_Xml(tmpFile.getAbsolutePath());                m_XMLDocument.extractDocumentData();                tmpFile.deleteOnExit();                tmpFile.delete();            } else {                m_XMLDocument = new Templates_Xml(m_FilePath + File.separator + TEMPLATES_XML_FILE);                m_XMLDocument.extractDocumentData();            }        } catch (IOException ioe){            String errMsg = "Failed extracting templates.xml file data "  ;            JahiaConsole.println("JahiaTemplatesPackageHandler::Constructor", errMsg + "\n" + ioe.toString());            throw new JahiaException ("JahiaTemplatesPackageHandler", errMsg ,                                    JahiaException.SERVICE_ERROR, JahiaException.ERROR, ioe);        }        // built the JahiaTemplatesPackage Object        m_Package = new JahiaTemplatesPackage(                                                m_XMLDocument.getPackageName(),                                                m_XMLDocument.getRootFolder(),                                                m_XMLDocument.getClassesFile(),                                                m_XMLDocument.getProvider(),                                                m_XMLDocument.getThumbnail()                                            );        m_Package.setFilePath(m_FilePath);        m_Package.setTemplates(m_XMLDocument.getTemplates());   }    /**     * Returns the Classes File     *     * @return (File) the Classes File     */    public File getClassesFile(){        return m_ClassesFile;    }    /**     * Returns the Generated JahiaTemplatesPackage Object     *     * @return (JahiaTemplatesPackage) the package object     */    public JahiaTemplatesPackage getPackage(){        return m_Package;    }    /**     * Unzip the contents of the jar file in it's current folder     *     */    public void unzip() throws JahiaException {        // Unzip the file        m_ArchFile.unzip();    }    /**     * Unzip the contents of the jar file in a gived folder     *     * @param (String) path , the path where to extract file     */    public void unzip(String path) throws JahiaException {        // Unzip the file        m_ArchFile.unzip(path);    }    /**     * Unzip the classes file in a gived folder     *     * @param (String) path , the path where to extract file     */    public void unzipClassesFile(String path) throws JahiaException {        // Unzip the file        //m_JarClassesFile.extractEntry(CLASSES_FILE_ENTRY, path);        if ( m_JarClassesFile != null ) {            m_JarClassesFile.unzip(path);        }    }    /**     * Unzip an entry in a gived folder     *     * @param (String) entryName , the name of the entry     * @param (String) path , the path where to extract file     */    public void extractEntry( String entryName,                             String path) throws JahiaException {        // Unzip the entry        m_ArchFile.extractEntry(entryName, path);    }    /**     * Close the Jar file     *     */    public void closeArchiveFile(){        m_ArchFile.closeArchiveFile();        if ( m_ArchFile != null ){            m_ArchFile.closeArchiveFile();        }    }    /**     * Delete the classes file     *     */    public void deleteClassesFile(){        if ( m_JarClassesFile != null ){            m_JarClassesFile.closeArchiveFile();            m_ClassesFile.delete();        }    }} // End Class JahiaTemplatePackage

⌨️ 快捷键说明

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