Re: Solution for finding images in a WAR file

2003-01-21 Thread Johan Åbrandt
This solution may or may not work in existing servers, but it may also 
break. The problem is that ServletContext-getRealPath() is allowed to 
return null, for example if the content is served from a WAR.

Rakesh Patel wrote:
Hi,
I have found a solution that I think works (have not got access to a Unix 
environment to confirm this) but I did not hard-code any window/unix specific 
paths.
Here's a snippet of code I used:
ServletContext scntxt = this.getServletContext();
String pathToFile = scntxt.getRealPath(/WEB-INF); // or whatever relative to 
web app root eg /images
String imagePath = file: + pathToFile;
org.apache.fop.configuration.Configuration.put(baseDir,imagePath);
as you can see, all my images are in web_app_root/WEB-INF.
The corresponding xml data file looks like this:
HTRelitiveRef HTRRKey=2 HTRRType=Picture HTRRID=/centurion.jpg HTRRLink= 
HTRRVisible=Fcenturion/HTRelitiveRef
I hope this saves others the problem of finding the solution across many posts!
Thanks
Rakesh
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
Johan Åbrandt
Technical Project Manager
(Tekninen projektipäällikkö)
Tel. +358 9 6817 3342
Mobile. +358 40 848 8068
[EMAIL PROTECTED]
Profit Software Oy
Meritullinkatu 11 C
00170 Helsinki, Finland
__
This message and its attachments have been found clean from known viruses 
with three different antivirus programs.
__

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Solution for finding images in a WAR file

2003-01-21 Thread Johan Åbrandt
 = loader.getResourceAsStream(
resourceBundlePath.toString() );
		}
		catch( IOException ioe ) 
		{			
			inputStream.close();
			throw ioe;
		}
	
		return inputStream;
	} // end of method getResourceAsStream

}
-Original Message-
From: Rakesh Patel [mailto:[EMAIL PROTECTED]
Sent: Monday, January 20, 2003 11:30 AM
To: [EMAIL PROTECTED]
Subject: Solution for finding images in a WAR file
Hi,
I have found a solution that I think works (have not got access to a Unix
environment to confirm this) but I did not hard-code any window/unix
specific paths.
Here's a snippet of code I used:
ServletContext scntxt = this.getServletContext();
String pathToFile = scntxt.getRealPath(/WEB-INF); // or whatever relative
to web app root eg /images
String imagePath = file: + pathToFile;
org.apache.fop.configuration.Configuration.put(baseDir,imagePath);
as you can see, all my images are in web_app_root/WEB-INF.
The corresponding xml data file looks like this:
HTRelitiveRef HTRRKey=2 HTRRType=Picture HTRRID=/centurion.jpg
HTRRLink= HTRRVisible=Fcenturion/HTRelitiveRef
I hope this saves others the problem of finding the solution across many
posts!
Thanks
Rakesh
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
Johan Åbrandt
Technical Project Manager
(Tekninen projektipäällikkö)
Tel. +358 9 6817 3342
Mobile. +358 40 848 8068
[EMAIL PROTECTED]
Profit Software Oy
Meritullinkatu 11 C
00170 Helsinki, Finland
__
This message and its attachments have been found clean from known viruses 
with three different antivirus programs.
__

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Solution for finding images in a WAR file

2003-01-20 Thread Rakesh Patel
Hi,

I have found a solution that I think works (have not got access to a Unix 
environment to confirm this) but I did not hard-code any window/unix specific 
paths.

Here's a snippet of code I used:

ServletContext scntxt = this.getServletContext();
String pathToFile = scntxt.getRealPath(/WEB-INF); // or whatever relative to 
web app root eg /images

String imagePath = file: + pathToFile;

org.apache.fop.configuration.Configuration.put(baseDir,imagePath);

as you can see, all my images are in web_app_root/WEB-INF.

The corresponding xml data file looks like this:

HTRelitiveRef HTRRKey=2 HTRRType=Picture HTRRID=/centurion.jpg 
HTRRLink= HTRRVisible=Fcenturion/HTRelitiveRef

I hope this saves others the problem of finding the solution across many posts!

Thanks

Rakesh

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Solution for finding images in a WAR file

2003-01-20 Thread Sharma, Siddharth
 )
{
try
{
  // I wish I could just do this:
strXml = inputStream.toString();
  outputStream = new
ByteArrayOutputStream(aBuffSize);
  
  synchronized ( outputStream ) 
  {
  while (
(k=inputStream.read(buff) ) != -1) 
  {
outputStream.write(
buff, 0, k);
  }

  // I can now grab the string I
want
  strXml =
outputStream.toString(); 
  outputStream.close();
  return strXml;
  } // end of synchronized block
  
  // That was a lot of work to pull a
String out of an inputStream.

}
catch( IOException e ) 
{

throw new IOException(
PSConfigurationManager.getPropertiesFromResourceBundle() caught IOException
when trying to load properties file  + e.getMessage() );
}   

}
}
catch( IOException ioe ) 
{   
throw ioe;
}
finally 
{
try 
{
inputStream.close();
}
catch( IOException ex ) 
{   
throw ex;   
}

}
return ;
} // end of method getPropertiesFromResourceBundle()



/**
 *  Returns the resource as a stream. Uses this class classloader to
find the resource
 *  relative to this class. Since this class is loaded by the
classloader of the 
 *  calling class (say servlet), the resource will be searched
realtive to the calling
 *  class
 */
private static final InputStream getResourceAsStream( String
resourceBundleName,
String strPath )
throws IOException 
{
InputStream inputStream = null;
try {
// null safety check
if( resourceBundleName == null || strPath == null)
{
throw new IOException(

ResourceLoader.getResourceAsStream() called with null filename );
}

StringBuffer resourceBundlePath = new
StringBuffer(strPath);
resourceBundlePath.append(/);
resourceBundlePath.append( resourceBundleName );

ClassLoader loader =
ResourceLoader.class.getClassLoader();  

inputStream = loader.getResourceAsStream(
resourceBundlePath.toString() );
}
catch( IOException ioe ) 
{   
inputStream.close();
throw ioe;
}   

return inputStream;
} // end of method getResourceAsStream


}


-Original Message-
From: Rakesh Patel [mailto:[EMAIL PROTECTED]
Sent: Monday, January 20, 2003 11:30 AM
To: [EMAIL PROTECTED]
Subject: Solution for finding images in a WAR file

Hi,

I have found a solution that I think works (have not got access to a Unix
environment to confirm this) but I did not hard-code any window/unix
specific paths.

Here's a snippet of code I used:

ServletContext scntxt = this.getServletContext();
String pathToFile = scntxt.getRealPath(/WEB-INF); // or whatever relative
to web app root eg /images

String imagePath = file: + pathToFile;

org.apache.fop.configuration.Configuration.put(baseDir,imagePath);

as you can see, all my images are in web_app_root/WEB-INF.

The corresponding xml data file looks like this:

HTRelitiveRef HTRRKey=2 HTRRType=Picture HTRRID=/centurion.jpg
HTRRLink= HTRRVisible=Fcenturion/HTRelitiveRef

I hope this saves others the problem of finding the solution across many
posts!

Thanks

Rakesh