Class UploadPolicy

java.lang.Object
org.apache.struts2.interceptor.DisableParams
org.apache.struts2.interceptor.UploadPolicy
All Implemented Interfaces:
Serializable, InterceptorParams

public class UploadPolicy extends DisableParams
Per-invocation upload validation policy for ActionFileUploadInterceptor.

A configured instance is held by the interceptor and copied for each invocation, so lazily resolved values never reach the shared interceptor.

Since:
7.3.0
See Also:
  • Constructor Details

    • UploadPolicy

      public UploadPolicy()
  • Method Details

    • setAllowedTypes

      public void setAllowedTypes(String allowedTypes)
      Parameters:
      allowedTypes - a comma-delimited list of content types, or null for no restriction
    • setAllowedExtensions

      public void setAllowedExtensions(String allowedExtensions)
      Parameters:
      allowedExtensions - a comma-delimited list of extensions, or null for no restriction
    • setMaximumSize

      public void setMaximumSize(Long maximumSize)
      Parameters:
      maximumSize - the maximum size in bytes, or null for no limit
    • getMaximumSize

      public Long getMaximumSize()
    • getAllowedTypes

      public Set<String> getAllowedTypes()
    • getAllowedExtensions

      public Set<String> getAllowedExtensions()
    • unresolved

      public void unresolved(String paramName)
      A parameter that could not be resolved makes this policy unusable: the upload is rejected rather than validated against a partially-resolved policy, so a broken expression cannot silently relax validation.

      DisableParams.DISABLED_PARAM is the one exception and is not recorded. It is not a validation dimension: its unresolved value is simply false, which leaves the interceptor running and every other part of the policy intact, so it cannot relax validation. Recording it would let a broken <param name="disabled">${...}</param> reject every upload of the invocation, which is a failure mode of its own rather than a safe default.

      Parameters:
      paramName - name of the parameter that could not be applied
    • isUnresolved

      public boolean isUnresolved()
    • getUnresolvedParams

      public Set<String> getUnresolvedParams()
    • copy

      public UploadPolicy copy()
      Returns:
      an independent copy, used to seed a per-invocation policy from the configured one