use of com.opensymphony.xwork2.Action in project qi4j-sdk by Qi4j.
the class ConstraintViolationInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext invocationContext = invocation.getInvocationContext();
ValueStack stack = invocationContext.getValueStack();
Object action = invocation.getAction();
if (action instanceof ValidationAware) {
ValidationAware va = (ValidationAware) action;
HashMap<Object, Object> propertyOverrides = new HashMap<Object, Object>();
for (Map.Entry<String, FieldConstraintViolations> fieldViolations : fieldConstraintViolations(invocationContext).entrySet()) {
addConstraintViolationFieldErrors(stack, va, fieldViolations.getKey(), fieldViolations.getValue());
propertyOverrides.put(fieldViolations.getKey(), getOverrideExpr(invocation, fieldViolations.getValue()));
}
// if there were some errors, put the original (fake) values in place right before the result
if (!propertyOverrides.isEmpty()) {
overrideActionValues(invocation, stack, propertyOverrides);
}
}
return invocation.invoke();
}
use of com.opensymphony.xwork2.Action in project bamboobsc by billchen198318.
the class BaseSimpleActionInfo method execute.
public void execute() {
ActionInvocation actionInvocation = ActionContext.getContext().getActionInvocation();
HttpServletRequest request = ServletActionContext.getRequest();
String action = SimpleUtils.getStr(actionInvocation.getProxy().getActionName(), "");
String namespace = SimpleUtils.getStr(actionInvocation.getProxy().getNamespace(), "");
String remoteAddr = SimpleUtils.getStr(request.getRemoteAddr(), "");
String referer = SimpleUtils.getStr(request.getHeader("referer"), "");
this.actionMethodName = actionInvocation.getProxy().getMethod();
ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByAction, action);
ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByAction, namespace);
ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByAction, remoteAddr);
ActionContext.getContext().getSession().put(Constants.SESS_PAGE_INFO_Referer_ByAction, referer);
this.pageInfoActionName = action;
this.pageInfoNamespace = namespace;
this.pageInfoRemoteAddr = remoteAddr;
this.pageInfoReferer = referer;
}
use of com.opensymphony.xwork2.Action in project bamboobsc by billchen198318.
the class ActionInfoSupportInterceptor method intercept.
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
/*
ActionInvocation ai=(ActionInvocation)ActionContext.getContext().get(ActionContext.ACTION_INVOCATION);
String action=ai.getProxy().getActionName();
String namespace=ai.getProxy().getNamespace();
*/
HttpServletRequest request = ServletActionContext.getRequest();
ActionContext context = actionInvocation.getInvocationContext();
String action = actionInvocation.getProxy().getActionName();
String namespace = actionInvocation.getProxy().getNamespace();
String remoteAddr = request.getRemoteAddr();
String referer = request.getHeader("referer");
context.getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByInterceptor, action);
context.getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByInterceptor, namespace);
context.getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByInterceptor, remoteAddr);
context.getSession().put(Constants.SESS_PAGE_INFO_Referer_ByInterceptor, referer);
return actionInvocation.invoke();
}
use of com.opensymphony.xwork2.Action in project bamboobsc by billchen198318.
the class JasperReportsResult method doExecute.
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
// Will throw a runtime exception if no "datasource" property. TODO Best place for that is...?
initializeProperties(invocation);
LOG.debug("Creating JasperReport for dataSource = {}, format = {}", dataSource, format);
HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(ServletActionContext.HTTP_RESPONSE);
// TODO Set content type to config settings?
if ("contype".equals(request.getHeader("User-Agent"))) {
try (OutputStream outputStream = response.getOutputStream()) {
response.setContentType("application/pdf");
response.setContentLength(0);
} catch (IOException e) {
LOG.error("Error writing report output", e);
throw new ServletException(e.getMessage(), e);
}
return;
}
// Construct the data source for the report.
ValueStack stack = invocation.getStack();
ValueStackDataSource stackDataSource = null;
Connection conn = (Connection) stack.findValue(connection);
if (conn == null)
stackDataSource = new ValueStackDataSource(stack, dataSource, wrapField);
if ("https".equalsIgnoreCase(request.getScheme())) {
// set the the HTTP Header to work around IE SSL weirdness
response.setHeader("CACHE-CONTROL", "PRIVATE");
response.setHeader("Cache-Control", "maxage=3600");
response.setHeader("Pragma", "public");
response.setHeader("Accept-Ranges", "none");
}
// Determine the directory that the report file is in and set the reportDirectory parameter
// For WW 2.1.7:
// ServletContext servletContext = ((ServletConfig) invocation.getInvocationContext().get(ServletActionContext.SERVLET_CONFIG)).getServletContext();
ServletContext servletContext = (ServletContext) invocation.getInvocationContext().get(ServletActionContext.SERVLET_CONTEXT);
String systemId = servletContext.getRealPath(finalLocation);
// TODO 更改 systemId 的位址
if (Constants.JASPER_REPORTS_RESULT_LOCATION_REPLACE_MODE) {
systemId = finalLocation;
}
Map parameters = new ValueStackShadowMap(stack);
File directory = new File(systemId.substring(0, systemId.lastIndexOf(File.separator)));
parameters.put("reportDirectory", directory);
parameters.put(JRParameter.REPORT_LOCALE, invocation.getInvocationContext().getLocale());
// put timezone in jasper report parameter
if (timeZone != null) {
timeZone = conditionalParse(timeZone, invocation);
final TimeZone tz = TimeZone.getTimeZone(timeZone);
if (tz != null) {
// put the report time zone
parameters.put(JRParameter.REPORT_TIME_ZONE, tz);
}
}
// Add any report parameters from action to param map.
Map reportParams = (Map) stack.findValue(reportParameters);
if (reportParams != null) {
LOG.debug("Found report parameters; adding to parameters...");
parameters.putAll(reportParams);
}
ByteArrayOutputStream output;
JasperPrint jasperPrint;
// Fill the report and produce a print object
try {
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(new File(systemId));
if (conn == null) {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, stackDataSource);
} else {
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
}
} catch (JRException e) {
LOG.error("Error building report for uri {}", systemId, e);
throw new ServletException(e.getMessage(), e);
}
// Export the print object to the desired output format
try {
if (contentDisposition != null || documentName != null) {
final StringBuffer tmp = new StringBuffer();
tmp.append((contentDisposition == null) ? "inline" : contentDisposition);
if (documentName != null) {
tmp.append("; filename=");
tmp.append(documentName);
tmp.append(".");
tmp.append(format.toLowerCase());
}
response.setHeader("Content-disposition", tmp.toString());
}
JRExporter exporter;
if (format.equals(FORMAT_PDF)) {
response.setContentType("application/pdf");
exporter = new JRPdfExporter();
} else if (format.equals(FORMAT_CSV)) {
response.setContentType("text/csv");
exporter = new JRCsvExporter();
} else if (format.equals(FORMAT_HTML)) {
response.setContentType("text/html");
// IMAGES_MAPS seems to be only supported as "backward compatible" from JasperReports 1.1.0
Map imagesMap = new HashMap();
request.getSession(true).setAttribute("IMAGES_MAP", imagesMap);
exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath() + imageServletUrl);
// Needed to support chart images:
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
request.getSession().setAttribute("net.sf.jasperreports.j2ee.jasper_print", jasperPrint);
} else if (format.equals(FORMAT_XLS)) {
response.setContentType("application/vnd.ms-excel");
exporter = new JRXlsExporter();
} else if (format.equals(FORMAT_XML)) {
response.setContentType("text/xml");
exporter = new JRXmlExporter();
} else if (format.equals(FORMAT_RTF)) {
response.setContentType("application/rtf");
exporter = new JRRtfExporter();
} else {
throw new ServletException("Unknown report format: " + format);
}
Map exportParams = (Map) stack.findValue(exportParameters);
if (exportParams != null) {
LOG.debug("Found export parameters; adding to exporter parameters...");
exporter.getParameters().putAll(exportParams);
}
output = exportReportToBytes(jasperPrint, exporter);
} catch (JRException e) {
LOG.error("Error producing {} report for uri {}", format, systemId, e);
throw new ServletException(e.getMessage(), e);
} finally {
try {
conn.close();
} catch (Exception e) {
LOG.warn("Could not close db connection properly", e);
}
}
response.setContentLength(output.size());
// Will throw ServletException on IOException.
writeReport(response, output);
}
use of com.opensymphony.xwork2.Action in project dhis2-core by dhis2.
the class LoadFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return INPUT;
}
FormType formType = dataSet.getFormType();
if (formType.isCustom() && dataSet.hasDataEntryForm()) {
dataEntryForm = dataSet.getDataEntryForm();
customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
return formType.toString();
}
// ---------------------------------------------------------------------
// Section / default form
// ---------------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
if (dataElements.isEmpty()) {
return INPUT;
}
Collections.sort(dataElements);
orderedDataElements = ListMap.getListMap(dataElements, de -> de.getCategoryCombo(dataSet));
orderedCategoryCombos = getDataElementCategoryCombos(dataElements, dataSet);
for (DataElementCategoryCombo categoryCombo : orderedCategoryCombos) {
List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
// -----------------------------------------------------------------
// Perform ordering of categories and their options so that they
// could be displayed as in the paper form. Note that the total
// number of entry cells to be generated are the multiple of options
// from each category.
// -----------------------------------------------------------------
numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
Map<Integer, List<DataElementCategoryOption>> optionsMap = new HashMap<>();
for (DataElementCategory category : categoryCombo.getCategories()) {
optionsMap.put(category.getId(), category.getCategoryOptions());
}
orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
// -----------------------------------------------------------------
// Calculating the number of times each category should be repeated
// -----------------------------------------------------------------
Map<Integer, Integer> catRepeat = new HashMap<>();
Map<Integer, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (DataElementCategory cat : categoryCombo.getCategories()) {
int categoryOptionSize = cat.getCategoryOptions().size();
if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
catColSpan = catColSpan / categoryOptionSize;
int total = optionCombos.size() / (catColSpan * categoryOptionSize);
Collection<Integer> cols = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
cols.add(i);
}
colRepeat.put(cat.getId(), cols);
catRepeat.put(cat.getId(), catColSpan);
}
}
catColRepeat.put(categoryCombo.getId(), colRepeat);
}
// ---------------------------------------------------------------------
// Get data entry form
// ---------------------------------------------------------------------
DataSet dsOriginal = dataSet;
if (dataSet.getFormType().isDefault()) {
DataSet dataSetCopy = new DataSet();
dataSetCopy.setUid(dataSet.getUid());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSet = dataSetCopy;
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
DataElementCategoryCombo categoryCombo = orderedCategoryCombos.get(i);
String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
Section section = new Section();
section.setUid(CodeGenerator.generateUid());
section.setId(i);
section.setName(name);
section.setSortOrder(i);
section.setDataSet(dataSetCopy);
dataSetCopy.getSections().add(section);
section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
formType = FormType.SECTION;
}
if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (child.getDataSets().contains(dsOriginal)) {
organisationUnitChildren.add(child);
}
}
Collections.sort(organisationUnitChildren);
organisationUnits.addAll(organisationUnitChildren);
getSectionForm(dataElements, dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataElements, dataSet);
return formType.toString();
}
Aggregations