From 513352d885f04ab1a945913623f39181722833b4 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Tue, 5 Nov 2024 15:04:23 +0100 Subject: [PATCH] feat: Update Moved Artifact Dependencies from Meeds - Meeds-io/meeds#2537 --- core/connector/pom.xml | 5 - core/core-configuration/pom.xml | 5 - core/services/pom.xml | 4 +- .../services/compress/CompressData.java | 518 ++++++++++++++++++ .../services/compress/TestCompressData.java | 99 ++++ .../conf/portal/test-configuration.xml | 6 + core/webui-administration/pom.xml | 4 - core/webui-explorer/pom.xml | 4 - core/webui/pom.xml | 4 - ecm-wcm-extension/pom.xml | 5 - ext/authoring/webui/pom.xml | 4 - testsuite/test/pom.xml | 4 - 12 files changed, 625 insertions(+), 37 deletions(-) create mode 100644 core/services/src/main/java/org/exoplatform/services/compress/CompressData.java create mode 100644 core/services/src/test/java/org/exoplatform/services/compress/TestCompressData.java diff --git a/core/connector/pom.xml b/core/connector/pom.xml index bba71270728..f574c812a3a 100644 --- a/core/connector/pom.xml +++ b/core/connector/pom.xml @@ -120,11 +120,6 @@ com.rometools rome - - io.meeds.core - exo.core.component.organization.api - provided - io.meeds.commons commons-component-common diff --git a/core/core-configuration/pom.xml b/core/core-configuration/pom.xml index 011df59f016..19e55ab6c2f 100644 --- a/core/core-configuration/pom.xml +++ b/core/core-configuration/pom.xml @@ -21,11 +21,6 @@ commons-component-common runtime - - io.meeds.core - exo.core.component.organization.api - runtime - org.exoplatform.ecms ecms-core-connector diff --git a/core/services/pom.xml b/core/services/pom.xml index 1cbac522c04..fa88e88a883 100644 --- a/core/services/pom.xml +++ b/core/services/pom.xml @@ -14,7 +14,7 @@ 1.0 All used ecms rest endpoints - 0.36 + 0.35 @@ -95,7 +95,7 @@ exo.kernel.component.cache - io.meeds.kernel + org.exoplatform.commons-exo exo.kernel.component.command diff --git a/core/services/src/main/java/org/exoplatform/services/compress/CompressData.java b/core/services/src/main/java/org/exoplatform/services/compress/CompressData.java new file mode 100644 index 00000000000..c450b4dcd67 --- /dev/null +++ b/core/services/src/main/java/org/exoplatform/services/compress/CompressData.java @@ -0,0 +1,518 @@ +/* + * Copyright (C) 2009 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.services.compress; + +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * Created by The eXo Platform SAS Author : Chung Nguyen + * nguyenchung136@yahoo.com Feb 10, 2006 + */ +public class CompressData +{ + /** + * The logger + */ + private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.common.CompressData"); + + private String base_; + + private List datas_ = new ArrayList(); + + protected static final int EOF = -1; + + protected static final int BUFFER = 2048; + + public CompressData() + { + + } + + public CompressData(String base) + { + base_ = base; + } + + public String getBase() + { + return base_; + } + + public void addFile(String entryName, File file) + { + try + { + InputStream is = new FileInputStream(file); + datas_.add(new InputStreamDataInstance(entryName, is)); + } + catch (FileNotFoundException e) + { + LOG.error(e.getLocalizedMessage(), e); + } + } + + public void addDir(File srcDir) + { + if (srcDir.isFile()) + { + addFile(srcDir.getName(), srcDir); + } + else + { + datas_.add(new FileDataInstance(srcDir.getName(), srcDir)); + } + // create recursive loop to go through all files in the srcDir..... + } + + public void addInputStream(String entryName, InputStream is) throws Exception + { + datas_.add(new InputStreamDataInstance(entryName, is)); + } + + public void createZipFile(String fileName) throws Exception + { + File fileZip = new File(fileName + ".zip"); + FileOutputStream out = new FileOutputStream(fileZip); + ZipOutputStream zos = new ZipOutputStream(out); + int size = datas_.size(); + byte InputData[] = new byte[BUFFER]; + if (size < 0) + { + throw new Exception("Data size is null"); + } + for (int i = 0; i < size; i++) + { + DataInstance di = datas_.get(i); + if (di instanceof InputStreamDataInstance) + { + InputStream is = di.getInputStream(); + zos.putNextEntry(new ZipEntry(di.getEntryName())); + int len; + while ((len = is.read(InputData)) != EOF) + { + zos.write(InputData, 0, len); + } + zos.closeEntry(); + } + else if (di instanceof FileDataInstance) + { + di.getZipOut(true, zos); + } + } + zos.close(); + out.close(); + } + + public void createZip(OutputStream os) throws Exception + { + int size = datas_.size(); + ZipOutputStream zos = new ZipOutputStream(os); + if (size == 0) + throw new Exception("Data is null"); + for (int i = 0; i < size; i++) + { + DataInstance di = datas_.get(i); + if (di instanceof InputStreamDataInstance) + { + InputStream is = di.getInputStream(); + zos.putNextEntry(new ZipEntry(di.getEntryName())); + int len; + byte InputData[] = new byte[BUFFER]; + while ((len = is.read(InputData)) != EOF) + { + zos.write(InputData, 0, len); + } + zos.closeEntry(); + } + else if (di instanceof FileDataInstance) + { + di.setType("Zip"); + InputStream is = di.getInputStream(); + int len; + byte[] data = new byte[BUFFER]; + while ((len = is.read(data)) != EOF) + { + os.write(data, 0, len); + } + is.close(); + } + } + zos.close(); + os.close(); + } + + public void createJarFile(String fileName) throws Exception + { + File fileZip = new File(fileName + ".jar"); + FileOutputStream out = new FileOutputStream(fileZip); + JarOutputStream jos = new JarOutputStream(out); + int size = datas_.size(); + if (size < 0) + throw new Exception("Data size is null"); + for (int i = 0; i < size; i++) + { + DataInstance di = datas_.get(i); + + if (di instanceof InputStreamDataInstance) + { + String entryName = di.getEntryName(); + InputStream is = di.getInputStream(); + jos.putNextEntry(new ZipEntry(entryName)); + int len; + byte InputData[] = new byte[BUFFER]; + while ((len = is.read(InputData)) != EOF) + { + jos.write(InputData, 0, len); + } + jos.closeEntry(); + } + else if (di instanceof FileDataInstance) + { + di.getJarOut(true, jos); + } + } + jos.close(); + out.close(); + } + + public void createJar(OutputStream os) throws Exception + { + int size = datas_.size(); + JarOutputStream jos = new JarOutputStream(os); + if (size == 0) + throw new Exception("Data is null"); + for (int i = 0; i < size; i++) + { + DataInstance di = datas_.get(i); + if (di instanceof InputStreamDataInstance) + { + InputStream is = di.getInputStream(); + + jos.putNextEntry(new ZipEntry(di.getEntryName())); + int len; + byte InputData[] = new byte[BUFFER]; + while ((len = is.read(InputData)) != EOF) + { + jos.write(InputData, 0, len); + } + jos.closeEntry(); + is.close(); + } + else if (di instanceof FileDataInstance) + { + di.setType("Jar"); + InputStream is = di.getInputStream(); + int len; + byte[] data = new byte[BUFFER]; + while ((len = is.read(data)) != EOF) + { + os.write(data, 0, len); + } + is.close(); + } + } + jos.close(); + os.close(); + } + + public void cleanDataInstance() + { + int count = datas_.size(); + for (int i = 0; i < count; i++) + { + datas_.remove(i); + } + } + + abstract public static class DataInstance + { + protected String entryName_; + + protected String typeZip_; + + abstract public InputStream getInputStream(); + + abstract public void getJarOut(boolean containParent, JarOutputStream jos) throws Exception; + + abstract public void getZipOut(boolean containParent, ZipOutputStream zos) throws Exception; + + public String getEntryName() + { + return entryName_; + } + + public void setType(String typeZip) + { + typeZip_ = typeZip; + } + + public String getType() + { + return typeZip_; + } + + } + + public static class FileDataInstance extends DataInstance + { + private File file_; + + public FileDataInstance(String entryName, File file) + { + entryName_ = entryName; + file_ = file; + } + + @Override + public InputStream getInputStream() + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + if (getType().equals("Zip")) + { + ZipOutputStream zos = new ZipOutputStream(baos); + try + { + getZipOut(true, zos); + } + catch (Exception e) + { + LOG.error(e.getLocalizedMessage(), e); + } + } + else + { + JarOutputStream jos; + try + { + jos = new JarOutputStream(baos); + getJarOut(true, jos); + } + catch (Exception e) + { + LOG.error(e.getLocalizedMessage(), e); + } + } + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + + try + { + baos.close(); + } + catch (IOException e) + { + LOG.error(e.getLocalizedMessage(), e); + } + + return is; + } + + @Override + public void getJarOut(boolean containParent, JarOutputStream jos) throws Exception + { + String path = file_.getAbsolutePath(); + InputStream bufInput = null; + List list = listFile(file_); + if (file_.isDirectory()) + list.remove(file_); + if (list == null || list.size() < 1) + throw new Exception("nothing in the list"); + for (File f : list) + { + StringBuilder filePath = new StringBuilder(f.getAbsolutePath()); + + if (f.getAbsolutePath().startsWith(path)) + { + if (containParent && file_.isDirectory()) + { + filePath = new StringBuilder(file_.getName()); + filePath.append(File.separator); + filePath.append(f.getAbsolutePath().substring(path.length() + 1)); + } + else if (file_.isDirectory()) + { + filePath = new StringBuilder(f.getAbsolutePath().substring(path.length() + 1)); + } + else + { + filePath = new StringBuilder(file_.getName()); + } + } + + if (f.isFile()) + { + bufInput = new FileInputStream(f); + } + else + { + filePath.append("/"); + } + + addToArchive(jos, bufInput, filePath.toString()); + } + } + + private List listFile(File dir) + { + final List list = new ArrayList(); + if (dir.isFile()) + { + list.add(dir); + return list; + } + dir.listFiles(new FileFilter() + { + public boolean accept(File f) + { + if (f.isDirectory()) + list.addAll(listFile(f)); + list.add(f); + return true; + } + }); + return list; + } + + public ZipOutputStream addToArchive(ZipOutputStream zipOutput, InputStream input, String entryName1) + throws Exception + { + byte data[] = new byte[BUFFER]; + ZipEntry entry = new ZipEntry(entryName1); + zipOutput.putNextEntry(entry); + if (input != null) + { + int count; + while ((count = input.read(data, 0, BUFFER)) != EOF) + zipOutput.write(data, 0, count); + } + zipOutput.closeEntry(); + return zipOutput; + } + + public JarOutputStream addToArchive(JarOutputStream jarOutput, InputStream input, String entryName1) + throws Exception + { + byte data[] = new byte[BUFFER]; + JarEntry entry = new JarEntry(entryName1); + jarOutput.putNextEntry(entry); + if (input != null) + { + int count; + while ((count = input.read(data, 0, BUFFER)) != EOF) + jarOutput.write(data, 0, count); + } + jarOutput.closeEntry(); + return jarOutput; + } + + @Override + public void getZipOut(boolean containParent, ZipOutputStream zos) throws Exception + { + String path = file_.getAbsolutePath(); + InputStream bufInput = null; + List list = listFile(file_); + if (file_.isDirectory()) + list.remove(file_); + if (list == null || list.size() < 1) + throw new Exception("nothing in the list"); + for (File f : list) + { + StringBuilder filePath = new StringBuilder(f.getAbsolutePath()); + + if (f.getAbsolutePath().startsWith(path)) + { + if (containParent && file_.isDirectory()) + { + filePath = new StringBuilder(file_.getName()); + filePath.append(File.separator); + filePath.append(f.getAbsolutePath().substring(path.length() + 1)); + } + else if (file_.isDirectory()) + { + filePath = new StringBuilder(f.getAbsolutePath().substring(path.length() + 1)); + } + else + { + filePath = new StringBuilder(file_.getName()); + } + } + + if (f.isFile()) + { + bufInput = new FileInputStream(f); + } + else + { + filePath.append("/"); + } + + addToArchive(zos, bufInput, filePath.toString()); + } + } + } + + public static class InputStreamDataInstance extends DataInstance + { + private InputStream is_; + + public InputStreamDataInstance(String entryName, InputStream is) + { + entryName_ = entryName; + is_ = is; + } + + @Override + public InputStream getInputStream() + { + return is_; + } + + @Override + public void getJarOut(boolean containParent, JarOutputStream jos) throws Exception + { + + } + + @Override + public void getZipOut(boolean containParent, ZipOutputStream zos) throws Exception + { + + } + + } + +} diff --git a/core/services/src/test/java/org/exoplatform/services/compress/TestCompressData.java b/core/services/src/test/java/org/exoplatform/services/compress/TestCompressData.java new file mode 100644 index 00000000000..783995e1400 --- /dev/null +++ b/core/services/src/test/java/org/exoplatform/services/compress/TestCompressData.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.services.compress; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Created by The eXo Platform SAS Author : Chung Nguyen + * nguyenchung136@yahoo.com Feb 13, 2006 + */ +public class TestCompressData extends TestCase +{ + + public TestCompressData(String name) + { + super(name); + } + + public void testCompressData() throws Exception + { + CompressData compress = new CompressData(); + CompressData compressIS = new CompressData(); + InputStream in = new FileInputStream("src/test/resources/ZipService.java"); + InputStream in2 = new FileInputStream("src/test/resources/helper.txt"); + // ---------- TEST InputStream --------------// + compressIS.addInputStream("ZipService.java", in); + compressIS.addInputStream("helper.txt", in2); + compressIS.createJarFile("target/ZipServiceJar"); + compressIS.createZipFile("target/ZipServiceZip"); + in.close(); + in2.close(); + + // ----------- Test with Add File ------------------// + + File file = new File("src/test/resources/ZipService.java"); + File file2 = new File("src/test/resources/helper.txt"); + compress.addFile("ZipService.java", file); + compress.addFile("helper.txt", file2); + compress.createZipFile("target/testZipFile"); + compress.createJarFile("target/testJarFile"); + // compress.cleanDataInstance(); + // --------------- Test thu muc --------------------------------// + // TODO what is t? + // File folder = new File("/home/exo/setup/tailieu/chung/hcm/images"); + // File folder1 = new File("/home/exo/setup/tailieu/chung/hcm/xuly"); + // CompressData compressF = new CompressData(); + // compressF.addDir(folder); + // compressF.addDir(folder1); + // compressF.createZipFile("/home/exo/setup/tailieu/chung/hcm/TestZip"); + // compress.createJarFile("/home/exo/setup/tailieu/chung/hcm/TestJar"); + } + + /** + * Testcase based on http://jira.exoplatform.org/browse/KER-94 + * @throws Exception + */ + public void testCompressIS() throws Exception + { + + CompressData compressData = new CompressData(); + + File f1 = new File("src/test/resources/ZipService.java"); + File f2 = new File("src/test/resources/helper.txt"); + + compressData.addFile("ZipService.java", f1); + compressData.addFile("helper.txt", f2); + + OutputStream outStream = new FileOutputStream(new File("target/CompressedZipIS.zip")); + compressData.createZip(outStream); + outStream.close(); + + outStream = new FileOutputStream(new File("target/CompressedJarIS.jar")); + compressData.createJar(outStream); + outStream.close(); + + } +} diff --git a/core/services/src/test/resources/conf/portal/test-configuration.xml b/core/services/src/test/resources/conf/portal/test-configuration.xml index b430d1b9744..20b54cb2885 100644 --- a/core/services/src/test/resources/conf/portal/test-configuration.xml +++ b/core/services/src/test/resources/conf/portal/test-configuration.xml @@ -30,4 +30,10 @@ + + + org.exoplatform.services.compress.CompressData + org.exoplatform.services.compress.CompressData + + diff --git a/core/webui-administration/pom.xml b/core/webui-administration/pom.xml index 9f574bf3595..1004e59b5f5 100755 --- a/core/webui-administration/pom.xml +++ b/core/webui-administration/pom.xml @@ -23,10 +23,6 @@ io.meeds.commons commons-component-common - - io.meeds.core - exo.core.component.organization.api - io.meeds.core exo.core.component.security.core diff --git a/core/webui-explorer/pom.xml b/core/webui-explorer/pom.xml index 50ae84965c5..77d987cd95c 100644 --- a/core/webui-explorer/pom.xml +++ b/core/webui-explorer/pom.xml @@ -40,10 +40,6 @@ io.meeds.commons commons-component-common - - io.meeds.core - exo.core.component.organization.api - io.meeds.core exo.core.component.security.core diff --git a/core/webui/pom.xml b/core/webui/pom.xml index 5e0fb6cd26b..3fe2faf1467 100644 --- a/core/webui/pom.xml +++ b/core/webui/pom.xml @@ -33,10 +33,6 @@ io.meeds.commons commons-component-common - - io.meeds.core - exo.core.component.organization.api - io.meeds.core exo.core.component.security.core diff --git a/ecm-wcm-extension/pom.xml b/ecm-wcm-extension/pom.xml index a7ca5fdcb2e..67148a191b8 100644 --- a/ecm-wcm-extension/pom.xml +++ b/ecm-wcm-extension/pom.xml @@ -41,11 +41,6 @@ commons-component-common runtime - - io.meeds.core - exo.core.component.organization.api - runtime - org.exoplatform.ecms ecms-core-publication diff --git a/ext/authoring/webui/pom.xml b/ext/authoring/webui/pom.xml index 80919884c43..4b94e07bccd 100644 --- a/ext/authoring/webui/pom.xml +++ b/ext/authoring/webui/pom.xml @@ -18,10 +18,6 @@ io.meeds.commons commons-component-common - - io.meeds.core - exo.core.component.organization.api - org.exoplatform.ecms ecms-core-publication diff --git a/testsuite/test/pom.xml b/testsuite/test/pom.xml index 92681c53723..a06cfc381ba 100644 --- a/testsuite/test/pom.xml +++ b/testsuite/test/pom.xml @@ -16,10 +16,6 @@ io.meeds.commons commons-testing - - io.meeds.core - exo.core.component.organization.api - io.meeds.core exo.core.component.security.core