Skip to content

Commit 98ff340

Browse files
committed
MCR-3551 allow hiding of publicly available derivates
1 parent 227dec6 commit 98ff340

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

mycore-base/src/main/java/org/mycore/services/zipper/MCRCompressServlet.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@
4040

4141
import org.apache.logging.log4j.LogManager;
4242
import org.apache.logging.log4j.Logger;
43+
import org.jdom2.Attribute;
4344
import org.jdom2.Element;
45+
import org.jdom2.filter.Filters;
46+
import org.jdom2.xpath.XPathExpression;
47+
import org.jdom2.xpath.XPathFactory;
4448
import org.mycore.access.MCRAccessManager;
49+
import org.mycore.common.MCRConstants;
4550
import org.mycore.common.MCRException;
4651
import org.mycore.common.MCRXlink;
4752
import org.mycore.common.content.MCRContent;
4853
import org.mycore.common.content.transformer.MCRContentTransformer;
4954
import org.mycore.common.content.transformer.MCRParameterizedTransformer;
5055
import org.mycore.common.xml.MCRLayoutService;
56+
import org.mycore.common.xml.MCRURIResolver;
5157
import org.mycore.common.xml.MCRXMLFunctions;
5258
import org.mycore.common.xsl.MCRParameterCollector;
5359
import org.mycore.datamodel.common.MCRISO8601Date;
@@ -183,14 +189,34 @@ private void sendObject(MCRObjectID id, MCRServletJob job, T container) throws E
183189
.getChild(MCRObjectStructure.ELEMENT_DERIVATE_OBJECTS)
184190
.getChildren("derobject");
185191

192+
XPathFactory xpathFactory = XPathFactory.instance();
193+
XPathExpression<Attribute> derivateTypeXpath = xpathFactory
194+
.compile("classification[@classid='derivate_types']/@categid",
195+
Filters.attribute(), null, MCRConstants.XML_NAMESPACE);
196+
XPathExpression<Boolean> exportedXpath = xpathFactory
197+
.compile(".//category/label[lang('x-export')]/@text='false'",
198+
Filters.fboolean(), null, MCRConstants.XML_NAMESPACE);
199+
186200
for (Element el : li) {
187201
if (el.getAttributeValue(MCRXMLConstants.INHERITED).equals("0")) {
188202
String ownerID = el.getAttributeValue(MCRXlink.HREF, XLINK_NAMESPACE);
189203
MCRObjectID derId = MCRObjectID.getInstance(ownerID);
190204
// here the access check is tested only against the derivate
191205
if (MCRAccessManager.checkDerivateContentPermission(derId, PERMISSION_READ)
192206
&& MCRXMLFunctions.isDisplayedEnabledDerivate(ownerID)) {
193-
sendDerivate(derId, null, container);
207+
208+
// export derivate if no derivate type has an 'x-export' property of 'false'
209+
boolean exported = derivateTypeXpath.evaluate(el).stream().noneMatch(derivateTypeAttribute -> {
210+
String derivateType = derivateTypeAttribute.getValue();
211+
Element derivateTypeElement = MCRURIResolver.obtainInstance()
212+
.resolve("classification:metadata:0:children:derivate_types:" + derivateType);
213+
return exportedXpath.evaluate(derivateTypeElement).get(0);
214+
});
215+
216+
if (exported) {
217+
sendDerivate(derId, null, container);
218+
}
219+
194220
}
195221
}
196222
}

mycore-classeditor/src/main/resources/components/classeditor/config/mycore.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ MCR.LayoutTransformerFactory.Default.Ignore=%MCR.LayoutTransformerFactory.Defaul
33

44
MCR.Module-solr.linkQuery=category.top:{0}
55

6-
MCR.classeditor.additionalLanguages=x-disable,x-display,x-group,x-logo,x-uri
6+
MCR.classeditor.additionalLanguages=x-disable,x-display,x-export,x-group,x-logo,x-uri
77

88
MCR.JSON.Manager.TypeAdapters.categoryType.Class=org.mycore.frontend.classeditor.MCRCategoryTypeAdapter
99
MCR.JSON.Manager.TypeAdapters.categoryIdType.Class=org.mycore.frontend.classeditor.MCRCategoryIDTypeAdapter

mycore-mods/src/main/resources/xsl/mods-enhancer.xsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
<xsl:variable name="ifsTemp">
1010
<xsl:for-each select="mycoreobject/structure/derobjects/derobject[mcrxsl:isDisplayedEnabledDerivate(@xlink:href)]">
11-
<der id="{@xlink:href}">
12-
<xsl:copy-of select="document(concat('xslStyle:mcr_directory-recursive:ifs:',@xlink:href,'/'))" />
13-
</der>
11+
<xsl:variable name="derivateType" select="classification[@classid='derivate_types']/@categid" />
12+
<xsl:variable name="derivateExported" select="not(document(concat('classification:metadata:0:children:derivate_types:',$derivateType))//category/label[lang('x-export')]/@text='false')" />
13+
<xsl:if test="$derivateExported">
14+
<der id="{@xlink:href}">
15+
<xsl:copy-of select="document(concat('xslStyle:mcr_directory-recursive:ifs:',@xlink:href,'/'))" />
16+
</der>
17+
</xsl:if>
1418
</xsl:for-each>
1519
</xsl:variable>
1620
<xsl:variable name="ifs" select="xalan:nodeset($ifsTemp)" />

mycore-mods/src/main/resources/xslt/utils/mods-enhancer.xsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111

1212
<xsl:variable name="ifs">
1313
<xsl:for-each select="mycoreobject/structure/derobjects/derobject[document(concat('userobjectrights:isWorldReadable:', @xlink:href))/boolean/text() = 'true']">
14-
<der id="{@xlink:href}">
15-
<xsl:copy-of select="document(concat('xslStyle:mcr_directory-recursive:ifs:',@xlink:href,'/'))" />
16-
</der>
14+
<xsl:variable name="derivateType" select="classification[@classid='derivate_types']/@categid" />
15+
<xsl:variable name="derivateExported" select="not(document(concat('classification:metadata:0:children:derivate_types:',$derivateType))//category/label[lang('x-export')]/@text='false')" />
16+
<xsl:if test="$derivateExported">
17+
<der id="{@xlink:href}">
18+
<xsl:copy-of select="document(concat('xslStyle:mcr_directory-recursive:ifs:',@xlink:href,'/'))" />
19+
</der>
20+
</xsl:if>
1721
</xsl:for-each>
1822
</xsl:variable>
1923

0 commit comments

Comments
 (0)