Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docx4j on Websphere Liberty #411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
.settings/
bin/
target/
/dist/
bin-testOutput/
.directory
.idea
.project
.classpath
.flattened-pom.xml
tmp/
release-zips/
patches/
**/target/*
*.iml
**/.idea/*
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.docx4j.jaxb.NamespacePrefixMapperUtils;
import org.docx4j.jaxb.NamespacePrefixMappings;

public class NamespacePrefixMapper extends com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator {
public class NamespacePrefixMapper extends com.sun.xml.bind.marshaller.NamespacePrefixMapper implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator {

// Must use 'internal' for Java 6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.docx4j.jaxb.McIgnorableNamespaceDeclarator;
import org.docx4j.jaxb.NamespacePrefixMapperInterface;

public class NamespacePrefixMapperRelationshipsPart extends com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator {
public class NamespacePrefixMapperRelationshipsPart extends com.sun.xml.bind.marshaller.NamespacePrefixMapper implements NamespacePrefixMapperInterface, McIgnorableNamespaceDeclarator {

// Must use 'internal' for Java 6

Expand Down
6 changes: 0 additions & 6 deletions docx4j-JAXB-ReferenceImpl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>

<!--

For Maven artifacts, see https://github.com/eclipse-ee4j/jaxb-ri#maven-artifacts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.docx4j.jaxb.ri;

import com.sun.xml.bind.v2.ContextFactory;
import org.docx4j.XmlUtils;
import org.docx4j.jaxb.Context;
import org.docx4j.jaxb.NamespacePrefixMapperUtils;
Expand All @@ -17,7 +18,7 @@ public class MarshalTest {
public void JAXBImplementationTest() throws JAXBException {

java.lang.ClassLoader classLoader = NamespacePrefixMapperUtils.class.getClassLoader();
JAXBContext testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader );
JAXBContext testContext = ContextFactory.createContext("org.docx4j.relationships",classLoader, null);

assertEquals("com.sun.xml.bind.v2.runtime.JAXBContextImpl", testContext.getClass().getName() );
}
Expand Down
5 changes: 5 additions & 0 deletions docx4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@
<version>1.0.1</version>
</dependency>
-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamSource;

import com.sun.xml.bind.v2.ContextFactory;
import org.apache.commons.io.FileUtils;
import org.docx4j.XmlUtils;
import org.docx4j.openpackaging.exceptions.Docx4JException;
Expand Down Expand Up @@ -65,7 +66,7 @@ public Word2003XmlConverter(Source source) throws JAXBException, Docx4JException
java.lang.ClassLoader classLoader = Word2003XmlConverter.class.getClassLoader();

JAXBResult result = new JAXBResult(
JAXBContext.newInstance("org.docx4j.convert.in.word2003xml", classLoader) );
ContextFactory.createContext("org.docx4j.convert.in.word2003xml", classLoader, null) );
XmlUtils.transform(source, xslt, null, result);

// set the unmarshalled content tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import com.sun.xml.bind.v2.ContextFactory;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -131,7 +132,7 @@ public final static Map<String, MicrosoftFonts.Font> getMsFontsFilenames() {
private final static void setupMicrosoftFontFilenames() throws Exception {

java.lang.ClassLoader classLoader = BestMatchingMapper.class.getClassLoader();
JAXBContext msFontsContext = JAXBContext.newInstance("org.docx4j.fonts.microsoft", classLoader);
JAXBContext msFontsContext = ContextFactory.createContext("org.docx4j.fonts.microsoft", classLoader, null);

Unmarshaller u = msFontsContext.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Expand Down Expand Up @@ -193,7 +194,7 @@ private static PhysicalFont getPhysicalFontByKey(String key) {
private final static void setupExplicitSubstitutionsMap() throws Exception {

java.lang.ClassLoader classLoader = BestMatchingMapper.class.getClassLoader();
JAXBContext substitutionsContext = JAXBContext.newInstance("org.docx4j.fonts.substitutions", classLoader);
JAXBContext substitutionsContext = ContextFactory.createContext("org.docx4j.fonts.substitutions", classLoader, null);

Unmarshaller u2 = substitutionsContext.createUnmarshaller();
u2.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import com.sun.xml.bind.v2.ContextFactory;
import org.docx4j.utils.ResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -45,7 +46,7 @@ private final static void setupMicrosoftFontsRegistry() throws Exception {
// filenamesToMsFontNames = new HashMap<String, String>();

java.lang.ClassLoader classLoader = MicrosoftFontsRegistry.class.getClassLoader();
JAXBContext msFontsContext = JAXBContext.newInstance("org.docx4j.fonts.microsoft", classLoader);
JAXBContext msFontsContext = ContextFactory.createContext("org.docx4j.fonts.microsoft", classLoader, null);

Unmarshaller u = msFontsContext.createUnmarshaller();
u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler());
Expand Down
34 changes: 18 additions & 16 deletions docx4j-core/src/main/java/org/docx4j/jaxb/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import com.sun.xml.bind.v2.ContextFactory;
import com.sun.xml.bind.v2.JAXBContextFactory;
import org.apache.commons.io.IOUtils;
import org.docx4j.utils.ResourceUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,7 +105,7 @@ public static JAXBImplementation getJaxbImplementation() {


try {
// JAXBContext.newInstance uses the context class loader of the current thread.
// ContextFactory.createContext uses the context class loader of the current thread.
// To specify the use of a different class loader,
// either set it via the Thread.setContextClassLoader() api
// or use the newInstance method.
Expand All @@ -117,7 +119,7 @@ public static JAXBImplementation getJaxbImplementation() {

java.lang.ClassLoader classLoader = Context.class.getClassLoader();

tempContext = JAXBContext.newInstance("org.docx4j.wml:org.docx4j.w14:org.docx4j.w15:" +
tempContext = ContextFactory.createContext("org.docx4j.wml:org.docx4j.w14:org.docx4j.w15:" +
"org.docx4j.com.microsoft.schemas.office.word.x2006.wordml:" +
"org.docx4j.dml:org.docx4j.dml.chart:org.docx4j.dml.chart.x2007:org.docx4j.dml.chartDrawing:org.docx4j.dml.compatibility:org.docx4j.dml.diagram:org.docx4j.dml.lockedCanvas:org.docx4j.dml.picture:org.docx4j.dml.wordprocessingDrawing:org.docx4j.dml.spreadsheetdrawing:org.docx4j.dml.diagram2008:" +
// All VML stuff is here, since compiling it requires WML and DML (and MathML), but not PML or SML
Expand Down Expand Up @@ -222,21 +224,21 @@ public static JAXBImplementation getJaxbImplementation() {
} else {
log.warn("Using unexpected JAXB: " + tempContext.getClass().getName());
}

jcThemePart = tempContext; //ContextFactory.createContext("org.docx4j.dml",classLoader );
jcDocPropsCore = ContextFactory.createContext("org.docx4j.docProps.core:org.docx4j.docProps.core.dc.elements:org.docx4j.docProps.core.dc.terms",classLoader, ProviderProperties.getProviderProperties() );
jcDocPropsCustom = ContextFactory.createContext("org.docx4j.docProps.custom",classLoader, ProviderProperties.getProviderProperties() );
jcDocPropsExtended = ContextFactory.createContext("org.docx4j.docProps.extended",classLoader, ProviderProperties.getProviderProperties() );
jcXmlPackage = ContextFactory.createContext("org.docx4j.xmlPackage",classLoader, ProviderProperties.getProviderProperties() );
jcRelationships = ContextFactory.createContext("org.docx4j.relationships",classLoader, ProviderProperties.getProviderProperties() );
jcCustomXmlProperties = ContextFactory.createContext("org.docx4j.customXmlProperties",classLoader, ProviderProperties.getProviderProperties() );
jcContentTypes = ContextFactory.createContext("org.docx4j.openpackaging.contenttype",classLoader, ProviderProperties.getProviderProperties() );

jcThemePart = tempContext; //JAXBContext.newInstance("org.docx4j.dml",classLoader );
jcDocPropsCore = JAXBContext.newInstance("org.docx4j.docProps.core:org.docx4j.docProps.core.dc.elements:org.docx4j.docProps.core.dc.terms",classLoader, ProviderProperties.getProviderProperties() );
jcDocPropsCustom = JAXBContext.newInstance("org.docx4j.docProps.custom",classLoader, ProviderProperties.getProviderProperties() );
jcDocPropsExtended = JAXBContext.newInstance("org.docx4j.docProps.extended",classLoader, ProviderProperties.getProviderProperties() );
jcXmlPackage = JAXBContext.newInstance("org.docx4j.xmlPackage",classLoader, ProviderProperties.getProviderProperties() );
jcRelationships = JAXBContext.newInstance("org.docx4j.relationships",classLoader, ProviderProperties.getProviderProperties() );
jcCustomXmlProperties = JAXBContext.newInstance("org.docx4j.customXmlProperties",classLoader, ProviderProperties.getProviderProperties() );
jcContentTypes = JAXBContext.newInstance("org.docx4j.openpackaging.contenttype",classLoader, ProviderProperties.getProviderProperties() );

jcSectionModel = JAXBContext.newInstance("org.docx4j.model.structure.jaxb",classLoader, ProviderProperties.getProviderProperties() );
jcSectionModel = ContextFactory.createContext("org.docx4j.model.structure.jaxb",classLoader, ProviderProperties.getProviderProperties() );

try {
//jcXmlDSig = JAXBContext.newInstance("org.plutext.jaxb.xmldsig",classLoader );
jcEncryption = JAXBContext.newInstance(
//jcXmlDSig = ContextFactory.createContext("org.plutext.jaxb.xmldsig",classLoader );
jcEncryption = ContextFactory.createContext(
"org.docx4j.com.microsoft.schemas.office.x2006.encryption:"
+ "org.docx4j.com.microsoft.schemas.office.x2006.keyEncryptor.certificate:"
+ "org.docx4j.com.microsoft.schemas.office.x2006.keyEncryptor.password:"
Expand All @@ -245,7 +247,7 @@ public static JAXBImplementation getJaxbImplementation() {
log.error(e.getMessage());
}

jcMCE = JAXBContext.newInstance("org.docx4j.mce",classLoader, ProviderProperties.getProviderProperties() );
jcMCE = ContextFactory.createContext("org.docx4j.mce",classLoader, ProviderProperties.getProviderProperties() );

log.debug(".. other contexts loaded ..");

Expand Down Expand Up @@ -274,7 +276,7 @@ public static JAXBContext getXslFoContext() {
Context tmp = new Context();
java.lang.ClassLoader classLoader = tmp.getClass().getClassLoader();

jcXslFo = JAXBContext.newInstance("org.plutext.jaxb.xslfo",classLoader );
jcXslFo = ContextFactory.createContext("org.plutext.jaxb.xslfo",classLoader, null);

} catch (JAXBException ex) {
log.error("Cannot determine XSL-FO context", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import com.sun.xml.bind.v2.ContextFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
Expand All @@ -36,7 +37,7 @@ public static synchronized Object getPrefixMapper() throws JAXBException {

if (testContext==null) {
java.lang.ClassLoader classLoader = NamespacePrefixMapperUtils.class.getClassLoader();
testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader );
testContext = ContextFactory.createContext("org.docx4j.relationships",classLoader, null);
}

if (testContext==null) {
Expand All @@ -52,8 +53,8 @@ public static synchronized Object getPrefixMapper() throws JAXBException {
throw new JAXBException("Can't create org.docx4j.jaxb.moxy.NamespacePrefixMapper", e);
}
}
if (testContext.getClass().getName().equals("com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl")) {
log.info("Using com.sun.xml.internal NamespacePrefixMapper");
if (testContext.getClass().getName().equals("com.sun.xml.bind.v2.runtime.JAXBContextImpl")) {
log.info("Using com.sun.xml NamespacePrefixMapper");
try {
Class c = Class.forName("org.docx4j.jaxb.suninternal.NamespacePrefixMapper");
prefixMapper = c.newInstance();
Expand Down Expand Up @@ -98,7 +99,7 @@ public static synchronized Object getPrefixMapperRelationshipsPart() throws JAXB

if (testContext==null) {
java.lang.ClassLoader classLoader = NamespacePrefixMapperUtils.class.getClassLoader();
testContext = JAXBContext.newInstance("org.docx4j.relationships",classLoader );
testContext = ContextFactory.createContext("org.docx4j.relationships",classLoader, null);
}

if (testContext==null) {
Expand All @@ -115,7 +116,7 @@ public static synchronized Object getPrefixMapperRelationshipsPart() throws JAXB
throw new JAXBException("Can't create org.docx4j.jaxb.moxy.NamespacePrefixMapper", e);
}
}
if (testContext.getClass().getName().equals("com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl")) {
if (testContext.getClass().getName().equals("com.sun.xml.bind.v2.runtime.JAXBContextImpl")) {
log.info("Using com.sun.xml.internal NamespacePrefixMapper");
try {
Class c = Class.forName("org.docx4j.jaxb.suninternal.NamespacePrefixMapperRelationshipsPart");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import com.sun.xml.bind.v2.ContextFactory;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.AbstractConversionSettings;
import org.docx4j.convert.out.html.HtmlCssHelper;
Expand Down Expand Up @@ -71,7 +72,7 @@ public String getImageTargetUri() {
static {

try {
jcSVG = JAXBContext.newInstance("org.plutext.jaxb.svg11");
jcSVG = ContextFactory.createContext("org.plutext.jaxb.svg11", SvgExporter.class.getClassLoader(), null);
oFactory = new ObjectFactory();

Source xsltSource = new StreamSource(
Expand Down
3 changes: 2 additions & 1 deletion docx4j-core/src/main/java/org/pptx4j/jaxb/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.xml.bind.JAXBContext;

import com.sun.xml.bind.v2.ContextFactory;
import org.docx4j.jaxb.ProviderProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class Context {

java.lang.ClassLoader classLoader = Context.class.getClassLoader();

jcPML = JAXBContext.newInstance("org.pptx4j.pml:" +
jcPML = ContextFactory.createContext("org.pptx4j.pml:" +
"org.docx4j.dml:org.docx4j.dml.chart:org.docx4j.dml.chartDrawing:org.docx4j.dml.compatibility:org.docx4j.dml.diagram:org.docx4j.dml.lockedCanvas:org.docx4j.dml.picture:org.docx4j.dml.wordprocessingDrawing:org.docx4j.dml.spreadsheetdrawing:" +
"org.pptx4j.com.microsoft.schemas.office.powerpoint.x2010.main:" +
"org.pptx4j.com.microsoft.schemas.office.powerpoint.x2012.main:" +
Expand Down
3 changes: 2 additions & 1 deletion docx4j-core/src/main/java/org/xlsx4j/jaxb/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.xml.bind.JAXBContext;

import com.sun.xml.bind.v2.ContextFactory;
import org.docx4j.jaxb.ProviderProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class Context {

java.lang.ClassLoader classLoader = Context.class.getClassLoader();

jcSML = JAXBContext.newInstance("org.xlsx4j.sml:" +
jcSML = ContextFactory.createContext("org.xlsx4j.sml:" +
"org.xlsx4j.schemas.microsoft.com.office.excel.x2010.spreadsheetDrawing:" +
"org.xlsx4j.schemas.microsoft.com.office.excel_2006.main:" +
"org.xlsx4j.schemas.microsoft.com.office.excel_2008_2.main",classLoader, ProviderProperties.getProviderProperties() );
Expand Down