Index: PlatformConfiguration.java =================================================================== RCS file: /home/eclipse/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java,v retrieving revision 1.63 diff -u -r1.63 PlatformConfiguration.java --- PlatformConfiguration.java 23 Jun 2004 00:20:25 -0000 1.63 +++ PlatformConfiguration.java 3 Nov 2004 20:44:41 -0000 @@ -7,19 +7,20 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Phil Loats/Erxiang Liu (IBM Corp.) - fix to only use Foundation APIs *******************************************************************************/ package org.eclipse.update.internal.configurator; import java.io.*; import java.lang.reflect.*; import java.net.*; -import java.nio.channels.*; +//import java.nio.channels.*; import java.util.*; import javax.xml.parsers.*; -import javax.xml.transform.*; -import javax.xml.transform.dom.*; -import javax.xml.transform.stream.*; +//import javax.xml.transform.*; +//import javax.xml.transform.dom.*; +//import javax.xml.transform.stream.*; import org.eclipse.core.runtime.*; import org.eclipse.osgi.service.datalocation.*; @@ -40,9 +41,10 @@ */ public class PlatformConfiguration implements IPlatformConfiguration, IConfigurationConstants { + private static final String XML_ENCODING = "UTF-8"; private static PlatformConfiguration currentPlatformConfiguration = null; private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - private static final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + //private static final TransformerFactory transformerFactory = TransformerFactory.newInstance(); private Configuration config; private URL configLocation; @@ -52,7 +54,7 @@ private boolean featuresChangeStampIsValid; private long pluginsChangeStamp; private boolean pluginsChangeStampIsValid; - private FileLock lock; + //private FileLock lock; private static final String ECLIPSE = "eclipse"; //$NON-NLS-1$ private static final String CONFIG_HISTORY = "history"; //$NON-NLS-1$ @@ -214,11 +216,12 @@ SiteEntry result = config.getSiteEntry(key); if (result == null) { // retry with decoded URL string - try { - key = URLDecoder.decode(key, "UTF-8"); //$NON-NLS-1$ - } catch (UnsupportedEncodingException e) { - // ignore - } +// try { +// key = URLDecoder.decode(key, "UTF-8"); //$NON-NLS-1$ + key = URLDecoder.decode(key); +// } catch (UnsupportedEncodingException e) { +// // ignore +// } result = config.getSiteEntry(key); } @@ -746,26 +749,26 @@ * @param url configuration directory */ private void getConfigurationLock(URL url) { - if (!url.getProtocol().equals("file")) //$NON-NLS-1$ - return; +// if (!url.getProtocol().equals("file")) //$NON-NLS-1$ +// return; - File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE+ File.separator+CONFIG_FILE_LOCK_SUFFIX); - verifyPath(url); - try { - RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$ - lock = raf.getChannel().lock(); - } catch (IOException ioe) { - lock = null; - } +// File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE+ File.separator+CONFIG_FILE_LOCK_SUFFIX); +// verifyPath(url); +// try { +// RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$ +// lock = raf.getChannel().lock(); +// } catch (IOException ioe) { +// lock = null; +// } } private void clearConfigurationLock() { - if (lock != null) { - try { - lock.channel().close(); - } catch (IOException ioe) { - } - } +// if (lock != null) { +// try { +// lock.channel().close(); +// } catch (IOException ioe) { +// } +// } } @@ -1073,12 +1076,14 @@ return installURL; } + //Old saveASXML, has to use standard XML parser and use javax.tranform.* package. + /* private void saveAsXML(OutputStream stream) throws CoreException { StreamResult result = null; try { DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); - + if (config == null) throw Utils.newCoreException(Messages.getString("PlatformConfiguration.cannotSaveNonExistingConfig"),null); //$NON-NLS-1$ @@ -1086,8 +1091,8 @@ doc.appendChild(doc.createComment("Created on " + config.getDate().toString())); //$NON-NLS-1$ Element configElement = config.toXML(doc); doc.appendChild(configElement); - - // Write out to a file + + // Write out to a file . Transformer transformer=transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ @@ -1105,7 +1110,36 @@ result.setOutputStream(null); result = null; } - } + } + */ + + private void saveAsXML(OutputStream stream) throws CoreException,IOException { + OutputStreamWriter xmlWriter = new OutputStreamWriter(stream,XML_ENCODING); + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setExpandEntityReferences(false); + factory.setValidating(false); + factory.setIgnoringComments(true); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.newDocument(); + + if (config == null) + throw Utils.newCoreException(Messages.getString("PlatformConfiguration.cannotSaveNonExistingConfig"),null); //$NON-NLS-1$ + + config.setDate(new Date()); + Element configElement = config.toXML(doc); + doc.appendChild(configElement); + + XMLPrintHandler.printComment(xmlWriter,"Created on " + config.getDate().toString()); + XMLPrintHandler.printNode(xmlWriter,doc,XML_ENCODING); + + } catch (Exception e) { + throw Utils.newCoreException("", e); //$NON-NLS-1$ + } finally { + xmlWriter.close(); + xmlWriter = null; + } + } private void reconcile() throws CoreException { long lastChange = config.getDate().getTime(); Index: XMLPrintHandler.java =================================================================== RCS file: XMLPrintHandler.java diff -N XMLPrintHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ XMLPrintHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Erxiang Liu - initial API and implementation + *******************************************************************************/ +package org.eclipse.update.internal.configurator; + +import java.io.IOException; +import java.io.OutputStreamWriter; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + + +public class XMLPrintHandler { + // used to print XML file + public static final String XML_COMMENT_END_TAG = "-->"; + public static final String XML_COMMENT_BEGIN_TAG = "