cmspublishlist.java

来自「找了很久才找到到源代码」· Java 代码 · 共 638 行 · 第 1/2 页

JAVA
638
字号

        return m_publishSubResources;
    }

    /**
     * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
     */
    public void readExternal(ObjectInput in) throws IOException {

        // read the history id
        m_publishHistoryId = internalReadUUID(in);
        // read the project id
        m_projectId = internalReadUUID(in);
        if (m_projectId.isNullUUID()) {
            m_projectId = null;
        }
        // read the flags
        m_publishSiblings = (in.readInt() != 0);
        m_publishSubResources = (in.readInt() != 0);
        // read the list of direct published resources
        m_directPublishResources = internalReadUUIDList(in);
        // read the list of published files
        m_fileList = internalReadUUIDList(in);
        // read the list of published folders
        m_folderList = internalReadUUIDList(in);
        // read the list of deleted folders
        m_deletedFolderList = internalReadUUIDList(in);
        // set revive flag to indicate that resource lists must be revived
        m_needsRevive = true;
    }

    /**
     * Revives the publish list by populating the internal resource lists with <code>CmsResource</code> instances.<p>
     * 
     * @param cms a cms object used to read the resource instances
     */
    public void revive(CmsObject cms) {

        if (m_needsRevive) {
            if (m_directPublishResources != null) {
                m_directPublishResources = internalReadResourceList(cms, m_directPublishResources);
            }
            if (m_fileList != null) {
                m_fileList = internalReadResourceList(cms, m_fileList);
            }
            if (m_folderList != null) {
                m_folderList = internalReadResourceList(cms, m_folderList);
            }
            if (m_deletedFolderList != null) {
                m_deletedFolderList = internalReadResourceList(cms, m_deletedFolderList);
            }
            m_needsRevive = false;
        }
    }

    /**
     * Returns the number of all resources to be published.<p>
     * 
     * @return the number of all resources to be published
     */
    public int size() {

        if (m_needsRevive) {
            return 0;
        } else {
            return m_folderList.size() + m_fileList.size() + m_deletedFolderList.size();
        }
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {

        StringBuffer result = new StringBuffer();
        result.append("\n[\n");
        if (isDirectPublish()) {
            result.append("direct publish of resources: ").append(m_directPublishResources.toString()).append("\n");
        } else {
            result.append("publish of project: ").append(m_projectId).append("\n");
        }
        result.append("publish history ID: ").append(m_publishHistoryId.toString()).append("\n");
        result.append("resources: ").append(m_fileList.toString()).append("\n");
        result.append("folders: ").append(m_folderList.toString()).append("\n");
        result.append("deletedFolders: ").append(m_deletedFolderList.toString()).append("\n");
        result.append("]\n");
        return result.toString();
    }

    /**
     * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
     */
    public void writeExternal(ObjectOutput out) throws IOException {

        // write the history id
        out.write(m_publishHistoryId.toByteArray());
        // write the project id
        out.write((m_projectId != null) ? m_projectId.toByteArray() : CmsUUID.getNullUUID().toByteArray());
        // write the flags
        out.writeInt((m_publishSiblings) ? 1 : 0);
        out.writeInt((m_publishSubResources) ? 1 : 0);
        // write the list of direct publish resources by writing the uuid of each resource
        if (m_directPublishResources != null) {
            out.writeInt(m_directPublishResources.size());
            for (Iterator i = m_directPublishResources.iterator(); i.hasNext();) {
                out.write(((CmsResource)i.next()).getStructureId().toByteArray());
            }
        } else {
            out.writeInt(NIL);
        }
        // write the list of published files by writing the uuid of each resource
        if (m_fileList != null) {
            out.writeInt(m_fileList.size());
            for (Iterator i = m_fileList.iterator(); i.hasNext();) {
                out.write(((CmsResource)i.next()).getStructureId().toByteArray());
            }
        } else {
            out.writeInt(NIL);
        }
        // write the list of published folders by writing the uuid of each resource
        if (m_folderList != null) {
            out.writeInt(m_folderList.size());
            for (Iterator i = m_folderList.iterator(); i.hasNext();) {
                out.write(((CmsResource)i.next()).getStructureId().toByteArray());
            }
        } else {
            out.writeInt(NIL);
        }
        // write the list of deleted folders by writing the uuid of each resource
        if (m_deletedFolderList != null) {
            out.writeInt(m_deletedFolderList.size());
            for (Iterator i = m_deletedFolderList.iterator(); i.hasNext();) {
                out.write(((CmsResource)i.next()).getStructureId().toByteArray());
            }
        } else {
            out.writeInt(NIL);
        }
    }

    /**
     * Adds a new/changed Cms folder resource to the publish list.<p>
     * 
     * @param resource a new/changed Cms folder resource
     * @param check if set an exception is thrown if the specified resource is unchanged, 
     *              if not set the resource is ignored
     * 
     * @throws IllegalArgumentException if the specified resource is unchanged
     */
    protected void add(CmsResource resource, boolean check) throws IllegalArgumentException {

        if (check) {
            // it is essential that this method is only visible within the db package!
            if (resource.getState().isUnchanged()) {
                throw new CmsIllegalArgumentException(Messages.get().container(
                    Messages.ERR_PUBLISH_UNCHANGED_RESOURCE_1,
                    resource.getRootPath()));
            }
        }
        if (resource.isFolder()) {
            if (resource.getState().isDeleted()) {
                if (!m_deletedFolderList.contains(resource)) {
                    // only add files not already contained in the list
                    m_deletedFolderList.add(resource);
                }
            } else {
                if (!m_folderList.contains(resource)) {
                    // only add files not already contained in the list
                    m_folderList.add(resource);
                }
            }
        } else {
            if (!m_fileList.contains(resource)) {
                // only add files not already contained in the list
                // this is required to make sure no siblings are duplicated
                m_fileList.add(resource);
            }
        }
    }

    /**
     * Appends all the given resources to this publish list.<p>
     * 
     * @param resources resources to be added to this publish list
     * @param check if set an exception is thrown if the a resource is unchanged, 
     *              if not set the resource is ignored
     * 
     * @throws IllegalArgumentException if one of the resources is unchanged
     */
    protected void addAll(Collection resources, boolean check) throws IllegalArgumentException {

        // it is essential that this method is only visible within the db package!
        Iterator i = resources.iterator();
        while (i.hasNext()) {
            add((CmsResource)i.next(), check);
        }
    }

    /**
     * @see java.lang.Object#finalize()
     */
    protected void finalize() throws Throwable {

        try {
            if (m_fileList != null) {
                m_fileList.clear();
            }
            if (m_folderList != null) {
                m_folderList.clear();
            }
            if (m_deletedFolderList != null) {
                m_deletedFolderList.clear();
            }
        } catch (Throwable t) {
            // ignore
        }

        super.finalize();
    }

    /**
     * Initializes the publish list, ensuring all internal lists are in the right order.<p>
     */
    protected void initialize() {

        if (m_folderList != null) {
            // ensure folders are sorted starting with parent folders
            Collections.sort(m_folderList, CmsResource.COMPARE_ROOT_PATH);
        }

        if (m_fileList != null) {
            // ensure files are sorted starting with files in parent folders
            Collections.sort(m_fileList, CmsResource.COMPARE_ROOT_PATH);
        }

        if (m_deletedFolderList != null) {
            // ensure deleted folders are sorted starting with child folders
            Collections.sort(m_deletedFolderList, CmsResource.COMPARE_ROOT_PATH);
            Collections.reverse(m_deletedFolderList);
        }
    }

    /**
     * Removes a Cms resource from the publish list.<p>
     * 
     * @param resource a Cms resource
     * 
     * @return true if this publish list contains the specified resource
     * 
     * @see List#remove(java.lang.Object)
     */
    protected boolean remove(CmsResource resource) {

        // it is essential that this method is only visible within the db package!
        boolean ret = m_fileList.remove(resource);
        ret |= m_folderList.remove(resource);
        ret |= m_deletedFolderList.remove(resource);
        return ret;
    }

    /**
     * Builds a list of <code>CmsResource</code> instances from a list of resource structure ids.<p>
     * 
     * @param cms a cms object
     * @param uuidList the list of structure ids
     * @return a list of <code>CmsResource</code> instances
     */
    private List internalReadResourceList(CmsObject cms, List uuidList) {

        List resList = new ArrayList(uuidList.size());
        for (Iterator i = uuidList.iterator(); i.hasNext();) {
            try {
                CmsResource res = cms.readResource((CmsUUID)i.next(), CmsResourceFilter.ALL);
                resList.add(res);
            } catch (CmsException exc) {
                LOG.error(exc);
            }
        }

        return resList;
    }

    /**
     * Reads a UUID from an object input.<p>
     * 
     * @param in the object input
     * @return a UUID
     * @throws IOException
     */
    private CmsUUID internalReadUUID(ObjectInput in) throws IOException {

        byte[] bytes = new byte[UUID_LENGTH];
        in.readFully(bytes, 0, UUID_LENGTH);
        return new CmsUUID(bytes);
    }

    /**
     * Reads a sequence of UUIDs from an objetc input and builds a list of <code>CmsResource</code> instances from it.<p>
     * 
     * @param in the object input
     * @return a list of <code>{@link CmsResource}</code> instances
     * 
     * @throws IOException if something goes wrong 
     */
    private List internalReadUUIDList(ObjectInput in) throws IOException {

        List result = null;

        int i = in.readInt();
        if (i >= 0) {
            result = new ArrayList();
            while (i > 0) {
                result.add(internalReadUUID(in));
                i--;
            }
        }

        return result;
    }
}

⌨️ 快捷键说明

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