mmidy 01/07/31 14:33:18
Modified: java/src/org/apache/xalan/extensions
ExtensionHandlerGeneral.java
java/src/org/apache/xalan/res XSLTErrorResources.java
java/src/org/apache/xalan/templates ElemExtensionDecl.java
Log:
Add support for external scripts (ie, the src attribute on a script element)
Revision Changes Path
1.15 +53 -4
xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java
Index: ExtensionHandlerGeneral.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ExtensionHandlerGeneral.java 2001/07/28 00:25:57 1.14
+++ ExtensionHandlerGeneral.java 2001/07/31 21:33:14 1.15
@@ -60,6 +60,9 @@
import java.util.Vector;
import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.InputStream;
//import org.w3c.dom.Element;
//import org.w3c.dom.Node;
@@ -71,6 +74,7 @@
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xml.utils.QName;
+import org.apache.xml.utils.SystemIDResolver;
import javax.xml.transform.TransformerException;
@@ -190,7 +194,7 @@
* @throws TransformerException
*/
public ExtensionHandlerGeneral(
- String namespaceUri, StringVector elemNames, StringVector
funcNames, String scriptLang, String scriptSrcURL, String scriptSrc)
+ String namespaceUri, StringVector elemNames, StringVector
funcNames, String scriptLang, String scriptSrcURL, String scriptSrc, String
systemId)
throws TransformerException
{
@@ -227,10 +231,55 @@
if (m_scriptSrcURL != null)
{
- throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_SRC_ATTRIB_NOT_SUPPORTED,
new Object[]{scriptLang})); //"src attribute not yet supported for "
- //+ scriptLang);
- }
+ URL url = null;
+ try{
+ url = new URL(m_scriptSrcURL);
+ }
+ catch (java.net.MalformedURLException mue)
+ {
+ int indexOfColon = m_scriptSrcURL.indexOf(':');
+ int indexOfSlash = m_scriptSrcURL.indexOf('/');
+ if ((indexOfColon != -1) && (indexOfSlash != -1)
+ && (indexOfColon < indexOfSlash))
+ {
+ // The url is absolute.
+ url = null;
+ throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_COULD_NOT_FIND_EXTERN_SCRIPT,
new Object[]{m_scriptSrcURL}), mue); //"src attribute not yet supported for "
+ //+ scriptLang);
+ }
+ else
+ {
+ try{
+ url = new URL(new
URL(SystemIDResolver.getAbsoluteURI(systemId)), m_scriptSrcURL);
+ }
+ catch (java.net.MalformedURLException mue2)
+ {
+ throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_COULD_NOT_FIND_EXTERN_SCRIPT,
new Object[]{m_scriptSrcURL}), mue2); //"src attribute not yet supported for "
+ //+ scriptLang);
+ }
+ }
+ }
+ if (url != null)
+ {
+ try
+ {
+ URLConnection uc = url.openConnection();
+ InputStream is = uc.getInputStream();
+ byte []bArray = new byte[uc.getContentLength()];
+ is.read(bArray);
+ m_scriptSrc = new String(bArray);
+
+ }
+ catch (IOException ioe)
+ {
+ throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_COULD_NOT_FIND_EXTERN_SCRIPT,
new Object[]{m_scriptSrcURL}), ioe); //"src attribute not yet supported for "
+ //+ scriptLang);
+ }
+ }
+
+ }
+
if (null == managerClass)
throw new
TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_INIT_BSFMGR,
null)); //"Could not initialize BSF manager");
1.21 +3 -3
xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java
Index: XSLTErrorResources.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XSLTErrorResources.java 2001/07/28 00:25:58 1.20
+++ XSLTErrorResources.java 2001/07/31 21:33:17 1.21
@@ -1863,12 +1863,12 @@
}
/** src attribute not yet supported for */
- public static final int ER_SRC_ATTRIB_NOT_SUPPORTED = 195;
+ public static final int ER_COULD_NOT_FIND_EXTERN_SCRIPT = 195;
static
{
- contents[ER_SRC_ATTRIB_NOT_SUPPORTED][1] =
- "src attribute not yet supported for {0}";
+ contents[ER_COULD_NOT_FIND_EXTERN_SCRIPT][1] =
+ "Could not get to external script at {0}";
}
/** The resource [] could not be found */
1.16 +1 -1
xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionDecl.java
Index: ElemExtensionDecl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionDecl.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ElemExtensionDecl.java 2001/07/28 00:25:58 1.15
+++ ElemExtensionDecl.java 2001/07/31 21:33:18 1.16
@@ -329,7 +329,7 @@
{
nsh = new ExtensionHandlerGeneral(declNamespace, this.m_elements,
this.m_functions, lang, srcURL,
- scriptSrc);
+ scriptSrc, getSystemId());
// System.out.println("Adding NS Handler: declNamespace = "+
// declNamespace+", lang = "+lang+", srcURL = "+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]