ecmarchitect.

com
Alfresco Developer Series Developing Custom Actions 2nd Edition

January, 2012
Jeff Potts

This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy o this license! visit http"##creativecommons.or$#licenses#by-sa#3.0# or send a letter to Creative Commons! %%% Castro Street! Suite &00! 'ountain (iew! Cali ornia! &%0%)! USA.

ecmarchitect.com
Alfresco Developer Series Developing Custom Actions 2nd Edition

January, 2012 Jeff Potts

About the Second Edition
This tutorial was ori$inally written in *anuary o +00,. - think it was actually the irst Al resco tutorial - wrote even thou$h - think o .Custom Content Types/ as the lo$ical place to start rom the perspective o someone rampin$ up on the plat orm. The ori$inal version was very short0it ocused only on how to make a custom action con i$urable within a rule in Al resco 12plorer. The second edition $reatly e2pands on the irst by buildin$ on the SomeCo e2ample started in the .Custom Content Types/ tutorial and addin$ a second action e2ample that sets a custom property de ined in the e2ample SomeCo model. Similar to the second edition o .content types/! my main intent o writin$ this revision was to illustrate how to use the action con i$uration new to Al resco % to wire the actions into the Al resco Share user inter ace. The old Al resco 12plorer instructions still e2ist. -3ve moved those to the Appendi2. They work ine in Al resco %! so i you are stuck on 12plorer! but have up$raded to Al resco %! you3ll still ind it use ul. The new action-related e2tension points in Al resco % make it much! much easier to add shortcuts and other usability improvements to Share with drastically less code than you3d need to do the same thin$ in older versions. A ter you read this tutorial! you3ll be able to add all sorts o cool thin$s to your Al resco installation. - you do! - hope you consider packa$in$ them up as an A'4! puttin$ the source somewhere public! and listin$ them on http"##addons.al resco.com. As always! please let me know i you ound this help ul. Any and all eedback is welcome on my blo$ at http"##ecmarchitect.com. 5ave un6 *e

Developing Custom Actions, 2nd Edition

T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense

4a$e + o %0

ecmarchitect.com
Table of Contents
About the Second 1dition..................................................................................................................... + -ntroduction........................................................................................................................................... 7 Setup.......................................................................................................................................................... 8 4art )" -mplementin$ an Action................................................................................................................. 8 9hat is an Action:................................................................................................................................ 8 12ample )" 'ove ;eplaced..............................................................................................................& 12ample +" Set 9eb <la$............................................................................................................... )0 -mplementin$ the 'ove ;eplaced Action...........................................................................................)0 Step )" 9rite the action e2ecuter class........................................................................................... )) Step +" Con i$ure the action in Sprin$........................................................................................... )+ -mplementin$ the Set 9eb <la$ action............................................................................................... )3 Step )" 9rite the Set9eb<la$ action e2ecuter class.......................................................................)3 Step +" Con i$ure the action in Sprin$........................................................................................... )7 *ava versus Server-side *avaScript......................................................................................................)7 4art +" Con i$urin$ the Action3s <ront-1nd in Share............................................................................... )7 Con i$urin$ the ;eplaceable Aspect in Share.....................................................................................)8 Con i$urin$ the 'ove ;eplaced ;ule Action in Share.......................................................................), Step )" Speci y the custom client-side component and set the action order...................................), Step +" Add a re erence to the custom client-side *avaScript ile to the head................................)= Step 3" -mplement the custom client-side *avaScript component.................................................. )& Con i$urin$ the Set 9eb <la$ U- Action in Share.............................................................................. +) Step )" Create two new repository tier actions............................................................................... ++ Step +" Update share-con i$-custom.2ml with the action con i$uration........................................ +3 Step 3" Create icons and locali>e the strin$s.................................................................................. +% <inishin$ Touches" 1valuators ? -ndicators....................................................................................... +7 Step )" @eclare a new evaluator in Sprin$ con i$.......................................................................... +7 Step +" Update the action con i$ in share-con i$-custom.2ml....................................................... +8 Step 3" Update the share-con i$-custom.2ml ile to show a document library indicator...............+, @eploy ? Test.................................................................................................................................+, Conclusion............................................................................................................................................... +& 9here to ind more in ormation..........................................................................................................+& About the Author.................................................................................................................................+& Appendi2..................................................................................................................................................30 Con i$urin$ the ;eplaceable Aspect in 12plorer................................................................................ 30 Con i$urin$ the 'ove ;eplaced ;ule Action in 12plorer.................................................................. 30 Step )" Create an action handler class............................................................................................ 3) Step +" Create a correspondin$ *S4 pa$e....................................................................................... 3) Step 3" Locali>e the 'ove ;eplaced Action.................................................................................. 3+ Developing Custom Actions, 2nd Edition 4a$e 3 o %0

T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense

ecmarchitect.com
Con i$urin$ the Set 9eb <la$ U- Action in 12plorer......................................................................... 3% Step )" Create a *S<-mana$ed Aean...............................................................................................3% Update web-client-con i$-custom.2ml with the new U- action.....................................................38 Locali>in$ the Set 9eb <la$ action................................................................................................ 3= Con i$urin$ the 1valuator to Show#5ide the Set 9eb <la$ U- Action in 12plorer...........................3=

Developing Custom Actions, 2nd Edition

T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense

4a$e % o %0

2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 7 o %0 . The Al resco 12plorer sections have been moved to the Appendi2 i you need them.or the oundation A4-. @ecidin$ whether to $o with the out-o -the-bo2 web client! a customi>ed web client! or buildin$ your own user inter ace rom scratch reDuires care ul thou$ht and analysis that is beyond the scope o this document.ule Action/. The document includes two di erent e2amples.12ecute Script/ action. -t is important to note that i you are lookin$ or Duick-and-dirty ways to operate a$ainst documents in the repository! you may not need a custom action.com Introduction Al resco is a le2ible plat orm or developin$ content mana$ement applications. The irst edition o this tutorial ocused on the Al resco 12plorer web client. 4art + e2plains how to con i$ure the user inter ace to work with the custom actions. <or e2ample! you could create some server-side *avaScript that $ets called rom the . This edition ocuses on the Al resco Share web client.'ove . This is particularly true when your reDuirements closely resemble the all-purpose document mana$ement use case.. Alternatively! developers can create custom applications usin$ the Content 'ana$ement -nteroperability Services BC'-SC A4-! web scripts! the web services A4.9here to ind more in ormation/ or a linkC. The irst article discussed how to create custom content types and then e2pose those to the Al resco user inter ace.ecmarchitect. The ocus in this article is on developin$ custom actions and con i$urin$ the user inter ace to show those custom actions. Er! you could run server-side *avaScript usin$ the *avaScript Console add-on available rom Share 12tras Bsee . Clients have several options to consider when selectin$ a user inter ace approach.eplaced/ will be used as a . Actions are use ul when" • • • Fou want to de ine one or more operations that can be e2ecuted repeatedly Fou want to make it easy or end-users to invoke common operations! either by clickin$ a menu item or by con i$urin$ a rule on a older that will e2ecute the operations automatically Fou want to per orm one or more operations on a schedule Bwhich isn3t covered in this documentC 4art ) o this document e2plains how to implement the . Ene action! called .back-end/ piece o the action. This article is the second in a series that covers Al resco rom a con i$uration and customi>ation perspective. 'any times! the out-o -the-bo2 web client is su icient! even i it has to be customi>ed sli$htly to it your reDuirements. The other action is called . Al resco comes with two web clients that can be used as-is or customi>ed.Set 9eb <la$/ and it will be called rom menu items in the user inter ace. Developing Custom Actions. There are C'-S A4-s that allow you to per orm bulk operations rom the command line.

Custom Content Types! + nd 1dition/ tutorial with the e2ception o the 9eb Services and C'-S e2amples. What is an Action? The term! . The code is inclusive o the code rom the . -n real li e! you3ll want to packa$e your customi>ations as A'4s or both the repository and Share tiers. This is easily done by creatin$ a Developing Custom Actions.3+ *ava ).8. The code that accompanies this article is split into two 1clipse proJects0one or repository tier con i$uration and customi>ation and the other or Share tier con i$uration and customi>ation. That3s because actions are reDuently used when con i$urin$ a rule on a older. 2nd Edition 4a$e 8 o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .-only distribution Ether operatin$ systems! databases! application servers! and Al resco versions will work with the e2amples in 4art )! but in 4art + .+ 'ySHL 7.com Setup Ae ore $ettin$ too ar down the road! here are a couple o notes about my setup"      'ac ES G Lion )0.s.80 B'acportsC Tomcat 8.you don3t understand how to e2tend Al resco3s content model with your own or how to con i$ure custom models in the Share and 12plorer user inter aces! read that tutorial irst..c Community! 9A.action/ is overloaded Duite heavily across the Al resco plat orm Band application development! in $eneralC. 1ach has its own build script which copies the arti acts into the appropriate places within the e2ploded Al resco and Share 9A. This e2ample uses the SomeCo content model established in that tutorial. Sometimes! the term .0. . Part 1: Implementing an Action Actions are very commonly used when implementin$ Al resco.emove Aspect! 'ove! Send 1mail! and Speciali>e Type.ecmarchitect.use some Share e2tension points that are new in Al resco %! so older versions may not work with the Share con i$uration e2amples.).. Some o the out-o -the-bo2 actions include thin$s like" Check-out! Check-in! Add Aspect! .0. <or the purposes o this document! an action is a discrete! reusable unit o work that can be per ormed a$ainst an obJect in the repository! and can optionally be con i$ured at runtime by the user. This part o the tutorial e2plains what actions are! sets up a couple o e2amples! then shows how actions are implemented in *ava.rule action/ is used to describe this type o action.0I+& Al resco %. <or e2ample! suppose that there is a reDuirement to always create a 4KL version o L-<s checked in to a speci ic older.

