Using Components as Boilerplates Using Components as Boilerplates Overview / CQ / Adobe Experience Manager 5.6.1 / Developing / When multiple authors develop content for large or multiple related web sites, it is often desirable to limit authors' ability to edit specific components on a page. For example, most authors should not be able to change boilerplate text that appears on multiple pages. However, senior authors or editors must be able to edit the text. Furthermore, authors must be able to edit other, non-boilerplate components on the same page. To use a component as boilerplate content, perform the following three tasks: • To set up boilerplate content, create an instance of the component and reference it from multiple pages. • To limit who can edit the component content, apply an ACL to the component instance. • To provide an effective authoring experience, prevent the opening of the compoent's editing dialog box. For ease of implementation and maintenance, the two types of users should belong to different user groups: • Authors who cannot edit boilerplate content. • Senior authors or editors who edit boilerplate content. SETTING UP THE BOILERPLATE CONTENT Create boilerplate content in a web page and include the content in several other web pages. Create the following items to set up boilerplate content: • A web page that contains the boilerplate content in one or more components. • A page component in your CQ5 application that references the boilerplate components in the JSP page using cq:include elements. • A template in your CQ5 application that uses your page component as the sling:resourceType. • Pages of your web site that are based on your template. The pages include the boilerplate content. NOTE Editing restrictions are not yet implemented on the boilerplate content. Create the boilerplate content 1. Create a page and add the component that provides the boilerplate content. 2. To add boilerplate content, open the page in edit mode and edit the component properties. Reference the boilerplate component 1. Use CRXDE Lite to create a component in your application folder. For the Super Type property, use foundation/components/page. 2. Open the JSP file of the component and add a cq:include element with the following attribute values: • path: The relative or absolute path to the boilerplate component. • resourceType: The path to the component implementation. 3. Create a template that uses the new component as the sling:resourceType. (See Templates.) 4. Create a page using the template. (See Creating a New Page.) Example A page located at /content/MySite/boilerplate-text contains a single Text component. This Text component provides the boilerplate text that is to appear on multiple pages of the site. The component contains the following value for the text property: <p>This text can only be edited by administrators.</p>. © 2012 Adobe Systems Incorporated. All rights reserved. Page 1 Created on 2014-11-11 Using Components as Boilerplates A component named contribpage is used to render page content. The contribpage.jsp code contains a cq:include element that references the boilerplatetext component instance: <% %><%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false"%><% %> <html> <cq:include script="head.jsp"/> <body> <cq:include path="/content/MySite/boilerplate-text/jcr:content/boilerplatetext" resourceType="/libs/ foundation/components/text"/> </body> </html> Note: The contribpage component has a sling:resourceSuperType property of foundation/components/ page. A template named ContributorPage uses the contribpage component as the sling:resourceType. Pages created with the template include the boilerplate component: PREVENTING CHANGES TO BOILERPLATE CONTENT To prevent users from modifying boilerplate content, apply an entry to the Access Control List (ACL) of the page that contains the boilerplate components. Use the following ACL entry property values to prevent a specific user or group from changing the properties of the boilerplate components: • Principal: The user or group that should not edit the boilerplate content. • Type: Deny • Priviledges: jcr:modifyProperties Note: With this configuration, the principal in the ACL item can open the edit dialog of the component and interact with widgets. However, upon clicking OK an error is displayed and the changes are not persisted. For information about configuring ACLs, see Managing Users and Groups. Example: In this example, the ACL of the boilerplate page is configured so that members of the contributor group cannot modify content. Only members of the Administrators group can edit components on the boilerplate page: © 2012 Adobe Systems Incorporated. All rights reserved. Page 2 Created on 2014-11-11 Using Components as Boilerplates Note: When a contributor opens a page that references the boilerplate component, it appears editable. The component highlights appear, and the editing dialog box can be opened. However, the property values cannot be changed. PREVENTING ACCESS TO THE COMPONENT EDITING DIALOG Prevent or allow users to open the editing dialog box of boilerplate components according to their permissions on the boilerplate page: • Prevent users from accessing the editing dialog box when they are not authorized to edit boilerplate content. • Allow access for users that are authorized to edit boilerplate content. Although ACLs prevent changes to content, ACLs do not prevent users from opening and interacting with the component editing dialog box. Prevent the opening of the dialog box so that users do not waste time editing content that cannot be persisted. To control access to the editing dialog box, add code to the JSP of the component that renders your page template. The code performs the following tasks: 1. Determine whether the user has permissions to modify the properties of the boilerplate page.The Session class provides a checkPermission method for checking the permissions of the current user. 2. If the user does not have permissions, bypass component handling of the component context.Set the ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE attribute of the HTTP request to true. 3. Add the component using cq:include.This was already discussed in Setting Up The Boilerplate Content. 4. Return the component context to the original configuration.Set the ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE attribute of the HTTP request to false. Example The contribpage component of the previous example uses the following code in the JSP file (note the required import statements): <% %><%@include file="/libs/foundation/global.jsp"%><% %><%@page session="false" import="com.day.cq.wcm.api.components.ComponentContext, java.security.AccessControlException, javax.jcr.RepositoryException"%><% %><html> <cq:include script="head.jsp"/> <body> <% Session session = slingRequest.getResourceResolver().adaptTo(Session.class); try { session.checkPermission("/content/MySite/boilerplate-text/jcr:content/boilerplatetext", Session.ACTION_SET_PROPERTY); }catch (AccessControlException e) { slingRequest.setAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, true); }catch (RepositoryException e) { © 2012 Adobe Systems Incorporated. All rights reserved. Page 3 Created on 2014-11-11 Using Components as Boilerplates log.error("*******RepositoryException******", e); } %> <cq:include path="/content/MySite/boilerplate-text/jcr:content/boilerplatetext" resourceType="foundation/components/text"/> <% slingRequest.removeAttribute(ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE); %> </body> </html> © 2012 Adobe Systems Incorporated. All rights reserved. Page 4 Created on 2014-11-11
© Copyright 2024