/** * Returns an annotation on a 'parameter method' in a parameters info class, i.e. a method that is annotated * with {@link @Parameter}. * * @param parametersInfo the parameters info class to analyze * @param parameterName the name of the parameter as returned by {@link Parameter#name()} * @param annotationClass the class of the annotation to find * @param <A> the annotation, or null if the annotation could not be found * @return * @deprecated Use {@link ParametersInfoUtils#getParameterAnnotation(ParametersInfo, String, Class)}. */ @Deprecated public static <A extends Annotation> A getParameterAnnotation(final ParametersInfo parametersInfo, final String parameterName, final Class<A> annotationClass) { return ParametersInfoUtils.getParameterAnnotation(parametersInfo, parameterName, annotationClass); } }
/** * Returns a proxy ParametersInfo object for the component class which resolves parameter from * HstComponentConfiguration : resolved means that possible property placeholders like ${1} or ${year}, where the * first refers to the first wildcard matcher in a resolved sitemap item, and the latter to a resolved parameter in * the resolved HstSiteMapItem * <p/> * <EM>NOTE: Because the returned ParametersInfo proxy instance is bound to the current request, you MUST NOT store * the returned object in a member variable or session. You should retrieve that per request.</EM> </P> * <p/> * The parameter map used has inherited parameters from ancestor components, which have precedence over child * components) * * @param component the HST component with a ParameterInfo annotation * @param componentConfig the HST component configuration * @param request the HST request * @return the resolved parameter value for this name, or <code>null</null> if not present */ @SuppressWarnings("unchecked") public static <T> T getParametersInfo(HstComponent component, final ComponentConfiguration componentConfig, final HstRequest request) { T parametersInfo = (T) request.getAttribute(PARAMETERS_INFO_ATTRIBUTE); if (parametersInfo != null) { return parametersInfo; } parametersInfo = ParametersInfoUtils.createParametersInfo(component, componentConfig, request); if (parametersInfo != null) { request.setAttribute(PARAMETERS_INFO_ATTRIBUTE, parametersInfo); } return parametersInfo; }
/** * Add <code>params</code> metadata to the {@code model} from the {@code window}. * @param window HST Component Window instance * @param model the {@link MetadataContributable} model instance where the parameter map should be contributed to */ private void addParametersInfoMetadata(HstComponentWindow window, HstRequest hstRequest, MetadataContributable model) { final ComponentConfiguration compConfig = window.getComponent().getComponentConfiguration(); if (compConfig == null) { return; } final Object paramsInfo = ParametersInfoUtils.createParametersInfo(window.getComponent(), compConfig, hstRequest); JsonNode paramsInfoNode = null; if (paramsInfo != null) { try { paramsInfoNode = getObjectMapper().valueToTree(paramsInfo); model.putMetadata(PARAMETERS_INFO_METADATA, paramsInfoNode); } catch (Exception e) { log.warn("Failed to convert ParametersInfo instance ({}) to ObjectNode.", paramsInfo, e); } } final ResolvedSiteMapItem resolvedSiteMapItem = RequestContextProvider.get().getResolvedSiteMapItem(); final ObjectNode paramsNode = getObjectMapper().getNodeFactory().objectNode(); for (String paramName : compConfig.getParameterNames()) { final String paramValue = compConfig.getParameter(paramName, resolvedSiteMapItem); if (paramValue != null) { paramsNode.put(paramName, paramValue); } } model.putMetadata(PARAMETERS_METADATA, paramsNode); }