Initial transform commit
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/.classpath b/bundles/org.eclipse.equinox.transforms.xslt/.classpath
new file mode 100644
index 0000000..ce73933
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/.cvsignore b/bundles/org.eclipse.equinox.transforms.xslt/.cvsignore
new file mode 100644
index 0000000..ba077a4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/.project b/bundles/org.eclipse.equinox.transforms.xslt/.project
new file mode 100644
index 0000000..63360e6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.equinox.transforms.xslt</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7c686bc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Tue Nov 21 14:57:12 EST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.pde.core.prefs b/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..c70bb38
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Tue Nov 21 13:38:29 EST 2006
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.transforms.xslt/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1044a0f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: XSLT Transform Extension
+Bundle-SymbolicName: org.eclipse.equinox.transforms.xslt
+Bundle-Version: 1.0.0
+Import-Package: org.osgi.framework;version="1.3.0"
+Eclipse-LazyStart: true
+Require-Bundle: system.bundle
+Export-Package: org.eclipse.equinox.transforms.xslt
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/about.html b/bundles/org.eclipse.equinox.transforms.xslt/about.html
new file mode 100755
index 0000000..18dee67
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>November 28, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/build.properties b/bundles/org.eclipse.equinox.transforms.xslt/build.properties
new file mode 100644
index 0000000..3de1425
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ hookconfigurators.properties
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/hookconfigurators.properties b/bundles/org.eclipse.equinox.transforms.xslt/hookconfigurators.properties
new file mode 100644
index 0000000..59a73fe
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/hookconfigurators.properties
@@ -0,0 +1,2 @@
+hook.configurators= \
+ org.eclipse.equinox.transforms.xslt.XSLTTransformingBundleFileWrapperFactoryHook
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTBundleFile.java b/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTBundleFile.java
new file mode 100644
index 0000000..4d1ed55
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTBundleFile.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.transforms.xslt;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.ref.SoftReference;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.equinox.transforms.CSVTransformingBundleFile;
+import org.eclipse.equinox.transforms.Pipe;
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.osgi.framework.BundleContext;
+
+public class XSLTBundleFile extends CSVTransformingBundleFile {
+
+ private static final Map templateMap = new HashMap();
+
+ public XSLTBundleFile(BundleContext context, BaseData data,
+ BundleFile delegate, TransformList transformList)
+ throws IOException {
+ super(context, data, delegate, transformList);
+ }
+
+ protected InputStream getInputStream(InputStream inputStream,
+ URL transformerUrl) throws IOException {
+ Templates template = getTemplate(transformerUrl);
+ if (template != null) {
+
+ Transformer transformer = null;
+ try {
+ transformer = template.newTransformer();
+ XSLTPipe pipe = new XSLTPipe(inputStream, transformer);
+ return pipe.getPipedInputStream();
+ } catch (TransformerConfigurationException e) {
+ log(e);
+ }
+ }
+
+ return null;
+ }
+
+ private synchronized Templates getTemplate(URL transformerURL) {
+ Templates templates = null;
+
+ SoftReference templatesRef = (SoftReference) templateMap
+ .get(transformerURL);
+ if (templatesRef != null) {
+ templates = (Templates) templatesRef.get();
+ }
+
+ if (templates == null) {
+ try {
+ InputStream xsltStream = transformerURL.openStream();
+ TransformerFactory tFactory = null;
+ try {
+ tFactory = TransformerFactory.newInstance();
+ StreamSource xsltSource = new StreamSource(xsltStream);
+ try {
+ templatesRef = new SoftReference(templates = tFactory
+ .newTemplates(xsltSource));
+ templateMap.put(transformerURL, templatesRef);
+ } catch (Exception e) {
+ // cant create the template. May be an IO
+ // exception from the source or perhaps a badly
+ // formed XSLT. We shouldn't fail in this case.
+ log(e);
+ }
+ } catch (TransformerFactoryConfigurationError e) {
+ // we can proceed without a factory
+ log(e);
+ }
+ } catch (IOException e) {
+ log(e);
+ }
+ }
+ return templates;
+ }
+}
+
+class XSLTPipe extends Pipe {
+ private Transformer transformer;
+
+ public XSLTPipe(InputStream original, Transformer transformer)
+ throws IOException {
+ super(original);
+ this.transformer = transformer;
+ }
+
+ protected void pipeInput(InputStream original, OutputStream result)
+ throws IOException {
+ try {
+ transformer.transform(new StreamSource(original), new StreamResult(
+ result));
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ throw new IOException(e.getMessage());
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTTransformingBundleFileWrapperFactoryHook.java b/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTTransformingBundleFileWrapperFactoryHook.java
new file mode 100644
index 0000000..d08dadf
--- /dev/null
+++ b/bundles/org.eclipse.equinox.transforms.xslt/src/org/eclipse/equinox/transforms/xslt/XSLTTransformingBundleFileWrapperFactoryHook.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.transforms.xslt;
+
+import java.io.IOException;
+
+import org.eclipse.equinox.transforms.TransformingBundleFileWrapperFactoryHook;
+import org.eclipse.equinox.transforms.CSVTransformingBundleFile.TransformList;
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+
+public class XSLTTransformingBundleFileWrapperFactoryHook extends
+ TransformingBundleFileWrapperFactoryHook {
+
+ private TransformList transformList;
+
+ public BundleFile wrapBundleFile(BundleFile bundleFile, Object content,
+ BaseData data, boolean base) throws IOException {
+ if (transformList != null)
+ return new XSLTBundleFile(getContext(), data, bundleFile,
+ transformList);
+ return null;
+ }
+
+ public void frameworkStart(BundleContext context) throws BundleException {
+ super.frameworkStart(context);
+
+ try {
+ transformList = new TransformList(context,
+ XSLTTransformingBundleFileWrapperFactoryHook.class
+ .getName());
+ transformList.open();
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void frameworkStop(BundleContext context) throws BundleException {
+ super.frameworkStop(context);
+ transformList.close();
+ }
+}