[opencms-dev] New Content Definition Questions

Bart Elberg belberg at idealcorp.com
Tue Aug 13 23:45:05 CEST 2002


Bottom line on my solution: I had to write a SQL access to get the user 
name.

I could not find any methods to get a CmsUser by the ID without first 
having a CmsObject.  Unfortunately the CmsObject is not provided to the 
content definition object when the table list is created.  It only calls 
the static getSortedList() method and then each of the getXXX() methods 
without ever passing in the CmsObject.  SOOoooooo... I wrote a method 
getLockOwner() and added that to the getFieldNames() method.  The 
drawback is that it is always displayed.  

  private static final String C_SELECT_BY_OC_ID =
    "select USER_NAME from CMS_USERS WHERE USER_ID=?";

  public String getLockOwner() throws CmsException
  {
    String result = null;
    Connection con = null;
    PreparedStatement statement = null;
    ResultSet res = null;
    try
    {
      con = DriverManager.getConnection(c_pool);
      statement = con.prepareStatement(C_SELECT_BY_OC_ID);
      statement.setInt(1, Id);
      res = statement.executeQuery();
      if(res.next())
      {
        result = res.getString(1);
      }
    }
    catch(SQLException e)
    {
      e.printStackTrace();
      throw new CmsException("[RbocsUser::getUserByOpenCmsId()] " + 
e.getMessage(), 2, e);
    }
    finally
    {
      try
      {
        res.close();
      }
      catch(Exception exception1)
      { }
      try
      {
        statement.close();
      }
      catch(Exception exception2)
      { }
      try
      {
        con.close();
      }
      catch(Exception exception3)
      { }
    }
   
    return result;
  }
 


Manfred Pruntsch wrote:

>>Thanks Manfred.  All of that is implemented and working.  What I was
>>really asking about was getting the username to display in the "Locked
>>by" column of the table where the content entries are listed.
>>
>Ok. You can find the user you want in the lockstate field. This number is
>the id from user who locked this resource (if the number >0). Read the
>apropriate user and show him in the column 'locked by'.
>Unfortunately I didn't found a method like getUserByID()... (...
>cms.getUsers(), list all users. As workaround you can pick up the user from
>the list by the id).
>I'm interesting in what solution you getting run.
>good luck,
>best regards
>Manfred
>
>
>
>
>>-----Original Message-----
>>From: owner-opencms-dev at www.opencms.org
>>[mailto:owner-opencms-dev at www.opencms.org]On Behalf Of Bart Elberg
>>Sent: Tuesday, August 13, 2002 4:00 PM
>>To: opencms-dev at www.opencms.org
>>Subject: Re: [opencms-dev] New Content Definition Questions
>>
>>
>>Thanks Manfred.  All of that is implemented and working.  What I was
>>really asking about was getting the username to display in the "Locked
>>by" column of the table where the content entries are listed.
>>
>>
>>Manfred Pruntsch wrote:
>>
>>>Hallo Bart,
>>>
>>>>1) Is it possible to get the "Locked by" column to display like it does
>>>>in the Explorer view? If so, what needs to be done?
>>>>
>>>The following code are needed by your content definition to make it
>>>lockable:
>>>
>>>1) variable declaration
>>>private int m_lockstate = -1;
>>>
>>>2) get method
>>>  /**
>>>  * Gets the lockstate of the CD.
>>>  * @returns Integer with the lockstate.
>>>  */
>>>  public int getLockstate() {
>>>     return m_lockstate;
>>>  }
>>>
>>>3) set method
>>>  /**
>>>  * Sets the lockstate of the CD.
>>>  * @param lockstate The int with lockstate.
>>>  */
>>>  public void setLockstate(int lockstate) {
>>>		m_lockstate = lockstate;
>>>  }
>>>
>>>4) isLockable method
>>>  /**
>>>  * This content definition is lockable. This class overwrite the
>>>isLockable method of the abstract
>>>  * backoffice to flag that this content definition uses the
>>>
>>lock feature
>>
>>>of the backoffice.
>>>  * @return boolean true if it is lockable.
>>>  */
>>>  public static boolean isLockable() {
>>>	   return true;
>>>  }
>>>
>>>Then, of course you have to add a lockstate field in your
>>>
>>datasource (table
>>
>>>in mysql for instance:
>>>name: lockstate
>>>type: int
>>>length: 11
>>>Null: not null
>>>Default: 0)
>>>You now are able to use the opencms built in lock/unlock mechanism by the
>>>contextmenu.
>>>I never used isReadable and isWriteable before but I can imagine it will
>>>work in a similar way.
>>>
>>>best regards
>>>Manfred
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: owner-opencms-dev at www.opencms.org
>>>>[mailto:owner-opencms-dev at www.opencms.org]On Behalf Of Bart Elberg
>>>>Sent: Tuesday, August 13, 2002 1:34 AM
>>>>To: opencms-dev at opencms.org
>>>>Subject: [opencms-dev] New Content Definition Questions
>>>>
>>>>
>>>>I have some questions about adding a new content definition and
>>>>controlling access to it in the back office/administration view.
>>>>
>>>>1) Is it possible to get the "Locked by" column to display like it does
>>>>in the Explorer view? If so, what needs to be done?
>>>>2) What controls access to each custom content entry? The documentation
>>>>talks about implementing isReadable() and isWriteable() methods and
>>>>calling them in the constructor, write(), and delete() methods. Using
>>>>that approach just allows the application to generate an exception. Is
>>>>is possible to make the non-writeable entries grayed-out in the list? or
>>>>just disable the "Edit" menu entry?
>>>>3) What determines what appears in the popup menu when left clicking on
>>>>a content entry? The only menu entries that are displayed currently are
>>>>Edit, Delete, and (Un)Lock. Is it possible to add other functions to the
>>>>menu like Copy, Rename, View History, ...?
>>>>
>>>>The closest example I can find is the "Module-management" back office,
>>>>but I haven't found where the magic happens in the code. Any
>>>>help/guidance on this is appreciated.
>>>>
>>>>System Configuration:
>>>>
>>>>OpenCMS: 4.6.1
>>>>Mandrake Linux: 2.4.18-6mdk
>>>>Tomcat: 4.0.3
>>>>JDK: 1.3.1 (for compiling)
>>>>1.4.0 (for JRE)
>>>>
>>>>Thanks!
>>>>
>>>>--
>>>>Bart Elberg
>>>>__________________________________________________
>>>>I.D.E.A.L. Technology Corporation - Orlando Office
>>>>http://www.idealcorp.com - 407.999.9870 x15
>>>>

>>>>




More information about the opencms-dev mailing list