if (extendedMetaDataOption.equals(Boolean.TRUE))
{
extendedMetaData =
resource == null || resource.getResourceSet() == null ?
ExtendedMetaData.INSTANCE :
new BasicExtendedMetaData(resource.getResourceSet().getPackageRegistry());
}
}
else
{
extendedMetaData = (ExtendedMetaData)options.get(XMLResource.OPTION_EXTENDED_META_DATA);
}
// set serialization options
if (!toDOM)
{
declareXML = !Boolean.FALSE.equals(options.get(XMLResource.OPTION_DECLARE_XML));
if (options.get(XMLResource.OPTION_FLUSH_THRESHOLD) instanceof Integer)
{
flushThreshold = (Integer)options.get(XMLResource.OPTION_FLUSH_THRESHOLD);
}
String temporaryFileName = null;
if (Boolean.TRUE.equals(options.get(XMLResource.OPTION_USE_FILE_BUFFER)))
{
try
{
temporaryFileName = File.createTempFile("XMLSave", null).getPath();
}
catch (IOException exception)
{
// If we can't create a temp file then we have to ignore the option.
}
}
Integer lineWidth = (Integer)options.get(XMLResource.OPTION_LINE_WIDTH);
int effectiveLineWidth = lineWidth == null ? Integer.MAX_VALUE : lineWidth;
String publicId = null, systemId = null;
if (resource != null && Boolean.TRUE.equals(options.get(XMLResource.OPTION_SAVE_DOCTYPE)))
{
publicId = resource.getPublicId();
systemId = resource.getSystemId();
}
if (useCache)
{
doc = ConfigurationCache.INSTANCE.getPrinter();
doc.reset(publicId, systemId, effectiveLineWidth, temporaryFileName);
escape = Boolean.TRUE.equals(options.get(XMLResource.OPTION_SKIP_ESCAPE)) ? null : ConfigurationCache.INSTANCE.getEscape();
}
else
{
doc = new XMLString(effectiveLineWidth, publicId, systemId, temporaryFileName);
escape = Boolean.TRUE.equals(options.get(XMLResource.OPTION_SKIP_ESCAPE)) ? null : new Escape();
}
if (Boolean.FALSE.equals(options.get(XMLResource.OPTION_FORMATTED)))
{
doc.setUnformatted(true);
}
escapeURI = Boolean.FALSE.equals(options.get(XMLResource.OPTION_SKIP_ESCAPE_URI)) ? escape : null;
if (options.containsKey(XMLResource.OPTION_ENCODING))
{
encoding = (String)options.get(XMLResource.OPTION_ENCODING);
}
else if (resource != null)
{
encoding = resource.getEncoding();
}
if (options.containsKey(XMLResource.OPTION_XML_VERSION))
{
xmlVersion = (String)options.get(XMLResource.OPTION_XML_VERSION);
}
else if (resource != null)
{
xmlVersion = resource.getXMLVersion();
}
if (escape != null)
{
int maxSafeChar = MAX_UTF_MAPPABLE_CODEPOINT;
if (encoding != null)
{
if (encoding.equalsIgnoreCase("ASCII") || encoding.equalsIgnoreCase("US-ASCII"))
{
maxSafeChar = MAX_ASCII_MAPPABLE_CODEPOINT;
}
else if (encoding.equalsIgnoreCase("ISO-8859-1"))
{
maxSafeChar = MAX_LATIN1_MAPPABLE_CODEPOINT;
}
}
escape.setMappingLimit(maxSafeChar);
if (!"1.0".equals(xmlVersion))
{
escape.setAllowControlCharacters(true);
}
escape.setUseCDATA(Boolean.TRUE.equals(options.get(XMLResource.OPTION_ESCAPE_USING_CDATA)));
}
resourceEntityHandler = (XMLResource.ResourceEntityHandler)options.get(XMLResource.OPTION_RESOURCE_ENTITY_HANDLER);
if (resourceEntityHandler instanceof XMLResource.URIHandler && !options.containsKey(XMLResource.OPTION_URI_HANDLER))
{
Map<Object, Object> newOptions = new LinkedHashMap<Object, Object>(options);
newOptions.put(XMLResource.OPTION_URI_HANDLER, resourceEntityHandler);
options = newOptions;
}
}
else
{
// DOM serialization
if (handler instanceof DefaultDOMHandlerImpl)
{
((DefaultDOMHandlerImpl)handler).setExtendedMetaData(extendedMetaData);
}
}
processDanglingHREF = (String) options.get(XMLResource.OPTION_PROCESS_DANGLING_HREF);
helper.setProcessDanglingHREF(processDanglingHREF);
map = (XMLResource.XMLMap) options.get(XMLResource.OPTION_XML_MAP);
if (map != null)
{
helper.setXMLMap(map);
if (map.getIDAttributeName() != null)
{
idAttributeName = map.getIDAttributeName();
}
}
if (resource != null)
{
eObjectToExtensionMap = resource.getEObjectToExtensionMap();
if (eObjectToExtensionMap.isEmpty())
{
eObjectToExtensionMap = null;
}
else if (extendedMetaData == null)
{
extendedMetaData =
resource.getResourceSet() == null ?
ExtendedMetaData.INSTANCE :
new BasicExtendedMetaData(resource.getResourceSet().getPackageRegistry());
}
}
if (extendedMetaData != null)
{