@SuppressWarnings("rawtypes") public static void createOutputFileName(RepositoryFile file, IOutputHandler outputHandler) { IPentahoSession userSession = PentahoSessionHolder.getSession(); ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(userSession); IActionSequence actionSequence = actionHelper.getActionSequence( file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ); String fileName = "content"; // $NON-NLS-1$ if (actionSequence != null) { String title = actionSequence.getTitle(); if ((title != null) && (title.length() > 0)) { fileName = title; } else { String sequenceName = actionSequence.getSequenceName(); if ((sequenceName != null) && (sequenceName.length() > 0)) { fileName = sequenceName; } else { List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences(); int i = 0; boolean done = false; while ((actionDefinitionsList.size() > i) && (!done)) { IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i); String componentName = actionDefinition.getComponentName(); if ((componentName != null) && (componentName.length() > 0)) { fileName = componentName; done = true; } else { ++i; } } } } } IMimeTypeListener mimeTypeListener = outputHandler.getMimeTypeListener(); if (mimeTypeListener != null) { mimeTypeListener.setName(fileName); } }
@SuppressWarnings({"unchecked", "rawtypes"}) public static String doParameter( final RepositoryFile file, IParameterProvider parameterProvider, final IPentahoSession userSession) throws IOException { ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper(); final IActionSequence actionSequence = helper.getActionSequence( file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ); final Document document = DocumentHelper.createDocument(); try { final Element parametersElement = document.addElement("parameters"); // noinspection unchecked final Map<String, IActionParameter> params = actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST); for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) { final String paramName = entry.getKey(); final IActionParameter paramDef = entry.getValue(); final String value = paramDef.getStringValue(); final Class type; // yes, the actual type-code uses equals-ignore-case and thus allows the user // to specify type information in a random case. sTrInG is equal to STRING is equal to the // value // defined as constant (string) if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) { type = String[].class; } else { type = String.class; } final String label = paramDef.getSelectionDisplayName(); final String[] values; if (StringUtils.isEmpty(value)) { values = new String[0]; } else { values = new String[] {value}; } createParameterElement( parametersElement, paramName, type, label, "user", "parameters", values); } createParameterElement( parametersElement, "path", String.class, null, "system", "system", new String[] {file.getPath()}); createParameterElement( parametersElement, "prompt", String.class, null, "system", "system", new String[] {"yes", "no"}); createParameterElement( parametersElement, "instance-id", String.class, null, "system", "system", new String[] {parameterProvider.getStringParameter("instance-id", null)}); // no close, as far as I know tomcat does not like it that much .. OutputFormat format = OutputFormat.createCompactFormat(); format.setSuppressDeclaration(true); format.setEncoding("utf-8"); // $NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(document); writer.flush(); return outputStream.toString("utf-8"); } catch (Exception e) { logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e); return null; } }