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

📄 cmsimportmoduledata.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }

    /**
     * Gets the media of the master from the xml-file
     * @param currentElement The current element of the xml-file
     * @return Vector The vector contains the media (CmsMasterMedia-Object) of the master
     */
    private Vector getMasterMedia(Element currentElement) throws CmsException{
        Vector masterMedia = new Vector();
        // get the mediafiles of the master
        NodeList mediaNodes = currentElement.getElementsByTagName(CmsExportModuledata.C_EXPORT_TAG_MASTER_MEDIA);
        // walk through all media
        for (int j = 0; j < mediaNodes.getLength(); j++) {
            // get the name of the file where the mediadata is stored
            String mediaFilename = ((Element) mediaNodes.item(j)).getFirstChild().getNodeValue();
            // try to get the information of the media
            if ((mediaFilename != null) && !("".equals(mediaFilename.trim()))) {
                CmsMasterMedia newMedia = getMediaData(mediaFilename);
                masterMedia.add(newMedia);
            }
        }
        return masterMedia;
    }

    /**
     * Gets the information for a single media from the media-file
     * @param mediaFilename The name of the xml-file that contains the media information
     * @return CmsMasterMedia The mediainformation from the media-file
     */
    private CmsMasterMedia getMediaData(String mediaFilename) throws CmsException{
        String position, width, height, size, mimetype, type, title, name, description, contentfile;
        // get the new media object
        CmsMasterMedia newMedia = new CmsMasterMedia();
        // get the file with the data of the media
        Document mediaXml = this.getXmlFile(mediaFilename);
        Element media = (Element)mediaXml.getDocumentElement();
        position = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_POSITION);
        try{
            newMedia.setPosition(Integer.parseInt(position));
        } catch (Exception e){
        }
        width = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_WIDTH);
        try{
            newMedia.setWidth(Integer.parseInt(width));
        } catch (Exception e){
        }
        height = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_HEIGHT);
        try{
            newMedia.setHeight(Integer.parseInt(height));
        } catch (Exception e){
        }
        size = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_SIZE);
        try{
            newMedia.setSize(Integer.parseInt(size));
        } catch (Exception e){
        }
        mimetype = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_MIMETYPE);
        newMedia.setMimetype(mimetype);
        type = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_TYPE);
        try{
            newMedia.setType(Integer.parseInt(type));
        } catch (Exception e){
        }
        title = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_TITLE);
        newMedia.setTitle(title);
        name = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_NAME);
        newMedia.setName(name);
        description = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_DESCRIPTION);
        newMedia.setDescription(description);
        // get the content of the media
        contentfile = getTextNodeValue(media, CmsExportModuledata.C_EXPORT_TAG_MEDIA_CONTENT);
        byte[] mediacontent = getFileBytes(contentfile);
        newMedia.setMedia(mediacontent);
        return newMedia;
    }

    /**
     * Checks whether the path is on the list of files which are excluded from the import
     *
     * @return boolean true if path is on the excludeList
     * @param excludeList list of pathnames which should not be (over) written
     * @param path a complete path of a resource
     */
    private boolean inExcludeList(Vector excludeList, String path) {
        boolean onList = false;
        if (excludeList == null) {
            return onList;
        }
        int i=0;
        while (!onList && i<excludeList.size()) {
            onList = (path.equals(excludeList.elementAt(i)));
            i++;
        }
        return onList;
    }

    /**
     * Creates missing property definitions if needed.
     *
     * @param name the name of the property.
     * @param propertyType the type of the property.
     * @param resourceType the type of the resource.
     *
     * @exception throws CmsException if something goes wrong.
     */
    private void createPropertydefinition(String name, String resourceType)
        throws CmsException {
        // does the propertydefinition exists already?
        try {
            m_cms.readPropertydefinition(name, resourceType);
        } catch(CmsException exc) {
            // no: create it
            m_cms.createPropertydefinition(name, resourceType);
        }
    }

    /**
     * Returns a byte-array containing the content of the file.
     *
     * @param filename The name of the file to read.
     * @return bytes[] The content of the file.
     */
    private byte[] getFileBytes(String filename) throws CmsException{
        try{
            // is this a zip-file?
            if(m_importZip != null) {
                // yes
                ZipEntry entry = m_importZip.getEntry(filename);
                InputStream stream = m_importZip.getInputStream(entry);

                int charsRead = 0;
                int size = new Long(entry.getSize()).intValue();
                byte[] buffer = new byte[size];
                while(charsRead < size) {
                    charsRead += stream.read(buffer, charsRead, size - charsRead);
                }
                stream.close();
                return buffer;
            } else {
                // no - use directory
                File file = new File(m_importResource, filename);
                FileInputStream fileStream = new FileInputStream(file);

                int charsRead = 0;
                int size = new Long(file.length()).intValue();
                byte[] buffer = new byte[size];
                while(charsRead < size) {
                    charsRead += fileStream.read(buffer, charsRead, size - charsRead);
                }
                fileStream.close();
                return buffer;
            }
        } catch (Exception e){
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION,e);
        }
    }

    /**
     * Returns a buffered reader for this resource using the importFile as root.
     *
     * @param filename The name of the file to read.
     * @return BufferedReader The filereader for this file.
     */
    private BufferedReader getFileReader(String filename)
        throws Exception{
        // is this a zip-file?
        if(m_importZip != null) {
            // yes
            ZipEntry entry = m_importZip.getEntry(filename);
            InputStream stream = m_importZip.getInputStream(entry);
            return new BufferedReader( new InputStreamReader(stream));
        } else {
            // no - use directory
            File xmlFile = new File(m_importResource, filename);
            return new BufferedReader(new FileReader(xmlFile));
        }
    }

    /**
     * Gets the import resource and stores it in object-member.
     */
    private void getImportResource()
        throws CmsException {
        try {
            // get the import resource
            m_importResource = new File(CmsBase.getAbsolutePath(m_importFile));

            // if it is a file it must be a zip-file
            if(m_importResource.isFile()) {
                m_importZip = new ZipFile(m_importResource);
            }
        } catch(Exception exc) {
            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Returns the text for this node.
     *
     * @param elem the parent-element.
     * @param tag the tagname to get the value from.
     * @return the value of the tag.
     */
    private String getTextNodeValue(Element elem, String tag) {
        try {
            return elem.getElementsByTagName(tag).item(0).getFirstChild().getNodeValue();
        } catch(Exception exc) {
            // ignore the exception and return null
            return null;
        }
    }

    /**
     * Gets the xml-config file from the import resource and stores it in object-member.
     * Checks whether the import is from a module file
     */
    private void getXmlConfigFile()
        throws CmsException {

        try {
            BufferedReader xmlReader = getFileReader(C_EXPORT_XMLFILENAME);
            m_docXml = A_CmsXmlContent.getXmlParser().parse(xmlReader);
            xmlReader.close();
         } catch(Exception exc) {

            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
    }

    /**
     * Gets a xml-file from the import resource
     * @param filename The name of the file to read
     * @return Document The xml-document
     */
    private Document getXmlFile(String filename)
        throws CmsException {
        Document xmlDoc;
        try {
            BufferedReader xmlReader = getFileReader(filename);
            xmlDoc = A_CmsXmlContent.getXmlParser().parse(xmlReader);
            xmlReader.close();
         } catch(Exception exc) {

            throw new CmsException(CmsException.C_UNKNOWN_EXCEPTION, exc);
        }
        return xmlDoc;
    }

    /**
	 * coverts String Date in long
	 *
	 * @param date String
	 * @return long
	 */
	private long convertDate(String date){
		java.text.SimpleDateFormat formatterFullTime = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        long adate=0;
        try{
            adate=formatterFullTime.parse(date).getTime();
        }catch(ParseException e){
        }
        return adate;
	}

    /**
     * Gets the content definition class method constructor
     * @returns content definition object
     */
    protected CmsMasterContent getContentDefinition(String classname, Class[] classes, Object[] objects) {
        CmsMasterContent cd = null;
        try {
            Class cdClass = Class.forName(classname);
            Constructor co = cdClass.getConstructor(classes);
            cd = (CmsMasterContent)co.newInstance(objects);
        } catch (InvocationTargetException ite) {
            if (com.opencms.core.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Invocation target exception!");
            }
        } catch (NoSuchMethodException nsm) {
            if (com.opencms.core.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Requested method was not found!");
            }
        } catch (InstantiationException ie) {
            if (com.opencms.core.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: the reflected class is abstract!");
            }
        } catch (Exception e) {
            if (com.opencms.core.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, "[CmsImportModuledata] "+classname + " contentDefinitionConstructor: Other exception! "+e);
            }
            if(com.opencms.core.I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(A_OpenCms.C_OPENCMS_INFO, e.getMessage() );
            }
        }
        return cd;
    }
}

⌨️ 快捷键说明

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