}
return result;
}
protected boolean runQuery( final IPentahoConnection localConnection, String rawQuery ) {
XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
try {
if ( localConnection == null ) {
return false;
}
if ( ComponentBase.debug ) {
debug( Messages.getInstance().getString( "XQueryBaseComponent.DEBUG_RUNNING_QUERY", rawQuery ) ); //$NON-NLS-1$
}
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 = new SAXReader();
Document document;
if ( url != null ) {
document = reader.read( url );
} else {
document = reader.read( inputStream );
}
Node commentNode = document.selectSingleNode( "/result-set/comment()" ); //$NON-NLS-1$
if ( commentNode != null ) {
String commentString = commentNode.getText();
StringTokenizer st = new StringTokenizer( commentString, "," ); //$NON-NLS-1$
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" ),
e ); //$NON-NLS-1$
}
}
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 );
rawQuery = "doc(\"" + documentPath + "\")" + rawQuery; //$NON-NLS-1$ //$NON-NLS-2$
}
}
if ( xQueryAction.getOutputPreparedStatement() != null ) {
return prepareFinalQuery( rawQuery, columnTypes );
} else {
return runFinalQuery( localConnection, rawQuery, columnTypes );
}
} catch ( Exception e ) {