Example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

Introduction

In this page you can find the example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes.

Prototype

public static RequestAttributes currentRequestAttributes() throws IllegalStateException 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:org.kuali.rice.krad.web.bind.UifViewBeanWrapper.java

/**
 * Determines whether one of the binding annotations is present within the given property path, and if
 * so returns whether access should be granted based on those annotation(s).
 *
 * <p>Binding annotations may occur anywhere in the property path. For example, if the path is 'object.field1',
 * a binding annotation may be present on the 'object' property or the 'field1' property. If multiple annotations
 * are found in the path, the annotation at the deepest level is taken. If both the protected and accessible
 * annotation are found at the same level, the protected access is used.</p>
 *
 * @param propertyPath path to look for annotations
 * @return Boolean true if an annotation is found and the access is allowed, false if an annotation is found
 * and the access is protected, null if no annotations where found in the path
 *///from   w  w  w  .  j  a va 2s .  c o m
protected Boolean checkBindingAnnotationsInPath(String propertyPath) {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    while (!StringUtils.isEmpty(propertyPath)) {
        String nestedPath = ObjectPropertyUtils.getPathTail(propertyPath);
        String parentPropertyPath = ObjectPropertyUtils.removePathTail(propertyPath);

        Class<?> parentPropertyClass = getWrappedClass();

        // for nested paths, we need to get the class of the immediate parent
        if (!StringUtils.isEmpty(parentPropertyPath)) {
            parentPropertyClass = ObjectPropertyUtils.getPropertyType(getWrappedInstance(), parentPropertyPath);
        }

        // remove index or map key to get the correct property name
        if (org.apache.commons.lang.StringUtils.endsWith(nestedPath, "]")) {
            nestedPath = org.apache.commons.lang.StringUtils.substringBefore(nestedPath, "[");
        }

        RequestProtected protectedAnnotation = (RequestProtected) CopyUtils
                .getFieldAnnotation(parentPropertyClass, nestedPath, RequestProtected.class);
        if ((protectedAnnotation != null)
                && annotationMatchesRequestMethod(protectedAnnotation.method(), request.getMethod())) {
            return Boolean.FALSE;
        }

        RequestAccessible accessibleAnnotation = (RequestAccessible) CopyUtils
                .getFieldAnnotation(parentPropertyClass, nestedPath, RequestAccessible.class);
        if (accessibleAnnotation != null) {
            boolean isAnnotationRequestMethod = annotationMatchesRequestMethod(accessibleAnnotation.method(),
                    request.getMethod());
            boolean isAnnotationMethodToCalls = annotationMatchesMethodToCalls(
                    accessibleAnnotation.methodToCalls(),
                    request.getParameter(UifConstants.CONTROLLER_METHOD_DISPATCH_PARAMETER_NAME));
            if (isAnnotationRequestMethod && isAnnotationMethodToCalls) {
                //((UifFormBase) this.bindingResult.getTarget()).getMethodToCall())) {
                return Boolean.TRUE;
            }
        }

        propertyPath = parentPropertyPath;
    }

    return null;
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from  w  ww . ja  va 2 s  .c om
 * @param lastLogonDate
 * @return
 */
public static Map<String, String> generateAdvancedSearchLinks(Date inputDate) {
    Map<String, String> retValue = new HashMap<String, String>();
    retValue.put("DOCUMENT", "");
    retValue.put("PLACE", "");
    retValue.put("PEOPLE", "");
    retValue.put("VOLUME", "");

    if (inputDate == null) {
        return retValue;
    }

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/src/AdvancedSearch.do?searchType=");
    stringBuilder.append(SearchType.DOCUMENT);
    stringBuilder.append("&dateLastUpdate=");
    stringBuilder.append(DateType.Between.toString());
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(inputDate));
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(Calendar.getInstance().getTime()));
    stringBuilder.append("&searchUUID=");
    stringBuilder.append(UUID.randomUUID());
    retValue.put("DOCUMENT", stringBuilder.toString());

    stringBuilder = new StringBuilder();
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/src/AdvancedSearch.do?searchType=");
    stringBuilder.append(SearchType.PEOPLE);
    stringBuilder.append("&dateLastUpdate=");
    stringBuilder.append(DateType.Between.toString());
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(inputDate));
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(Calendar.getInstance().getTime()));
    stringBuilder.append("&searchUUID=");
    stringBuilder.append(UUID.randomUUID());
    retValue.put("PEOPLE", stringBuilder.toString());

    stringBuilder = new StringBuilder();
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/src/AdvancedSearch.do?searchType=");
    stringBuilder.append(SearchType.PLACE);
    stringBuilder.append("&dateLastUpdate=");
    stringBuilder.append(DateType.Between.toString());
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(inputDate));
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(Calendar.getInstance().getTime()));
    stringBuilder.append("&searchUUID=");
    stringBuilder.append(UUID.randomUUID());
    retValue.put("PLACE", stringBuilder.toString());

    stringBuilder = new StringBuilder();
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/src/AdvancedSearch.do?searchType=");
    stringBuilder.append(SearchType.VOLUME);
    stringBuilder.append("&dateLastUpdate=");
    stringBuilder.append(DateType.Between.toString());
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(inputDate));
    stringBuilder.append('|');
    stringBuilder.append(DateUtils.getStringDate(Calendar.getInstance().getTime()));
    stringBuilder.append("&searchUUID=");
    stringBuilder.append(UUID.randomUUID());
    retValue.put("VOLUME", stringBuilder.toString());

    return retValue;
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from   ww w.ja  v a  2 s.co  m
 * @param documentExplorer
 * @return
 */
