Skip to content

Commit

Permalink
Updated the code for dotCMS 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yasindilekci committed Sep 26, 2016
1 parent 4305836 commit b2a118e
Show file tree
Hide file tree
Showing 35 changed files with 1,021 additions and 29 deletions.
5 changes: 0 additions & 5 deletions MANIFEST.MF

This file was deleted.

3 changes: 0 additions & 3 deletions build.xml

This file was deleted.

6 changes: 0 additions & 6 deletions conf/toolbox-ext.xml

This file was deleted.

Binary file removed lib/SuperCSV-with_src-1.52.jar
Binary file not shown.
Binary file removed lib/dom4j-1.6.1.jar
Binary file not shown.
Binary file removed lib/geronimo-stax-api_1.0_spec-1.0.jar
Binary file not shown.
Binary file removed lib/poi-ooxml-3.6-20091214.jar
Binary file not shown.
Binary file removed lib/poi-ooxml-schemas-3.6-20091214.jar
Binary file not shown.
Binary file removed lib/xmlbeans-2.3.0.jar
Binary file not shown.
162 changes: 162 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>nl.isaac.dotcms.plugin.excelreader</groupId>
<artifactId>isaac-dotcms-excelreader</artifactId>
<version>3.2.1</version>
<packaging>bundle</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<prerequisites>
<maven>3.0</maven>
</prerequisites>

<organization>
<name>ISAAC Software Solutions</name>
<url>http://www.isaac.nl</url>
</organization>

<repositories>
<repository>
<id>dotcms</id>
<name>dotcms Maven Repository</name>
<url>http://repo.dotcms.com/artifactory/repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>nl.isaac.dotcms.excelreader.osgi.Activator</Bundle-Activator>
<Import-Package> </Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>

<Data-Files>conf,ext</Data-Files>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.dotcms</groupId>
<artifactId>dotcms</artifactId>
<version>3.2.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.commons-io</artifactId>
<version>2.0.1_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<version>1.8.6</version>
<artifactId>quartz</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.felix</artifactId>
<version>4.2.1_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.org.apache.felix.http.bundle</artifactId>
<version>2.2.0_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.commons-lang</artifactId>
<version>2.4_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.tika-app</artifactId>
<version>1.3_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.portlet</artifactId>
<version>1.0_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.dotcms.lib</groupId>
<artifactId>dot.jettison</artifactId>
<version>1.1_1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.3.1</version>
</dependency>

</dependencies>
</project>
26 changes: 26 additions & 0 deletions src/main/assembly/create-zipfile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd">

<formats>
<format>zip</format>
</formats>

<includeBaseDirectory>false</includeBaseDirectory>

<fileSets>
<fileSet>
<directory>/src/main/java/</directory>
<outputDirectory>/isaac-dotcms-excelreader/src/</outputDirectory>
</fileSet>
<fileSet>
<directory>/src/main/resources/</directory>
<outputDirectory>/isaac-dotcms-excelreader/</outputDirectory>
</fileSet>
<fileSet>
<directory>/target/lib</directory>
<outputDirectory>/isaac-dotcms-excelreader/lib</outputDirectory>
</fileSet>
</fileSets>
</assembly>
24 changes: 24 additions & 0 deletions src/main/java/nl/isaac/dotcms/excelreader/osgi/Activator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nl.isaac.dotcms.excelreader.osgi;

import nl.isaac.dotcms.excelreader.viewtool.ExcelReaderTool;
import nl.isaac.dotcms.util.osgi.ExtendedGenericBundleActivator;
import nl.isaac.dotcms.util.osgi.ViewToolScope;

import com.dotcms.repackage.org.osgi.framework.BundleContext;

