public void execute()

in plugins/xslt/src/main/java/org/apache/struts2/result/xslt/XSLTResult.java [160:231]


    public void execute(ActionInvocation invocation) throws Exception {
        if (invocation == null) {
            throw new IllegalArgumentException("Invocation cannot be null!");
        }

        long startTime = System.currentTimeMillis();
        String location = getStylesheetLocation();

        if (location == null) {
            throw new IllegalArgumentException("Parameter 'stylesheetLocation' cannot be null!");
        }

        if (parse) {
            ValueStack stack = invocation.getStack();
            location = TextParseUtil.translateVariables(location, stack);
        }

        try {
            HttpServletResponse response = invocation.getInvocationContext().getServletResponse();
            response.setStatus(status);
            response.setCharacterEncoding(encoding);
            PrintWriter writer = response.getWriter();

            // Create a transformer for the stylesheet.
            Templates templates = null;
            Transformer transformer;
            if (location != null) {
                templates = getTemplates(location);
                transformer = templates.newTransformer();
            } else {
                TransformerFactory factory = createTransformerFactory();
                transformer = factory.newTransformer();
            }

            transformer.setURIResolver(getURIResolver());
            transformer.setErrorListener(buildErrorListener());

            String mimeType;
            if (templates == null) {
                mimeType = "text/xml"; // no stylesheet, raw xml
            } else {
                mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
            }

            if (mimeType == null) {
                // guess (this is a servlet, so text/html might be the best guess)
                mimeType = "text/html";
            }

            response.setContentType(mimeType);

            Object result = invocation.getAction();
            if (exposedValue != null) {
                ValueStack stack = invocation.getStack();
                result = stack.findValue(exposedValue);
            }

            Source xmlSource = getDOMSourceForStack(result);

            // Transform the source XML to System.out.
            LOG.debug("xmlSource = {}", xmlSource);
            transformer.transform(xmlSource, new StreamResult(writer));

            writer.flush(); // ...and flush...

            LOG.debug("Time: {}ms", (System.currentTimeMillis() - startTime));

        } catch (Exception e) {
            LOG.error("Unable to render XSLT Template, '{}'", location, e);
            throw e;
        }
    }