List of usage examples for org.apache.commons.jelly JellyContext findVariable
public Object findVariable(String name)
From source file:com.cloudbees.plugins.credentials.CredentialsDescriptor.java
/** * {@inheritDoc}/* ww w.jav a2s .c o m*/ */ @Override public void calcFillSettings(String field, Map<String, Object> attributes) { if (attributes.containsKey("fillUrl")) { // the user already provided a custom one, get out of the way super.calcFillSettings(field, attributes); return; } // this is an ugly hack to make the @ContextInPath annotation more failsafe super.calcFillSettings(field, attributes); if (attributes.containsKey("fillUrl")) { try { JellyContext jelly = Functions.getCurrentJellyContext(); Object it = jelly.findVariable("it"); if (it instanceof CredentialsStore) { ModelObject context = ((CredentialsStore) it).getContext(); for (CredentialsSelectHelper.ContextResolver r : ExtensionList .lookup(CredentialsSelectHelper.ContextResolver.class)) { String token = r.getToken(context); if (token != null) { String fillUrl = (String) attributes.get("fillUrl"); if (fillUrl != null) { if (fillUrl.indexOf('?') != -1) { fillUrl = fillUrl + '&'; } else { fillUrl = fillUrl + '?'; } attributes.put("fillUrl", fillUrl + "$provider=" + URLEncoder.encode(r.getClass().getName(), "UTF-8") + "&$token=" + URLEncoder.encode(token, "UTF-8")); } } } } } catch (AssertionError e) { // ignore, we did the best we could } catch (UnsupportedEncodingException e) { // ignore, we did the best we could } } }
From source file:com.cloudbees.plugins.credentials.CredentialsDescriptor.java
/** * {@inheritDoc}//from w w w . j av a 2s . c o m */ @Override public void calcAutoCompleteSettings(String field, Map<String, Object> attributes) { if (attributes.containsKey("autoCompleteUrl")) { // the user already provided a custom one, get out of the way super.calcAutoCompleteSettings(field, attributes); return; } // this is an ugly hack to make the @ContextInPath annotation more failsafe super.calcAutoCompleteSettings(field, attributes); if (attributes.containsKey("autoCompleteUrl")) { try { JellyContext jelly = Functions.getCurrentJellyContext(); Object it = jelly.findVariable("it"); if (it instanceof CredentialsStore) { ModelObject context = ((CredentialsStore) it).getContext(); for (CredentialsSelectHelper.ContextResolver r : ExtensionList .lookup(CredentialsSelectHelper.ContextResolver.class)) { String token = r.getToken(context); if (token != null) { String autoCompleteUrl = (String) attributes.get("autoCompleteUrl"); if (autoCompleteUrl != null) { if (autoCompleteUrl.indexOf('?') != -1) { autoCompleteUrl = autoCompleteUrl + '&'; } else { autoCompleteUrl = autoCompleteUrl + '?'; } attributes.put("autoCompleteUrl", autoCompleteUrl + "$provider=" + URLEncoder.encode(r.getClass().getName(), "UTF-8") + "&$token=" + URLEncoder.encode(token, "UTF-8")); } } } } } catch (AssertionError e) { // ignore, we did the best we could } catch (UnsupportedEncodingException e) { // ignore, we did the best we could } } }