Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports 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 3 of the License, or
* (at your option) any later version.
*
* JasperReports 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 JasperReports. If not, see .
*/
package net.sf.jasperreports.util;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.map.ReferenceMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.exolab.castor.xml.XMLContext;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRPropertiesUtil;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.util.CompositeClassloader;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.util.VersionComparator;
import net.sf.jasperreports.engine.xml.JRXmlBaseWriter;
/**
* @author Teodor Danciu ([email protected])
*/
public class CastorUtil
{
private static final Log log = LogFactory.getLog(CastorUtil.class);
public static final String EXCEPTION_MESSAGE_KEY_MAPPINGS_LOADING_ERROR = "util.castor.mappings.loading.error";
/**
*
*/
private static final String CASTOR_READ_XML_CONTEXT_KEY = "net.sf.jasperreports.castor.read.xml.context";
private static final String CASTOR_WRITE_XML_CONTEXT_KEY = "net.sf.jasperreports.castor.write.xml.context";
private static final Object CONTEXT_KEY_NULL = new Object();
private JasperReportsContext jasperReportsContext;
private VersionComparator versionComparator;
/**
*
*/
private CastorUtil(JasperReportsContext jasperReportsContext)
{
this.jasperReportsContext = jasperReportsContext;
this.versionComparator = new VersionComparator();
}
/**
*
*/
public static CastorUtil getInstance(JasperReportsContext jasperReportsContext)
{
return new CastorUtil(jasperReportsContext);
}
private XMLContext getReadXmlContext()
{
return getXmlContext(CASTOR_READ_XML_CONTEXT_KEY, null);//always reading with the last version mappings
}
private XMLContext getWriteXmlContext()
{
String targetVersion = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(
JRXmlBaseWriter.PROPERTY_REPORT_VERSION);
if (log.isDebugEnabled())
{
log.debug("using write mappings for version " + targetVersion);
}
return getXmlContext(CASTOR_WRITE_XML_CONTEXT_KEY, targetVersion);
}
/**
*
*/
private XMLContext getXmlContext(String contextCacheKey, String version)
{
ClassLoader castorClassLoader = Mapping.class.getClassLoader();
ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
Object cacheKey;
ClassLoader contextClassLoader;
if (threadClassLoader == null || threadClassLoader.equals(castorClassLoader))
{
cacheKey = CONTEXT_KEY_NULL;
contextClassLoader = castorClassLoader;
}
else
{
cacheKey = threadClassLoader;
contextClassLoader = new CompositeClassloader(castorClassLoader, threadClassLoader);
}
Map