gump build fixing - move system properties tinkering into junit class

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-08-03 23:09:10 +00:00
parent 77315b425f
commit 5a4575bb8c
2 changed files with 16 additions and 35 deletions

View File

@ -22,8 +22,15 @@ package org.apache.poi.sl.draw.geom;
import java.io.InputStream;
import java.util.LinkedHashMap;
import javax.xml.bind.*;
import javax.xml.stream.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.EventFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
@ -37,7 +44,6 @@ import org.apache.poi.util.POILogger;
public class PresetGeometries extends LinkedHashMap<String, CustomGeometry> {
private final static POILogger LOG = POILogFactory.getLogger(PresetGeometries.class);
protected final static String BINDING_PACKAGE = "org.apache.poi.sl.draw.binding";
private static final String JAXPFACTORYID = "javax.xml.stream.XMLInputFactory";
protected static PresetGeometries _inst;
@ -53,8 +59,6 @@ public class PresetGeometries extends LinkedHashMap<String, CustomGeometry> {
}
};
fixXmlSystemProperties();
XMLInputFactory staxFactory = XMLInputFactory.newFactory();
XMLEventReader staxReader = staxFactory.createXMLEventReader(is);
XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter);
@ -115,21 +119,4 @@ public class PresetGeometries extends LinkedHashMap<String, CustomGeometry> {
return _inst;
}
public static void fixXmlSystemProperties() {
// handling for illegal system properties - mainly because of failing gump build
String xmlFactClass = System.getProperty(JAXPFACTORYID);
if (xmlFactClass != null) {
try {
Class.forName(xmlFactClass);
} catch (Exception e) {
LOG.log(POILogger.ERROR, "Invalid xml input factory config detected. ("+JAXPFACTORYID+"="+xmlFactClass+")");
try {
System.clearProperty(JAXPFACTORYID);
} catch (Exception e2) {
LOG.log(POILogger.ERROR, "Failed to remove invalid xml input factory", e2);
}
}
}
}
}

View File

@ -26,8 +26,6 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLInputFactory;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.util.JvmBugs;
import org.apache.poi.xslf.XSLFTestDataSamples;
@ -46,7 +44,7 @@ public class TestPPTX2PNG {
@BeforeClass
public static void activateJaxpDebug() {
jaxpDebugEnable = setDebugFld(true);
fixDefaultInputFactory();
setXmlInputFactory();
}
@AfterClass
@ -69,17 +67,13 @@ public class TestPPTX2PNG {
}
}
private static void fixDefaultInputFactory() {
String originalValue = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
private static void setXmlInputFactory() {
String propName = "javax.xml.stream.XMLInputFactory";
String propVal = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
try {
Field fld = XMLInputFactory.class.getDeclaredField("DEFAULIMPL");
fld.setAccessible(true);
String val = (String)fld.get(null);
if (!originalValue.equals(val)) {
System.out.println("DefaultXMLInputFactory illegal changed to: "+val);
fld.set(null, originalValue);
}
} catch (Exception e) {
Class.forName(propVal);
System.setProperty(propName, propVal);
} catch (Exception e){
// ignore
}
}