|
From: <php...@li...> - 2009-06-01 07:10:23
|
Hi,
If I understand your code correctly, your function "saxon" is called with
two arguments, $xml and $xsl being proxies for two (potentially large)
Strings.
As long as you don't evaluate these proxies (explicitly using
java_values($xml) or implicitly using a cast to ((string)$xml)), there
shouldn't be any performance problems.
The java_values() call forces the bridge to evaluate a proxy and to return
the result as a potentially large PHP value (string or array or ....). I
would call java_values() only if necessary. E.g. at the end of the script,
or right before manipulating it with native e.g. php str_* functions.
The $system->setProperty() assumes ownership of the back end. Instead of
setting the property over and over again I would set it once with a java
-D... parameter. Or rely on the JEE environment to do the correct
initialisation of your library.
Regards,
Jost Boekemeier
31. Mai 2009 4:55 nachm. schrieb am <
php...@li...>:
Hi,
I'm working on porting an application to PHP that relies on some Java
functionality. I've decided to use the PHP/Java Bridge.
Here is what I've got in PHP. Summary: it takes in two strings, xml
and xsl, and should return the result of applying the xsl transform on
the xml.
So far, so good! I originally was having trouble getting the result
back out into a PHP string variable, but there was just a simple typo
in the code, So my post is turning into a slightly different
question.
Could someone familiar with the PHP/Java bridge look over my code and
let me know if it looks like I've got the "right idea" I'm concerned
about performance, and the fact that the variables $xml and $xsl could
potentially be very large (megabytes of text)
Thanks in advance for any insight you can give me. This is new ground
for me, and I want to make sure I'm not making any major mistakes.
------
function saxon($xml,$xsl){
require_once("http://localhost:8080/JavaBridgeTemplate5442/java/Java.inc
");
$System = java("java.lang.System");
$System->setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
$TransformerFactory = java("javax.xml.transform.TransformerFactory");
$tFactory = $TransformerFactory->newInstance();
$xmlString = new Java("java.lang.String", $xml);
$xslString = new Java("java.lang.String", $xsl);
$xmlStringReader = new Java("java.io.StringReader", $xmlString);
$xslStringReader = new Java("java.io.StringReader", $xslString);
$xmlStreamSource = new
Java("javax.xml.transform.stream.StreamSource", $xmlStringReader);
$xslStreamSource = new
Java("javax.xml.transform.stream.StreamSource", $xslStringReader);
$transformer = $tFactory->newTransformer($xslStreamSource);
$outputStringWriter = new Java("java.io.StringWriter");
$outputStreamResult = new
Java("javax.xml.transform.stream.StreamResult",$outputStringWriter);
$transformer->transform($xmlStreamSource,$outputStreamResult);
$outputString = new Java("java.lang.String");
$outputString = $outputStringWriter->toString();
return (java_values($outputString));
}
--
John
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals.
Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
|