|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.carbide.internal.discovery.ui.wizard; |
|
18 |
|
19 import java.io.IOException; |
|
20 import java.io.InputStream; |
|
21 import java.io.OutputStream; |
|
22 import java.net.URI; |
|
23 import java.text.MessageFormat; |
|
24 import java.util.Collection; |
|
25 |
|
26 import com.nokia.cpp.internal.api.utils.core.Pair; |
|
27 |
|
28 /** |
|
29 * Serializes feature infos and repository URIs into output stream as XML |
|
30 * Example serialized single test connection: |
|
31 * |
|
32 * <blockquote><pre> |
|
33 *<featuresConfiguration version="1"> |
|
34 * <autoImportOriginalVersions value="false"/> |
|
35 * <repository uri="http://cdn.symbian.org/carbide/updates/3.0/discovery"/> |
|
36 * <feature id="com.nokia.example.feature.group" version="1.0.0"/> |
|
37 *</featuresConfiguration> |
|
38 * </pre></blockquote> |
|
39 */ |
|
40 class Streamer { |
|
41 |
|
42 private static final String CURRENT_VERSION = "1"; //$NON-NLS-1$ |
|
43 |
|
44 private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"; //$NON-NLS-1$ |
|
45 private static final String FEATURES_CONFIG_START = "<featuresConfiguration version=\"" + CURRENT_VERSION + "\">\n"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
46 private static final String FEATURES_CONFIG_END = "</featuresConfiguration>\n"; //$NON-NLS-1$ |
|
47 private static final String AUTO_IMPORT_ORIGINAL_VERSION_FMT = "\t<autoImportOriginalVersions value=\"{0}\"/>\n"; //$NON-NLS-1$ |
|
48 private static final String REPOSITORY_FMT = "\t<repository uri=\"{0}\"/>\n"; //$NON-NLS-1$ |
|
49 private static final String FEATURE_FMT = "\t<feature id=\"{0}\" version=\"{1}\"/>\n"; //$NON-NLS-1$ |
|
50 |
|
51 public static void writeToXML(OutputStream os, Collection<URI> repositories, Collection<FeatureInfo> featureInfos) throws IOException { |
|
52 os.write(XML_HEADER.getBytes()); |
|
53 os.write(FEATURES_CONFIG_START.getBytes()); |
|
54 |
|
55 // write auto-import original versions |
|
56 String originalVersionElement = MessageFormat.format(AUTO_IMPORT_ORIGINAL_VERSION_FMT, false); |
|
57 os.write(originalVersionElement.getBytes()); |
|
58 |
|
59 // write the repositories |
|
60 for (URI uri : repositories) { |
|
61 String repositoryElement = MessageFormat.format(REPOSITORY_FMT, uri); |
|
62 os.write(repositoryElement.getBytes()); |
|
63 } |
|
64 |
|
65 // write the featureInfos |
|
66 for (FeatureInfo info : featureInfos) { |
|
67 String featureElement = MessageFormat.format(FEATURE_FMT, info.getId(), info.getVersion()); |
|
68 os.write(featureElement.getBytes()); |
|
69 } |
|
70 |
|
71 os.write(FEATURES_CONFIG_END.getBytes()); |
|
72 os.close(); |
|
73 } |
|
74 |
|
75 public static Pair<Collection<URI>, Collection<FeatureInfo>> readFromXML(InputStream is) { |
|
76 |
|
77 return null; // TODO |
|
78 } |
|
79 } |