[opencms-dev] Extracting Copyright-value
Alex Kandzior
alex at opencms.org
Wed Nov 27 09:15:03 CET 2024
The embedded Java „scriptlet“ code in your JSP does not have access to the „cms“ object you imported in the taglib.
You can access a CmsObject like this:
<%
org.opencms.file.CmsObject cms = (org.opencms.file.CmsObject)getJspContext().getAttribute("cms");
%>
> Am 27.11.2024 um 07:57 schrieb Atle Enersen via opencms-dev <opencms-dev at opencms.org>:
>
> Hello, and thanks for the answer, Alex.
>
> I am almost there, but the https://documentation.opencms.org/javadoc/tld/ is down so I am stuck for now.
>
> This code chokes at line 4 in the code pasted below. An error occurred at line: [46] in the jsp file: [/WEB-INF/jsp/offline/system/modules/org.enersen.core/formatters/enersenarticlesimple.jsp] cms cannot be resolved
>
> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><%@ page import="org.opencms.file.*, org.opencms.main.CmsException" %>
> <cms:formatter var="content">
> <%
> CmsObject cmsObject = cms.getCmsObject();
> String imagePath = (String) pageContext.getAttribute("content.value.ImageTop");
>
> try {
> CmsResource resource = cmsObject.readResource(imagePath);
> out.println("Resource Name: " + resource.getName() + "<br>");
> out.println("Resource Type: " + resource.getTypeId() + "<br>");
> out.println("Resource Path: " + resource.getRootPath() + "<br>");
> } catch (CmsException e) {
> e.printStackTrace();
> out.println("Error reading resource: " + e.getMessage());
> }
> %>
>
>
> Alt godt, hilsen Atle Enersen.
> --
> Telefon: +47 48 06 31 71
>
>
>
>
> opencms-dev på vegne av opencms-dev-request at opencms.org <mailto:opencms-dev-request at opencms.org> <opencms-dev-bounces at opencms.org <mailto:opencms-dev-bounces at opencms.org> på vegne av opencms-dev-request at opencms.org <mailto:opencms-dev-request at opencms.org>> skrev følgende den 26.11.2024, 12:00:
>
>
> Send opencms-dev mailing list submissions to
> opencms-dev at opencms.org <mailto:opencms-dev at opencms.org>
>
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.opencms.org/mailman/listinfo/opencms-dev <https://lists.opencms.org/mailman/listinfo/opencms-dev>
> or, via email, send a message with subject or body 'help' to
> opencms-dev-request at opencms.org <mailto:opencms-dev-request at opencms.org>
>
>
> You can reach the person managing the list at
> opencms-dev-owner at opencms.org <mailto:opencms-dev-owner at opencms.org>
>
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of opencms-dev digest..."
>
>
>
>
> Today's Topics:
>
>
> 1. Re: Extracting Copyright-value (Alex Kandzior)
>
>
>
>
> ----------------------------------------------------------------------
>
>
> Message: 1
> Date: Mon, 25 Nov 2024 12:39:04 +0100
> From: Alex Kandzior <alex at opencms.org <mailto:alex at opencms.org>>
> To: The OpenCms mailing list <opencms-dev at opencms.org <mailto:opencms-dev at opencms.org>>
> Subject: Re: [opencms-dev] Extracting Copyright-value
> Message-ID: <041ACD40-4B52-4BC6-93B5-2CBE9B0093E6 at opencms.org <mailto:041ACD40-4B52-4BC6-93B5-2CBE9B0093E6 at opencms.org>>
> Content-Type: text/plain; charset="utf-8"
>
>
> You need to read the "Copyright" property from the file resource.
>
>
> Traditional tag notation:
> <c:set var="imageCopyright"><cms:property name="Copyright" file="%path-to-your-image%" default="" /></c:set>
>
>
> More modern direct EL notation:
> <c:set var="imageCopyright" value="${cms.vfs.readResource['%path-to-your-image%'].property['Copyright']}" />
>
>
> For further inspiration, you may also look here (around line 230):
> https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.template/resources/system/modules/alkacon.mercury.template/tags/image-vars.tag <https://github.com/alkacon/mercury-template/blob/master/alkacon.mercury.template/resources/system/modules/alkacon.mercury.template/tags/image-vars.tag>
>
>
> Kind regards,
> Alex.
>
>
> -------------------
> Alexander Kandzior
>
>
> Alkacon Software - The OpenCms Experts
> http://www.alkacon.com <http://www.alkacon.com> - http://www.opencms.org <http://www.opencms.org >
>
>
>
>
>> Am 25.11.2024 um 10:28 schrieb Atle Enersen via opencms-dev <opencms-dev at opencms.org <mailto:opencms-dev at opencms.org>>:
>>
>> Hello.
>>
>> I can find the title of a page using:
>>
>> <title><c:out value="${cms.title}" /></title>
>>
>> But I cannot find any way to extract the value of the Image-property of a regular Image object. I have consulted the documentation but found nothing. The image itself works and are displayed ok.
>>
>> Can anyone help?
>>
>> Here is the extracted definition from the xsd:
>>
>> <xsd:complexType name="OpenCmsEnersenArticleSimple">
>> <xsd:sequence>
>> <xsd:element name="ImageTop" type="OpenCmsVfsFile" />
>> </xsd:sequence>
>> <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
>> </xsd:complexType>
>>
>> <Setting>
>> <PropertyName>ImageTop</PropertyName>
>> <Widget>imagegallery</Widget>
>> <WidgetConfig>{useformat:true}</WidgetConfig>
>> <Search>false</Search>
>> </Setting>
>>
>> Alt godt/best regards, hilsen Atle Enersen.
>> --
>> Telefon: +47 48 06 31 71
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please visit
>> https://lists.opencms.org/mailman/listinfo/opencms-dev <https://lists.opencms.org/mailman/listinfo/opencms-dev>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.opencms.org/pipermail/opencms-dev/attachments/20241125/6fc5152d/attachment-0001.htm> <http://lists.opencms.org/pipermail/opencms-dev/attachments/20241125/6fc5152d/attachment-0001.htm>>
>
>
> ------------------------------
>
>
> Subject: Digest Footer
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> https://lists.opencms.org/mailman/listinfo/opencms-dev <https://lists.opencms.org/mailman/listinfo/opencms-dev>
>
>
>
>
> ------------------------------
>
>
> End of opencms-dev Digest, Vol 135, Issue 2
> *******************************************
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> https://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
>
More information about the opencms-dev
mailing list