Generate User Shortcut out of Wiki page

Description
martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Generate User Shortcut out of Wiki page

Postby martins » Thu Oct 27, 2011 1:40 pm

I'm searching for a user-friendly way to generate a "User Shortcut" from a Wiki page. I'd prefere a Button that autmaticly generates a "User Shortcut" for the current user, with a predefined name, in current scope.

Background: the standard button for generating shortcuts is very difficult to find and users don't know which scope they have to select within the "New Shortcut" dialog.

I've searched the API javadoc for the keyword "shortcut" but I couldn't find any methods to handle shortcuts.

Any Ideas?

keith.roseberry
Posts: 5
Joined: Wed Apr 02, 2008 7:10 pm
Location: Vermont, USA
Contact:

Re: Generate User Shortcut out of Wiki page

Postby keith.roseberry » Wed Nov 02, 2011 1:17 pm

I haven't run across the ability to manipulate shortcuts from within the API.

The only solution that comes to mind is to install the Wiki Scripting Tools (http://extensions.polarion.com/polarion/extensions/extension.jsp?extension=PE-174), which provides the $polarionTool object. Using $polarionTool you can gain access to the Subversion repository by invoking the "getRepositoryService" method, which returns an object of type IRepositoryService. Then, obtain an IRepositoryConnection object by invoking the "getConnection" method with an ILocation object that refers to the user's shortcut file in the Subversion repository (.polarion/user-management/users/{userid}/shortcuts.xml). Update or create the file to add a new shortcut.

The following example code retrieves the "shortcuts.xml" file from the current user's repository storage area and dumps it to the screen. I attempted to use the $xmlTool to parse the xml file, but it kept returning null so I reverted to processing the file byte-by-byte.

- Keith

Code: Select all

## ----------
## Start a transaction. A repository connection can only be used
## within a transaction.
## ----------

$transactionService.beginTx()

## ----------
## Build the path to the current user's storage area in Subversion.
## ----------

#set($userId   = $securityService.getCurrentUser())
#set($path     = "/.polarion/user-management/users/$userId/shortcuts.xml")
#set($location = $polarionTool.location.getLocation($path))

## ----------
## Obtain a repository connection to the current Subversion location.
## ----------

#set($connection = $polarionTool.getRepositoryService().getConnection($polarionTool.location))

## ----------
## Determine if the "shortcuts.xml" file exists in the current user's
## storage area.
## ----------

#if($connection.isFile($location))

  ## ----------
  ## Dump the contents of the file to the wiki page.
  ## ----------

  #set($shortcutsXml = $connection.getContent($location))

  {pre}
  #set($output = "")
  #foreach($i in [1 .. $shortcutsXml.available()])
    #set($byte = $shortcutsXml.read())
    #if(!$byte.equals(13))
      #if($byte.equals(10))
        #set($output = "$output<br/>")
      #else
        #if($byte.equals(32))
          #set($output = "$output&nbsp;")
        #else
          #set($output = "$output&#$byte;")
        #end
      #end
    #end
  #end
  {/pre}

  $output \\

#end

## ----------
## Rollback the transaction, as this is only a demonstration.
## ----------

$transactionService.rollbackTx()


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 16 guests