|
1 /* |
|
2 * Copyright (c) 2002 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 "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 */ |
|
18 |
|
19 |
|
20 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
21 #pragma warning (disable:4786) |
|
22 #include "Extract.h" |
|
23 #include "LayoutCompilerErr.h" |
|
24 #include "HtmlParse.h" |
|
25 #include "LayoutParse.h" |
|
26 #include "LayoutWriter.h" |
|
27 #include <fstream> |
|
28 #include <iostream> |
|
29 |
|
30 typedef LayoutProcessArgsErr<LayoutExtract> LayoutExtractArgsErr; |
|
31 |
|
32 |
|
33 int LayoutExtract::Extract(const vector<string>& args) |
|
34 { |
|
35 ParseArgs(args); |
|
36 |
|
37 THtmlParseLayout html; |
|
38 ifstream in(iDocName.c_str()); |
|
39 if (!in.is_open()) |
|
40 throw NotFoundErr(iDocName); |
|
41 cout << "reading html " << iDocName << endl; |
|
42 html.Parse(in); |
|
43 in.close(); |
|
44 |
|
45 TLayout* layout = &html; |
|
46 TLayParseLayout lay; |
|
47 if (iMergeName.size()) |
|
48 { |
|
49 ifstream merge(iMergeName.c_str()); |
|
50 if (!merge.is_open()) |
|
51 throw NotFoundErr(iDocName); |
|
52 cout << "reading layout " << iMergeName << endl; |
|
53 lay.Parse(merge); |
|
54 merge.close(); |
|
55 |
|
56 cout << "merging " << iDocName << " into " << iMergeName << endl; |
|
57 lay.Merge(TLayout::KMergeModeMerge, html); |
|
58 layout = &lay; |
|
59 } |
|
60 |
|
61 TLayoutWriter writer(*layout, iLayoutName); |
|
62 writer.Write(""); |
|
63 |
|
64 return 0; |
|
65 } |
|
66 |
|
67 void LayoutExtract::ParseArgs(const vector<string>& args) |
|
68 { |
|
69 if (args.size() < 4) |
|
70 throw LayoutExtractArgsErr(); |
|
71 |
|
72 iDocName = args[2]; |
|
73 |
|
74 int layoutIndex = 3; |
|
75 if (args[3][0] == '-') |
|
76 { |
|
77 if (args[3].size() < 3 || args[3][1] != 'o') |
|
78 throw LayoutExtractArgsErr(); |
|
79 |
|
80 iMergeName = args[3].substr(2); |
|
81 layoutIndex++; |
|
82 } |
|
83 |
|
84 if (args.size() <= layoutIndex) |
|
85 throw LayoutExtractArgsErr(); |
|
86 |
|
87 iLayoutName = args[layoutIndex]; |
|
88 } |
|
89 |
|
90 void LayoutExtract::ShowHelp(ostream& stream) |
|
91 { |
|
92 stream << endl; |
|
93 stream << "LayoutCompiler extract <docName> [-o<oldLayout>] <layoutName>" << endl; |
|
94 stream << " <docName> is the name of the HTML Layout specification" << endl; |
|
95 stream << " <oldLayout> is an optional layout file which the extracted layout will be" << endl; |
|
96 stream << " merged with" << endl; |
|
97 stream << " <layoutName> is the name of the resulting layout file" << endl; |
|
98 stream << " You can use the same name for <oldLayout> and <layoutName>" << endl; |
|
99 } |
|
100 |
|
101 // End of File |