Skip to content

Commit

Permalink
add dependency checks and some refactoring, version 0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
anneferger committed Jun 27, 2023
1 parent 55371b5 commit 420e1f6
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 63 deletions.
38 changes: 37 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pl.psnc.dl.ege</groupId>
<artifactId>ege-framework</artifactId>
<version>0.5.2</version>
<version>0.5.3</version>
<name>EGE Framework</name>
<properties>

Expand Down Expand Up @@ -137,6 +137,42 @@
</plugin>
</plugins>
</reporting>-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<failOnViolation>false</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>
check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>8.2.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>pl.psnc.dl.ege</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pl/psnc/dl/ege/ExceptionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface ExceptionListener {
*
* @param ex received exception
*/
public void catchException(Exception ex);
void catchException(Exception ex);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public interface ConfigurableConverter extends Converter {
* @param params converters parameters
* @throws EGEException
*/
public void configure(Map<String,String> params) throws EGEException;
void configure(Map<String,String> params) throws EGEException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Collection;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -60,7 +59,7 @@
*
* @author mariuszs
*/
public class EGEConfigurationManager
public final class EGEConfigurationManager
{

private final static String EXTENSION_POINT_ID = "pl.psnc.dl.ege.root";
Expand Down Expand Up @@ -121,7 +120,7 @@ private List<PluginLocation> getLocationsList(String dirRegex)
int counter = 0;
while (locs.hasMoreElements()) {
final URL location = locs.nextElement();
String matchString = "^(jar:[a-zA-Z][a-zA-Z0-9\\+\\-\\.]*:.*\\!/).*plugin.xml.*{1}$";
String matchString = "^(jar:[a-zA-Z][a-zA-Z0-9\\+\\-\\.]*:.*\\!/).*plugin.xml.*\\{1\\}$";
Pattern pattern = Pattern.compile(matchString);
Matcher matcher = pattern.matcher(location.toExternalForm());
LOGGER.debug("Found : " + location.toExternalForm());
Expand All @@ -132,7 +131,7 @@ private List<PluginLocation> getLocationsList(String dirRegex)
try {
String pluginDirectory = getDirectoryName(location,
"plugin" + counter);
System.out.println("Location and PluginDirectory " + location + " " + pluginDirectory);
LOGGER.debug("Location and PluginDirectory " + location + " " + pluginDirectory);
File directory = unpackZIP(location, pluginDirectory);
if (directory == null) {
continue;
Expand Down Expand Up @@ -389,13 +388,11 @@ private List<PluginWrapper> getAllComponents(ExtensionPoint ep)
{
List<PluginWrapper> plugins = new ArrayList();
List<Extension> extensions = new ArrayList(ep.getConnectedExtensions());
if(ep.getId().equals("XslConverter")) {
if(ep.getId().equals("XslConverter") && extensions.size() > 0) {
// search for all plugin.xml files in stylesheets and add the extensions
if(extensions.size() > 0)
getXslExtensions(extensions, ep);
}
for (Iterator iter = extensions.iterator(); iter.hasNext();) {
Extension element = (Extension) iter.next();
for (Extension element : extensions) {
try {
pluginManager.activatePlugin(element
.getDeclaringPluginDescriptor().getId());
Expand Down Expand Up @@ -465,7 +462,6 @@ private void getXslExtensions(List<Extension> extensions, ExtensionPoint ep) {
List<Properties> props = handler.getProperties();
List<String> ids = handler.getIds();
Properties params = null;

for(int i = 0; i<props.size(); i++) {
MockExtension mockExtension = new MockExtension(ids.get(i),
extensions.get(0).getDeclaringPluginDescriptor());
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/pl/psnc/dl/ege/configuration/EGEConstants.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package pl.psnc.dl.ege.configuration;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import java.io.FileInputStream;
import org.apache.logging.log4j.Logger;
Expand All @@ -23,8 +21,8 @@ public final class EGEConstants {

static {
try {
System.out.println(PATH);
oxgProps.load(new FileInputStream(PATH + File.separator + "oxgarage.properties"));
LOGGER.debug(PATH);
oxgProps.load(new FileInputStream(PATH + File.separator + "oxgarage.properties"));
} catch (java.io.IOException e) {
try {
oxgProps.load(new FileInputStream(PATH + File.separator + "oxgarage.properties"));
Expand Down Expand Up @@ -69,13 +67,13 @@ public final class EGEConstants {
public static final String BUFFER_TEMP_PATH = TEMP_PATH + File.separator + "buff";

static {
boolean success = (new File(BUFFER_TEMP_PATH)).mkdirs();
boolean success = new File(BUFFER_TEMP_PATH).mkdirs();
if (!success) {
LOGGER.error("Could not create dir " + BUFFER_TEMP_PATH);
}
}
static {
boolean success = (new File(EGE_EXT_DIRECTORY)).mkdirs();
boolean success = new File(EGE_EXT_DIRECTORY).mkdirs();
if (!success) {
LOGGER.error("Could not create dir " + EGE_EXT_DIRECTORY);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pl/psnc/dl/ege/utils/DataBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,9 @@ public InputStream getStream()
*/
public void deleteFile()
{
if (!os.isInMemory()) {
if (os.getFile().exists()) {
if (!os.isInMemory() && os.getFile().exists()) {
LOGGER.debug("Removing tmp file : " + os.getFile());
os.getFile().delete();
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/pl/psnc/dl/ege/utils/EGEIOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ public static void constructZip(File file, ZipOutputStream out, String dir)

File[] files = file.listFiles();

for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
constructZip(files[i], out, dir + files[i].getName() + "/");
for (File f : files) {
if (f.isDirectory()) {
constructZip(f, out, dir + f.getName() + "/");
continue;
}

// read file
try {
fi = new FileInputStream(files[i]);
fi = new FileInputStream(f);
origin = new BufferedInputStream(fi, BUFFER);

// create zip entry
ZipEntry entry = new ZipEntry(dir + files[i].getName());
ZipEntry entry = new ZipEntry(dir + f.getName());

// add entries to ZIP file
out.putNextEntry(entry);
Expand Down Expand Up @@ -275,6 +275,7 @@ public static void unzipStream(InputStream in, File outputDir)
finally {
dest.flush();
dest.close();
fos.close();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pl/psnc/dl/ege/utils/IOResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IOResolver {
* @param dir
* @throws IOException
*/
public void decompressStream(InputStream is, File dir) throws IOException;
void decompressStream(InputStream is, File dir) throws IOException;

/**
* Method should be responsible for compressing output data received from any of
Expand All @@ -34,6 +34,6 @@ public interface IOResolver {
* @return
* @throws IOException
*/
public void compressData(File dir, OutputStream os) throws IOException;
void compressData(File dir, OutputStream os) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ else if (queries.length == 1) {
private String[] resolveQueries()
{
String params = request.getRequestURL().toString();
params = (params.endsWith(SLASH) ? params : params + SLASH);
params = params.endsWith(SLASH) ? params : params + SLASH;
params = params.substring(params.indexOf(CONVERSIONS_SLICE_BASE),
params.length());
String[] queries = params.split(SLASH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void startElement(String uri, String localName, String name,
throws SAXException
{
if (localName.equals("conversion")) {
currentIndex = Integer.parseInt((attributes.getValue("index")));
currentIndex = Integer.parseInt(attributes.getValue("index"));
Map<String,String> props = properties.get(currentIndex);
if(props!=null){
throw new SAXException("Error reading properties: vertices with same index ("+currentIndex+") found!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package pl.psnc.dl.ege.webapp.request;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class CustomizationRequestResolver extends RequestResolver {
public static final String CUSTOMIZATION_SLICE_BASE = "Customization";

private static final String EN = "en";

private static final Logger LOGGER = LogManager
.getLogger(CustomizationRequestResolver.class);

public CustomizationRequestResolver(HttpServletRequest request, Method method)
throws RequestResolvingException
{
Expand Down Expand Up @@ -81,7 +73,7 @@ private void resolveGET()
private String[] resolveQueries()
{
String params = request.getRequestURL().toString();
params = (params.endsWith(SLASH) ? params : params + SLASH);
params = params.endsWith(SLASH) ? params : params + SLASH;
params = params.replaceFirst(".*" + CUSTOMIZATION_SLICE_BASE + "\\/", "");

String[] queries = params.split(SLASH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void resolveGET() throws RequestResolvingException{
private String[] resolveQueries()
{
String params = request.getRequestURL().toString();
params = (params.endsWith(SLASH) ? params : params + SLASH);
params = params.endsWith(SLASH) ? params : params + SLASH;
params = params.substring(params.indexOf(SLICE_BASE),
params.length());
String[] queries = params.split(SLASH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public String encodeDataType(DataType dataType)
public DataType decodeDataType(String uriPart)
{
try {
String[] partial = (URLDecoder.decode(uriPart, "UTF-8"))
String[] partial = URLDecoder.decode(uriPart, "UTF-8")
.split(SPLITTER);
DataType dataType = null;
String mime = partial[1] + SLASH + partial[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void resolveGET() throws RequestResolvingException{
private String[] resolveQueries()
{
String params = request.getRequestURL().toString();
params = (params.endsWith(SLASH) ? params : params + SLASH);
params = params.endsWith(SLASH) ? params : params + SLASH;
params = params.substring(params.indexOf(SLICE_BASE),
params.length());
String[] queries = params.split(SLASH);
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/pl/psnc/dl/ege/webapp/servlethelpers/Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public class Conversion {

private static final String EZP_EXT = ".ezp";

private static final String FORMAT_DOCX = "docx";

private static final String FORMAT_ODT = "oo";

private static final String APPLICATION_MSWORD = "application/msword";

private static final String APPLICATION_EPUB = "application/epub+zip";
Expand Down Expand Up @@ -136,7 +132,7 @@ protected static void printConversionsPaths(HttpServletResponse response,
StringBuffer pathopt = new StringBuffer();
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ((rr.getRequest().getServerPort() == 80 || rr.getRequest().getServerPort() == 443) ? "" : ":" + rr.getRequest().getServerPort()) +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().endsWith(
RequestResolver.SLASH) ? "" : "/");
resp.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
resp.append("<conversions-paths xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" +
Expand Down Expand Up @@ -172,7 +168,7 @@ protected static void printConversionsPaths(HttpServletResponse response,
if (paramsDefs.length() > 0) {
Properties props = new Properties();
props.loadFromXML(new ByteArrayInputStream(paramsDefs.getBytes("UTF-8")));
Set<Object> keySet = new TreeSet(props.keySet());
Set<Object> keySet = new TreeSet<Object>(props.keySet());
for (Object key : keySet) {
if (!key.toString().endsWith(".type")) {
pathopt.append("<property id=\"" + key
Expand Down Expand Up @@ -216,7 +212,7 @@ protected static void printConversionPossibilities(HttpServletResponse response,
try {
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ((rr.getRequest().getServerPort() == 80 || rr.getRequest().getServerPort() == 443) ? "" : ":" + rr.getRequest().getServerPort()) +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().endsWith(
RequestResolver.SLASH) ? "" : "/");
String prefix = rr.getRequest().getRequestURL().toString()
+ (rr.getRequest().getRequestURL().toString().endsWith(SLASH) ? ""
Expand Down Expand Up @@ -276,7 +272,7 @@ protected static void performConversion(HttpServletResponse response,
InputStream is = null;
String fname;
for (ConversionsPath path : cp) {
if ((pathFrame.size() - 1) != path.getPath().size()) {
if (pathFrame.size() - 1 != path.getPath().size()) {
continue;
}
found = true;
Expand Down Expand Up @@ -366,7 +362,7 @@ private static void doConvert(HttpServletResponse response,
ConversionRequestResolver rr,
EGE ege,
ConversionsPath cpath,
InputStream ins,
InputStream instr,
String fname,
FileItemIterator iter,
File buffDir)
Expand Down Expand Up @@ -411,7 +407,7 @@ private static void doConvert(HttpServletResponse response,
+ File.separator + newTemp + EZP_EXT);
fos = new FileOutputStream(zipFile);
ior.compressData(buffDir, fos);
ins = new FileInputStream(zipFile);
InputStream ins = new FileInputStream(zipFile);
File szipFile = new File(EGEConstants.BUFFER_TEMP_PATH
+ File.separator + newTemp + ZIP_EXT);
fos = new FileOutputStream(szipFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void printAvailableCustomizationSettings(HttpServletResponse response,
}
String baseprefix = rr.getRequest().getScheme() + "://" +
rr.getRequest().getServerName() + ((rr.getRequest().getServerPort() == 80 || rr.getRequest().getServerPort() == 443) ? "" : ":" + rr.getRequest().getServerPort()) +
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().toString().endsWith(
rr.getRequest().getContextPath() + (rr.getRequest().getContextPath().endsWith(
RequestResolver.SLASH) ? "" : "/");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<customizations xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"" +
Expand All @@ -102,6 +102,7 @@ private void printAvailableCustomizationSettings(HttpServletResponse response,
out.println("</customization-setting>");
}
out.println("</customizations>");
out.close();
} catch (IOException ex) {
throw new ServletException(ex);
}
Expand Down Expand Up @@ -194,7 +195,7 @@ private void performCustomization(String[] csString, RequestResolver rr,
localCustomizationFile = fields.get("customization");

String filename = (usedCustomization.startsWith("c-") ? usedCustomization.substring(2) : usedCustomization);
if (usedCustomization == "c-mei-local") {
if (usedCustomization.equals("c-mei-local")) {
try {
filename = ((File) fields.get("customization")).getName();
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 420e1f6

Please sign in to comment.