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

📄 cmsimportversion2.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                            String acflags = CmsImport.getChildElementTextValue(
                                currentEntry,
                                CmsImportExportManager.N_FLAGS);
                            String allowed = CmsImport.getChildElementTextValue(
                                currentEntry,
                                CmsImportExportManager.N_ACCESSCONTROL_ALLOWEDPERMISSIONS);
                            String denied = CmsImport.getChildElementTextValue(
                                currentEntry,
                                CmsImportExportManager.N_ACCESSCONTROL_DENIEDPERMISSIONS);

                            // add the entry to the list
                            aceList.add(getImportAccessControlEntry(res, id, allowed, denied, acflags));
                        }
                        importAccessControlEntries(res, aceList);
                        if (LOG.isInfoEnabled()) {
                            LOG.info(Messages.get().getBundle().key(
                                Messages.LOG_IMPORTING_4,
                                new Object[] {
                                    String.valueOf(i + 1),
                                    String.valueOf(importSize),
                                    translatedName,
                                    destination}));
                        }

                    } else {
                        // resource import failed, since no CmsResource was created
                        m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_OK);
                        m_report.println(org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));
                        if (LOG.isInfoEnabled()) {
                            LOG.info(Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(i + 1),
                                String.valueOf(importSize),
                                translatedName));
                        }
                    }
                } else {
                    // skip the file import, just print out the information to the report
                    m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    m_report.println(org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(Messages.get().getBundle().key(
                            Messages.LOG_SKIPPING_3,
                            String.valueOf(i + 1),
                            String.valueOf(importSize),
                            translatedName));
                    }
                }
            }

            // now merge the body and page control files. this only has to be done if the import
            // version is below version 3
            if ((getVersion() < 3) && m_convertToXmlPage) {
                mergePageFiles();
                removeFolders();
            }
        } catch (Exception e) {
            m_report.println(e);
            m_report.addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            throw new CmsImportExportException(message, e);
        } finally {
            // set the flag to overwrite colliding resources back to its original value
            OpenCms.getImportExportManager().setOverwriteCollidingResources(old_overwriteCollidingResources);
        }
    }

    /**
     * Imports a resource (file or folder) into the cms.<p>
     * 
     * @param source the path to the source-file
     * @param destination the path to the destination-file in the cms
     * @param uuid  the structure uuid of the resource
     * @param uuidresource  the resource uuid of the resource
     * @param resourceTypeId the ID of the file's resource type
     * @param resourceTypeName the name of the file's resource type
     * @param lastmodified the timestamp of the file
     * @param properties a list with properties for this resource
     * 
     * @return imported resource
     */
    private CmsResource importResource(
        String source,
        String destination,
        String uuid,
        String uuidresource,
        int resourceTypeId,
        String resourceTypeName,
        long lastmodified,
        List properties) {

        byte[] content = null;
        CmsResource res = null;
        String targetName = null;

        try {
            // get the file content
            if (source != null) {
                content = getFileBytes(source);
            }

            content = convertContent(source, destination, content, resourceTypeName);

            // get all required information to create a CmsResource
            int size = 0;
            if (content != null) {
                size = content.length;
            }
            // get the required UUIDs         
            CmsUUID curUser = m_cms.getRequestContext().currentUser().getId();
            CmsUUID newUuidstructure = new CmsUUID();
            CmsUUID newUuidresource = new CmsUUID();
            if (uuid != null) {
                newUuidstructure = new CmsUUID(uuid);
            }
            if (uuidresource != null) {
                newUuidresource = new CmsUUID(uuidresource);
            }

            // extract the name of the resource form the destination
            targetName = destination;
            if (targetName.endsWith("/")) {
                targetName = targetName.substring(0, targetName.length() - 1);
            }

            boolean isFolder = false;
            try {
                isFolder = CmsFolder.isFolderType(resourceTypeId);
            } catch (Throwable t) {
                // the specified resource type ID might be of an unknown resource type.
                // as another option, check the content length and resource type name 
                // to determine if the resource is a folder or not.              
                isFolder = ((size == 0) && CmsResourceTypeFolder.RESOURCE_TYPE_NAME.equalsIgnoreCase(resourceTypeName));
            }

            // create a new CmsResource                         
            CmsResource resource = new CmsResource(
                newUuidstructure,
                newUuidresource,
                targetName,
                resourceTypeId,
                isFolder,
                0,
                m_cms.getRequestContext().currentProject().getUuid(),
                CmsResource.STATE_NEW,
                lastmodified,
                curUser,
                lastmodified,
                curUser,
                CmsResource.DATE_RELEASED_DEFAULT,
                CmsResource.DATE_EXPIRED_DEFAULT,
                1,
                size,
                System.currentTimeMillis(),
                0);

            if (RESOURCE_TYPE_LINK_ID == resourceTypeId) {
                // store links for later conversion
                m_report.print(Messages.get().container(Messages.RPT_STORING_LINK_0), I_CmsReport.FORMAT_NOTE);
                m_linkStorage.put(m_importPath + destination, new String(content));
                m_linkPropertyStorage.put(m_importPath + destination, properties);
                res = resource;
            } else {
                //  import this resource in the VFS                         
                String resName = m_importPath + destination;
                res = m_cms.importResource(resName, resource, content, properties);
                try {
                    m_cms.unlockResource(resName);
                } catch (CmsLockException e) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(Messages.get().getBundle().key(
                            Messages.LOG_IMPORTEXPORT_UNABLE_TO_UNLOCK_RESOURCE_1,
                            resName), e);
                    }
                }
            }

            m_report.println(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

        } catch (CmsException exc) {
            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCE_1,
                targetName);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), exc);
            }
            // an error while importing the file
            m_report.println(exc);
            try {
                // Sleep some time after an error so that the report output has a chance to keep up
                Thread.sleep(1000);
            } catch (Exception e) {
                // ignore
            }
        }
        return res;
    }

    /**
     * Merges a single page.<p>
     * 
     * @param resourcename the resource name of the page
     * @throws CmsImportExportException if something goes wrong
     * @throws CmsXmlException if the page file could not be unmarshalled 
     */
    private void mergePageFile(String resourcename) throws CmsXmlException, CmsImportExportException {

        try {

            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_START_MERGING_1, resourcename));
            }

            // in OpenCms versions <5 node names have not been case sensitive. thus, nodes are read both in upper
            // and lower case letters, or have to be tested for equality ignoring upper/lower case...

            // get the header file
            CmsFile pagefile = m_cms.readFile(resourcename, CmsResourceFilter.ALL);
            Document contentXml = CmsXmlUtils.unmarshalHelper(pagefile.getContents(), null);

            // get the <masterTemplate> node to check the content. this node contains the name of the template file.
            String masterTemplateNodeName = "//masterTemplate";
            Node masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName);
            if (masterTemplateNode == null) {
                masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toLowerCase());
            }
            if (masterTemplateNode == null) {
                masterTemplateNode = contentXml.selectSingleNode(masterTemplateNodeName.toUpperCase());
            }

            // there is only one <masterTemplate> allowed
            String mastertemplate = null;
            if (masterTemplateNode != null) {
                // get the name of the mastertemplate
                mastertemplate = masterTemplateNode.getText().trim();
            }

            // get the <ELEMENTDEF> nodes to check the content.
            // this node contains the information for the body element.
            String elementDefNodeName = "//ELEMENTDEF";
            Node bodyNode = contentXml.selectSingleNode(elementDefNodeName);
            if (bodyNode == null) {
                bodyNode = contentXml.selectSingleNode(elementDefNodeName.toLowerCase());
            }

            // there is only one <ELEMENTDEF> allowed
            if (bodyNode != null) {

                String bodyclass = null;
                String bodyname = null;
                Map bodyparams = null;

                List nodes = ((Element)bodyNode).elements();
                for (int i = 0, n = nodes.size(); i < n; i++) {

                    Node node = (Node)nodes.get(i);

                    if ("CLASS".equalsIgnoreCase(node.getName())) {
                        bodyclass = node.getText().trim();
                    } else if ("TEMPLATE".equalsIgnoreCase(node.getName())) {
                        bodyname = node.getText().trim();
                        if (!bodyname.startsWith("/")) {
                            bodyname = CmsResource.getFolderPath(resourcename) + bodyname;
                        }
                    } else if ("PARAMETER".equalsIgnoreCase(node.getName())) {
                        Element paramElement = (Element)node;
                        if (bodyparams == null) {

⌨️ 快捷键说明

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