action/.actions/ to distin$uish the actual menu item! the U.ecmarchitect. Drawing 1: Actions in Explorer rule config Drawing 2: Actions in Share rule config Aut actions aren3t limited to runnin$ as part o a rule. These are o ten called .actions in Al resco 12plorer" Developing Custom Actions.actions and the .com rule that watches or new or updated L-<s and then runs the .U.Trans orm and Copy -ma$e/ action when it inds an obJect that meets the criteria.rule action/ or simply! the . The screenshots below show the out-o -the-bo2 actions available when con i$urin$ a rule in Al resco.browse/ U.details/ U. These screenshots show the . o %0 . @rawin$ ) is Al resco 12plorer and @rawin$ + is Al resco Share. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e . Actions can be called rom menu items in the user inter ace Bboth 12plorer and ShareC.action! rom the thin$ that actually does the work! the .

ecmarchitect.actions available in the document library3s document list as well as the document details pa$e" Developing Custom Actions.com Drawing 3: Browse UI actions in Explorer Drawing 4: Details UI actions in Explorer Similarly! Al resco Share has U. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e = o %0 .

Consider SomeCo! the ictitious company introduced in the content types tutorial. 2nd Edition 4a$e & o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .ecmarchitect. Developing Custom Actions.com Drawing 5: Browse UI actions in Share Drawing : Details UI actions in Share So actions can be invoked rom a rule and can be tri$$ered rom a menu item. Example 1: Move Replaced Usin$ actions and work low to$ether can be an e ective way to customi>e the web client or the needs o the business. Aecause the same action can be invoked rom all o these places! actions are a power ul way to write content operations once and then levera$e them in many places. Actions can also be called rom code which means they can be invoked rom server-side *avaScript! work lows! web scripts! or any other piece o code that can $et to the Action Service. Suppose SomeCo wants to use Al resco to mana$e the policies and procedures or their entire or$ani>ation. They need to be able to track when a new policy or procedure is published that supersedes an older policy document.

-n the irst tutorial! that la$ was set either by editin$ the ield in the user inter ace or by runnin$ code. Con i$urin$ the action in Sprin$ Ence that3s done! the action can be called rom code usin$ the Action Service! or it can be wired in to the user inter ace Bincludin$ rule con i$urationC! which is covered in 4art +. -mplementin$ the action3s business lo$ic involves two steps" ).ecall rom the irst tutorial that SomeCo publishes a subset o the documents in their repository to a company portal. The irst part! where to move the old documents! will be a parameter that $ets passed to the action.replaces/ relationship. -n act! Al resco already has a MreplaceableM aspect in the out-o -the-bo2 content model. Implementing the Move Replaced Action Actions run a$ainst speci ic nodes. A MreplacesM relationship is a pretty common reDuirement. SomeCo uses a la$ on the obJect to keep track o which documents should be shown on the portal. -n this e2ample! the action needs to ind the documents that the . Developing Custom Actions.replaceable/ aspect de ines an association called .ecmarchitect. The second part will levera$e a . Example : Set !eb "lag . Al resco has a .'ove/ action! but doesn3t have a .eplaced/ action can easily be created to accomplish this. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )0 o %0 . All that is needed is some con i$uration to e2pose this relationship to the user inter ace.riendly by providin$ menu items in the user inter ace that can enable and disable the la$.'ove . Kow it is time to make it a bit more user.actioned upon node/ replaces so they can be moved. 9hen someone moves a policy into the Approved older! i that policy replaces an older policy! the older policy needs to be automatically moved to the Archived older.cm"replaces/. -n order to do this! the action needs to know where to move the old documents to and it needs to know how to ind the old documents.eplaced/ action. The business lo$ic will reside in an action e2ecuter class.com SomeCo uses three olders to keep track o the state o their policies" @ra t! Approved! and Archived. SomeCo uses Al resco3s Simple 9ork lows to move policies rom older to older. 9ritin$ the action e2ecuter class +. So! the out-o -the-bo2 content model already accommodates documents that replace other documents. The rest o this document e2plains how to implement both o these actions includin$ the con i$uration necessary to make them available rom the user inter ace.'ove . This will allow SomeCo end-users to call the action rom a rule con i$ured on any older! without urther involvement rom the development team. A new . The .

