Dear Wiki user, You have subscribed to a wiki page or wiki category on "Jakarta-slide Wiki" for change notification.
The following page has been changed by James Kelly: http://wiki.apache.org/jakarta-slide/Sample_API_application The comment on the change is: added section on creating groups and links from mailing list example ------------------------------------------------------------------------------ } }}} + + = Creating GroupNodes and LinkNodes = + From Michael Plomer's post to the Slide-Users mailing list on 2003-05-24 + + {{{ + First, you'll need to obtain a NamespaceAccessToken: + }}} + {{{ + // prepare the namespace access token (assuming you want the default namespace) + String namespace = Domain.getDefaultNamespace(); + NamespaceAccessToken nat = Domain.accessNamespace(new SecurityToken(this), namespace); + // "this" is a HttpServlet in my case, but could be almost anything (or so I think...) + }}} + {{{ + Next, you need a SlideToken, which you could construct, for instance, from the credentials in your servlets request (that is, assuming you are writing a servlet...). + }}} + {{{ + // prepare the slide token Principal principal = request.getUserPrincipal(); + CredentialsToken credentials; + if (principal == null) + credentials = new CredentialsToken(""); + else + credentials = new CredentialsToken(principal); + SlideToken st = new SlideTokenImpl(credentials); + }}} + {{{ + Creating a group node is pretty straightforward, most of the code deals with exception handling: + }}} + {{{ + // prepare the structure helper + Structure structureHelper = nat.getStructureHelper(); + + try { + try { + // start namespace tansaction + nat.begin(); + // create the node in the structure + ObjectNode object = new GroupNode(); + structureHelper.create(st, object,"/users/testgroup"); + // commit the transaction + nat.commit(); + } catch (AccessDeniedException ex) { + ... // handle exception + throw ex; + } catch (ObjectAlreadyExistsException ex) { + ... // handle exception + throw ex; + } catch (Exception ex) { + ... // handle exception + throw ex; + } + // ... SUCCESS ... + } catch (Exception ex) { + try { + nat.rollback(); + } catch (SystemException sysex) { // catch silently } + } + }}} + {{{ + Linking users into the group should be done like this: + }}} + {{{ + // prepare the structure helper + Structure structureHelper = nat.getStructureHelper(); + + try { + try { + // start namespace tansaction + nat.begin(); + // retrieve the node to be linked + ObjectNode object = structureHelper.retrieve(st,"/users/testuser"); + // create the link node + structureHelper.createLink(st, new LinkNode(),"/users/testgroup/testuser", object); + // commit the transaction + nat.commit(); + } catch (AccessDeniedException ex) { + ... // handle exception + throw ex; + } catch (ObjectAlreadyExistsException ex) { + ... // handle exception + throw ex; + } catch (Exception ex) { + ... // handle exception + throw ex; + } + // ... SUCCESS ... + } catch (Exception ex) { + try { + nat.rollback(); + } catch (SystemException sysex) { // catch silently } + } + }}} + {{{ + Hope this helps. Keep in mind that while this code is from a servlet + I wrote and actually works, I might have edited in some errors when + writing this mail... + }}} + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]