<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
    <screen name="ListContentApproval">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set field="rootContentId" from-field="parameters.rootContentId" default-value="${parameters.contentId}"/>
                <set field="rootContentRevisionSeqId" from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}"/>
                <set field="contentId" from-field="parameters.rootContentId" default-value="${parameters.contentId}"/>
                <set field="contentRevisionSeqId" from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}"/>

                <service service-name="getMostRecentRevision" result-map="revisionResult">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                </service>
                <set field="mostRecentRevisionSeqId" from-field="revisionResult.mostRecentRevisionSeqId"/>

                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="approval"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <service service-name="getApprovalsWithPermissions" result-map="result">
                    <field-map field-name="rootContentId" from-field="contentId"/>
                    <field-map field-name="contentRevisionSeqId" from-field="contentRevisionSeqId"/>
                    <field-map field-name="checkPermission" value="false"/>
                </service>

                <set field="contentApprovalList" from-field="result.contentApprovalList"/>
                <set field="title" value="${uiLabelMap.ContentCompDocApprovalsFor} ${contentId}, ${uiLabelMap.ContentCompDocRev} ${contentRevisionSeqId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container>
                            <link target="ListWaitingContentApproval" text="${uiLabelMap.ContentCompDocViewWaitingApprovals}" style="buttontext">
                                <parameter param-name="contentId"/>
                                <parameter param-name="contentRevisionSeqId"/>
                            </link>
                        </container>
                        <section>
                            <condition><if-compare field="content.contentTypeId" operator="equals" value="COMPDOC_INSTANCE"/></condition>
                            <widgets><include-screen name="rootInstanceApprovalStatus"/></widgets>
                        </section>
                        <screenlet title="${uiLabelMap.PageTitleListContentApproval}">
                            <include-form name="ListContentApproval" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                        <section>
                            <condition>
                                <if-compare field="content.contentTypeId" operator="equals" value="COMPDOC_TEMPLATE"/>
                            </condition>
                            <actions>
                                <set field="title" value="${uiLabelMap.PageTitleEditCompDocInstance} [${rootContentId}]"/>
                                <set from-field="parameters.contentRevisionSeqId" default-value="${parameters.rootContentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                            </actions>
                            <widgets>
                                <screenlet title="${uiLabelMap.CommonAdd}">
                                    <include-form name="AddContentApproval" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                </screenlet>
                            </widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ListWaitingContentApproval">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" default-value="${parameters.contentId}" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                <set from-field="parameters.rootContentId" default-value="${parameters.contentId}" field="contentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}" field="contentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>

                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="menuName" value="empty"/>
                <set field="currentMenuItemName" value="approval"/>
                <set field="titleProperty" value="ContentCompDocViewWaitingApprovals"/>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="approval"/>
                <service service-name="checkForWaitingApprovals" result-map="result">
                </service>

                <set field="contentApprovalList" from-field="result.contentApprovalList"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocViewWaitingApprovals}">
                            <include-form name="ListWaitingContentApproval" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="EditContentApproval">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="approval"/>

                <entity-one entity-name="ContentApproval" value-field="contentApproval" use-cache="true">
                    <field-map field-name="contentApprovalId" from-field="parameters.contentApprovalId"/>
                </entity-one>
                <set from-field="contentApproval.contentId" field="rootContentId"/>
                <set from-field="contentApproval.contentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true">
                    <field-map field-name="contentId" from-field="contentApproval.contentId"/>
                </entity-one>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="title" value="${uiLabelMap.PageTitleEditContentApprovalEditPage} ${contentApproval.contentApprovalId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.PageTitleEditContentApprovalEditPage}">
                            <include-form name="EditContentApproval" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ListContentRevisions">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set from-field="rootContentId" field="contentId"/>
                <set from-field="rootContentRevisionSeqId" field="contentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="revision"/>

                <entity-one entity-name="Content" value-field="content" use-cache="true">
                    <field-map field-name="contentId" from-field="contentId"/>
                </entity-one>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <entity-and entity-name="ContentRevision" list="contentRevisionList" use-cache="true">
                    <field-map field-name="contentId" from-field="contentId"/>
                </entity-and>

                <set field="title" value="${uiLabelMap.ContentCompDocRevisionListPageForContent} ${rootContentId} ${uiLabelMap.ContentCompDocRev} ${rootContentRevisionSeqId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocRevisionListPageForContent}">
                            <include-form name="ListContentRevisions" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="EditContentRevision">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" default-value="${parameters.contentId}" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                <set from-field="parameters.contentId" field="contentId"/>
                <set from-field="parameters.contentRevisionSeqId" field="contentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="revision"/>
                <set field="title" value="${uiLabelMap.ContentCompDocRevisionListPageForContent} ${rootContentId} ${uiLabelMap.ContentCompDocRevisions} ${rootContentRevisionSeqId}"/>

                <entity-one entity-name="ContentRevision" value-field="contentRevision" use-cache="true"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocRevisionListPageForContent}">
                            <include-form name="EditContentRevision" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ListContentRevisionItem">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set from-field="rootContentId" field="contentId"/>
                <set from-field="rootContentRevisionSeqId" field="contentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="revision"/>
                <set field="title" value="${uiLabelMap.ContentCompDocRevisionListPageForContent} ${rootContentId} ${uiLabelMap.ContentCompDocRevisions} ${rootContentRevisionSeqId}"/>

                <entity-and entity-name="ContentRevisionItem" list="contentRevisionItemList" use-cache="true">
                    <field-map field-name="contentId" from-field="parameters.contentId"/>
                    <field-map field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId"/>
                </entity-and>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocRevisionListPageForContent}">
                            <include-form name="ListContentRevisionItem" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="EditContentRevisionItem">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set from-field="parameters.contentId" default-value="${rootContentId}" field="contentId"/>
                <set from-field="parameters.contentRevisionSeqId" default-value="${rootContentRevisionSeqId}" field="contentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="revision"/>
                <set field="title" value="${uiLabelMap.ContentCompDocRevisionItemEditPage} ${contentId} ${uiLabelMap.ContentCompDocRevisions} ${contentRevisionSeqId}"/>

                <entity-one entity-name="ContentRevisionItem" value-field="contentRevisionItem" use-cache="true"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocRevisionItemEditPage}">
                            <include-form name="EditContentRevisionItem" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="FindCompDoc">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_VIEW"/>
            </condition>
            <actions>
                <set field="menuName" value="empty"/>
                <set field="titleProperty" value="PageTitleFindCompDoc"/>
                <set field="entityName" value="ContentAssocViewFrom"/>
                <set field="queryString" from-field="result.queryString"/>
                <set field="currentContentMenuItemName" value=""/>
                <set field="viewIndex" from-field="requestParameters.VIEW_INDEX" type="Integer"/>
                <set field="viewSize" from-field="requestParameters.VIEW_SIZE" type="Integer" default-value="20"/>
                <!-- there is a bad sideeffect of the DataResource admin screens. sets dataResourceId in session. -->
                <set field="dataResourceId" to-scope="user"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <section>
                            <widgets>
                                <decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
                                    <decorator-section name="menu-bar">
                                        <container style="button-bar">
                                            <link target="AddRootCompDocTemplate" text="${uiLabelMap.PageTitleCreateNewRootCompDocTemplate}" style="buttontext create"/>
                                            <link target="ListWaitingContentApproval" text="${uiLabelMap.ContentCompDocViewWaitingApprovals}" style="buttontext"/>
                                        </container>
                                    </decorator-section>
                                    <decorator-section name="search-options">
                                        <include-form name="FindCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                    </decorator-section>
                                    <decorator-section name="search-results">
                                        <include-form name="ListCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                    </decorator-section>
                                </decorator-screen>
                            </widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <!-- Combining this with FindCompDoc, don't see any reason to have them separate...
    <screen name="ListCompDoc">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set field="menuName" value="empty"/>
                <set field="title" value="List CompDoc"/>
                <set field="entityName" value="ContentAssocViewFrom"/>
                <set field="queryString" from-field="result.queryString"/>
                <set field="currentContentMenuItemName" value=""/>
                <set field="viewIndex" from-field="requestParameters.VIEW_INDEX" type="Integer"/>
                <set field="viewSize" from-field="requestParameters.VIEW_SIZE" type="Integer" default-value="20"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <container>
                            <link target="FindCompDoc" style="buttontext" text="${uiLabelMap.CommonFind">
                        <parameter param-name="contentId"/>
                        <parameter param-name="contentRevisionSeqId"/>
                        <parameter param-name="rootTemplateContentId"/>
                        <parameter param-name="rootTemplateRevSeqId"/>
                        <parameter param-name="rootInstanceContentId"/>
                        <parameter param-name="rootInstanceRevSeqId" from-field="rootInstanceRevSeqId"/>
                      </link>
                            <link target="AddRootCompDocTemplate"  text="${ContentCreateNewRootCompDocTemplate}" style="buttontext">
                        <parameter param-name="contentId"/>
                        <parameter param-name="contentRevisionSeqId"/>
                        <parameter param-name="rootTemplateContentId"/>
                        <parameter param-name="rootTemplateRevSeqId"/>
                        <parameter param-name="rootInstanceContentId"/>
                        <parameter param-name="rootInstanceRevSeqId"/>
                      </link>
                        </container>
                    </decorator-section>
                </decorator-screen>
             </widgets>
        </section>
    </screen>
    -->
    <screen name="ViewInstances">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set field="menuName" value="tree"/>
                <set field="entityName" value="ContentAssocViewFrom"/>
                <set field="queryString" from-field="result.queryString"/>
                <set field="currentContentMenuItemName" value=""/>
                <set field="viewIndex" from-field="requestParameters.VIEW_INDEX" type="Integer"/>
                <set field="viewSize" from-field="requestParameters.VIEW_SIZE" type="Integer" default-value="20"/>
                <set field="contentTypeId" value="COMPDOC_TEMPLATE"/>
                <entity-and entity-name="Content" list="compDocFindList">
                    <field-map field-name="instanceOfContentId" from-field="parameters.rootContentId"/>
                    <field-map field-name="contentTypeId" value="COMPDOC_INSTANCE"/>
                </entity-and>
                <set field="title" value="${uiLabelMap.ContentCompDocViewInstances} ${parameters.rootContentId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <screenlet title="${uiLabelMap.ContentCompDocViewInstances}">
                            <container style="button-bar">
                                <link target="AddRootCompDocTemplate" text="${uiLabelMap.PageTitleCreateNewRootCompDocTemplate}" style="buttontext">
                                    <parameter param-name="contentId"/>
                                    <parameter param-name="contentRevisionSeqId"/>
                                </link>
                            </container>
                            <include-form name="ListCompDocInstances" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        </screenlet>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="EditRootCompDoc">
        <section>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="edit"/>
                <set from-field="parameters.rootContentId" default-value="${parameters.contentId}" field="contentId"/>
                <set from-field="contentId" field="rootContentId"/>
                <entity-one entity-name="Content" value-field="content" use-cache="false"/>
                <entity-one entity-name="DataResource" value-field="dataResource" use-cache="false">
                    <field-map field-name="dataResourceId" from-field="content.dataResourceId"/>
                </entity-one>
                <set from-field="dataResource.mimeTypeId" field="mimeTypeId"/>
                <set from-field="content.contentTypeId" field="contentTypeId"/>
                <entity-condition entity-name="ContentRevision" list="contentRevisions" use-cache="true">
                    <condition-list combine="and">
                        <condition-expr field-name="contentId" operator="equals" from-field="rootContentId"/>
                    </condition-list>
                    <order-by field-name="-contentRevisionSeqId"/>
                </entity-condition>
                <set from-field="parameters.contentRevisionSeqId" default-value="${contentRevisions[0].contentRevisionSeqId}" field="contentRevisionSeqId"/>
                <set from-field="contentRevisionSeqId" field="rootContentRevisionSeqId"/>
            </actions>

            <widgets>
                <section>
                    <condition>
                        <if-compare field="contentTypeId" operator="equals" value="COMPDOC_TEMPLATE"/>
                    </condition>
                    <actions>
                        <set field="title" value="${uiLabelMap.PageTitleEditCompDocTemplate} ${rootContentId}"/>
                        <set from-field="parameters.contentRevisionSeqId" default-value="${contentRevisions[0].contentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                    </actions>
                    <widgets>
                        <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                            <decorator-section name="body">
                                <screenlet title="${uiLabelMap.PageTitleEditCompDocTemplate}">
                                    <container>
                                        <link target="AddRootCompDocInstance" text="${uiLabelMap.PageTitleCreateInstanceOfThisTemplate}" style="buttontext">
                                            <parameter param-name="contentId" from-field="rootContentId"/>
                                            <parameter param-name="contentRevisionSeqId" from-field="rootContentRevisionSeqId"/>
                                        </link>
                                        <link target="ViewInstances">
                                            <parameter param-name="rootContentId"/>
                                            <parameter param-name="contentRevisionSeqId" from-field="rootContentRevisionSeqId"/>
                                        </link>
                                    </container>
                                    <include-form name="EditRootCompDocTemplate" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                </screenlet>
                            </decorator-section>
                        </decorator-screen>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <if-compare field="content.contentTypeId" operator="equals" value="COMPDOC_INSTANCE"/>
                    </condition>
                    <actions>
                        <set field="title" value="${uiLabelMap.PageTitleEditCompDocInstance} [${rootContentId}]"/>
                        <set from-field="parameters.contentRevisionSeqId" default-value="${parameters.rootContentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                    </actions>
                    <widgets>
                        <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                            <decorator-section name="body">
                                <screenlet title="${uiLabelMap.PageTitleEditCompDocInstance}">
                                    <include-form name="EditRootCompDocInstance" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                </screenlet>
                            </decorator-section>
                        </decorator-screen>
                    </widgets>
                </section>
            </widgets>
        </section>
    </screen>
    <screen name="EditChildCompDoc">
        <section>
             <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set field="menuName" value="subtree"/>
                <set field="currentMenuItemName" value="edit"/>
                <!--
                    rootContentId, as always, refers to the root of the CompDoc tree.
                    If parameters.caContentIdTo exists (coming back from a persist operation) is set to rootContentId.
                    The rootContentId field is set from parameters.rootContentId, but if it does not exist, it is set from caContentIdTo.
                    -->
                <set field="contentId" from-field="parameters.contentId"/>
                <set field="rootContentId" from-field="parameters.rootContentId" default-value="${parameters.caContentIdTo}"/>
                <!-- need to get the latest rootContentRevisionSeqId -->
                <service service-name="getMostRecentRevision" result-map="revisionResult">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                </service>
                <set field="mostRecentRevisionSeqId" from-field="revisionResult.mostRecentRevisionSeqId"/>
                <set field="rootContentRevisionSeqId" from-field="parameters.rootContentRevisionSeqId" default-value="${parameters.contentRevisionSeqId}"/>
                <set field="rootContentRevisionSeqId" from-field="rootContentRevisionSeqId" default-value="${mostRecentRevisionSeqId}"/>

                <entity-one entity-name="Content" value-field="itemContent" use-cache="false">
                    <field-map field-name="contentId" from-field="contentId"/>
                </entity-one>
                <entity-one entity-name="ContentAssoc" value-field="contentAssoc">
                    <field-map field-name="contentIdTo" from-field="rootContentId"/>
                    <field-map field-name="contentId" from-field="contentId"/>
                    <field-map field-name="fromDate" from-field="parameters.caFromDate"/>
                    <field-map field-name="contentAssocTypeId" value="COMPDOC_PART"/>
                </entity-one>

                <!-- If parameters.itemContentRevisionSeqId does not exist, it is necessary to the contentRevisionSeqId
                    from the ContentRevisionItem that is most recent, but not greater than the rootContentRevisionSeqId.
                    This operation effectively gets the current ContentRevisionItem entity, in any case, and
                    that is needed to get the dataResourceId for this revision, which may not be the latest.
                    -->
                <entity-condition entity-name="ContentRevisionItem" list="contentRevisionItems" use-cache="true">
                    <condition-list combine="and">
                        <condition-expr field-name="contentId" from-field="rootContentId"/>
                        <condition-expr field-name="itemContentId" from-field="contentId"/>
                        <condition-expr field-name="contentRevisionSeqId" operator="less-equals" from-field="parameters.contentRevisionSeqId" ignore-if-empty="true"/>
                    </condition-list>
                    <order-by field-name="-contentRevisionSeqId"/>
                </entity-condition>
                <set field="itemContentRevisionSeqId" from-field="parameters.itemContentRevisionSeqId" default-value="${contentRevisionItems[0].contentRevisionSeqId}"/>
                <set field="dataResourceId" from-field="contentRevisionItems[0].newDataResourceId" default-value="${itemContent.dataResourceId}"/>
                <entity-one entity-name="DataResource" value-field="dataResource" use-cache="false">
                    <field-map field-name="dataResourceId" from-field="dataResourceId"/>
                </entity-one>
                <set field="mimeTypeId" from-field="dataResource.mimeTypeId"/>
            </actions>
            <widgets>
                <section>
                    <condition>
                        <if-compare field="itemContent.contentTypeId" operator="equals" value="TEMPLATE"/>
                    </condition>
                    <actions>
                        <set field="title" value="${uiLabelMap.PageTitleEditCompDocTemplate} [${contentId}, part of ${rootContentId}]"/>
                        <set field="childCompDocTarget" value="updateChildCompDocTemplate"/>
                        <set field="contentTypeId" value="TEMPLATE"/>
                    </actions>
                    <widgets>
                        <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                            <decorator-section name="body">
                                <section>
                                    <condition>
                                        <if-compare-field field="mostRecentRevisionSeqId" operator="equals" to-field="rootContentRevisionSeqId"/>
                                    </condition>
                                    <widgets>
                                        <container><label style="tableheadtext" text="${uiLabelMap.ContentEditingLatestRevision} [${mostRecentRevisionSeqId}]"/></container>
                                        <include-form name="EditChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                        <include-screen name="ContentViewLink"/>
                                        <include-screen name="UploadCompDocContent"/>
                                    </widgets>
                                </section>
                                <section>
                                    <condition>
                                        <and>
                                            <not><if-empty field="mostRecentRevisionSeqId"/></not>
                                            <not><if-empty field="rootContentRevisionSeqId"/></not>
                                            <if-compare-field field="mostRecentRevisionSeqId" operator="greater" to-field="rootContentRevisionSeqId"/>
                                        </and>
                                    </condition>
                                    <widgets>
                                        <container>
                                            <label style="tableheadtext" text="${uiLabelMap.ContentCompDocRevisions} [${rootContentRevisionSeqId}], Latest is [${mostRecentRevisionSeqId}]"/>
                                            <link style="buttontext" text="${uiLabelMap.ContentLatest}" target="EditChildCompDoc">
                                                <parameter param-name="contentId"/>
                                                <parameter param-name="rootContentId"/>
                                                <parameter param-name="caFromDate" from-field="fromDate"/>
                                            </link>
                                            <include-screen name="ContentViewLink"/>
                                        </container>
                                        <include-form name="ViewChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                    </widgets>
                                </section>
                            </decorator-section>
                        </decorator-screen>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <if-compare field="itemContent.contentTypeId" operator="equals" value="DOCUMENT"/>
                    </condition>
                    <actions>
                        <set field="title" value="${uiLabelMap.PageTitleEditCompDocInstance} [${contentId} of ${contentId}]"/>
                        <set value="updateChildCompDocInstance" field="childCompDocTarget"/>
                        <set value="DOCUMENT" field="contentTypeId"/>
                        <!--
                        <entity-condition entity-name="MaxRevisionItemView" list="rootRevList" use-cache="false" >
                           <condition-list combine="and">
                                <condition-expr field-name="rootRevisionContentId" operator="equals" env-name="rootInstanceContentId"/>
                                <condition-expr field-name="contentId" operator="equals" env-name="contentId"/>
                           </condition-list>

                           <select-field field-name="rootRevisionContentId"/>
                           <select-field field-name="contentId"/>
                           <select-field field-name="maxRevisionSeqId"/>

                           <order-by field-name="-maxRevisionSeqId"/>
                        </entity-condition>
                        <set from-field="rootRevList[0].maxRevisionSeqId" field="rootInstanceRevSeqId"/>
                            -->
                        <entity-one entity-name="Content" value-field="templateContent" use-cache="false">
                            <field-map field-name="contentId" from-field="itemContent.instanceOfContentId"/>
                        </entity-one>
                        <entity-one entity-name="DataResource" value-field="templateDataResource" use-cache="false">
                            <field-map field-name="dataResourceId" from-field="templateContent.dataResourceId"/>
                        </entity-one>
                    </actions>
                    <widgets>
                        <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                            <decorator-section name="body">
                                <include-screen name="ContentViewLink"/>
                                <include-form name="EditChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                                <include-screen name="UploadCompDocContent"/>
                            </decorator-section>
                        </decorator-screen>
                    </widgets>
                </section>
            </widgets>
        </section>
    </screen>
    <screen name="ContentViewLink">
        <section>
            <actions>
            </actions>
            <widgets>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/msword"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/pdf"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.oasis.opendocument.text"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/jpeg"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/gif"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/tiff"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/png"/>
                        </or>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <container>
                            <link target="ViewCompDocContentBinary" text="${uiLabelMap.PageTitleViewCompDocContentBinary}" style="buttontext">
                            <parameter param-name="contentId"/>
                            <parameter param-name="contentRevisionSeqId" from-field="itemContentRevisionSeqId"/>
                            <parameter param-name="rootContentId"/>
                           </link>
                        </container>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/html"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/plain"/>
                        </or>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <container>
                        <link target="ViewCompDocContentHtml" text="${uiLabelMap.PageTitleViewCompDocContentHtml}" style="buttontext">
                            <parameter param-name="contentId"/>
                            <parameter param-name="contentRevisionSeqId" from-field="itemContentRevisionSeqId"/>
                            <parameter param-name="rootContentId"/>
                       </link>
                        </container>
                    </widgets>
                </section>
                <section>
                    <condition>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!-- link on form
                        <container>
                            <link target="EditSurvey" text="${uiLabelMap.PageTitleViewCompDocContent}" style="buttontext">
                                <parameter param-name="surveyId from-field="dataResource.relatedDetailId"/>
                                <parameter param-name="rootContentId"/>
                            </link>
                        </container>
                            -->
                    </widgets>
                </section>
                <section>
                    <condition>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!-- link on form
                        <container>
                            <link target="EditSurveyResponse" text="${uiLabelMap.PageTitleViewCompDocContent}" style="buttontext">
                                <parameter param-name="surveyResponseId from-field="dataResource.relatedDetailId"/>
                                <parameter param-name="rootContentId"/>
                            </link>
                        </container>
                            -->
                    </widgets>
                </section>
                <section>
                    <condition>
                      <not>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/msword"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/pdf"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.oasis.opendocument.text"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/jpeg"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/gif"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/tiff"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/png"/>

                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/html"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/plain"/>

                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                        </or>
                      </not>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!--
                        <label text="View screen not available for mime-type: ${dataResource.mimeTypeId}"/>
                            -->
                    </widgets>
                </section>
            </widgets>
        </section>
    </screen>
    <screen name="UploadCompDocContent">
        <section>
            <actions>
            </actions>
            <widgets>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/msword"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/pdf"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.oasis.opendocument.text"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/jpeg"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/gif"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/tiff"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/png"/>
                        </or>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <include-form name="UploadCompDocContent" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/html"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/plain"/>
                        </or>
                    </condition>
                    <actions>
                        <entity-one entity-name="ElectronicText" value-field="electronicText">
                            <field-map field-name="dataResourceId" from-field="dataResource.dataResourceId"/>
                        </entity-one>
                        <set from-field="electronicText.textData" field="textData"/>
                    </actions>
                    <widgets>
                        <include-form name="EditCompDocTextContent" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
                            <!--
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                                -->
                        </or>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!-- Don't put this link here. It is called in the form.
                                <include-form name="UploadCompDocSurveyId" location="component://content/widget/compdoc/CompDocForms.xml"/>
                        -->
                        <include-form name="UploadCompDocPdf2Survey" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
                            <!--
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                                -->
                        </or>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!-- Don't put this link here. It is called in the form.
                                <link text="Edit Survey Response"/>
                                -->
                    </widgets>
                </section>
                <section>
                    <condition>
                      <not>
                        <or>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/msword"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/pdf"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.oasis.opendocument.text"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/jpeg"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/gif"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/tiff"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="image/png"/>

                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/html"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="text/plain"/>

                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
                            <if-compare field="dataResource.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                        </or>
                      </not>
                    </condition>
                    <actions>
                    </actions>
                    <widgets>
                        <!--
                        <label text="Upload screen not available for mime-type: ${dataResource.mimeTypeId}"/>
                            -->
                    </widgets>
                </section>
            </widgets>
        </section>
    </screen>
    <screen name="ViewCompDocContentHtml">
        <section>
            <actions>
            </actions>
            <widgets>
                <content content-id="${parameters.contentId}"/>
            </widgets>
        </section>
    </screen>
    <screen name="AddRootCompDocInstance">
        <section>
             <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set value="COMPDOC_INSTANCE" field="contentTypeId"/>
                <entity-condition entity-name="ContentRevision" list="contentRevisions" use-cache="true">
                    <condition-list combine="and">
                        <condition-expr field-name="contentId" operator="equals" from-field="rootContentId"/>
                    </condition-list>
                    <order-by field-name="-contentRevisionSeqId"/>
                </entity-condition>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${contentRevisions[0].contentRevisionSeqId}" field="rootContentRevisionSeqId"/>
                <entity-one entity-name="Content" value-field="templateContent">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                </entity-one>
                <set from-field="templateContent.contentName" field="contentName"/>

                <set field="menuName" value="tree"/>
                <set field="title" value="${uiLabelMap.ContentCompDocAddDocumentInstancePageForTemplate}: ${rootContentId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="AddRootCompDocInstance" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="AddRootCompDocTemplate">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="titleProperty" value="PageTitleAddCompositeDocumentTemplate"/>
                <set field="contentTypeId" value="COMPDOC_TEMPLATE"/>
                <set field="createChildCompDoc" value="createChildCompDocTemplate"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="AddRootCompDocTemplate" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="AddChildCompDocInstance">
        <section>
             <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="titleProperty" value="PageTitleAddCompositeDocumentInstance"/>
                <set field="contentIdTo" from-field="parameters.rootContentId"/>
                <set field="templateContentId" from-field="parameters.instanceOfContentId"/>
                <entity-one entity-name="Content" value-field="templateContent">
                    <field-map field-name="contentId" from-field="templateContentId"/>
                </entity-one>
                <set from-field="templateContent.contentName" field="contentName"/>

                <get-related-one value-field="templateContent" relation-name="DataResource" to-value-field="templateDataResource"/>
                <set field="templateDataResourceTypeId" from-field="templateDataResource.dataResourceTypeId"/>
                <set field="mimeTypeId" from-field="templateDataResource.mimeTypeId"/>

                <set field="contentAssocTypeId" value="COMPDOC_PART"/>
                <set field="contentTypeId" value="DOCUMENT"/>
                <set field="sequenceNum" from-field="parameters.caSequenceNum" default-value="${parameters.sequenceNum}"/>
                <set field="childCompDocTarget" value="createChildCompDocInstance"/>
                <set field="contentId" from-field="parameters.contentId"/>

                <set field="rootContentId" from-field="parameters.rootContentId" default-value="${parameters.contentIdTo}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="AddChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="AddChildCompDocTemplate">
        <section>
             <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="titleProperty" value="PageTitleAddCompositeDocumentTemplate"/>
                <set field="contentIdTo" from-field="parameters.rootContentId" default-value="${parameters.contentIdTo}"/>
                <set field="rootContentId" from-field="contentIdTo"/>
                <set field="rootContentRevisionSeqId" from-field="parameters.rootContentRevisionSeqId"/>
                <set field="contentAssocTypeId" value="COMPDOC_PART"/>
                <set field="sequenceNum" from-field="parameters.caSequenceNum" default-value="${parameters.sequenceNum}"/>
                <set field="contentTypeId" value="TEMPLATE"/>
                <set field="contentId" value=""/>
                <set field="instanceOfDataResourceTypeId" value=""/>
                <set field="childCompDocTarget" value="createChildCompDocTemplate"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="AddChildCompDoc" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ViewCompDocTemplateTree">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>
            <actions>
                <set from-field="parameters.rootContentId" field="rootContentId"/>
                <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                <set value="COMPDOC_TEMPLATE" field="contentTypeId"/>
                <service service-name="getMostRecentRevision" result-map="revisionResult">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                </service>
                <set from-field="revisionResult.mostRecentRevisionSeqId" field="mostRecentRevisionSeqId"/>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${mostRecentRevisionSeqId}" field="rootContentRevisionSeqId"/>

                <set field="menuName" value="tree"/>
                <set field="title" value="${uiLabelMap.ContentTemplateRoot} ${rootContentId}, ${uiLabelMap.ContentCompDocRev} ${rootContentRevisionSeqId}"/>
                <set field="currentMenuItemName" value="viewtree"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                                <container>
                                    <link target="ViewInstances" text="${uiLabelMap.ContentCompDocViewInstances}" style="buttontext">
                                        <parameter param-name="rootContentId"/>
                                        <parameter param-name="contentRevisionSeqId" from-field="rootContentRevisionSeqId"/>
                                    </link>
                                    <link target="AddRootCompDocInstance" text="${uiLabelMap.PageTitleCreateInstanceOfThisTemplate}" style="buttontext">
                                        <parameter param-name="rootContentId"/>
                                        <parameter param-name="rootContentRevisionSeqId"/>
                                    </link>
                                </container>
                        <include-tree name="CompDocTemplateTree" location="component://content/widget/compdoc/CompDocTemplateTree.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ViewCompDocInstanceTree">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_CREATE"/>
            </condition>

            <actions>
                <set field="menuName" value="tree"/>
                <set field="currentMenuItemName" value="viewtree2"/>
                   <set from-field="parameters.rootContentId" field="rootContentId"/>
                   <set from-field="parameters.rootContentRevisionSeqId" field="rootContentRevisionSeqId"/>
                   <set value="COMPDOC_INSTANCE" field="contentTypeId"/>

                <service service-name="getMostRecentRevision" result-map="revisionResult">
                    <field-map field-name="contentId" from-field="parameters.rootContentId"/>
                </service>
                <set from-field="revisionResult.mostRecentRevisionSeqId" field="mostRecentRevisionSeqId"/>
                <set from-field="parameters.rootContentRevisionSeqId" default-value="${mostRecentRevisionSeqId}" field="rootContentRevisionSeqId"/>

                <entity-one entity-name="Content" value-field="instanceContent">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                </entity-one>
                <set from-field="instanceContent.instanceOfContentId" field="templateContentId"/>
                <entity-condition entity-name="ContentRevision" list="contentTemplateRevisions" use-cache="true">
                    <condition-list combine="and">
                        <condition-expr field-name="contentId" operator="equals" from-field="templateContentId"/>
                    </condition-list>
                    <order-by field-name="-contentRevisionSeqId"/>
                </entity-condition>
                <set field="templateContentRevisionSeqId" from-field="contentTemplateRevisions[0].contentRevisionSeqId"/>
                <set field="title" value="${uiLabelMap.ContentRoot} ${rootContentId}, ${uiLabelMap.ContentCompDocRev} ${rootContentRevisionSeqId}  ${uiLabelMap.FormFieldTitle_instanceOfContentId} ${instanceContent.instanceOfContentId}, ${uiLabelMap.ContentCompDocRev} ${templateContentRevisionSeqId}"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                       <container>
                            <link target="GenCompDocPdf" text="${uiLabelMap.ContentCompDocGeneratePDF}" style="buttontext">
                                <parameter param-name="contentId" from-field="rootContentId"/>
                                <parameter param-name="contentRevisionSeqId"/>
                            </link>
                        </container>
                       <include-tree name="CompDocInstanceTree" location="component://content/widget/compdoc/CompDocTemplateTree.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="rootTemplateLine">
        <section>
            <widgets>
                <include-menu name="rootTemplateLine" location="component://content/widget/compdoc/CompDocMenus.xml"/>
            </widgets>
        </section>
    </screen>
    <screen name="rootInstanceLine">
        <section>
            <widgets>
                <include-menu name="rootInstanceLine" location="component://content/widget/compdoc/CompDocMenus.xml"/>
                <include-screen name="rootInstanceApprovalStatus"/>
            </widgets>
        </section>
    </screen>
    <screen name="rootInstanceApprovalStatus">
        <section>
            <actions>
                <service service-name="getFinalApprovalStatus" result-map="approvalStatusResult">
                    <field-map field-name="contentId" from-field="rootContentId"/>
                    <field-map field-name="contentRevisionSeqId" from-field="rootContentRevisionSeqId"/>
                </service>
                <entity-one entity-name="StatusItem" value-field="statusItem">
                    <field-map field-name="statusId" from-field="approvalStatusResult.approvalStatusId"/>
                </entity-one>
            </actions>
            <widgets>
                <container>
                    <label text="${uiLabelMap.ContentCompDocApprovalStatus}: ${statusItem.description}" style="h2"/>
                    <section>
                        <condition>
                            <and>
                                <if-compare-field field="mostRecentRevisionSeqId" operator="equals" to-field="rootContentRevisionSeqId"/>
                                <if-compare field="approvalStatusResult.approvalStatusId" operator="equals" value="CNTAP_NOT_READY"/>
                            </and>
                        </condition>
                        <widgets>
                            <link text="${uiLabelMap.ContentCompDocStartApprovalProcess}" target="prepForApproval" style="buttontext">
                                <parameter param-name="rootContentId"/>
                                <parameter param-name="rootContentRevisionSeqId"/>
                            </link>
                        </widgets>
                    </section>
                </container>
            </widgets>
        </section>
    </screen>

    <screen name="childTemplateLine">
        <section>
            <actions>
                <script location="component://content/groovyScripts/content/PrepSeqNo.groovy"/>
            </actions>
            <widgets>
                <include-menu name="childTemplateLine" location="component://content/widget/compdoc/CompDocMenus.xml"/>
            </widgets>
        </section>
    </screen>
    <screen name="childInstanceLine">
        <section>
            <actions>
                <script location="component://content/groovyScripts/content/PrepSeqNo.groovy"/>
                <!--  find the most recent ContentAssoc/ContentRevisionItem view using the rootInstanceContentId
                      as the contentId value and rootInstanceRevSeqId for the revision
                      and the contentId of the current template part as the itemContentId
                      -->
                <entity-condition entity-name="ContentAssocRevisionItemView" use-cache="false" list="assocRevisionItemViewList">
                   <condition-list combine="and">
                        <condition-expr field-name="contentIdTo" operator="equals" from-field="rootContentId"/>
                        <condition-expr field-name="rootRevisionContentId" operator="equals" from-field="rootContentId"/>
                        <condition-expr field-name="instanceOfContentId" operator="equals" from-field="contentId"/>
                        <condition-expr field-name="contentAssocTypeId" operator="equals" value="COMPDOC_PART"/>
                        <condition-expr field-name="contentRevisionSeqId" operator="less-equals" from-field="rootContentRevisionSeqId"/>
                        <condition-expr field-name="fromDate" operator="less-equals" from-field="nowTimestamp"/>
                        <condition-list combine="or">
                            <condition-expr field-name="thruDate" operator="equals" value=""/>
                            <condition-expr field-name="thruDate" operator="greater" from-field="nowTimestamp"/>
                        </condition-list>
                   </condition-list>

                   <select-field field-name="rootRevisionContentId"/>
                   <select-field field-name="itemContentId"/>
                   <select-field field-name="maxRevisionSeqId"/>
                   <select-field field-name="contentId"/>
                   <select-field field-name="contentIdTo"/>
                   <select-field field-name="contentAssocTypeId"/>
                   <select-field field-name="fromDate"/>
                   <select-field field-name="sequenceNum"/>

                   <order-by field-name="-maxRevisionSeqId"/>
                </entity-condition>
            </actions>
            <widgets>
                <!--
                <label text="rootRevisionContentId : ${rootRevisionContentId}"></label>
                <label text="itemContentId : ${itemContentId}"></label>
                <label text="maxRevisionSeqId : ${maxRevisionSeqId}"></label>
                <label text="contentIdTo : ${contentIdTo}"></label>
                <label text="fromDate : ${fromDate}"></label>
                <label text="instanceContentId : ${instanceContentId}"></label>
                <label text="instanceContentRevisionSeqId : ${instanceContentRevisionSeqId}"></label>
                <label text="assocRevisionItemView : ${assocRevisionItemView}"></label>
                -->
                <container>
                    <label text="${contentName}" style="tableheadtext"/>
                    <section>
                        <condition>
                            <if-compare-field field="mostRecentRevisionSeqId" operator="equals" to-field="rootContentRevisionSeqId"/>
                        </condition>
                        <widgets>
                            <link text="${uiLabelMap.PageTitleAddCompDocInstance}" target="AddChildCompDocInstance" style="buttontext">
                                <parameter param-name="rootContentId"/>
                                <parameter param-name="instanceOfContentId" from-field="contentId"/>
                                <parameter param-name="caSequenceNum" from-field="maxRevisionSeqId"/>
                            </link>
                        </widgets>
                    </section>
                </container>
                <iterate-section entry="assocRevisionItemView" list="assocRevisionItemViewList">
                    <section>
                        <actions>
                            <entity-one entity-name="Content" value-field="instanceContent" auto-field-map="false">
                                <field-map field-name="contentId" from-field="assocRevisionItemView.itemContentId"/>
                            </entity-one>
                            <entity-one entity-name="DataResource" value-field="instanceDataResource" auto-field-map="false">
                                <field-map field-name="dataResourceId" from-field="instanceContent.dataResourceId"/>
                            </entity-one>
                        </actions>
                        <widgets>
                            <container>
                                <label text="- ${instanceContent.contentName} [${instanceContent.contentId}] - ${instanceDataResource.objectInfo} ${instanceDataResource.relatedDetailId}" style="tableheadtext"/>
                                <link text="${uiLabelMap.PageTitleEditCompDocInstance}" target="EditChildCompDoc"  style="buttontext">
                                    <parameter param-name="contentId" from-field="assocRevisionItemView.contentId"/>
                                    <parameter param-name="rootContentId" from-field="assocRevisionItemView.contentIdTo"/>
                                    <parameter param-name="caContentAssocTypeId" from-field="assocRevisionItemView.contentAssocTypeId"/>
                                    <parameter param-name="caFromDate" from-field="assocRevisionItemView.fromDate"/>
                                    <parameter param-name="contentRevisionSeqId" from-field="assocRevisionItemView.maxRevisionSeqId"/>
                                    <parameter param-name="rootContentRevisionSeqId"/>
                                </link>
                                <link text="${uiLabelMap.ContentCompDocGeneratePDF}" target="GenContentPdf" style="buttontext">
                                    <parameter param-name="contentId" from-field="assocRevisionItemView.contentId"/>
                                    <parameter param-name="caSequenceNum" from-field="sequenceNum"/>
                                </link>
                            </container>
                        </widgets>
                    </section>
                </iterate-section>
            </widgets>
        </section>
    </screen>

    <screen name="EditContentRevisionAndItem">
        <section>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="EditContentRevisionAndItem" location="component://content/widget/compdoc/CompDocForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="EditCompDocContentRole">
        <section>
            <condition>
                <if-has-permission permission="CONTENTMGR" action="_UPDATE"/>
            </condition>
            <actions>
                <set field="menuName" value="tree"/>
                <set field="titleProperty" value="ContentCompDocContentRoleEditPage"/>
                <set field="currentMenuItemName" value="role"/>

                <set field="defaultContentId" from-field="contentId" from-scope="user"/>
                <set field="contentId" from-field="parameters.contentId" to-scope="screen" default-value="${defaultContentId}"/>
                <set field="contentId" from-field="contentId" to-scope="user"/>
                <set field="contentRoleTarget" value="CompDoc"/>
            </actions>
            <widgets>
                <decorator-screen name="commonCompDocDecorator" location="component://content/widget/CommonScreens.xml">
                    <decorator-section name="body">
                        <include-form name="ListContentRole" location="component://content/widget/content/ContentForms.xml"/>
                        <include-form name="AddContentRole" location="component://content/widget/content/ContentForms.xml"/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
    <screen name="ViewCompDocContent">
        <section>
            <actions>
                <entity-one entity-name="Content" value-field="content" use-cache="true"/>
                <entity-one entity-name="DataResource" value-field="dataResource" use-cache="true">
                    <field-map field-name="dataResourceId" from-field="content.dataResourceId"/>
                </entity-one>
            </actions>
            <widgets>
                <section>
                    <condition>
                        <or>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                            <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                        </or>
                    </condition>
                    <widgets>
                    </widgets>
                </section>
                <section>
                    <condition>
                        <not>
                            <or>
                                <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY"/>
                                <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="SURVEY_RESPONSE"/>
                            </or>
                        </not>
                    </condition>
                    <widgets>
                    </widgets>
                </section>
            </widgets>
        </section>
    </screen>
</screens>
