diff --git a/src/main/java/org/olat/core/util/xml/EnhancedMapper.java b/src/main/java/org/olat/core/util/xml/EnhancedMapper.java index 90979e61f086e54504a88095793b2f665fd27fbd..636c1c2a1abf4d663859f2bf29181242ff777a68 100644 --- a/src/main/java/org/olat/core/util/xml/EnhancedMapper.java +++ b/src/main/java/org/olat/core/util/xml/EnhancedMapper.java @@ -21,6 +21,7 @@ package org.olat.core.util.xml; import org.hibernate.collection.internal.PersistentBag; import org.hibernate.collection.internal.PersistentList; +import org.hibernate.collection.internal.PersistentMap; import com.thoughtworks.xstream.mapper.MapperWrapper; @@ -42,19 +43,10 @@ public class EnhancedMapper extends MapperWrapper { return PersistentBag.class; } else if("org.hibernate.collection.PersistentList".equals(elementName)) { return PersistentList.class; + } else if("org.hibernate.collection.PersistentMap".equals(elementName)) { + return PersistentMap.class; } else { return super.realClass(elementName); } } - - @SuppressWarnings("rawtypes") - public String serializedClass(final Class type) { - if(PersistentBag.class.equals(type)) { - return "org.hibernate.collection.PersistentBag"; - } else if(PersistentList.class.equals(type)) { - return "org.hibernate.collection.PersistentList"; - } else { - return super.serializedClass(type); - } - } } diff --git a/src/main/java/org/olat/core/util/xml/EnhancedXStream.java b/src/main/java/org/olat/core/util/xml/EnhancedXStream.java new file mode 100644 index 0000000000000000000000000000000000000000..6edcaadcea6771c2e69b9a564909a8737e9e5322 --- /dev/null +++ b/src/main/java/org/olat/core/util/xml/EnhancedXStream.java @@ -0,0 +1,77 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.util.xml; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.hibernate.collection.internal.PersistentBag; +import org.hibernate.collection.internal.PersistentList; +import org.hibernate.collection.internal.PersistentMap; +import org.hibernate.collection.internal.PersistentSet; +import org.hibernate.collection.internal.PersistentSortedMap; +import org.hibernate.collection.internal.PersistentSortedSet; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.collections.CollectionConverter; +import com.thoughtworks.xstream.converters.collections.MapConverter; +import com.thoughtworks.xstream.mapper.MapperWrapper; + +/** + * This implmentation of XStream automatically convert hibernat list, set and map + * to standard java collections and convert by import / deserialization + * the old hibernate 3 collection packages to the new one. + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class EnhancedXStream extends XStream { + + public EnhancedXStream() { + super(); + + addDefaultImplementation(PersistentList.class, List.class); + addDefaultImplementation(PersistentBag.class, List.class); + addDefaultImplementation(PersistentMap.class, Map.class); + addDefaultImplementation(PersistentSortedMap.class, Map.class); + addDefaultImplementation(PersistentSet.class, Set.class); + addDefaultImplementation(PersistentSortedSet.class, Set.class); + addDefaultImplementation(ArrayList.class, List.class); + + registerConverter(new CollectionConverter(getMapper()) { + public boolean canConvert(@SuppressWarnings("rawtypes") Class type) { + return PersistentList.class == type || PersistentBag.class == type; + } + }); + + registerConverter(new MapConverter(getMapper()) { + public boolean canConvert(@SuppressWarnings("rawtypes") Class type) { + return PersistentMap.class == type; + } + }); + } + + @Override + protected MapperWrapper wrapMapper(MapperWrapper next) { + return new EnhancedMapper(next); + } + +} diff --git a/src/main/java/org/olat/core/util/xml/Util.java b/src/main/java/org/olat/core/util/xml/Util.java deleted file mode 100644 index ec9dd25d270c60a7a7b397139a5762a66ea38eb7..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/util/xml/Util.java +++ /dev/null @@ -1,81 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ -package org.olat.core.util.xml; - -import java.beans.XMLEncoder; -import java.io.BufferedOutputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.util.Iterator; -import java.util.List; - -import org.dom4j.Element; -import org.olat.core.logging.OLATRuntimeException; - -/** - * enclosing_type Description: <br> - * - * @author Felix Jost - */ -public class Util { - - /** - * @param o - * @param file - */ - public static void writeObjectAsXML(Object o, String file) { - - XMLEncoder e; - try { - e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file))); - e.writeObject(o); - e.close(); - } catch (FileNotFoundException e1) { - throw new OLATRuntimeException(Util.class, "Error writing object to XML.", e1); - } - - } - - /** - * @param elem - * @return String - */ - public static String getTextsOnly(Element elem) { - StringBuilder sb = new StringBuilder(); - visit(sb, elem); - return sb.toString(); - } - - private static void visit(StringBuilder sb, Element elem) { - sb.append(elem.getTextTrim()); - List children = elem.elements(); - for (Iterator it_ch = children.iterator(); it_ch.hasNext();) { - Element element = (Element) it_ch.next(); - visit(sb, element); - } - } - -} \ No newline at end of file diff --git a/src/main/java/org/olat/core/util/xml/XMLPrettyPrinter.java b/src/main/java/org/olat/core/util/xml/XMLPrettyPrinter.java deleted file mode 100644 index 0405e5c3c37e1d1a4ce83d8f3f57664ecce570b7..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/core/util/xml/XMLPrettyPrinter.java +++ /dev/null @@ -1,129 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ - -package org.olat.core.util.xml; - - -/** - * Description:<br> - * TODO: Felix Class Description for XMLPrettyPrinter - * <P> - * Initial Date: 09.09.2005 <br> - * - * @author Felix - */ -public class XMLPrettyPrinter { -/* - public static String prettyPrint(String in) { - StringBuilder sb = new StringBuilder(); - DefaultHandler handler = new SAXIndent(sb); - // Parse the input with the default (non-validating) parser - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.parse(new InputSource(new StringReader(in)), handler); - try { - StringWriter sw = new StringWriter(); - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.setOutputProperty(OutputKeys.INDENT, "yes"); - t.setOutputProperty(OutputKeys.METHOD, "xml"); - t.setOutputProperty(OutputKeys.STANDALONE, "yes"); - t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); - - t.transform(new StreamSource(new StringReader(componentListenerInfo)), new StreamResult(sw)); - String res = sw.getBuffer().toString(); - componentListenerInfo = res; - } catch (Exception e) { - // ignore - } - String r = componentListenerInfo; - } -*/ -} -/* -class SAXIndent extends DefaultHandler { - private static String sNEWLINE = "\n"; - private StringBuilder sb; - - SAXIndent(StringBuilder sb) { - this.sb = sb; - } - - public void startDocument() throws SAXException { - echoString(sNEWLINE + "<?xml ...?>" + sNEWLINE + sNEWLINE); - } - - public void endDocument() throws SAXException { - echoString(sNEWLINE); - } - - public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) throws SAXException { - echoTextBuffer(); - String eName = ("".equals(localName)) ? qName : localName; - echoString("<" + eName); // element name - if (attrs != null) { - for (int i = 0; i < attrs.getLength(); i++) { - String aName = attrs.getLocalName(i); // Attr name - if ("".equals(aName)) aName = attrs.getQName(i); - echoString(" " + aName + "=\"" + attrs.getValue(i) + "\""); - } - } - echoString(">"); - } - - public void endElement(String namespaceURI, String localName, // local name - String qName) // qualified name - throws SAXException { - echoTextBuffer(); - String eName = ("".equals(localName)) ? qName : localName; - echoString("</" + eName + ">"); // element name - } - - public void characters(char[] buf, int offset, int len) throws SAXException { - String s = new String(buf, offset, len); - sb.append(s); - } - - // ---- Helper methods ---- - - // Display text accumulated in the character buffer - private void echoTextBuffer() throws SAXException { - if (textBuffer == null) return; - echoString(textBuffer.toString()); - textBuffer = null; - } - - // Wrap I/O exceptions in SAX exceptions, to - // suit handler signature requirements - private void echoString(String s) throws SAXException { - try { - if (null == out) out = new OutputStreamWriter(System.out, "UTF8"); - out.write(s); - out.flush(); - } catch (IOException ex) { - throw new SAXException("I/O error", ex); - } - } -} -*/ diff --git a/src/main/java/org/olat/core/util/xml/XStreamHelper.java b/src/main/java/org/olat/core/util/xml/XStreamHelper.java index 9cc6dd8fd31217183645b0ae5cdc62c6e4fe98a9..baafef39b8d6a265b49d2700c811a11448013a14 100644 --- a/src/main/java/org/olat/core/util/xml/XStreamHelper.java +++ b/src/main/java/org/olat/core/util/xml/XStreamHelper.java @@ -40,7 +40,6 @@ import org.olat.core.util.FileUtils; import org.olat.core.util.vfs.VFSLeaf; import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.mapper.MapperWrapper; /** * Description:<br> @@ -225,7 +224,8 @@ public class XStreamHelper { * writing to a configured XML mapping */ public static XStream createXStreamInstance() { - return new EnhancedXStream(); + EnhancedXStream xstream = new EnhancedXStream(); + return xstream; } /** @@ -379,12 +379,4 @@ public class XStreamHelper { FileUtils.closeSafely(os); } } - - private static class EnhancedXStream extends XStream { - @Override - protected MapperWrapper wrapMapper(MapperWrapper next) { - return new EnhancedMapper(next); - } - } - } diff --git a/src/main/java/org/olat/course/repository/ImportPortfolioReferencesController.java b/src/main/java/org/olat/course/repository/ImportPortfolioReferencesController.java index d386470e3e06367b05dd86b79a5f73254b337d23..4b3bfacf7772f79be766d32dcf7b1a1358a9ae82 100644 --- a/src/main/java/org/olat/course/repository/ImportPortfolioReferencesController.java +++ b/src/main/java/org/olat/course/repository/ImportPortfolioReferencesController.java @@ -50,6 +50,7 @@ import org.olat.course.nodes.CourseNode; import org.olat.course.nodes.portfolio.PortfolioCourseNodeEditController; import org.olat.portfolio.EPTemplateMapResource; import org.olat.portfolio.manager.EPFrontendManager; +import org.olat.portfolio.manager.EPXStreamHandler; import org.olat.portfolio.model.structel.EPStructuredMapTemplate; import org.olat.portfolio.model.structel.PortfolioStructure; import org.olat.portfolio.model.structel.PortfolioStructureMap; @@ -59,7 +60,6 @@ import org.olat.repository.RepositoryEntryImportExport; import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryTableModel; import org.olat.repository.controllers.RepositorySearchController; -import org.olat.repository.handlers.PortfolioHandler; import org.olat.repository.handlers.RepositoryHandler; import org.olat.repository.handlers.RepositoryHandlerFactory; import org.olat.resource.OLATResource; @@ -174,7 +174,7 @@ public class ImportPortfolioReferencesController extends BasicController { public static RepositoryEntry doImport(RepositoryEntryImportExport importExport, CourseNode node, boolean keepSoftkey, Identity owner) { File fExportedFile = importExport.importGetExportedFile(); - PortfolioStructure structure = PortfolioHandler.getAsObject(fExportedFile); + PortfolioStructure structure = EPXStreamHandler.getAsObject(fExportedFile, false); if(structure == null) { log.warn("Error adding portfolio map resource during repository reference import: " + importExport.getDisplayName()); return null; diff --git a/src/main/java/org/olat/package-cleanup.txt b/src/main/java/org/olat/package-cleanup.txt deleted file mode 100644 index a6b041836315ca8b95a1158e27be5f869db77d85..0000000000000000000000000000000000000000 --- a/src/main/java/org/olat/package-cleanup.txt +++ /dev/null @@ -1,25 +0,0 @@ -Entfernen aller versions etc. Tags die beim mergen Konflikte bereiten und eh überflüssig sind: - -1) Paket selektieren und auf Search gehen -2) File search nach ^ *\*.*\$:*$ (regexp enablen) -3) Nicht suchen sondern replace drücken -4) Jede gefundene Stelle duchsteppen und ersetzen mit nichts -5) Refresh (F5) -6) Synchronize, outgoing changes -7) Jeden change anschauen und die Leerzeile weglöschen. So hat man grad - die Kontrolle dass alles korrekt gelöscht ist. Zudem immer schauen ob Tags vergessen - gegangen sind (Ein paar werden mit der regexp nicht gefunden) -8) Checkin - - -Packages (inklusive subpackages) - -PACKAGE WER STATUS -------------------------------- -admin fg done -basesecurity fg done -bookmark fg done -catalog fg done -collaboration fg done -configuration fg done -org.olat.gui.components fj done diff --git a/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java b/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java index 1e6888537c04271cd00e45015284bdbab97fcca8..b9a5dd5ac3e157ccaf86304a156c0c6243384669 100755 --- a/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java +++ b/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Set; import org.olat.basesecurity.BaseSecurity; -import org.olat.basesecurity.BaseSecurityManager; import org.olat.basesecurity.Constants; import org.olat.basesecurity.IdentityShort; import org.olat.basesecurity.Policy; diff --git a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java index 91f4c90b0637af73564fb4399f8ac230658d9414..5956f4f2bd56283909b834baa5d628de25934bd4 100755 --- a/src/main/java/org/olat/portfolio/manager/EPStructureManager.java +++ b/src/main/java/org/olat/portfolio/manager/EPStructureManager.java @@ -1877,6 +1877,9 @@ public class EPStructureManager extends BasicManager { private static class KeyStructureToStructureLinkComparator implements Comparator<EPStructureToStructureLink>, Serializable { + + private static final long serialVersionUID = 366101659547497002L; + public KeyStructureToStructureLinkComparator() { // } diff --git a/src/main/java/org/olat/portfolio/manager/EPXStreamHandler.java b/src/main/java/org/olat/portfolio/manager/EPXStreamHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..c4a2dec75fd1c87212e367b31f0e455c1d135e3d --- /dev/null +++ b/src/main/java/org/olat/portfolio/manager/EPXStreamHandler.java @@ -0,0 +1,150 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.portfolio.manager; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.io.Writer; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.io.IOUtils; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; +import org.olat.core.util.xml.XStreamHelper; +import org.olat.portfolio.model.restriction.CollectRestriction; +import org.olat.portfolio.model.structel.EPAbstractMap; +import org.olat.portfolio.model.structel.EPDefaultMap; +import org.olat.portfolio.model.structel.EPPage; +import org.olat.portfolio.model.structel.EPStructureElement; +import org.olat.portfolio.model.structel.EPStructureToArtefactLink; +import org.olat.portfolio.model.structel.EPStructureToStructureLink; +import org.olat.portfolio.model.structel.EPStructuredMap; +import org.olat.portfolio.model.structel.EPStructuredMapTemplate; +import org.olat.portfolio.model.structel.PortfolioStructure; + +import com.thoughtworks.xstream.XStream; + +/** + * + * + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class EPXStreamHandler { + + private static final OLog log = Tracing.createLoggerFor(EPXStreamHandler.class); + + private static final XStream myStream = XStreamHelper.createXStreamInstance(); + private static Templates filterArtefactsTemplates; + + static { // initialize supported types + myStream.alias("defaultMap", EPDefaultMap.class); + myStream.alias("structureMap", EPStructuredMap.class); + myStream.alias("templateMap", EPStructuredMapTemplate.class); + myStream.alias("structure", EPStructureElement.class); + myStream.alias("page", EPPage.class); + myStream.alias("structureToArtefact", EPStructureToArtefactLink.class); + myStream.alias("structureToStructure", EPStructureToStructureLink.class); + myStream.alias("collectionRestriction", CollectRestriction.class); + myStream.omitField(EPAbstractMap.class, "ownerGroup"); // see also OLAT-6344 + + try { + InputStream xsltIn = EPXStreamHandler.class.getResourceAsStream("portfolio_without_artefacts.xsl"); + Source xsltSource = new StreamSource(xsltIn); + filterArtefactsTemplates = TransformerFactory.newInstance().newTemplates(xsltSource); + } catch (TransformerConfigurationException e) { + log.error("", e); + } catch (TransformerFactoryConfigurationError e) { + log.error("", e); + } + } + + public static final PortfolioStructure copy(PortfolioStructure structure) { + String stringuified = myStream.toXML(structure); + PortfolioStructure newStructure = (PortfolioStructure)myStream.fromXML(stringuified); + return newStructure; + } + + public static final PortfolioStructure getAsObject(File fMapXml, boolean withArtefacts) { + try { + //extract from zip + InputStream in = new FileInputStream(fMapXml); + ZipInputStream zipIn = new ZipInputStream(in); + //open the entry of the map + zipIn.getNextEntry(); + + Writer buffer = new StringWriter(); + if(!withArtefacts) { + Transformer transformer = filterArtefactsTemplates.newTransformer(); + transformer.transform(new StreamSource(zipIn), new StreamResult(buffer)); + } else { + IOUtils.copy(zipIn, buffer); + } + + PortfolioStructure struct = (PortfolioStructure) myStream.fromXML(buffer.toString()); + // OLAT-6344: reset ownerGroup from earlier exports. A new group is created by import in ePFMgr.importPortfolioMapTemplate() later on anyway. + ((EPAbstractMap) struct).setOwnerGroup(null); + return struct; + } catch (Exception e) { + log.error("Cannot export this map: " + fMapXml, e); + } + return null; + } + + public static final InputStream toStream(PortfolioStructure structure) + throws IOException { + String xmlStructure = myStream.toXML(structure); + try { + //prepare a zip + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ZipOutputStream zipOut = new ZipOutputStream(out); + zipOut.putNextEntry(new ZipEntry("map.xml")); + InputStream in = new ByteArrayInputStream(xmlStructure.getBytes("UTF8")); + IOUtils.copy(in, out); + zipOut.closeEntry(); + zipOut.close(); + + //prepare media resource + byte[] outArray = out.toByteArray(); + IOUtils.closeQuietly(out); + IOUtils.closeQuietly(in); + return new ByteArrayInputStream(outArray); + } catch (IOException e) { + log.error("Cannot export this map: " + structure, e); + return null; + } + } +} diff --git a/src/main/java/org/olat/portfolio/manager/portfolio_without_artefacts.xsl b/src/main/java/org/olat/portfolio/manager/portfolio_without_artefacts.xsl new file mode 100644 index 0000000000000000000000000000000000000000..3bc232532d8e7cf7fe578a3066204fe2701b86ac --- /dev/null +++ b/src/main/java/org/olat/portfolio/manager/portfolio_without_artefacts.xsl @@ -0,0 +1,10 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:template match="artefacts"> + <!-- Ommit artefacts --> + </xsl:template> + <xsl:template match="@*|node()"> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> + </xsl:template> +</xsl:stylesheet> \ No newline at end of file diff --git a/src/main/java/org/olat/repository/handlers/PortfolioHandler.java b/src/main/java/org/olat/repository/handlers/PortfolioHandler.java index 4d8a3b3c56c0b90cf04aed22e39a68e4fdeb3571..48cf095b6bdb262f04174f1aec5223ed8e9da284 100644 --- a/src/main/java/org/olat/repository/handlers/PortfolioHandler.java +++ b/src/main/java/org/olat/repository/handlers/PortfolioHandler.java @@ -25,12 +25,21 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + import org.olat.core.CoreSpringFactory; import org.olat.core.commons.fullWebApp.LayoutMain3ColsController; import org.olat.core.gui.UserRequest; @@ -55,6 +64,7 @@ import org.olat.portfolio.EPSecurityCallbackFactory; import org.olat.portfolio.EPTemplateMapResource; import org.olat.portfolio.EPUIFactory; import org.olat.portfolio.manager.EPFrontendManager; +import org.olat.portfolio.manager.EPXStreamHandler; import org.olat.portfolio.model.restriction.CollectRestriction; import org.olat.portfolio.model.structel.EPAbstractMap; import org.olat.portfolio.model.structel.EPDefaultMap; @@ -76,7 +86,6 @@ import org.olat.resource.accesscontrol.ui.RepositoryMainAccessControllerWrapper; import org.olat.resource.references.ReferenceManager; import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.collections.CollectionConverter; import de.bps.onyx.plugin.StreamMediaResource; @@ -97,7 +106,6 @@ public class PortfolioHandler implements RepositoryHandler { public static final String PROCESS_CREATENEW = "create_new"; public static final String PROCESS_UPLOAD = "upload"; - public static XStream myStream = XStreamHelper.createXStreamInstance(); private static final boolean DOWNLOADABLE = false; private static final boolean EDITABLE = true; @@ -108,24 +116,6 @@ public class PortfolioHandler implements RepositoryHandler { static { // initialize supported types supportedTypes = new ArrayList<String>(1); supportedTypes.add(EPTemplateMapResource.TYPE_NAME); - - myStream.alias("defaultMap", EPDefaultMap.class); - myStream.alias("structureMap", EPStructuredMap.class); - myStream.alias("templateMap", EPStructuredMapTemplate.class); - myStream.alias("structure", EPStructureElement.class); - myStream.alias("page", EPPage.class); - myStream.alias("structureToArtefact", EPStructureToArtefactLink.class); - myStream.alias("structureToStructure", EPStructureToStructureLink.class); - myStream.alias("collectionRestriction", CollectRestriction.class); - myStream.omitField(EPAbstractMap.class, "ownerGroup"); // see also OLAT-6344 - //myStream.addDefaultImplementation(PersistentList.class, List.class); - myStream.addDefaultImplementation(ArrayList.class, List.class); - /*myStream.registerConverter(new CollectionConverter(myStream.getMapper()) { - public boolean canConvert(Class type) { - return PersistentList.class == type; - } - });*/ - } /** @@ -211,8 +201,7 @@ public class PortfolioHandler implements RepositoryHandler { public OLATResourceable createCopy(OLATResourceable res, UserRequest ureq) { EPFrontendManager ePFMgr = (EPFrontendManager)CoreSpringFactory.getBean("epFrontendManager"); PortfolioStructure structure = ePFMgr.loadPortfolioStructure(res); - String stringuified = myStream.toXML(structure); - PortfolioStructure newStructure = (PortfolioStructure)myStream.fromXML(stringuified); + PortfolioStructure newStructure = EPXStreamHandler.copy(structure); PortfolioStructureMap map = ePFMgr.importPortfolioMapTemplate(newStructure, ureq.getIdentity()); return map.getOlatResource(); } @@ -239,54 +228,14 @@ public class PortfolioHandler implements RepositoryHandler { EPFrontendManager ePFMgr = (EPFrontendManager)CoreSpringFactory.getBean("epFrontendManager"); PortfolioStructure structure = ePFMgr.loadPortfolioStructure(res); - String xmlStructure = myStream.toXML(structure); try { - //prepare a zip - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ZipOutputStream zipOut = new ZipOutputStream(out); - zipOut.putNextEntry(new ZipEntry("map.xml")); - InputStream in = new ByteArrayInputStream(xmlStructure.getBytes("UTF8")); - FileUtils.copy(in, zipOut); - zipOut.closeEntry(); - zipOut.close(); - - //prepare media resource - byte[] outArray = out.toByteArray(); - FileUtils.closeSafely(out); - FileUtils.closeSafely(in); - InputStream inOut = new ByteArrayInputStream(outArray); + InputStream inOut = EPXStreamHandler.toStream(structure); mr = new StreamMediaResource(inOut, null, 0l, 0l); } catch (IOException e) { log.error("Cannot export this map: " + structure, e); } - return mr; } - - public static final PortfolioStructure getAsObject(File fMapXml) { - try { - //extract from zip - InputStream in = new FileInputStream(fMapXml); - ZipInputStream zipIn = new ZipInputStream(in); - ZipEntry entry = zipIn.getNextEntry(); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - FileUtils.copy(zipIn, out); - zipIn.closeEntry(); - zipIn.close(); - - //prepare decoding with xstream - byte[] outArray = out.toByteArray(); - String xml = new String(outArray); - PortfolioStructure struct = (PortfolioStructure) myStream.fromXML(xml); - // OLAT-6344: reset ownerGroup from earlier exports. A new group is created by import in ePFMgr.importPortfolioMapTemplate() later on anyway. - ((EPAbstractMap) struct).setOwnerGroup(null); - return struct; - } catch (IOException e) { - log.error("Cannot export this map: " + fMapXml, e); - } - return null; - } /** * @see org.olat.repository.handlers.RepositoryHandler#getDetailsComponent(org.olat.core.id.OLATResourceable, diff --git a/src/test/java/org/olat/portfolio/EPFrontendManagerTest.java b/src/test/java/org/olat/portfolio/EPFrontendManagerTest.java index 9b510dccea1a9f0bf7aebb7b7ac6aa39e5b31b7d..120dcc82c26acf765c76f692e4f2fa11dd408df3 100644 --- a/src/test/java/org/olat/portfolio/EPFrontendManagerTest.java +++ b/src/test/java/org/olat/portfolio/EPFrontendManagerTest.java @@ -133,6 +133,7 @@ public class EPFrontendManagerTest extends OlatTestCase { epStructureManager.savePortfolioStructure(struct11); //structure element 2 from page 1 PortfolioStructure struct12 = epFrontendManager.createAndPersistPortfolioStructureElement(page1, "template-structure-1.2", "template-structure-1.2"); + assertNotNull(struct12); //first page PortfolioStructure page2 = epFrontendManager.createAndPersistPortfolioPage(templateEl, "template-page-2", "template-page-2"); //structure element 1 from page 2 diff --git a/src/test/java/org/olat/portfolio/EPImportTest.java b/src/test/java/org/olat/portfolio/EPImportTest.java new file mode 100644 index 0000000000000000000000000000000000000000..039953b9ce49f82a15d5ee0173b212d5622f3788 --- /dev/null +++ b/src/test/java/org/olat/portfolio/EPImportTest.java @@ -0,0 +1,67 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.portfolio; + +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; + +import junit.framework.Assert; + +import org.junit.Test; +import org.olat.core.commons.persistence.DB; +import org.olat.portfolio.manager.EPFrontendManager; +import org.olat.portfolio.manager.EPXStreamHandler; +import org.olat.portfolio.model.structel.PortfolioStructure; +import org.olat.portfolio.model.structel.PortfolioStructureMap; +import org.olat.test.OlatTestCase; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Test different imports + * + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class EPImportTest extends OlatTestCase { + + @Autowired + private DB dbInstance; + @Autowired + private EPFrontendManager epFrontendManager; + + + @Test + public void testImportFromOpenOLAT_81_Hibernate3() throws URISyntaxException { + URL mapUrl = EPImportTest.class.getResource("map_81.xml.zip"); + assertNotNull(mapUrl); + File mapFile = new File(mapUrl.toURI()); + //import the map + PortfolioStructure rootStructure = EPXStreamHandler.getAsObject(mapFile, false); + PortfolioStructureMap importedMap = epFrontendManager.importPortfolioMapTemplate(rootStructure, null); + Assert.assertNotNull(importedMap); + dbInstance.commitAndCloseSession(); + } + + + +} diff --git a/src/test/java/org/olat/portfolio/map_81.xml.zip b/src/test/java/org/olat/portfolio/map_81.xml.zip new file mode 100644 index 0000000000000000000000000000000000000000..4c751bf9e016f4b4279a94c7aa5c09006324af70 Binary files /dev/null and b/src/test/java/org/olat/portfolio/map_81.xml.zip differ diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index 97971c0a860b9cbcb3dd255234718c30eae5d97f..15495ea596476e3c00db7975b77901618500e796 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -122,6 +122,7 @@ import org.junit.runners.Suite; org.olat.portfolio.EPFrontendManagerTest.class, org.olat.portfolio.EPStructureManagerTest.class, org.olat.portfolio.EPStructureToArtefactTest.class, + org.olat.portfolio.EPImportTest.class, org.olat.commons.info.InfoManagerTest.class, org.olat.core.commons.service.tagging.SimpleTagProposalManagerTest.class, org.olat.commons.coordinate.singlevm.SingleVMLockerTest.class,