public static String getDocumentExplorerNextPageUrl(DocumentExplorer documentExplorer) {
    if (documentExplorer == null) {
        return "";
    }

    if (documentExplorer.getImage().getImageOrder() == documentExplorer.getTotal().intValue()) {
        return "";
    }

    StringBuilder stringBuilder = new StringBuilder(
            ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()
                    .getRequestURI());
    stringBuilder.append("?entryId=")
            .append(documentExplorer.getEntryId() == null ? "" : documentExplorer.getEntryId().toString())
            .append("&volNum=").append(documentExplorer.getVolNum()).append("&volLetExt=")
            .append(documentExplorer.getVolLetExt() == null ? "" : documentExplorer.getVolLetExt())
            .append("&imageOrder=").append(documentExplorer.getImage().getImageOrder() + 1).append("&total=")
            .append(documentExplorer.getTotal() == null ? "" : documentExplorer.getTotal().toString())
            .append("&totalRubricario=")
            .append(documentExplorer.getTotalRubricario() == null ? ""
                    : documentExplorer.getTotalRubricario().toString())
            .append("&totalCarta=")
            .append(documentExplorer.getTotalCarta() == null ? "" : documentExplorer.getTotalCarta().toString())
            .append("&totalAppendix=")
            .append(documentExplorer.getTotalAppendix() == null ? ""
                    : documentExplorer.getTotalAppendix().toString())
            .append("&totalOther=")
            .append(documentExplorer.getTotalOther() == null ? "" : documentExplorer.getTotalOther().toString())
            .append("&totalGuardia=").append(documentExplorer.getTotalGuardia() == null ? ""
                    : documentExplorer.getTotalGuardia().toString());

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from w  ww .ja  va  2  s. c  o  m
 * @param documentExplorer
 * @return
 */
public static String getDocumentExplorerPreviousPageUrl(DocumentExplorer documentExplorer) {
    if (documentExplorer == null) {
        return "";
    }

    if (documentExplorer.getImage().getImageOrder() == 1) {
        return "";
    }

    StringBuilder stringBuilder = new StringBuilder(
            ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()
                    .getRequestURI());
    stringBuilder.append("?entryId=")
            .append(documentExplorer.getEntryId() == null ? "" : documentExplorer.getEntryId().toString())
            .append("&volNum=").append(documentExplorer.getVolNum()).append("&volLetExt=")
            .append(documentExplorer.getVolLetExt() == null ? "" : documentExplorer.getVolLetExt())
            .append("&imageOrder=").append(documentExplorer.getImage().getImageOrder() - 1).append("&total=")
            .append(documentExplorer.getTotal() == null ? "" : documentExplorer.getTotal().toString())
            .append("&totalRubricario=")
            .append(documentExplorer.getTotalRubricario() == null ? ""
                    : documentExplorer.getTotalRubricario().toString())
            .append("&totalCarta=")
            .append(documentExplorer.getTotalCarta() == null ? "" : documentExplorer.getTotalCarta().toString())
            .append("&totalAppendix=")
            .append(documentExplorer.getTotalAppendix() == null ? ""
                    : documentExplorer.getTotalAppendix().toString())
            .append("&totalOther=")
            .append(documentExplorer.getTotalOther() == null ? "" : documentExplorer.getTotalOther().toString())
            .append("&totalGuardia=").append(documentExplorer.getTotalGuardia() == null ? ""
                    : documentExplorer.getTotalGuardia().toString());

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from  www.  ja v  a2  s .  c o m
 * @param category
 * @param idUserHistory
 * @return
 */
private static String getHistoryNavigatorUrl(Category category, Integer idUserHistory) {
    if ((category == null) || (idUserHistory == null)) {
        return null;
    }

    String url = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest()
            .getContextPath();
    switch (category) {
    case DOCUMENT:
        url += "/src/docbase/ShowDocumentFromHistory.do?idUserHistory=";
        url += idUserHistory;
        break;
    case PEOPLE:
        url += "/src/peoplebase/ShowPersonFromHistory.do?idUserHistory=";
        url += idUserHistory;
        break;
    case PLACE:
        url += "/src/geobase/ShowPlaceFromHistory.do?idUserHistory=";
        url += idUserHistory;
        break;
    case VOLUME:
        url += "/src/volbase/ShowVolumeFromHistory.do?idUserHistory=";
        url += idUserHistory;
        break;
    default:
        break;
    }

    return url;
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from   w w w .  ja  v a 2s  .co  m
 * @return
 */
public static String getImageDigitized() {
    StringBuilder stringBuilder = new StringBuilder("<img src=\"");
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/images/1024/img_digitized_small_document.png\">");
    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * //from   w ww .  j  a v a  2s  .  co  m
 * @param forum
 * @return
 */
public static Object getShowForumCompleteDOMUrl(Forum forum) {
    StringBuilder stringBuilder = new StringBuilder("");
    if (forum != null) {
        stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
                .getRequest().getContextPath());
        stringBuilder.append("/community/ShowForum.do?forumId=");
        stringBuilder.append(forum.getForumId());
        stringBuilder.append("&completeDOM=true");
    }

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * /*  w  ww . ja  va2s . c  o m*/
 * @return
 */
public static String getShowForumHrefUrl(Forum forum) {
    StringBuilder stringBuilder = new StringBuilder("<a href=\"");
    if (forum != null) {
        stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
                .getRequest().getContextPath());
        stringBuilder.append("/community/ShowForum.do?forumId=");
        stringBuilder.append(forum.getForumId());
        stringBuilder.append("&\" class=\"forum\">");
        stringBuilder.append(forum.getTitle());
        stringBuilder.append("</a>");
    } else {
        stringBuilder.append("&\" class=\"forum\" />");
        stringBuilder.append("</a>");
    }

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * /*from   w  ww  . j  ava 2 s  .  co  m*/
 * @return
 */
public static String getShowForumIndexUrl(Forum forum) {
    if (forum == null) {
        return "";
    }

    StringBuilder stringBuilder = new StringBuilder("<img src=\"");
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/images/forum/img_chronology.png\" alt=\"Chronology\" />");
    stringBuilder.append(System.getProperty("line.separator"));
    stringBuilder.append("<a href=\"");
    stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest().getContextPath());
    stringBuilder.append("/community/ShowForum.do?forumId=");
    stringBuilder.append(forum.getForumId());
    stringBuilder.append("&completeDOM=true\" class=\"boardIndex\">");
    stringBuilder.append(forum.getTitle());
    stringBuilder.append("</a>");

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.HtmlUtils.java

/**
 * /*w w w  .j a va2  s  .  co  m*/
 * @param forum
 * @return
 */
public static String getShowForumUrl(Forum forum) {
    StringBuilder stringBuilder = new StringBuilder("");
    if (forum != null) {
        stringBuilder.append(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
                .getRequest().getContextPath());
        stringBuilder.append("/community/ShowForum.do?forumId=");
        stringBuilder.append(forum.getForumId());
    }

    return stringBuilder.toString();
}