HI Paul,<br><br>thanks for the info and the script.<br><br>I'll look into it.<br>If possible I'll try and add that to my module action, however.<br>That way it should be executed when the module is deployed/updated.<br>
I'll keep you posted on my progress.<br><br>Thanks again.<br><br>Cheers,<br><br>Thomas<br><br><div class="gmail_quote">2011/10/5 Paul-Inge Flakstad <span dir="ltr"><<a href="mailto:flakstad@npolar.no">flakstad@npolar.no</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div link="blue" vlink="purple" lang="NO-BOK"><div><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">Hi Thomas,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">If you can’t do this using the Admin panel (apparently it has no switch to specify shared/individual property, so I see the problem) I think the easiest solution would be to write a simple JSP script that does the job.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">I’ve included a script that I wrote some time ago. HTH.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">Cheers,<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">Paul<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><%-- <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    Document   : script-change-property<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    Created on : 16.mar.2011, 14:19:29<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    </span><span style="font-size:11.0pt;color:#1F497D">Author     : Paul-Inge Flakstad <flakstad at <a href="http://npolar.no" target="_blank">npolar.no</a>><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">--%><%@ page import="org.opencms.jsp.CmsJspActionElement,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 java.util.List,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 java.util.Iterator,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 java.util.Locale,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 org.opencms.file.CmsObject,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 org.opencms.file.CmsResource,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 org.opencms.file.CmsResourceFilter,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 org.opencms.file.CmsProperty,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 org.opencms.main.OpenCms" session="true" %><%!<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                 <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">/**<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">* Gets an exception's stack strace as a string.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">*/<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">public String getStackTrace(Exception e) {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    String trace = "<div style=\"border:1px solid #900; color:#900; font-family:Courier, Monospace; font-size:80%; padding:1em; margin:2em;\">";<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    trace+= "<p style=\"font-weight:bold;\">" + e.getMessage() + "</p>";<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    StackTraceElement[] ste = e.getStackTrace();<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    for (int i = 0; i < ste.length; i++) {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        StackTraceElement stElem = ste[i];<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        trace += stElem.toString() + "<br />";<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    }<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    trace += "</div>";<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    return trace;<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">%><%<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Action element and CmsObject<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">CmsObject cmso = cms.getCmsObject();<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Locale<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">Locale locale = cms.getRequestContext().getLocale();<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">String loc = locale.toString();<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Constants used in the script<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final String FOLDER = "/your/content/folder/"; // Folders to collect files from<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final String RESOURCE_TYPE_NAME = "your_resource_type_name"; // The type name of resources to collect<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final String PROPERTY_NAME = "your_property_name"; // The name of the property to change<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final String OLD_VALUE = "your_old_value"; // The old property value<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final String NEW_VALUE = "your_new_value"; // The new property value<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final boolean READ_TREE = true; // Collect files in sub-tree?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Filter for the resource type<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">final CmsResourceFilter FILTER = CmsResourceFilter.ALL.addRequireType(OpenCms.getResourceManager().getResourceType(RESOURCE_TYPE_NAME).getTypeId());<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Get files<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">List filesInFolder = cmso.readResources(FOLDER, FILTER, READ_TREE);<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">Iterator iFilesInFolder = filesInFolder.iterator();<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">// Process collected files<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">while (iFilesInFolder.hasNext()) {<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    CmsResource resource = (CmsResource)iFilesInFolder.next(); // Get the next collected resource<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    String resourceName = resource.getName(); // The collected resource's name<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    String resourcePath = cmso.getSitePath(resource); // The collected resource's path, relative to the current site<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    // Get a list of all siblings (includes the resource itself)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    List siblings = cmso.readSiblings(resourcePath, FILTER);<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    // Print some info<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    out.println("<h4>Collected file: <code>" + resourcePath + " (" + resourceName + ")</code> plus " + (siblings.size()-1) + " siblings</h4>");<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    out.println("Using locale: <code>" + loc + "</code><br />");<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    try {<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // Get the property object, which will be used to modify property value<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        CmsProperty property = cmso.readPropertyObject(resource, PROPERTY_NAME, false);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // Here you could add check for whether or not the property needs to be written<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // Handle case: null-property<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        if (property.isNullProperty()) {<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            property = new CmsProperty(PROPERTY_NAME, null, null, true);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        }        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // Set and write the property value<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        out.println("Writing (" + PROPERTY_NAME + "='" + NEW_VALUE + "' on resource " + resourcePath + ") ...<br />");<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //cmso.lockResource(resourcePath); // Commented out ==> Require (parent folder) lock to be present before running this script<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        property.setValue(NEW_VALUE, CmsProperty.TYPE_SHARED); // Write the value as shared<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        property.setValue("", CmsProperty.TYPE_INDIVIDUAL); // Remove any individual value<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // IMPORTANT: Comment out the next line to run a test of the script without writing anything<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //cmso.writePropertyObject(resourcePath, property); // Write property on the resource<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        //cmso.unlockResource(resourcePath); // Commented out ==> Require (parent folder) lock to be present before running this script<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        // Handle siblings<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        Iterator iSiblings = siblings.iterator();<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        while (iSiblings.hasNext()) {<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            CmsResource sibling = (CmsResource)iSiblings.next();<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            String siblingPath = cmso.getSitePath(sibling);<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            if (!siblingPath.equals(resourcePath)) {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                out.println("Processing sibling: <code>" + siblingPath + "</code><br />");<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">                // Do something with the sibling<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">            }<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        }<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        out.println("Done!<br />");<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        out.println("<hr />"); <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    } catch (Exception e) {<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">        out.println(getStackTrace(e));<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">    }<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US">}<u></u><u></u></span></p><p class="MsoNormal">
<span style="font-size:11.0pt;color:#1F497D" lang="EN-US">%><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D" lang="EN-US"><u></u> <u></u></span></p><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt" lang="EN-US">From:</span></b><span style="font-size:10.0pt" lang="EN-US"> <a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a> [mailto:<a href="mailto:opencms-dev-bounces@opencms.org" target="_blank">opencms-dev-bounces@opencms.org</a>] <b>On Behalf Of </b>Thomas Göttlich<br>
<b>Sent:</b> 5. oktober 2011 11:01<br><b>To:</b> The OpenCms mailing list<br><b>Subject:</b> [opencms-dev] How do I update shared properties?<u></u><u></u></span></p></div><div><div></div><div class="h5"><p class="MsoNormal">
<span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal">Hi all,<br><br>I'm currently restructuring our site and modules. <br>During this process, some templates are moved from one module to another.<br>However, there are a couple of existing pages that have the shared property "template-elements" already set and I don't know how to update them.<br>
<br>Of course I can update the indivudal file properties in administration but that would result in quite inconsistent properties.<br><br>Example:<br><br>old template path:  /system/modules/my.module.old/templates/sometemplate.jsp<br>
new template path: /system/modules/my.module.new/templates/sometemplate.jsp<br><br>When I update the individual properties for the files that use that template, I get this:<br><br><br>somefile: <br>- template-elements (indiv.): /system/modules/my.module.new/templates/sometemplate.jsp    <-- this is ok<br>
- template-elements (shared): /system/modules/my.module.old/templates/sometemplate.jsp   <-- still the old value<br><br>I changed the resourcetype definition to use the new path as shared "template-elements" property, but that didn't update the existing files.<br>
<br>How would I do that?<br><br>Regards,<br><br>Thomas<u></u><u></u></p></div></div></div></div><br><br>
_______________________________________________<br>
This mail is sent to you from the opencms-dev mailing list<br>
To change your list options, or to unsubscribe from the list, please visit<br>
<a href="http://lists.opencms.org/mailman/listinfo/opencms-dev" target="_blank">http://lists.opencms.org/mailman/listinfo/opencms-dev</a><br></blockquote></div><br>