diff -r 7c3b884eb33b -r 2ccd3660a736 core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/Streamer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/com.nokia.carbide.discovery.ui/src/com/nokia/carbide/internal/discovery/ui/wizard/Streamer.java Wed Aug 11 15:25:32 2010 -0500 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +package com.nokia.carbide.internal.discovery.ui.wizard; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.text.MessageFormat; +import java.util.Collection; + +import com.nokia.cpp.internal.api.utils.core.Pair; + +/** + * Serializes feature infos and repository URIs into output stream as XML + * Example serialized single test connection: + * + *
+ *<featuresConfiguration version="1">
+ *	<autoImportOriginalVersions value="false"/>
+ *	<repository uri="http://cdn.symbian.org/carbide/updates/3.0/discovery"/>
+ *	<feature id="com.nokia.example.feature.group" version="1.0.0"/>
+ *</featuresConfiguration>
+ * 
+ */ +class Streamer { + + private static final String CURRENT_VERSION = "1"; //$NON-NLS-1$ + + private static final String XML_HEADER = "\n\n"; //$NON-NLS-1$ + private static final String FEATURES_CONFIG_START = "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + private static final String FEATURES_CONFIG_END = "\n"; //$NON-NLS-1$ + private static final String AUTO_IMPORT_ORIGINAL_VERSION_FMT = "\t\n"; //$NON-NLS-1$ + private static final String REPOSITORY_FMT = "\t\n"; //$NON-NLS-1$ + private static final String FEATURE_FMT = "\t\n"; //$NON-NLS-1$ + + public static void writeToXML(OutputStream os, Collection repositories, Collection featureInfos) throws IOException { + os.write(XML_HEADER.getBytes()); + os.write(FEATURES_CONFIG_START.getBytes()); + + // write auto-import original versions + String originalVersionElement = MessageFormat.format(AUTO_IMPORT_ORIGINAL_VERSION_FMT, false); + os.write(originalVersionElement.getBytes()); + + // write the repositories + for (URI uri : repositories) { + String repositoryElement = MessageFormat.format(REPOSITORY_FMT, uri); + os.write(repositoryElement.getBytes()); + } + + // write the featureInfos + for (FeatureInfo info : featureInfos) { + String featureElement = MessageFormat.format(FEATURE_FMT, info.getId(), info.getVersion()); + os.write(featureElement.getBytes()); + } + + os.write(FEATURES_CONFIG_END.getBytes()); + os.close(); + } + + public static Pair, Collection> readFromXML(InputStream is) { + + return null; // TODO + } +}