<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Change property in action class</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16945" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Hi Enrico</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>I don't think a user - admin user or not - is 
allowed to change any resource that is locked by another user - therefore you 
cannot overwrite a property without first owning the lock 
on the resource.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Without going too deep into your problem, </FONT></SPAN>I 
think you can temporarily change the lock using the 
API. See org.opencms.file.CmsObject: </FONT></SPAN><SPAN 
class=693293208-18122009><FONT face=Arial color=#0000ff size=2>The 
current lock can be accessed with getLock, and you can 
perform the "steal lock" operation by calling changeLock. Furthermore, 
there are the getLock and 
unlockResource methods. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>In theory, this means you can read the current lock, 
steal the lock and do whatever while you own it, and then setting the 
lock back to its original state. However, re-creating the lock could be a 
problem, as you would have to switch user and become the user who 
originally owned the lock (or am I wrong?) before calling 
lockResource, as there is no method to lock a given resource to a given 
user.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Remember also that resources cannot be modified in the 
Online project, you'll need to set it to Offline (see 
org.opencms.file.CmsRequestContext#setCurrentProject(org.opencms.file.CmsProject)).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Hope this helps you.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Cheers,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=693293208-18122009><FONT face=Arial 
color=#0000ff size=2>Paul</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> opencms-dev-bounces@opencms.org 
  [mailto:opencms-dev-bounces@opencms.org] <B>On Behalf Of </B>Popall, 
  Enrico<BR><B>Sent:</B> 16. desember 2009 17:09<BR><B>To:</B> 
  opencms-dev@opencms.org<BR><B>Subject:</B> [opencms-dev] Change property in 
  action class<BR></FONT><BR></DIV>
  <DIV></DIV><!-- Converted from text/rtf format --><BR>
  <P><SPAN lang=en-us><FONT face=Arial size=2>Hi everybody</FONT></SPAN> </P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>I'm trying to set a property of a 
  resource inside of an action class that listens to 
  I_CmsEventListener.EVENT_RESOURCE_MODIFIED.</FONT></SPAN></P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>The problem is that once I'm not 
  logged in as "Admin" I can't change this property. The error message: Resource 
  XYZ is not locked by current user "Admin". Again, that happens when I'm not 
  logged in as Admin. The class works as expected if I login as Admin and modify 
  the resource then. Another user which also has root admin rights but is not 
  named "Admin" can't do it.</FONT></SPAN></P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>So my guess was that the system 
  internally somehow switches the user prior to firing the event. 
  cmsObject.getRequestContext().currentUser().getFullName() confirms this. The 
  context also tells me that it is in the Online project (which kinda explains 
  the Admin).</FONT></SPAN></P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>Any ideas how to get around this? 
  Is there a way to change the lock of this resource temporary and then set it 
  back to it's original state? Or overwrite a property since you are the admin 
  in this situation anyway? Or is there another way to catch events in the 
  Offline project?</FONT></SPAN></P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>The whole task is to put the 
  categories (relations --> assign categories) in a property field that is 
  indexable for the search. Maybe I'm on a wrong path here and I don't 
  need/can't to do this via the action class. If someone has an idea, please let 
  me know too.</FONT></SPAN></P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>Thanks and best 
  regards</FONT></SPAN><SPAN lang=de></SPAN> </P>
  <P><SPAN lang=de><B><FONT face="Trebuchet MS" 
  size=2>__________________________________</FONT></B></SPAN> <BR><SPAN 
  lang=de><B><FONT face="Trebuchet MS" size=2>Enrico Popall</FONT></B></SPAN> 
  <BR><SPAN lang=de><B><FONT face="Trebuchet MS" size=2>Software 
  AG</FONT></B></SPAN> <BR><SPAN lang=de><FONT face="Trebuchet MS" size=2>Global 
  Marketing</FONT></SPAN> <BR><SPAN lang=de><FONT face="Trebuchet MS" 
  size=2>Uhlandstr.12, 64297 Darmstadt, Germany</FONT></SPAN><SPAN 
  lang=en-us></SPAN> </P>
  <P><SPAN lang=en-us><FONT face=Arial size=2>Tel: +49 6151 922998</FONT></SPAN> 
  </P></BLOCKQUOTE></BODY></HTML>