Quản lý cấu hình web - part 40 pptx

10 246 0
Quản lý cấu hình web - part 40 pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Leveraging Alfresco Framework for WCM [ 372 ] 4. Choose Execute a script from the available list of actions and click on the Set Values and Add button. Select copy_wcm.js from the list of available JavaScript les to execute and click on OK. 5. Click on Finish. This will execute the copy_wcm.js JavaScript and copy the content to the WCM in a specied web project and a specied folder, as shown in the following screenshot: You can also congure this 'Execute Script' as a rule on the videos folder. For conguring it as a business rule, you can follow the same steps as mentioned in the DM to WCM Using Business Rule section. Just choose the Execute a Script action during conguration and copy_wcm.js as a value. If you congure this rule for Inbound Documents, it will automatically copy the videos le to the corresponding destination folder in WCM. Image transformation in WCM Alfresco leverages the power of ImageMagick for image transformations. Refer to Chapter 2, Installation and Conguration for installing ImageMagick. Alfresco JavaScript provides some APIs to perform image transformations. The prerequisite for this is to have ImageMagick installed. The Script node has the APIs mentioned in the following section for image transformation. Download from Wow! eBook <www.wowebook.com> Chapter 11 [ 373 ] Image transformation APIs Alfresco provides the following APIs for image transformations. transformImage is overloaded with different parameters. You can use any of these based on your requirement: • transformImage(string mimetype): This will transform an image to a new type specied in mimetype and will return the transformed image node if successful or null if failed. • transformImage(string mimetype, string options): This will transform an image to a new type specied in mimetype by applying the supplied ImageMagick options and will return the transformed image node if successful or null if failed. • transformImage(string mimetype, ScriptNode destination): This will transform an image to a new type specied in mimetype and will return the transformed image node if successful or null if failed. A new image document will be created in specied destination folder. • transformImage(string mimetype, string options, ScriptNode destination) : This will transform an image to a new type specied in mimetype by applying the supplied ImageMagick options and will return the transformed image node if successful or null if failed. A new image document will be created in the specied destination folder. Conguring new action for image transformation in WCM Following are the steps to congure image transformation as an action in Alfresco. 1. Congure action for transform image in web-client-config-custom.xml le as: <config> <actions> <! Transform Image Action > <action id="tranform_image"> <permissions> <permission allow="true">Write</permission> </permissions> <evaluator>org.alfresco.web.action.evaluator. WCMWorkflowEvaluator</evaluator> <label-id>title_action_transform_image</label-id> <image>/images/icons/action.gif</image> <action>browseSandbox</action> Download from Wow! eBook <www.wowebook.com> Leveraging Alfresco Framework for WCM [ 374 ] <script>/Company Home/ Data Dictionary/Scripts/transform_image.js</script> <params> <param name="id">#{actionContext.id}</param> </params> <target>new</target> </action> </actions> </config> 2. Add this action in the action group for avm_file_browse in the web-client-config-custom.xml le, as follows: <config> <actions> <action-group id="avm_file_browse" replace="true"> <show-link>false</show-link> <action idref="edit_file" /> <action idref="update_file" /> <action idref="preview_file" /> <action idref="cut_avm_node" /> <action idref="copy_avm_node" /> <action idref="file_details" /> <action idref="unlock_file" /> <action idref="delete_file_browse" /> <action idref="tranform_image" /> </action-group> </actions> </config> 3. Now we need to create JavaScript le, which will be executed when this action is performed. This JavaScript will be responsible for transforming the image. The JavaScript transform_image.js will look as follows: logger.log("called :: " + args["id"]); var path = args["id"]; var node = avm.lookupNode(path) logger.log("node : "+ node); var thumbImage = node.transformImage("image/png", "-resize 120",node.parent); 4. Here, you can specify any image type for transformation instead of image/png and also can specify the required options as the second argument in transformImage API. Download from Wow! eBook <www.wowebook.com> Chapter 11 [ 375 ] 5. Upload this JavaScript in the Company Home | Data Dictionary | Scripts folder as shown in the following screenshot: 6. Now the new action for Image Transformation will be available for any content in WCM. Using image transformation action in WCM In this section, we will see how we can use this action, which we congured in the previous section. 1. Go to the Cignex web project and click on Browse Website. Browse to the ROOT | images folder. You can see the images available there as shown in the following screenshot: Download from Wow! eBook <www.wowebook.com> Leveraging Alfresco Framework for WCM [ 376 ] 2. Currently, we have the Expand-snap.JPG image le available. We will apply the Transform Image action on this and we will have the same image transformed into PNG as Expand-snap.png le with resizing. Download the sample code les from the Packt website. Advanced search in WCM The success of content management systems depends on its ability to locate the required content with fewer clicks. You will realize the benets of having a powerful search engine when you have a large amount of content in your content management system. Unlike many commercial content management systems, Alfresco includes a free and very powerful search engine called Lucene as part of installation. Hence you don't have to buy and install a third-party search engine. And moreover, you don't have to deal with integration issues and upgrades. In Alfresco DM, you will be able to search both content and properties. You can do a full-text search on any word in content, regardless of the format. You can search for content in a particular space. You can also search for content belonging to certain categories or of a specic type. We will leverage this searching capability of Alfresco DM in WCM as well with the help of the Lucene search engine. In this section, we will see how we can use Lucene to search the content stored in Alfresco WCM and easily do a full-text search on any word in content, regardless of the format. Searching in WCM is similar to the searching in DM, but in WCM, Lucene-based search is only possible in the Staging Sandbox. It is not possible for any User's Sandbox or also the Workow Sandbox. XPath-based searching is possible for all the WCM stores including User's Sandbox and Workow Sandbox. However, the drawback of XPath search is that the performance might slow down depending on the query and the store structure, as the implementation walks the object model. Download from Wow! eBook <www.wowebook.com> Chapter 11 [ 377 ] WCM search can be performed via Java, JavaScript, FreeMarker template, or the Node Browser. For more information on search, refer to http://wiki.alfresco.com/wiki/Search. Using JavaScript Using JavaScript API for search, you can search the content against WCM stores. Alfresco provides search as a root object for JavaScript, which provides access to Lucene search. The available APIs to perform search are: • luceneSearch(string query): This will perform a full-text Lucene search with the provided query and return the search result as an array of Script node objects. • luceneSearch(string store, string query): This will perform a full-text Lucene search in the specied store with the provided query and return the search result as an array of Script node objects. • luceneSearch(string query, string sortColumn, boolean asc): This will perform a full-text Lucene search with the provided query and return the sorted search result based on the column specied and the sorting order as an array of Script node objects. • luceneSearch(string store, string query, string sortColumn, boolean asc) : This will perform a full-text Lucene search in the specied store with the provided query and return the sorted search result based on the column specied and the sorting order as an array of Script node objects. • xpathSearch(string xpath): This will perform an Alfresco XPath search and return the search result as an array of Script node objects. • xpathSearch(string store, string xpath): This will perform an Alfresco XPath search in the specied store and return the search result as an array of Script node objects. • ScriptNode findNode(NodeRef noderef): This will return a Script node for the specied noderef. • ScriptNode findNode(string noderef): This will return a Script node for the specied noderef in the form of String. Download from Wow! eBook <www.wowebook.com> Leveraging Alfresco Framework for WCM [ 378 ] Here for the Lucene query, you can pass any valid Lucene query as an argument. While building the Lucene query, you can use multiple query criteria with combination of relational operator. For example, to search text "cignex", you can have the query as TEXT:cignex, as follows: var results = search.luceneSearch("avm://wwwcignex","TEXT:cignex"); This will search for the text "cignex" in wwwcignex store (Staging Sandbox of the web project named wwwcignex). Now if you want to restrict the search to some specic folder within the store, you can have path criteria in the query as PATH:"www/avm_webapps/ROOT/common//*", as follows: var results = search.luceneSearch("avm://wwwcignex","TEXT:cignex" AND PATH:\"www/avm_webapps/ROOT/common//*\""); AVM API to search in WCM store Alfresco provides search APIs to perform search in the Alfresco Repository. The following is the API used to perform Lucene search in WCM. • store.luceneSearch(query): This will perform a Lucene search with the provided query against the store and return the search result as an array of AVM nodes. To perform the search on a particular store, you need to get the store rst and then you can execute search against that store, that is: var store = avm.lookupStore("wwwcignex"); var results = store.luceneSearch("wca\\:parentformname:news"); Using FreeMarker template Similar to JavaScript, FreeMarker template language also provides the API to perform the search against the WCM stores; the API is: • store.luceneSearch(query): This will perform a Lucene search with the provided query against the store and return the search result as an array of AVM nodes. For example, to search all the folders in the web project, you can have the query as follows: <#assign store = avm.lookupStore("wwwcignex)> <list store.luceneSearch(TYPE:"cm:folder") as l_search_result> <li> ${l_search_result.properties.name} </li> <#list> Download from Wow! eBook <www.wowebook.com> Chapter 11 [ 379 ] Using the Node browser You can use the Node browser available in Alfresco Explorer to search the content in the WCM stores. But only Admin users can have access to Node Browser. In order to use the Node browser: 1. Click on the Administration Console button ( )on the top menu bar. 2. Click on the Node Browser option on the Administration console screen. 3. It will have a list of all the stores of repository. Select the appropriate WCM store in which you want to perform the search. 4. In the combo box for Search, select the Search Language, that is, lucene or xpath, and so on. 5. In the Search text area, provide the search query for the specic language. 6. Click on Search. It will perform the search and return the result nodes. Using Java Java also provides Search Service to perform the search operations. The APIs available in search service to execute search are as follows: • query(Storeref store, String language, String query): This will search against the specied store in WCM with the given query and language. • query(Storeref store, String language, String query, QueryParameterDefinition[] queryParameterDefinition) : This will search against the specied store in WCM with the given query language and Query Parameters. Here you can have a parameterized query. Download from Wow! eBook <www.wowebook.com> Leveraging Alfresco Framework for WCM [ 380 ] • query(Storeref store, Qname queryId, QueryParameter[] queryParameters) : This will execute a canned query against the specied store with the given query identier and query parameters. • query(SearchParameters searchParameters): This will perform search using the specied Search Parameters. All of the previous APIs for search using search service available in Alfresco will return Search results as a ResultSet. You can iterate this result set and perform any further processing. Case study: User Interface for Advanced Search in WCM In this section, we will discuss the case study of UI for Advance Search in WCM. Here we will provide different criteria for search, such as choosing the web form of which we want to search the content and the facility to choose the path in the ROOT folder to search the content. For this we will use Lucene search so that it will search only in a Staging Sandbox. This search example is for free text-based search and does not provide the capability to search the content based on its property. We will see the example of searching content based on the content property in the next section. To implement this functionality: 1. Provide a link for Advance Search in the browse-sandbox.jsp page as: <div style="float:right;padding-right:20px;padding-top:3px"> <a:actionLink id="advance-search-image" value="Advance Search" image="/images/icons/search_icon.gif" showLink="false" showLink="false" action="advanceSearch" /> <a:actionLink id="advance-search-apply" value="Advance Search" showLink="false" action="advanceSearch" /> </div> 2. Create a new JSP le in the jsp/extension/wcm/search folder for rendering the Search UI Page. Download from Wow! eBook <www.wowebook.com> Chapter 11 [ 381 ] 3. Add a managed bean denition in the faces-config-custom.xml le. This bean is going to handle search parameter retrieval process for Advanced Search JSP. <managed-bean> <description> The bean that holds a state for the Advanced Search screen. </description> <managed-bean-name>CustomAdvancedSearchBean</managed-bean-name> <managed-bean-class>com.cignex.web.bean.wcm.CustomAdvancedSearchBean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>nodeService</property-name> <value>#{NodeService}</value> </managed-property> <managed-property> <property-name>searchService</property-name> <value>#{SearchService}</value> </managed-property> <managed-property> <property-name>serviceRegistry</property-name> <value>#{ServiceRegistry}</value> </managed-property> </managed-bean> 4. Implement class com.cignex.web.bean.wcm.CustomAdvancedSearchBean and implement a method [public Search ()] that will perform the search with the specied parameters. This class will also have corresponding elds for all search components. 5. Create a Java class, CustomAdvanceSearchBean, with the specied package structure, which will actually perform the search in the repository. Download the sample code les from the Packt website. Download from Wow! eBook <www.wowebook.com> . </description> <managed-bean-name>CustomAdvancedSearchBean</managed-bean-name> <managed-bean-class>com.cignex .web. bean.wcm.CustomAdvancedSearchBean </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> . the web- client-config-custom.xml le, as follows: <config> <actions> <action-group id="avm_file_browse" replace="true"> <show-link>false</show-link> . <property-name>nodeService</property-name> <value>#{NodeService}</value> </managed-property> <managed-property> <property-name>searchService</property-name>

Ngày đăng: 05/07/2014, 20:21

Tài liệu cùng người dùng

Tài liệu liên quan