Hi.
On Thu, May 23, 2013 at 11:31 AM, Lance Java <lance.j...@googlemail.com>wrote:

> I think the easiest way would be to decorate the JavaScriptStackSource
> service. Wrap the default implementation with a version which decorates
> getStack(String name) to return a custom JavaScriptStack implementation.
>
> The custom JavaScriptStack will provide wrappers for:
> List<Asset> getJavaScriptLibraries();
> List<StylesheetLink> getStylesheets();
>
> You'll need to delegate to AssetPathConverter  in Asset.toClientURL() and
> StylesheetLink.getURL()
>

Was thinking about this and as far as I can see with this approach I would
then get 'cdn' urls for the different scripts that make up the stack, and
not the stack url itself - but could be wrong.

I did try to implement my own proposed solution with Advice - quite simple
and it seems to be working fine. Although there could be side-effects I'm
not aware of yet ...

*@Advise(serviceInterface = JavaScriptStackPathConstructor.class)*
*public static void adviseJavaScriptStackPathConstructor(*
* MethodAdviceReceiver receiver,*
* @Local final AssetPathConverter assetPathConverter) {*
*try {*
*  MethodAdvice ma = new MethodAdvice(){*
*  @Override*
*  public void advise(MethodInvocation invocation) {*
*  invocation.proceed();*
*  List<String> paths = (List<String>) invocation.getReturnValue();*
*  if(paths==null) return;*
*  *
*  List<String> newList = new ArrayList<>(paths.size());*
*  for (String path : paths) {*
*  newList.add(assetPathConverter.convertAssetPath(path));*
*  }*
*  invocation.setReturnValue(newList);*
*  }*
*  };**   *
*  Class<?> serviceInterface = receiver.getInterface();*
*  
receiver.adviseMethod(serviceInterface.getMethod("constructPathsForJavaScriptStack",
String.class), ma);**   *
*  } catch (Exception e) {*
*  throw new RuntimeException("Can't find methods. Changed API?", e);*
*  }*
*}*

Let me know if you have further suggestions/ideas.

thanks
Magnus

Reply via email to