From e7e5ca1f4136940ad31529bf667899ef4d9f6d6e Mon Sep 17 00:00:00 2001 From: "nikolas.laskaris" Date: Mon, 12 May 2014 09:56:29 +0000 Subject: [PATCH] Removed xalan dependency and made the needed changes to the code which makes the xsl transformations. git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@95546 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 6 +-- .../framework/core/session/ASLSession.java | 8 ++++ .../framework/core/util/LayoutPortlets.java | 44 +++++++++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index dbb04d0..9d76bf3 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.applicationsupportlayer aslcore - 4.3.0-SNAPSHOT + 4.4.0-SNAPSHOT Application Support Layer Core @@ -96,13 +96,13 @@ kxml2 2.3.0 - + net.sourceforge.addressing addressing diff --git a/src/main/java/org/gcube/application/framework/core/session/ASLSession.java b/src/main/java/org/gcube/application/framework/core/session/ASLSession.java index af99621..1c53b7e 100644 --- a/src/main/java/org/gcube/application/framework/core/session/ASLSession.java +++ b/src/main/java/org/gcube/application/framework/core/session/ASLSession.java @@ -24,6 +24,7 @@ import org.gcube.application.framework.core.util.SessionConstants; //import org.gcube.application.framework.core.util.UserCredential; //import org.gcube.common.core.scope.GCUBEScope; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; //import org.gridforum.jgss.ExtendedGSSCredential; /** @@ -41,6 +42,7 @@ public class ASLSession{ private String externalSessionID; private String username; // private ExtendedGSSCredential credential; + private String parentScope; private String scope; private HashMap notifiers; String scopeName; @@ -246,6 +248,12 @@ public class ASLSession{ innerSession.clear(); } + public String getParentScope(){ + ScopeBean bean = new ScopeBean(getScope()); + parentScope = bean.enclosingScope().toString(); + return parentScope; + } + /** * invalidates the session */ diff --git a/src/main/java/org/gcube/application/framework/core/util/LayoutPortlets.java b/src/main/java/org/gcube/application/framework/core/util/LayoutPortlets.java index 0c011e6..c0c0b59 100644 --- a/src/main/java/org/gcube/application/framework/core/util/LayoutPortlets.java +++ b/src/main/java/org/gcube/application/framework/core/util/LayoutPortlets.java @@ -16,20 +16,21 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; 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.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.apache.xalan.processor.TransformerFactoryImpl; + +//import org.apache.xalan.processor.TransformerFactoryImpl; import org.gcube.application.framework.core.session.ASLSession; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -119,20 +120,35 @@ public class LayoutPortlets { * @return the HTML. * @throws TransformerException if an error occurs. */ - public static String transform(String xml, String xslt) throws TransformerException - { - - TransformerFactoryImpl factory = new TransformerFactoryImpl(); - StreamSource sourceInput = new StreamSource(new ByteArrayInputStream(xslt.getBytes())); - Templates sheet = factory.newTemplates(sourceInput); - - Transformer instance = sheet.newTransformer(); - instance.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); +// public static String transform_OLD(String xml, String xslt) throws TransformerException +// { +// +// TransformerFactoryImpl factory = new TransformerFactoryImpl(); +// StreamSource sourceInput = new StreamSource(new ByteArrayInputStream(xslt.getBytes())); +// Templates sheet = factory.newTemplates(sourceInput); +// +// Transformer instance = sheet.newTransformer(); +// instance.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); +// StringWriter w = new StringWriter(); +// instance.transform(new StreamSource(new StringReader(xml)), new StreamResult(w)); +// +// return w.toString(); +// } + + public static String transform(String dataXML, String inputXSL) + throws TransformerConfigurationException, + TransformerException + { + StreamSource xsltInput = new StreamSource(new ByteArrayInputStream(inputXSL.getBytes())); StringWriter w = new StringWriter(); - instance.transform(new StreamSource(new StringReader(xml)), new StreamResult(w)); - + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(xsltInput); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true"); + transformer.transform(new StreamSource(new StringReader(dataXML)), new StreamResult(w)); return w.toString(); - } + } + + //method to convert Document to String private static String getStringFromDocument(Document doc)