()ileNot)ound%xception e) { // $o not. 4lus! ollowin$ the same patterns to implement this customi>ation will make it easier or someone to support and makes it easier to share our code with others or even to contribute the code back to the Al resco community proJect.e replaces associations for t.create2Name(Namespace&ervice.is node *ist0AssociationRef1 assocRefs = node&ervice. etParameter!alue(PARA"#$%&'INA'I(N#)(*$%R)+ tr. public void executeImpl(Action ruleAction.'oveAction12ecuter.e2ecuter.al resco.in - !isting 1: Alfresco"s out#of#the#$ox action executer for %o&e The code simply $rabs the parameter value or the destination older and then calls the <ile<olderService to do the move. et'ar etAssocs(actionedUponNodeRef. NodeRef actionedUponNodeRef) { // et t.ere are none. null)+ catc. The e2ecute-mpl method is where the move lo$ic is handled.is%mpt. . This is a $ood start or 'ove . Al resco3s e2ecuter class or the 'ove action is called or$. -3ll copy it into my own repository proJect and call it 'ove. The new action is doin$ a move! so the e2istin$ 'ove action is a $ood place to start.com Step 1: !rite t#e action executer class At its most basic! an action consists o an Action 12ecuter class and its associated Sprin$ bean con i$uration.()) { Developing Custom Actions.action.you have the Al resco source you can ind it in the repository proJect. Al resco is open source--it would be a shame to i$nore that valuable resource. return if (assocRefs. Ae ore startin$! thou$h! think about similar code that mi$ht already e2ist within Al resco that mi$ht be a $ood startin$ point or the new action. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )) o %0 . All .eplaced. NodeRef actionedUponNodeRef) { NodeRef destinationParent = (NodeRef)ruleAction.repo. destinationParent. -n act! the only di erence between the 'ove action and the custom 'ove . 6replaces6)) )+ // if t.ecmarchitect. -t looks like this" public void executeImpl(Action ruleAction. -mplementin$ an action involves e2tendin$ Action12ecuterAbstractAase and then implementin$ the e2ecute-mpl method.need to do is modi y the e2ecute-mpl method to ind the nodes related to the current node by a MreplacesM association! and then or each result! set up and per orm a move.3(N'%N'#"($%*#4#5#URI.eplacedAction12ecuter.move(actionedUponNodeRef. { file)older&ervice.eplaced action is that the node bein$ moved isn3t the current node--it3s the node on the tar$et end o a MreplacesM association. ((2NamePattern) 2Name.

conte2t. return return+ .node&ervice.ecmarchitect.ttp9//777.move(tar etNodeRef.exists(tar etNodeRef) == true) { tr.e replaces association NodeRef tar etNodeRef = assocNode.e2tension/ directory to keep them separate rom the rest o the Al resco web application. destinationParent.someco-action-conte2t. -t contains the ollowin$" 0:xml version=.. <or this e2ample! .or /dtd/sprin <beans."oveReplacedAction%xecuter6 parent=6action< executer61 0propert.is. etParameter!alue(PARA"#$%&'INA'I(N#)(*$%R)+ for (AssociationRef assocNode 9 assocRefs) { // create a noderef for t.sprin frame7or8.in . ()ileNot)ound%xception e) { // $o not.5.:1 0>$(3'?P% beans PU@*I3 .// end if is%mpt. { file)older&ervice.dtd.2ml/ and placed it in #con i$#al resco#e2tension.else { NodeRef destinationParent = (NodeRef)ruleAction.// next assocNode .<//&PRINA//$'$ @%AN//%N. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )+ o %0 .executer. name=6node&ervice61 0ref bean=6Node&ervice6 /1 0/propert. - !isting 2: 'he custo( action executer for %o&e )eplace* The only other chan$e needed is to chan$e the value o the constant KA'1 rom MmoveM to MmovereplacedM.action. et'ar etRef()+ // if t.1 0/bean1 Developing Custom Actions.com // no 7or8 to do.created a ile called . name=6file)older&ervice61 0ref bean=6)ile)older&ervice6 /1 0/propert.U')<=. Those iles reside in the .e node exists if (t. encodin =.1 0propert. BThrou$hout this document -3ll only include relevant pieces o these classes0check the source that accompanies this article or code that actually compilesC. Step : Configure t#e action in Spring -n the content types tutorial! you learned that Sprin$ bean con i$urations $o in iles that end with .someco.2ml/. . null)+ .catc.1 0beans1 0bean id=6move<replaced6 class=6com.4.

$ata'.sc"published/ that keeps track o when the content was last published to the portal.@((*%AN.eplacedAction! this action e2tends Action12ecuterAbstractAase.pe$efinition.sc"webable/. Ence in place! the action can be invoked rom code.eplaced e2ample! the steps are" ). Step 1: !rite t#e Set!eb"lag action executer class Like the 'ove.add( ne7 Parameter$efinitionImpl( PARA"#A3'I!%. The Sprin$ conte2t ile $oes in 91A-K<#classes#al resco#e2tension.eplacedAction12ecuter class! *A.com 0/beans1 !isting 3: Spring configuration for %o&e )eplace* That3s all there is to it. Actions declare parameters by overridin$ the add4arameter@e initions method" B(verride protected void addParameter$efinitions(*ist0Parameter$efinition1 param*ist) { param*ist.sc"isActive/ la$. *ust like in the 'ove . Also in that aspect is a date property named .sc"published/ property with the current date. Fou could compile the 'ove.*abel(PARA"#A3'I!%)))+ - Developing Custom Actions. The value to set it to Btrue or alseC can be passed in as a parameter to the action. etParam$ispla. 9hen the la$ is set to true! the action should set the .ecall rom the content types tutorial that the property is a boolean named .action in the user inter ace to allow end-users the ability to enable or disable a piece o content or display on the portal with a sin$le click. That3s obviously not $oin$ to be use ul or end users! thou$h. This action could be called rom a rule! but SomeCo intends to con i$ure a U. false. The Set 9eb <la$ action! then! needs to set the . Con i$ure the action in Sprin$ Then! the action will be ready to use. it up! and deploy it to Al resco3s 91A--K<#lib. -n act! the Ant build ile that accompanies this code does Just that. 9rite the action e2ecuter class +. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )3 o %0 . Ae ore wirin$ the action into the user inter ace! let3s look at another Action 12ecuter e2ample.ecmarchitect. The action takes a parameter that speci ies the value or the .sc"isActive/ la$.sc"isActive/ which is de ined as part o an aspect named . . Implementing the Set Web Flag action This action will be used to set the la$ on content which should be shown in the SomeCo portal.

e sc9isActive propert.the custom action had additional parameters this method would have one paramList.addAspect(actionedUponNodeRef. etParameter!alue(PARA"#A3'I!%)+ if (active)la == null) active)la = true+ // default // set t. &erialiCable1 properties = node&ervice.e sc9publis.NA"%&PA3%#&("%3(#3(N'%N'#"($%*.e aspect and set t.com !isting 4: Declaring a para(eter for an action The constructor or the 4arameter@e inition-mpl takes the name o the parameter! the parameter3s data type! whether or not the parameter is mandatory! and a label. The ne2t step is to create the action3s lo$ic in the e2ecute-mpl method" B(verride protected void executeImpl(Action action.ecmarchitect.e properties node&ervice. been added. &ome3o"odel.NA"%&PA3%#&("%3(#3(N'%N'#"($%*.create2Name( &ome3o"odel. properties)+ - !isting 5: Action executer for Set +e$ .put( 2Name. &ome3o"odel. NodeRef actionedUponNodeRef) { @oolean active)la = (@oolean)action.A&P%3'#&3#E%@A@*%). to true "ap02Name.e aspect . etProperties(actionedUponNodeRef)+ properties. 2Name. The code $rabs the value o the active parameter.asAspect(actionedUponNodeRef.as alread.create2Name(&ome3o"odel. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )% o %0 . to no7 properties. . &ome3o"odel.the active la$ is bein$ set to true! the date property is added to the map.ed propert.create2Name( &ome3o"odel. . &ome3o"odel.NA"%&PA3%#&("%3(#3(N'%N'#"($%*. add t. Then! it sets up a map to hold properties.put( 2Name. 2name.PR(P#PU@*I&D%$).add call or each parameter.er7ise.else { // ot. .create2Name(&ome3o"odel.PR(P#I&#A3'I!%). properties)+ .e properties if (node&ervice. set t.NA"%&PA3%#&("%3(#3(N'%N'#"($%*. The last part o the method Just checks to see whether the aspect needs to be added or not. ne7 $ate())+ // if t.A&P%3'#&3#E%@A@*%))) { node&ervice. Developing Custom Actions..setProperties(actionedUponNodeRef.so! the aspect can be added and the properties set in a sin$le call.lag The lo$ic should be pretty easy to ollow. active)la )+ if (active)la ) { // set t.

2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )7 o %0 .ecmarchitect. So the user inter ace needs to know where to show that menu item and how to invoke the Set9eb<la$ action in the repository. Developing Custom Actions. Al resco % added some e2tensibility eatures that make it much easier to con i$ure actions in Share than it used to be.executer. That means the user inter ace needs to know how to let the end user pick a tar$et older. This is an attractive option or teams lackin$ in *ava skills. The tradeo is that the *avaScript A4. 5owever! action e2ecuters can also be implemented usin$ server-side *avaScript. The steps are the same" write the lo$ic! then con i$ure it throu$h Sprin$.someco. Java versus Server-side JavaScript A Duick side-note be ore movin$ on to the ront-end" The action e2ecuter e2amples shown in 4art ) were both implemented in *ava. The result was an action that could be called rom code. Aut both actions need to be invoked by end-users. -n the case o the 'ove . Part : Configuring t#e Action$s "ront%End in S#are -n 4art ) o this document you learned how to create an Action 12ecuter class.does not have )00N o the eature set o the Al resco *ava A4-. That3s covered in 4art +. name=6node&ervice61 0ref bean=6Node&ervice6 /1 0/propert.1 0/bean1 !isting : Spring configuration for Set +e$ .lag This action is now ready to be wired in to the user inter ace. 9hen the end-user con i$ures the action! they need to speci y the directory to send the replaced documents to. Fou may also see a per ormance di erence with the *avaScript A4-! which essentially wraps the lower-level *ava A4-. The Set 9eb <la$ action $ives end-users the ability to set the active la$ and the publish date with a sin$le click o a menu item. So -3ll use Share and i you need to see how to do the e2act same thin$ in 12plorer! check the Appendi2.action.eplaced action! an end-user will con i$ure a rule that will invoke the action. Al resco 12plorer used to be the only choice. Al resco Share is usually the pre erred web client these days.com Step : Configure t#e action in Spring The Sprin$ con i$uration or this action $oes in the same conte2t ile as the pervious action" 0bean id=6set<7eb<fla 6 class=6com.&etEeb)la 6 parent=6action<executer61 0propert. The speci ic steps to con i$ure the user inter ace or these two actions depend on the web client bein$ used.

=6true6 /1 <field id="cm:replaces" label-id="assoc.ecmarchitect.: /onfiguring the c(:replaces association and this" 0field id=6cm9sentdate6 read<onl.appearance/ elements! like this" 0><< cm9 eo rap.cm"replaceable/ aspect can be added to the list o aspects a user can see! like this" 0visible1 0aspect name=6sc97ebable6 /1 0aspect name=6sc9productRelated6 /1 0aspect name=6cm9replaceable6 /1 0/visible1 !isting -: A**ing the replacea$le aspect to the list of &isi$le aspects Ke2t! the . The web-e2tension#messa$es#sc'odel.cm_replaces"/> 0/appearance1 !isting 0: /onfiguring the c(:replaces association The last step in e2posin$ the .cm"content/ or policies! but this would work the same way i a speci ic content type! like .cm"replaces/ association is locali>in$ the labels. ield visibility/ and .cm#replaces=Replaces !isting 11: !ocali2ing the replacea$le aspect Developing Custom Actions.share-con i$-custom.ic aspect <<1 0s. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )8 o %0 .cm:replaceable --> <show id="cm:replaces" /> 0/field<visibilit.cm"replaces/ as part o the . That3s easy to i2.ecall rom the content types tutorial that the Share user inter ace con i$uration resides in a ile called .properties ile already e2ists! so add the ollowin$" Gcm9replaceable aspect.=6true6 /1 0field id=6cm9subFectline6 read<onl.cm"replaceable/ aspect. Aut neither the aspect nor the association are con i$ured to be displayed in the Share user inter ace.o7 id=6cm9lon itude6 /1 <!-. So -3ve copied the orm con i$uration or .2ml/. *ust like in the content types tutorial! the association is con i$ured by addin$ children to the . -n this e2ample! SomeCo will use instances o .cm#replaceable=Replaceable assoc.2ml/.1 !isting .share-con i$-custom. The .cm"replaceable/ aspect and .sc"hr4olicy/! were used instead.cm"content/ rom the out-o -the-bo2 orm con i$uration into .com Con iguring the Replaceable Aspect in Share Al resco3s out-o -the-bo2 content model already de ines an association called . .o7 id=6cm9latitude6 /1 0s.cm"replaces/ association needs to show up when editin$ properties.

Everride the rule details and rule edit web script to include a . And it is a lot easier than it used to be i that makes you eel any better. Aut this action takes a node re erence as an ar$ument and makin$ an end-user provide a node re erence or the tar$et older would be a very bad thin$.R leConfi!"ctionC stom</component> 0confi <definitions 7ebscript=6/api/actiondefinitions61 !isting 11: /onfiguring Share to use a custo( client#si*e co(ponent for rule config Developing Custom Actions. Everride the rule con i$ action web script to point to a custom client-side component and to set the order the action appears in the action list. +. Aut rule con i$ still lives in the rule con i$ web script.ule Action in Share.head/ section o the pa$e that points to the client-side *avaScript where the custom client-side component lives.copied the ile into con i$#al resco#web-e2tension#sitewebscripts#or$#al resco#components#rules#con i$. -n Al resco %! a lot o work has been done to make customi>in$ and e2tendin$ the user inter ace easier.2ml. Step 1: Specif& t#e custom client%side component and set t#e action order -n Al resco %! a lot o the action con i$uration has been pulled into share. Un ortunately! at the moment! $ettin$ a older picker to show up or this action takes a bit more work than it ou$ht to. Let3s $o throu$h the steps. Ay de ault! Share will try to render a plain te2t ield or the ar$ument which mi$ht work in some cases.eplaced action as-is it will automatically $et added to the list o actions users can select when con i$urin$ a rule.orm-con i$-custom. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e ).$et.you deploy the 'ove .eplaced . . o %0 . <or e2ample! in the code that accompanies this article! . -n this case! copy the rule-con i$-action. -t looks like a pain! but once you i$ure it out it isn3t too bad.script/ re erence in the .2ml ile rom OTE'CATI5E'1#webapps#share#91A--K<#classes#al resco#sitewebscripts#or$#al resco#components#rules#con i$ into your own proJect. The irst chan$e is to speci y a custom client-side *avaScript component" 0rule<confi t.con i$. -nstead! Share needs to render a older picker dialo$ or the tar$et older ar$ument. 9rite the custom client-side component.pe=6action61 <component>SomeCo. Con iguring the Move Replaced Rule Action in Share Share is pretty smart. Luckily! Al resco has already developed such a dialo$0Share Just has to be told to use it. Aut in this e2ample! the action takes an ar$ument. So or simple actions! you won3t have to do anythin$ urther. Until then! here is what is involved" ). 3. This isn3t a bi$ deal0it is easy to override one or more iles that make up a web script.ecmarchitect. 'y $uess is that this will $et resolved in the uture.com The ne2t step is to con i$ure the 'ove .

'ove/" 0menu1 0 roup1 0item id=6select6/1 0/ roup1 0 roup1 0action name=6script6/1 0/ roup1 0 roup1 0action name=6cop. tl and ruleedit. The modi ications to both are identical and are as ollows" 0Blin8 rel=6st.url.$et.head.css6 /1 0Bscript t.PheadQ/ section o the pa$e so the browser knows about it.context-/res/components/rules/rule< details. <or rules! there are two web scripts that will need to re er to the custom client-side *avaScript" .context-/res/components/rules/rule<details.ref=6H {pa e.eet6 t.head.ecmarchitect. 9eb scripts that end with .Fs610/Bscript1 <!--C stom %a#ascript file incl de for detail mode --> <&script t'pe="te(t/%a#ascript" src=") *pa!e. So the rule-details.rule edit/.pe=6text/css6 . 2nd Edition 4a$e )= o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .head. -n this case! it makes sense to see it in the list ri$ht a ter . rl.com This will be a new client-side *avaScript component that will $et created shortly.0/action1 name=6move61"ove0/action1 name="mo#e-replaced">$o#eReplaced</action> name=6simple<7or8flo761&impleEor8flo70/action1 !isting 13: Specif4ing which client#si*e han*ler to use for %o&e )eplace* Step : Add a reference to t#e custom client%side 'avaScript file to t#e #ead The client-side *avaScript ile where the custom client-side component resides needs to be pulled in to the .pe=6text/Favascript6 src=6H{pa e.%s"></&script> !isting 14: A**ing the client#si*e 5a&aScript reference to hea* Ekay! at this point! the rule orm will be lookin$ or a custom client-side *avaScript component called Developing Custom Actions.613op. tl iles are copied rom OTE'CATI5E'1#webapps#share#91A-K<#classes#al resco#site-webscripts#or$#al resco#components#rules. tl/ are used or this purpose.url. Ke2t! the action $ets arran$ed in the list o actions.$et.les.6/1 0action name=6move6/1 <action name="mo#e-replaced"/> 0/ roup1 !isting 12: 3lacing the %o&e )eplace* action in the rule action list <inally! the action $ets bound with a client-side *avaScript unction" 0action 0action <action 0action name=6cop.conte(t+/someco/components/r les/confi!/r le-confi!-actionc stom.rule details/ and .

superclass.Rule3onfi Action3ustom.PheadQ/ element will include a re erence to the custom client-side *avaScript ile where the component will reside.components#rules#con i$/ so .Rule3onfi Action3ustom = function(.is+ -+ !isting 1 : Snippet of client#si*e 5a&aScript showing the )ule/onfigAction/usto( constructor .renderers)+ return t.mer$e calls provide a way to avoid re-typin$ a bunch o code that e2ists in the parent class.is. -t3s time to implement the client-side *avaScript.Js.renderers = ?AD((.is)+ // Instance variables t.mer e(t.rere ister(t.ecmarchitect.superclass.is. our o7n name t.superclass.uleCon i$ActionCustom! the action will show up in the ri$ht place! and the pa$e3s .*avaScript/ have a word in common that obJect inheritance would work the same way: 5ow literal o you6 Aasically! what3s $oin$ on here is that the constructor is callin$ its superclass constructor! then it is re$isterin$ itsel with the Al resco component mana$er. Al resco has their rule-related client-side *avaScript under .is. if (t.Rule3onfi Action3ustom.lan .tmlId) { &ome3o. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e )& o %0 .renderers.is.tmlId)+ // Re<re ister 7it.include client-side *avaScript in my 1clipse proJect under .is.call(t.mer e(t. -t is important that you namespace everythin$ in Al resco to avoid collisions with Al resco3s code or other add-ons you mi$ht install.peof &ome3o == 6undefined6 II >&ome3o) { var &ome3o = {-+ - !isting 15: Declaring a So(e/o na(espace in client#si*e 5a&aScript Ke2t! comes the constructor or the component B-3ve le t out some borin$ stu ! check the source or the ull listin$C" &ome3o.util.customisations. The irst thin$ the rule-con i$-action-custom. Step (: Implement t#e custom client%side 'avaScript component The <ree'arker iles have been modi ied to include a re erence to a ile called rule-con i$-actioncustom.3omponent"ana er.src#web#someco/.lan . Developing Custom Actions.Rule3onfi Action3ustom.used the same older structure. 9hat! you thou$ht Just because .is.. The FU.com SomeCo.constructor. Ay convention! .*ava/ and .this is your irst oray into the world o obJect-oriented client-side *avaScript! rela2.customisations)+ t.customisations = ?AD((. &ome3o.name = 6&ome3o. &ome3o.Rule3onfi Action3ustom6+ Alfresco. .Js ile does is declare a SomeCo namespace.

Te2t is what is displayed or the component in read mode.eplaced handler is de ined" ?AD((.6+ return confi $ef+ -.arca"destinationdialo$-button/ that is de ined in the superclass.parameter$efinitions)+ // "a8e parameter renderer create a 6$estination6 button t.parameter$efinitions.you needed to produce markup or a parameter or which Al resco doesn3t already have a renderer! you would add the appropriate code to the renderers obJect. displa.Rule3onfi Action.at displa.pe = 6pat. rule3onfi .com The inal bit is where the e2tend actually happens! and the 'ove. edit9 function(confi $ef.#.is.*abel9 t. t. -n this case! edit levera$es an e2istin$ renderer called . rule3onfi .({ t.#t. The 'ove.is.Rule3onfi Action3ustom. #destinationParam9 6destination<folder6 -)+ return confi $ef+ -. #button*abel9 t.is.# etParam$ef(confi $ef. The edit method is what is responsible or $eneratin$ the button that invokes the older picker.ms (6button. Developing Custom Actions. as pat. confi %l) { // Dide all parameters since 7e are usin a cusotm ui but set default values t. -)+ !isting 1-: Defining the %o&e)eplace* client#si*e han*ler This part is a copy o the out-o -the-bo2 handler or 'ove with the obJect renamed to 'ove. .eplaced.ecmarchitect.to6). { /JJ J 3U&'("I&A'I(N& J/ customisations9 { "oveReplaced9 { text9 function(confi $ef.extend(&ome3o.is. -.s an destination folder bro7ser confi $ef.select<folder6).pus.ideParameters(confi $ef. 6destination<folder6).pe9 6arca9destination<dialo <button6. 2nd Edition 4a$e +0 o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .eplaced obJect has two methods" te2t and edit. 1dit is or edit mode.ms (6label. Alfresco. confi %l) { // $ispla.

actions that call a web pa$e Be2ternal or within ShareC! U.com 9ith this inal step in place! end-users can con i$ure a rule that invokes the 'ove .actions. Fou can con i$ure" • • • • U. Drawing -: /onfiguring the %o&e )eplace* action in Share Con iguring the Set Web Flag !I Action in Share Kow it is time to shi t ocus rom rule actions to U.ecmarchitect. SomeCo wants end-users to be able to click an item in the menu that either enables or disables the web la$.actions that invoke rule actions on the repository tier that take no parameters! U.actions that call arbitrary client-side *avaScript action handlers.actions to the menu. 2nd Edition 4a$e +) o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . Developing Custom Actions. Fou can see the dialo$ that $ets launched when the Select button is clicked as well as the little older icon and older path that are rendered once a selection is made. Fou can see this happenin$ in the screenshot below.eplaced action. Al resco % has a ramework that allows you to easily add new U.actions that invoke rule actions on the repository tier that launch a dialo$ to $ather parameters be ore passin$ those parameters to an action on the repository tier! U. The rule editor will use the custom handler or the action so that a older picker dialo$ is used to select the tar$et older.

The Sprin$ con i$uration or the action is similarly short" 0bean id=6enable<7eb<fla 6 class=6com. .2ml with the action con i$uration 3. There needs to be one action or enablin$ the active la$ and one or disablin$ it and neither should take a parameter. . At some point! Al resco will probably enhance the ramework to meet this use case.lag A$ain! -3m leavin$ out the disable-web.: Su$#classing Set+e$.1 0/bean1 !isting 10: Spring configuration for Ena$le +e$ .com .could use the action ramework out-o -the-bo2 to invoke a dialo$ that lets the user set the action la$ to true or alse and then call the set web la$ action. Developing Custom Actions. 5ere3s the 1nable9eb<la$ action e2ecuter in its entirety" public class %nableEeb)la extends &etEeb)la { B(verride protected void executeImpl(Action action.lag to pro&i*e a new action that *oesn"t re6uire para(eters The @isable9eb<la$ action looks Just like this but sets the active la$ to alse. Until then! or this e2ample! -3m $oin$ to $o the . 2nd Edition 4a$e ++ o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . NodeRef actionedUponNodeRef) { action.ecall that the Set 9eb <la$ action takes one parameter0the value o the active la$.PARA"#A3'I!%. true)+ super.ecmarchitect.you look in the list above! you3ll see there isn3t an option to hardcode arbitrary parameters in the action con i$ when the action is called. . Aut that doesn3t meet the sin$le-click reDuirement! and a orm is overkill to $rab one boolean value.no parameter/ route! which means -3ll have to add two new actions on the repository tier that don3t reDuire parameters to be passed in.executer.ri$ht/ answer here0it3s Just a matter o where you want to write the code.setParameter!alue(&etEeb)la .won3t repeat it here. Create two new repository tier actions that take no parameters +. actionedUponNodeRef)+ - !isting 1.la$ bean but it looks Just like this one with a di erent class. Update share-con i$-custom. Create icons and locali>e the strin$s Step 1: Create t)o ne) repositor& tier actions Fou created action e2ecuter classes in 4art ) o this tutorial so this is nothin$ new.someco. So! the steps to ollow or this e2ample are" ). Ay sub-classin$ the e2istin$ Set9eb<la$ action! code can be kept to a minimum.action.%nableEeb)la 6 parent=6set<7eb<fla 61 0propert. There3s no . name=6publicAction61 0value1false0/value1 0/propert. So we3re orced to either call a custom client-side *avaScript action handler or add new actions to the repository tier that don3t take parameters.executeImpl(action.

2ml. -t is a .ecmarchitect.someco-web-enable/ action is a little more involved.2ml in Al resco %.someco. Actions and action $roups live in the .com0/param1 0param name=6tar et61#blan80/param1 0/action1 0action id=6someco<7eb<enable6 t. 9hat3s cool is that Al resco has already provided a client-side handler called . 5ere are the action de initions or the web site action and web enable" 0><< Actions <<1 0confi evaluator=6strin <compare6 condition=6$oc*ibActions61 0actions1 0action id=6someco<7eb<site6 t. Step : *pdate s#are%config%custom+xml )it# t#e action configuration The ne2t step is to con i$ure the Share user inter ace to show the U.actions in the document library and document details menus. Action con i$uration consists o two parts. 9hile we3re at it! -3m $oin$ to also drop in a U.Javascript/ action! which means it is callin$ a client-side *avaScript handler.link/ type o an action! which means it is invokin$ a U.7eb< site6 icon=6someco<7ebsite61 0param name=6. This action uses the built-in onActionSimple.failure0/param1 0/action1 !isting 21: UI action *eclaration for +e$ Site an* +e$ Ena$le The .ref61. The action con i$ has moved to share-con i$-custom. The item-d Developing Custom Actions.publicAction/ property to alse hides these actions rom the action dropdowns.onSimple. -t Just needs to know the name o the repository tier action to invoke Bthe ones created in Step )C and messa$es to display on success and ailure.someco-web-disable/ because it is so similar. The labels and icons will $et set up in the ne2t step.pe=6Favascript6 label=6actions.pe=6lin86 label=6actions.7eb<fla .epoAction! but what i you needed to $ather parameters rom the end-user be ore callin$ the action: <or that you can use onAction<orm@ialo$. There3s no real reason to do that! in this case0it3s Just an e2ample.ttp9//ecmarc. 2nd Edition 4a$e +3 o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .itect.actions/ element contains a list o action de initions. The .7eb<fla .@ocLibActions/ con i$ within share-con i$-custom. -t is a .someco. The . -3ve le t out .epoAction/. The .com Settin$ the .action that calls a web pa$e Just or kicks.L that is provided in a parameter.enabled0/param1 0param name=6failure"essa e61messa e.actionLroups/ element contains a list o action $roups.someco-web-site/ action is really simple.7eb<enable6 icon=6someco<create<7ebsite61 0param name=6function61onAction&impleRepoAction0/param1 0permissions1 0permission allo7=6true61Erite0/permission1 0/permissions1 0param name=6action61enable<7eb<fla 0/param1 0param name=6success"essa e61messa e. Action $roups are thin$s like the list o actions shown in the document library document list or the document details pa$e.

icon/ attribute.disabled=&uccessfull. disabled t. 1ntirely lackin$ in $raphics skills! .someco. Developing Custom Actions.someco/ so they would not be con used with others.7eb<disable=&3 $isable Eeb messa e. The last part o the con i$ is the action de initions. Take a look at the document-trans orm action as an e2ample. Byou are ollowin$ alon$! don3t or$et to deploy both the repository tier proJect and the share tier proJect because you made chan$es in bothC. Al resco will look in a path or an icon that starts with that name and ends with .orm-con i$-custom.7eb<fla .7eb<site=&ome3o actions. 5ere they are" Gactions actions.src#web#components#documentlibrary#actions/.e &ome3o active fla !isting 22: !ocali2e* strings for the new actions 9ith icons and locali>ed strin$s in place! you could deploy and run and everythin$ should work.ecmarchitect.someco. This slots the actions into the appropriate $roups" 0actionAroups1 0actionAroup id=6document<bro7se61 0action index=6K556 id=6someco<7eb<site6 /1 0action index=6K456 id=6someco<7eb<enable6 /1 0action index=6KL56 id=6someco<7eb<disable6 /1 0/actionAroup1 0actionAroup id=6document<details61 0action index=6K556 id=6someco<7eb<site6 /1 0action index=6K456 id=6someco<7eb<enable6 /1 0action index=6KL56 id=6someco<7eb<disable6 /1 0/actionAroup1 0/actionAroups1 0/confi 1 !isting 21: UI action groups exten*e* to inclu*e custo( actions There are a couple o thin$s to note about the action con i$uration. They will $et mer$ed in. <irst! you don3t have to copy in the out-o -the-bo2 actions and action $roups. 2nd Edition 4a$e +% o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . Second! the order o the action items in the list can be controlled by settin$ the inde2 attribute. Step (: Create icons and locali.-)8. The locali>ed strin$s can $o in the e2istin$ sc'odel.someco.pn$/. enabled t.made sure to name the icons startin$ with . Aecause this is Al resco3s older structure! .enabled=&uccessfull.properties ile.7eb<enable=&3 %nable Eeb actions.e t#e strings The last step is to provide some icons or the actions and locali>e the action labels.e &ome3o active fla messa e.7eb<fla . The hi$her the inde2! the lower in the list the menu items appear.e &ome3o active fla messa e.failure=%rror settin t.7eb<fla .com speci ies a orm -@ correspondin$ to a orm de ined in share.2ml.$rabbed a couple o out-o -the-bo2 icons that looked somewhat applicable and copied them in to my proJect under . -n step + the action element had an .

actions show up at the same time! which is lame. @eclare a new evaluator in Sprin$ con i$ that e2tends the . That3s easy to i2 with an evaluator and that3s covered in the ne2t section.action needs to hide based on a metadata value.value/ evaluator +.2ml ile to show a document library indicator A ter these steps are complete! the U. Al resco has several . This isn3t entirely relevant to the subJect at hand! but because they work Just like evaluators and because it makes it easy to see rom the document library which content has the active la$ set! -3m $oin$ to add a third step" 3. -n this e2ample! the U.evaluators/ that can be levera$ed out-o -the-bo2 to do this.2ml to point to the evaluator Al resco % has also made it easy to con i$ure . Update the action con i$ in share-con i$-custom. <or this e2ample! the out-o -the-bo2 . 2nd Edition 4a$e +7 o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . Step 1: -eclare a ne) evaluator in Spring config Enly one evaluator is needed or this e2ample. Finishing "ouches# Evaluators $ Indicators .you are writin$ a U.value/ evaluator will do Duite nicely. The steps! then! will be as ollows" ).actions can show or hide themselves based on that. The out-o -the-bo2 evaluators live in slin$shot-document-library-conte2t.action based on certain conditions is a pretty common reDuirement. Aut hidin$ a U.ecmarchitect.com Aut! what you3ll notice is that both the 1nable and @isable U. Fou can also write completely new evaluators usin$ *ava deployed to the Share tier. Update the share-con i$-custom.indicators/! which are little icons in the document library column. The evaluator Just needs to know the value o the active la$0the U.action that should show up all o the time! you don3t need to do anythin$ else. 1valuators live in Sprin$ con i$ and Developing Custom Actions. The enable should only show up when the active la$ is not set to true.actions will show or hide themselves appropriately and end-users will be able to see documents with the active la$ set to true rom the document list.actions based on thin$s like" • • • • • The presence o an aspect The type o a node 'imetype The type o site the document library is sittin$ in The name o the site 1valuators can also be chained to$ether i multiple conditions need to apply.2ml so re er to that ile or the ull list o evaluators and an e2ample o how chainin$ works. Fou can hide U. The disable should only show up when the active la$ is set to true.

2ml! -3ve made the ollowin$ modi ications! hi$hli$hted in bold" 0action id=6someco<7eb<enable6 t.ecmarchitect.7eb<fla .someco.added the evaluator to that ile" 0bean id=6someco.alfresco.you wanted to check or a speci ic aspect! or e2ample! you would e2tend the aspect evaluator and then speci y the aspect you are lookin$ or in one o the properties. name=6comparator61 0bean class=6or .sc9isActive6 /1 0propert.is"cti#e</e#al ator> 0/action1 0action id=6someco<7eb<disable6 t.custom-slin$shotapplication-conte2t.value61 0propert. name=6value6 value=6true6 /1 0/bean1 0/propert.evaluator.doclib.1 0/bean1 !isting 23: Declaring a new e&aluator that chec7s the &alue of sc:isActi&e This bean e2tends the out-o -the-bo2 .properties.failure0/param1 <e#al ator ne!ate="tr e">someco.isActive6 parent=6evaluator.7eb<fla .disabled0/param1 0param name=6failure"essa e61messa e.action. All evaluators work similarly.com Sprin$ con i$ resides in iles endin$ with .enabled0/param1 0param name=6failure"essa e61messa e.conte2t. This proJect already has . 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e +8 o %0 .true/. .someco.&trin %Muals3omparator61 0propert.failure0/param1 Developing Custom Actions.2ml/.accessor/ is the name o the property the evaluator needs to inspect.doclib.e#al ator.7eb<fla .7eb<enable6 icon=6someco<create<7ebsite61 0param name=6function61onAction&impleRepoAction0/param1 0permissions1 0permission allo7=6true61Erite0/permission1 0/permissions1 0param name=6action61enable<7eb<fla 0/param1 0param name=6success"essa e61messa e.evaluator.value/ evaluator and provides properties speci ic to our needs.pe=6Favascript6 label=6actions. This is another place where you want to make sure you are usin$ your own namespace.someco/ in the bean -@.7eb<fla .7eb. The comparator does a strin$ comparison a$ainst the value o . Step : *pdate t#e action config in s#are%config%custom+xml 9ith an evaluator declared the ne2t step is to tell the action con i$uration which evaluator to use to decide whether or not to show the U.2ml/ so .7eb<disable6 icon=6someco<delete<7ebsite61 0param name=6function61onAction&impleRepoAction0/param1 0permissions1 0permission allo7=6true61Erite0/permission1 0/permissions1 0param name=6action61disable<7eb<fla 0/param1 0param name=6success"essa e61messa e. Kote the use o .action. So! back over in share-con i$-custom. name=6accessor6 value=6node. -n this case! the .action.doclib.pe=6Favascript6 label=6actions.action.

! the sc"isActive property is set to trueC the web enable action will be hidden. Step (: *pdate t#e s#are%config%custom+xml file to s#o) a document librar& indicator The last step is really not needed at all i all you are doin$ is addin$ an action to the menu.pes1 0><< 3ustom Indicators <<1 0indicators1 0indicator id=6someco<7ebsite6 index=64561 0evaluator1someco.doclib. .com <e#al ator>someco.e. The $oal here is to show a little icon in the document library only i the .enable/ action into .e#al ator. 2nd Edition 4a$e +. Aut because it is easy to do and levera$es the same evaluator written in the previous step! . .action.-)8. Test .compressor *A.ecmarchitect.you3ve been ollowin$ alon$ and you3ve waited to deploy until now! it3s time to try it out. -ndicators are part o the . And each proJect includes a build. <or the someco-web-enable action! the evaluator is ne$ated. The code that accompanies this article includes an Ant build ile in each o the two proJects.copied the same icon used or the . o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . Ence those are set! you should be able to run . The Share proJect3s build.evaluator.ant deploy/ or each o the two proJects! start Tomcat! and test.the evaluator returns alse! the action will show itsel .2ml.properties ile. All it needs is a pointer to an evaluator. So i the evaluator returns true Bi.! which is used as part o the build process. -eplo& . -n this case! the one created earlier can be reused" 0/t. . The repository proJect3s build.doclib.you are already thinkin$! . .didn3t think you3d mind.properties ile needs to know the location o the e2panded Al resco S@R and the location o the e2panded Al resco webapp root.properties ile needs to know the location o the e2panded Share webapp root and the location o the FU.action.5ey! that sounds like an evaluator6/ you3ve $ot it.is"cti#e</e#al ator> 0/action1 !isting 24: Specif4ing the e&aluator in the action configuration Aoth actions use the same evaluator.sc"isActive/ property is set to true.@ocumentLibrary/ con i$ in share-con i$-custom.src#web#components#documentlibrary#indicators/ or this purpose.isActive0/evaluator1 0/indicator1 0/indicators1 0/confi 1 !isting 25: A**ing an in*icator to the *ocu(ent li$rar4 configuration Al resco will use the indicator3s id attribute appended with .pn$/ or the icon.everythin$ is workin$ correctly! you should see the SomeCo web site link and either the SC 9eb Developing Custom Actions.

com 1nable or the SC 9eb @isable menu items rom both the browse menu and the details pa$e as shown below. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e += o %0 .ecmarchitect. Developing Custom Actions.

Clickin$ the .SomeCo/ menu item will open a browser window to the U.ecmarchitect.: In*icators show which content has the acti&e flag set in Share Drawing 11: /usto( UI actions in the *ocu(ent *etails page Drawing 0: /usto( UI actions in the *ocu(ent list Clickin$ the .L speci ied in the con i$uration.com Drawing .SC @isable 9eb/ should invoke the action on the repository tier and then Developing Custom Actions. 2nd Edition 4a$e +& o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .

Those actions can be called rom code usin$ the Action Service and they can be invoked rom the user inter ace by con i$urin$ rules or by settin$ up U. About the Author *e 4otts is the Chie Community E icer or Al resco So tware.com re resh the metadata and the action list. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 30 o %0 . <or $eneral development help! see the @eveloper Luide. 'ike 5at ield and @avid @raper are two e2amples o Al resco en$ineer blo$s that are e2tremely use ul i you are customi>in$ Share. Where to ind more in ormation • • • • • • • • • All source code used in this e2ample is available here.ocused book on Al resco. E icial documentation or both 1nterprise and Community is available at docs.you are ready to cover new $round! try another ecmarchitect.com tutorial in the Al resco @eveloper Series.ead more at *e Ss blo$! ecmarchitect. *e has been a reco$ni>ed and award-winnin$ leader in the Al resco community or many years. The Al resco S@R comes with a Custom Action e2ample. 12amples ran$e rom code! to tutorials and in ormative blo$ posts! to code camps! meetups! and con erence sessions. -n +00=! *e wrote the Al resco @eveloper Luide! the irst developer.al resco. 5e has also been active in the Apache Chemistry proJect where he leads the development o cmislib! the 4ython A4. Share 12tras has many e2amples o deeper Share customi>ation as well as documentation o Al resco3s client-side *avaScript components.or C'-S.com.com. Conclusion This article has shown how actions can be used to implement reusable operations that can be run a$ainst content in the repository.actions and placin$ those alon$side other menu items in places like the document list and the details pa$e. Developing Custom Actions. . <or deployment help! see 4acka$in$ and @eployin$ 12tensions in the Al resco wiki. *e has made many contributions to the Al resco community since he started workin$ with Al resco in +007.ecmarchitect. 5ope ully it has sparked some ideas about how you could use custom actions in your ne2t Al resco implementation. . 5e has over )= years o content mana$ement and collaboration e2perience! most o that havin$ come rom senior leadership positions in consultin$ or$ani>ations. <or help customi>in$ the data dictionary! see the @ata @ictionary wiki pa$e.

Create a correspondin$ *S4 pa$e 3. Con iguring the Replaceable Aspect in E%plorer Al resco3s out-o -the-bo2 content model contains an aspect called .un Action/! a user inter ace has to be provided.ecmarchitect.<label<id=6replaces6 /1 0/propert.com Appendix Kot everyone is able to use Al resco Share as their user inter ace.con i$/ element tells the user inter ace to show the .replaces/ relationship. Developing Custom Actions.eplaced Action was implemented in 4art ). Con iguring the Move Replaced Rule Action in E%plorer The back-end lo$ic or the 'ove . The .cm"replaces/ relationship" 0confi evaluator=6aspect<name6 condition=6cm9replaceable61 0propert.<s. The sections within this Appendi2 show you how to do the same thin$ 4art + covers! but uses Al resco 12plorer instead o Al resco Share.2ml ile created in the content types tutorial.eet1 0/confi 1 !isting 2-: /onfiguring the replacea$le aspect for the Explorer UI 9ith this con i$uration in place! end-users can edit a document3s metadata to maintain the . Create an action handler class +. Locali>e the strin$s. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 3) o %0 . ..<s.eet1 0s.cm"replaceable/ but it is not e2posed in the U-. 1nd-users need to be able to declare which documents a new document should replace! so the aspect will need to be added to the web-client-con i$-custom.o7<association name=6cm9replaces6 displa.aspects/ element should now look like this" 0aspects1 0aspect name=6sc97ebable6/1 0aspect name=6sc9productRelated6/1 0aspect name=6cm9replaceable6/1 0/aspects1 !isting 2 : A**ing the replacea$le aspect to the Explorer UI config And a new . This is done by" ).users are $oin$ to speci y parameters or an action when con i$urin$ it as part o a rule or when invokin$ it via .

Copy M#source#web#Jsp#actions#move.Fsp6 P1 Developing Custom Actions.bean. The bean handler class handles the MviewM or the action con i$uration. The customi>ed *S4s will be deployed to a di erent directory structure so any e2istin$ relative links that need to point to out-o -the-bo2 *S4s need to point to .JspM rom the Al resco 9eb Client proJect into the custom repository proJect.actions.updated as ollows" 0PB include file=6/Fsp/parts/titlebar.eplacedM action both have a destination older and no other con i$urable properties! only minor modi ications are needed to make it work or the new action.com Step 1: Create an action #andler class Al resco3s bean handler class or the 'ove action is called or$. <irst! the custom action will have its own *S4 or the presentation so the $et*S44athBC method needs to chan$e rom this" public &trin return etN&PPat.NA"%)+ !isting 2.chan$ed the property name rom MactionImoveM to MactionImoveIreplacedM.al resco.Fsp6+ public &trin etN&PPat.web. Step : Create a corresponding 'SP page The *S4 pa$e that handles the move con i$uration or 'ove . Aut the title needs to be di erent! so it reDuires its own pa$e.use Msrc#web#TnamespaceU#JspM or all customi>ed Al resco *S4s by convention! so the ull path to the *S4 in the custom proJect is! Msrc#web#someco#Jsp#actions#move-replaced.() { etN&PPat.JspM.eplaced is identical to the out-o -the-bo2 move.#Jsp#parts#V/.: 'he out#of#the#$ox get5S33ath (etho* in %o&e8an*ler9:a&a to this" public final static &trin 3U&'("#A3'I(N#N&P = 6/someco/Fsp/actions/6 O "oveReplacedAction%xecuter.NA"% O 6. -n this case there are three includes that . The actual te2t will be in a resource bundle! so . 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 3+ o %0 . . Aecause both the M'oveM action and our M'ove .ecmarchitect. The $enerateSummaryBC method is responsible or that messa$e.() { return 3U&'("#A3'I(N#N&P+ - !isting 20: 'he new get5S33ath (etho* in %o&e)eplace*8an*ler9:a&a All -3m doin$ here is tellin$ the bean where to ind our customi>ed *S4.'ove5andler and it resides in the Al resco source in the 9eb Client proJect.handlers. And! because the pa$e is in a di erent older structure than the Al resco *S4! the e2istin$ *S4 includes will need to be updated because they use relative links. Ke2t! i you3ve ever con i$ured an action be ore you know that the user inter ace includes a short summary o what the action is $oin$ to do.("oveAction%xecuter.

messa es. title#action#move#replaced="ove Replaced Action !isting 33: !ocali2e* strings for the replacea$le aspect an* %o&e )eplace* in we$client9properties The last step is to hook in to the Al resco action wi>ard U. The . name=6resource@undles61 0list1 0value1alfresco.Fsp6 P1 0PB include file=6/Fsp/parts/breadcrumb. That3s it or the *ava and *S4 code.properties. .is 7ill move t.2ml ile needs to be updated to point to a resource bundle.e tar et node of a replaces association to a specified space..title="ove replaced document to space move<replaced.need to create a resource bundle so .so that when someone con i$ures a rule or simple work low! the new action is listed as a valid choice.created a ile in al resco#e2tension#messa$es called somecoactions. Kow it is time to locali>e the action.1 0/bean1 !isting 31: Spring configuration nee*e* to specif4 the action resource $un*le Ke2t! .ecmarchitect. Kote that this ile name and path matches the resource bundle declaration rom the previous step.{5-.added the ollowin$ entries to the ile" Gcm9replaceable replaces=Replaces G"ove Replaced Action action#move#replaced="ove replaced to .actionResource@undles6 parent=6actionResource@undles61 0propert. Step (: /ocali.elf.cm"replaces/ aspect also needs to be locali>ed.somecoactions0/value1 0/list1 0/propert. .description='.properties.Fsp6 P1 !isting 31: %o*ifie* inclu*e state(ents in (o&e#replace*9:sp To point to the custom title property in the resource bundle! .com 0PB include file=6/Fsp/parts/s.e t#e Move Replaced Action The someco-action-conte2t. 2nd Edition 4a$e 33 o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense . So! .added the ollowin$ to that ile" 0bean id=6someco. !isting 32: !ocali2e* strings for the %o&e )eplace* action The summary te2t and the *S4 title $et pulled rom al resco#e2tension#webclient.extension.chan$ed the title-d attribute o the r"pa$e ta$ rom MtitleIactionImoveM to MtitleIactionImoveIreplacedM..edited the al resco#e2tension#web-clientDeveloping Custom Actions. GG GG &ome3o Actions I4=N file GG G "ove Replaced action move<replaced.

. <or local development and testin$! the Ant3s deploy! which essentially does a copy into the e2ploded webapp! will be ine. A ter the aspect has been applied! you should see a MreplacesM section in the document3s properties.. This establishes the MreplacesM association. Con i$ure the action to move documents to the MArchivedM space."oveReplacedDandler6 /1 0/action<. 1dit the properties and select a document to replace. To set up a test! you3ll need to add the replaceable aspect to a piece o test content. -n real li e! you3ll want to packa$e your e2tensions as an A'4 and then use the 'odule 'ana$ement Tool B''TC to mer$e the A'4 with the Al resco 9A.andler.andlers1 0.andler for 6"ove Replaced6 action <<1 0action<.com con i$-custom.andler name=6move<replaced6 class=6com.ecmarchitect.not! double-check the web-client-con i$-custom.someco.action. 2nd Edition 4a$e 3% o %0 T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense .andlers1 0/confi 1 !isting 34: Action wi2ar* configuration to *eclare the custo( action han*ler The code that accompanies this document includes a sample Ant build.eplacedM action. Developing Custom Actions.andlers <<1 0confi evaluator=6strin <compare6 condition=6Action EiCards61 0><< add custom action .2ml ile and added the ollowin$" 0><< action . Kow add a rule to the space in which M4ublishedM documents reside. .2ml ile that can be used to deploy the iles to the ri$ht spot within the Al resco 9A.. The rule should run the new M'ove .2ml ile.

Create a *S<-mana$ed bean +. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 37 o %0 . -t will be called rom a menu item in the 12plorer user inter ace.setParameter!alue(&etEeb)la .ro7s '..ecmarchitect. Con iguring the Set Web Flag !I Action in E%plorer The Set 9eb <la$ action isn3t meant to be called rom a rule so it does not have a 5andler class or a *S4. id)+ Retr.in 'ransaction3allbac80(bFect1() { public (bFect execute() t.in 'ransaction3allbac80(bFect1 callbac8 = ne7 Retr.com To test the lo$ic! paste the document with the MreplacesM association into the M4ublishedM space.actions/. etRetr. Locali>e the action Step 1: Create a 'S"%managed 0ean The 9ebSettin$sAean class $ets called when the U.NA"%.PARA"#A3'I!%.. null)+ action. et&toreRef().U. 5ere is a snippet rom the bean3s setActive method" final NodeRef ref = ne7 NodeRef(Repositor. These menu items are o ten called . &etEeb)la . Update web-client-con i$-custom.action is clicked.2ml 3.in 'ransactionDelper(fc)+ Retr. active)la )+ &etEeb)la action%xecuter = (&etEeb)la ) Developing Custom Actions.ro7able { ActionImpl action = ne7 ActionImpl(ref.in 'ransactionDelper txnDelper = Repositor. Assumin$ the back-end action already e2ists! the steps to inte$rate it into the 12plorer user inter ace are" ). The document it is replacin$ should $et automatically moved to the MArchivedM older.

dtd61 0faces<confi 1 0mana ed<bean1 0description1 '.7eb. et@ean(&etEeb)la .aces configuration for the +e$ Settings Bean Kow that *S< knows about the new bean it can be wired into the 12plorer user inter ace.4.1 0propert. ms )+ &trin formId = Utils. et3omponent()).ecmarchitect.is. ms . Inc.com/dtd/7eb<facesconfi #4#4.<name1 0value1G{@ro7se@ean-0/value1 0/mana ed<propert.&%!%RI'?#IN)(.reset()+ !isting 35: /usto( +e$SettingsBean9:a&a This snippet shows a transaction bein$ set up be ore instantiatin$ and e2ecutin$ the Set9eb<la$ action e2ecuter class.:1 0>$(3'?P% faces<confi PU@*I3 6<//&un "icros.5.2ml in 91A--K< with the ollowin$ content" 0:xml version=.add"essa e(formId O . 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 38 o %0 .4//%N6 6.bean. O PAN%*#I$#&PA3%#PR(P&. "&A#&U33%&&#E%@#&%'#A3'I!%)+ )aces"essa e faces"s = ne7 )aces"essa e()aces"essa e.ttp9//Fava. faces"s )+ return null+ -+ txnDelper.sun. 0/description1 0mana ed<bean<name1Eeb&ettin s@ean0/mana ed<bean<name1 0mana ed<bean<class1com.doIn'ransaction(callbac8)+ t.NA"%)+ action%xecuter.1 0/mana ed<bean1 0/faces<confi 1 !isting 3 : .someco.<name1bro7se@ean0/propert. This is done by creatin$ a ile called aces-con i$-conte2t.stems.at mana es &3 Eeb settin s. et"essa e(fc.9. etParent)orm(fc. Developing Custom Actions. et$ocument().execute(action.U')<=.e bean t. Ence the class is complete it has to be wired in to *avaServer <aces. encodin =. et3lientId(fc)+ )aces3ontext. ref)+ &trin ms = Application.Eeb&ettin s@ean0/mana ed<bean< class1 0mana ed<bean<scope1session0/mana ed<bean<scope1 0mana ed<propert. The rest o the code deals with providin$ the user some eedback a ter the action runs.//$'$ Nava&erver )aces 3onfi 4. etEebApplication3ontext(fc).com )aces3ontextUtils. event.bro7se@ean. et3urrentInstance().

9eb @isable/ to the document details screen.com *pdate )eb%client%config%custom+xml )it# t#e ne) *I action There are several menus within the Al resco 12plorer user inter ace. 0><< *in8 to &ome3o.ecmarchitect. o %0 . Actions B-3m talkin$ about .L.more/ menu! and the document details screen.com0/.action $roups/.actions/ nowC can be de ined once and then added to as many action $roups as needed.9eb 1nable/ and .actions.9eb Site/ menu item to the browse menu! the .ref1 0ima e1/someco/ima es/icons/7ebsite. . The irst one is a simple action that invokes a U.s 7eb site <<1 0action id=67eb#site61 0label1&ome3o0/label1 0. The ne2t part o the con i$uration de ines the U.ref1.added the ollowin$ to web-client-con i$-custom. 0><< set sc9isActive to true <<1 0action id=67eb#enable61 0permissions1 Developing Custom Actions.itect. -t also adds the .ttp9//ecmarc.L! an action Blike Set 9eb <la$C! or a 9i>ard or @ialo$.e @ro7se screen <<1 0action< roup id=6document#bro7se#menu61 0action idref=67eb#site6 /1 0/action< roup1 0><< Actions "enu for $ocument $etails screen <<1 0action< roup id=6doc#details#actions61 0action idref=67eb#enable6 /1 0action idref=67eb#disable6 /1 0action idref=67eb#site6 /1 0/action< roup1 !isting 3-: Action groups an* action references for Explorer This part o the con i$uration adds a . if0/ima e1 0tar et1ne70/tar et1 0/action1 !isting 3.2ml" 0><< UI Actions <<1 0confi 1 0actions1 0action< roup id=6document#bro7se61 0action idref=67eb#site6 /1 0/action< roup1 0><< Actions "enu for a document in t. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 3.sc"isActive/ la$. This tutorial doesn3t cover wi>ards and dialo$s! but it does provide e2amples o the irst two.: Action *eclaration for the +e$ Site UI action in Explorer The ne2t one enables the .action mi$ht call an arbitrary U. These are called .U. A U.

if0/ima e1 0action<listener1G{Eeb&ettin s@ean.permissions/ element points to an out-o -the-bo2 permission called .evaluator. .evaluator.9rite/.you want to deploy and test your action be ore writin$ that class! Just comment out the evaluator.had a little bit o trouble $ettin$ that to work so .someco.setActive-0/action<listener1 0params1 0param name=6id61G{action3ontext. The . -t mi$ht make sense to instead create a custom role! like .enable/ case e2cept that it passes a di erent value or the active la$.9rite/ and will ollow up later with how to modi y the e2ample to use a custom role.decided to keep it simple or now and use . The .id-0/param1 0param name=6active61false0/param1 0/params1 0/action1 0/actions1 0/confi 1 or1 !isting 41: Action *eclaration for +e$ Disa$le in Explorer Developing Custom Actions.evaluator/ element is a *ava class discussed in the ne2t section. c.action.action.ecmarchitect. -t3s almost identical to the .Eeb$isable%valuator0/evaluat 0label<id1disableEeb0/label<id1 0ima e1/someco/ima es/icons/delete#7ebsite. if0/ima e1 0action<listener1G{Eeb&ettin s@ean.Eeb%nable%valuator0/evaluato r1 0label<id1enableEeb0/label<id1 0ima e1/someco/ima es/icons/create#7ebsite. The . 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 3= o %0 .com 0><< eac.action-listener/ re ers to the *S<-mana$ed bean created in the previous step.er0/permission1 0/permissions1 0evaluator1com.setActive-0/action<listener1 0params1 0param name=6id61G{action3ontext.4ortal4ublisher/ and use that. permission can be an Allo7 or $en.someco. permission can be an Allo7 or $en. 5onestly! .id-0/param1 0param name=6active61true0/param1 0/params1 0/action1 !isting 30: Action *eclaration for Ena$le +e$ in Explorer The .params/ element passes ar$uments into the 9ebSettin$sAean. -3m assumin$ anyone with write access to the node is also allowed to publish the content to the web.sc"isActive/ la$. c.ec8 <<1 0permission allo7=6true61Erite0/permission1 0/permissions1 0evaluator1com. 0><< set sc9isActive to false <<1 0action id=67eb#disable61 0permissions1 0><< eac.ec8 <<1 0permission allo7=6true61PortalPublis. The inal piece o con i$ sets up the menu item to disable the .

NA"%&PA3%#&("%3(#3(N'%N'#"($%*.A&P%3'#&3#E%@A@*%))) { return true+ // c. !isting 41: !ocali2ing the Set +e$ .. it can be enabled if (>node..e active propert. et3urrentInstance()+ // c.t .NA"%&PA3%#&("%3(#3(N'%N'#"($%*.ec8 t. The only thin$ le t to do is to implement the evaluator as a *ava class.ing t#e Set !eb "lag action .SC 9eb 1nable/ and .locali>ed the action by addin$ the ollowin$ to somecoactions. &ome3o"odel.et been added. Fou3ll notice when lookin$ at the document details pa$e! however! that the .you deploy now you should see menu items in the ri$ht places.(context). et&erviceRe istr.PR(P#I&#A3'I!%))+ Developing Custom Actions.evaluator/ and that3s the topic o the ne2t section. node.e isActive fla .is 7ill add t.en c..asn.(ref.e active propert. t.ec8 t. Node&ervice node&vc = Repositor. NodeRef ref = ne7 NodeRef(Repositor.e aspect .SC 9eb @isable/ menu items both show up. And i you click them they should work. The 9eb1nable1valuator class implements the Action1valuator inter ace.title=&ets t.properties" G &et 7eb fla action set<7eb<fla .sc"isActive/ la$.e sc97ebable aspect and set t. Con iguring the Evaluator to Sho&'(ide the Set Web Flag !I Action in E%plorer The inal step in con i$urin$ the Set 9eb <la$ action within the Al resco 12plorer user inter ace is to write an evaluator that hides#shows the menu items appropriately based on the value o the . 5idin$ and showin$ menu items is the Job o an . etNode&ervice()+ boolean active = (@oolean)node&vc.ecmarchitect. &ome3o"odel.ec8 t.lag action . The evaluators have already been speci ied in the web-client-con i$-custom.com /ocali.e aspect. To reduce con usion and clutter! the enable item should only show when the la$ hasn3t been set or is set to alse and the disable item should only show when the la$ has been set to true.create2Name(&ome3o"odel. The ma$ic happens within the evaluate method and is as ollows" public boolean evaluate(Node node) { )aces3ontext context = )aces3ontext.2ml. etPropert. 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e 3& o %0 . et&toreRef().description='. 2Name.create2Name(&ome3o"odel.e &3 Eeb )la set<7eb<fla . etId())+ // if t.asAspect( 2Name.

The evaluator or disable is so similar! it doesn3t make sense to repeat it here.ant deploy/ and then restartin$ Tomcat! you should be able to enable and disable the web la$ usin$ the menu items on the document details pa$e.the la$ is alse! return true to show the enable menu item. The menu items should only show up or users in the appropriate role! and they should hide themselves based on the value o the active la$. Then! the evaluator checks the value o the active la$ and simply returns the opposite o its value B. -t actually doesn3t matter i the aspect is there or not0i it isn3t! the Set 9eb <la$ action will add it.the la$ is true! return alse to hide the enable menu itemC. En deployin$ the repository proJect usin$ . 2nd Edition T is !or" is licensed under t e Creative Commons Attri#ution$S are Ali"e %&0 'nported (icense 4a$e %0 o %0 . Developing Custom Actions.ecmarchitect.com return >active+ - !isting 42: 'he +e$ Ena$le E&aluator This code checks or the presence o the . .sc"webable/ aspect.

Sign up to vote on this title
UsefulNot useful