use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class GetResource method doPost.
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
// TODO perform any authorization here...
// TODO support caching
PentahoSystem.systemEntryPoint();
try {
IPentahoSession session = getPentahoSession(request);
// $NON-NLS-1$
String resource = request.getParameter("resource");
if ((resource == null) || StringUtil.doesPathContainParentPathSegment(resource)) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0001_RESOURCE_PARAMETER_MISSING"));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
String resLower = resource.toLowerCase();
String resourcePath;
if (resLower.endsWith(".xsl")) {
// $NON-NLS-1$
// $NON-NLS-1$
resourcePath = "system/custom/xsl/" + resource;
} else if (resLower.endsWith(".mondrian.xml")) {
// $NON-NLS-1$
// Ensure user is authenticated by checking the default role
// gets defaultRole from pentahoObjects-s-s.x
String defaultRole = PentahoSystem.get(String.class, "defaultRole", null);
if (defaultRole != null) {
if (!SecurityHelper.getInstance().isGranted(session, new SimpleGrantedAuthority(defaultRole))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
// If no defaultRole is defined, then just continue action as per normal.
resourcePath = resource;
} else if (resLower.endsWith(".jpg") || resLower.endsWith(".jpeg") || resLower.endsWith(".gif") || resLower.endsWith(".png") || resLower.endsWith(".bmp")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
resourcePath = resource;
} else {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0002_INVALID_FILE", resource));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
IActionSequenceResource asqr = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"", resourcePath);
InputStream in = asqr.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
if (in == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("GetResource.ERROR_0003_RESOURCE_MISSING", resourcePath));
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
String mimeType = getServletContext().getMimeType(resourcePath);
String resourceName = resourcePath;
if (resourcePath.indexOf("/") != -1) {
// $NON-NLS-1$
// $NON-NLS-1$
resourceName = resourcePath.substring(resourcePath.lastIndexOf("/") + 1);
}
// $NON-NLS-1$ //$NON-NLS-2$
response.setHeader("content-disposition", "attachment;filename=" + resourceName);
if ((null == mimeType) || (mimeType.length() <= 0)) {
// Hard coded to PNG because BIRT does not give us a mime type at
// all...
// $NON-NLS-1$
response.setContentType("image/png");
} else {
response.setContentType(mimeType);
}
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// $NON-NLS-1$ //$NON-NLS-2$
response.setHeader("expires", "0");
// Open the input and output streams
OutputStream out = response.getOutputStream();
try {
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
int totalBytes = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
totalBytes += count;
}
response.setContentLength(totalBytes);
} finally {
in.close();
out.close();
}
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class MDXBaseComponent method getConnectionOrig.
protected IPentahoConnection getConnectionOrig() {
IPentahoConnection localConnection = null;
MdxConnectionAction connAction = (MdxConnectionAction) getActionDefinition();
try {
String mdxConnectionStr = connAction.getMdxConnectionString().getStringValue();
Properties mdxConnectionProps = (Properties) connAction.getConnectionProps().getValue();
String jdbcStr = connAction.getConnection().getStringValue();
String jndiStr = connAction.getJndi().getStringValue();
String location = connAction.getLocation().getStringValue();
String role = connAction.getRole().getStringValue();
String catalog = connAction.getCatalog().getStringValue();
if ((catalog == null) && (connAction.getCatalogResource() != null)) {
IActionSequenceResource resource = getResource(connAction.getCatalogResource().getName());
catalog = resource.getAddress();
if (resource.getSourceType() == IActionSequenceResource.URL_RESOURCE) {
if (!catalog.startsWith("solution:") && !catalog.startsWith("http:")) {
// $NON-NLS-1$
if (fileExistsInRepository(catalog)) {
// About allowed "solution:"
// Extra step to make sure that remote mondrian models
// fully qualified aren't munged
// MB
// $NON-NLS-1$
catalog = "solution:" + catalog;
}
}
} else if ((resource.getSourceType() == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resource.getSourceType() == IActionSequenceResource.FILE_RESOURCE)) {
if (!catalog.startsWith("solution:")) {
// $NON-NLS-1$
catalog = "solution:" + catalog;
}
}
}
if (catalog == null) {
// $NON-NLS-1$
warn(Messages.getInstance().getString("MDXBaseComponent.ERROR_0007_CATALOG_NOT_DEFINED", getActionName()));
} else {
if (mdxConnectionProps != null) {
mdxConnectionProps.put(MdxConnectionAction.CATALOG_ELEMENT, catalog);
}
}
String userId = connAction.getUserId().getStringValue();
String password = connAction.getPassword().getStringValue();
if (mdxConnectionProps != null) {
localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, mdxConnectionProps, getSession(), this);
} else {
if (mdxConnectionStr != null) {
localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, mdxConnectionStr, getSession(), this);
} else {
String connectStr = null;
if (jdbcStr != null) {
// $NON-NLS-1$
connectStr = jdbcStr + "; Catalog=" + catalog;
} else if (jndiStr != null) {
IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
if (datasourceService.getDataSource(jndiStr) == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
return null;
}
// $NON-NLS-1$ //$NON-NLS-2$
connectStr = "dataSource=" + jndiStr + "; Catalog=" + catalog;
// Add extra definitions from platform mondrian metadata
MondrianCatalog mc = getMondrianCatalog(catalog);
try {
connectStr += ";" + mc.getDataSourceInfo();
} catch (Exception e) {
// Just swallow the exception
}
}
if (role != null) {
// $NON-NLS-1$
connectStr += "; Role=" + role;
}
Properties props = new Properties();
props.setProperty(IPentahoConnection.CONNECTION, connectStr);
props.setProperty(IPentahoConnection.PROVIDER, location);
if (userId != null) {
props.setProperty(IPentahoConnection.USERNAME_KEY, userId);
}
if (password != null) {
props.setProperty(IPentahoConnection.PASSWORD_KEY, password);
}
localConnection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, props, getSession(), this);
}
if (localConnection == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0005_INVALID_CONNECTION"));
return null;
}
}
if (localConnection instanceof MDXConnection) {
MDXConnection mdxConn = (MDXConnection) localConnection;
if (connAction != null) {
if ((connAction.getExtendedColumnNames() != ActionInputConstant.NULL_INPUT)) {
mdxConn.setUseExtendedColumnNames(connAction.getExtendedColumnNames().getBooleanValue());
}
}
}
return localConnection;
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return null;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class JFreeChartEngine method getImage.
/**
* @param imageName
* String that contains a path to the image
* @return the image
*/
public static Image getImage(final String imageName, final IPentahoSession session) {
Image image = null;
try {
IActionSequenceResource resource = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"", imageName);
InputStream is = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
image = ImageIO.read(is);
} catch (IOException e) {
JFreeChartEngine.log.error(null, e);
}
return image;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class RuntimeContext method addXFormHeader.
private void addXFormHeader() {
XForm.createXFormHeader(RuntimeContext.PARAMETER_FORM, xformHeader);
IActionSequenceResource resource = paramManager.getCurrentResource(parameterXsl);
if (!parameterXsl.endsWith(".xsl") && (resource != null)) {
// load the parameter page template
try {
parameterTemplate = getResourceAsString(resource);
} catch (Exception e) {
// TODO log this
}
}
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class XQueryBaseComponent method runQuery.
protected boolean runQuery(final IPentahoConnection localConnection, String rawQuery) {
XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
try {
if (localConnection == null) {
return false;
}
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("XQueryBaseComponent.DEBUG_RUNNING_QUERY", rawQuery));
}
String documentPath = null;
int resourceType = -1;
String srcXml = xQueryAction.getSourceXml().getStringValue();
org.pentaho.actionsequence.dom.IActionResource xmlResource = xQueryAction.getXmlDocument();
InputStream inputStream = null;
URL url = null;
if (srcXml != null) {
inputStream = new FileInputStream(new File(createTempXMLFile(srcXml)));
} else if (xmlResource != null) {
// we have a local document to use as the data source
IActionSequenceResource resource = getResource(xmlResource.getName());
resourceType = resource.getSourceType();
if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) {
inputStream = resource.getInputStream(RepositoryFilePermission.READ);
} else if (resourceType == IActionSequenceResource.XML) {
inputStream = new FileInputStream(new File(createTempXMLFile(resource.getAddress())));
} else {
url = new URL(documentPath);
}
}
// Retrieve the column types
String[] columnTypes = null;
if (retrieveColumnTypes()) {
try {
SAXReader reader = XMLParserFactoryProducer.getSAXReader(null);
Document document;
if (url != null) {
document = reader.read(url);
} else {
document = reader.read(inputStream);
}
// $NON-NLS-1$
Node commentNode = document.selectSingleNode("/result-set/comment()");
if (commentNode != null) {
String commentString = commentNode.getText();
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(commentString, ",");
List columnTypesList = new LinkedList();
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
columnTypesList.add(token);
}
columnTypes = (String[]) columnTypesList.toArray(new String[0]);
}
} catch (Exception e) {
getLogger().warn(Messages.getInstance().getString("XQueryBaseComponent.ERROR_0009_ERROR_BUILDING_COLUMN_TYPES"), // $NON-NLS-1$
e);
}
}
if (rawQuery != null) {
if (rawQuery.indexOf("{" + XQueryBaseComponent.XML_DOCUMENT_TAG + "}") >= 0) {
// $NON-NLS-1$//$NON-NLS-2$
rawQuery = TemplateUtil.applyTemplate(rawQuery, XQueryBaseComponent.XML_DOCUMENT_TAG, documentPath);
} else {
Calendar now = Calendar.getInstance();
File temp = File.createTempFile("tempXQuery" + now.getTimeInMillis(), ".xml");
temp.deleteOnExit();
OutputStream out = new FileOutputStream(temp);
IActionSequenceResource resource = getResource(xmlResource.getName());
inputStream = resource.getInputStream(RepositoryFilePermission.READ);
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
inputStream.close();
documentPath = temp.getAbsolutePath();
documentPath = FilenameUtils.separatorsToUnix(documentPath);
// $NON-NLS-1$ //$NON-NLS-2$
rawQuery = "doc(\"" + documentPath + "\")" + rawQuery;
}
}
if (xQueryAction.getOutputPreparedStatement() != null) {
return prepareFinalQuery(rawQuery, columnTypes);
} else {
return runFinalQuery(localConnection, rawQuery, columnTypes);
}
} catch (Exception e) {
getLogger().error(Messages.getInstance().getString("XQueryBaseComponent.ERROR_0010_ERROR_RUNNING_QUERY"), // $NON-NLS-1$
e);
return false;
}
}
Aggregations