public class Activator extends ExtendedGenericBundleActivator {

@Override
public void start(BundleContext context) throws Exception {
// Default DotCMS call
initializeServices(context);

addViewTool(context, ExcelReaderTool.class, "excel", ViewToolScope.REQUEST);
}

@Override
public void stop(BundleContext context) throws Exception {
unregisterServices(context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
import java.util.Map;
import java.util.Map.Entry;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.supercsv.io.CsvMapReader;
import org.supercsv.io.ICsvMapReader;
import org.supercsv.prefs.CsvPreference;

import com.dotcms.repackage.org.apache.poi.ss.usermodel.Cell;
import com.dotcms.repackage.org.apache.poi.ss.usermodel.DateUtil;
import com.dotcms.repackage.org.apache.poi.ss.usermodel.Row;
import com.dotcms.repackage.org.apache.poi.ss.usermodel.Sheet;
import com.dotcms.repackage.org.apache.poi.ss.usermodel.Workbook;
import com.dotcms.repackage.org.apache.poi.ss.usermodel.WorkbookFactory;
import com.dotmarketing.util.Logger;

public class ExcelUtil {
Expand All @@ -38,7 +38,7 @@ public class ExcelUtil {
* all the other rows are parsed using the given RowStrategy. All thrown exceptions in the row
* are stored in the returned ExcelUtilStatus and returned after executing the stategy.
*
* @param fis The FileInputStream containing the excel sheet (.xls, not .xlsx)
* @param is The FileInputStream containing the excel sheet (.xls, not .xlsx)
* @param rowStrategy The method to perform on all the rows except for the header row
* @return an ExcelUtilStatus containing info about the executed rows
* @throws IOException when there's a problem with the excel sheet file
Expand Down Expand Up @@ -70,12 +70,12 @@ public static void executeStrategyOnExcelSheet(InputStream is, RowStrategy rowSt
}
}
} catch(Exception e) {
Logger.warn(ExcelUtil.class, "Can't read Excel file, trying csv format: " + e.getMessage());
bis.reset();
//TODO: catch the exceptions from the workbookfactory: IllegalArgumentException + IllegalFormatException
Logger.warn(ExcelUtil.class, "Can't read Excel file, trying csv format: " + e.getMessage());
ICsvMapReader inFile = new CsvMapReader(new InputStreamReader(bis), CsvPreference.EXCEL_PREFERENCE);
try {
final String[] header = inFile.getCSVHeader(true);
final String[] header = inFile.getHeader(true);
Map<String, String> stringMap;
while((stringMap = inFile.read(header)) != null) {
Map<String, Object> row = getStringMapAsMap(stringMap);
Expand All @@ -89,11 +89,7 @@ public static void executeStrategyOnExcelSheet(InputStream is, RowStrategy rowSt
} catch (IOException ioe) {
Logger.error(ExcelUtil.class, "Can't read excel file as CSV", ioe);
Logger.error(ExcelUtil.class, "Original WorkbookFactory excel reader error:", e);
} finally {
inFile.close();
}
} finally {
bis.close();
}

status.setFinished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.Map;
import java.util.TreeMap;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.dotcms.repackage.org.codehaus.jettison.json.JSONException;
import com.dotcms.repackage.org.codehaus.jettison.json.JSONObject;

/**
* The ExcelUtilStatus can be used to store import status messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @copyright Copyright (c) 2011 ISAAC Software Solutions B.V. (http://www.isaac.nl)
*/

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -17,18 +19,24 @@

import javax.servlet.http.HttpServletRequest;

import nl.isaac.dotcms.excelreader.osgi.Activator;
import nl.isaac.dotcms.excelreader.shared.RequestUtil;
import nl.isaac.dotcms.excelreader.util.DefaultRowStrategy;
import nl.isaac.dotcms.excelreader.util.ExcelReaderCacheGroupHandler;
import nl.isaac.dotcms.excelreader.util.ExcelReaderDotCMSFileKey;
import nl.isaac.dotcms.excelreader.util.ExcelReaderFileKey;
import nl.isaac.dotcms.excelreader.util.ExcelUtil;
import nl.isaac.dotcms.excelreader.util.ExcelUtilStatus;

import org.apache.velocity.tools.view.context.ViewContext;
import org.apache.velocity.tools.view.tools.ViewTool;

import com.dotcms.repackage.org.osgi.framework.FrameworkUtil;
import com.dotmarketing.beans.Host;
import com.dotmarketing.business.web.WebAPILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.Logger;
import com.liferay.portal.PortalException;
import com.liferay.portal.SystemException;
/**
Expand Down Expand Up @@ -84,6 +92,19 @@ public void sort(List<Map<String, Object>> sheet, String key) {
Collections.sort(sheet, new FieldComparator(key));
}

public List<Map<String, Object>> readTestExcel(String testFileName) {
DefaultRowStrategy strategy = new DefaultRowStrategy(true);
ExcelUtilStatus status = new ExcelUtilStatus();
try (InputStream is = FrameworkUtil.getBundle(Activator.class).getResource("ext/test/" + testFileName).openStream()) {
ExcelUtil.executeStrategyOnExcelSheet(is, strategy, status);
return strategy.getData();
} catch (IOException e) {
Logger.warn(this, "Exception while reading test excel file " + testFileName, e);
}

return null;
}

private class FieldComparator implements Comparator<Map<String, Object>> {
private String field;

Expand Down
Loading

0 comments on commit b2a118e

Please sign in to comment.