Skip to content

Commit 11d1fd5

Browse files
authored
rework document tree (#452)
1 parent f7520c7 commit 11d1fd5

File tree

102 files changed

+6543
-4613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6543
-4613
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ set(ODR_SOURCE_FILES
8787
"src/odr/odr.cpp"
8888
"src/odr/quantity.cpp"
8989
"src/odr/style.cpp"
90+
"src/odr/table_dimension.cpp"
91+
"src/odr/table_position.cpp"
9092

9193
"${CMAKE_CURRENT_BINARY_DIR}/src/odr/internal/git_info.cpp"
9294
"src/odr/internal/magic.cpp"
@@ -99,15 +101,14 @@ set(ODR_SOURCE_FILES
99101
"src/odr/internal/cfb/cfb_util.cpp"
100102

101103
"src/odr/internal/common/document.cpp"
102-
"src/odr/internal/common/document_element.cpp"
103104
"src/odr/internal/common/file.cpp"
104105
"src/odr/internal/common/filesystem.cpp"
105106
"src/odr/internal/common/image_file.cpp"
106107
"src/odr/internal/common/path.cpp"
107108
"src/odr/internal/common/random.cpp"
108109
"src/odr/internal/common/style.cpp"
109110
"src/odr/internal/common/table_cursor.cpp"
110-
"src/odr/internal/common/table_position.cpp"
111+
"src/odr/table_position.cpp"
111112
"src/odr/internal/common/table_range.cpp"
112113
"src/odr/internal/common/temporary_file.cpp"
113114

@@ -133,25 +134,24 @@ set(ODR_SOURCE_FILES
133134

134135
"src/odr/internal/odf/odf_crypto.cpp"
135136
"src/odr/internal/odf/odf_document.cpp"
136-
"src/odr/internal/odf/odf_element.cpp"
137+
"src/odr/internal/odf/odf_element_registry.cpp"
137138
"src/odr/internal/odf/odf_file.cpp"
138139
"src/odr/internal/odf/odf_manifest.cpp"
139140
"src/odr/internal/odf/odf_meta.cpp"
140141
"src/odr/internal/odf/odf_parser.cpp"
141-
"src/odr/internal/odf/odf_spreadsheet.cpp"
142142
"src/odr/internal/odf/odf_style.cpp"
143143

144144
"src/odr/internal/oldms/oldms_file.cpp"
145145

146146
"src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp"
147-
"src/odr/internal/ooxml/presentation/ooxml_presentation_element.cpp"
147+
"src/odr/internal/ooxml/presentation/ooxml_presentation_element_registry.cpp"
148148
"src/odr/internal/ooxml/presentation/ooxml_presentation_parser.cpp"
149149
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp"
150-
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp"
151150
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp"
151+
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element_registry.cpp"
152152
"src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.cpp"
153153
"src/odr/internal/ooxml/text/ooxml_text_document.cpp"
154-
"src/odr/internal/ooxml/text/ooxml_text_element.cpp"
154+
"src/odr/internal/ooxml/text/ooxml_text_element_registry.cpp"
155155
"src/odr/internal/ooxml/text/ooxml_text_parser.cpp"
156156
"src/odr/internal/ooxml/text/ooxml_text_style.cpp"
157157
"src/odr/internal/ooxml/ooxml_crypto.cpp"

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ As an alternative to the Conan remote you can also export the package locally vi
3838
## Version
3939

4040
Versions and history are tracked on [GitHub](https://github.com/opendocument-app/OpenDocument.core).
41+
42+
## Testing
43+
44+
### Running the HTML Comparison Server
45+
46+
Scripts and Docker images can be found here https://github.com/opendocument-app/compare-html
47+
48+
```bash
49+
./test/scripts/compare_output_server.sh
50+
```

cli/src/back_translate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
#include <odr/internal/util/file_util.hpp>
66

7-
#include <iostream>
87
#include <string>
98

109
using namespace odr;
1110

1211
int main(int, char **argv) {
12+
const std::shared_ptr logger =
13+
Logger::create_stdio("odr-back-translate", LogLevel::verbose);
14+
1315
const std::string input{argv[1]};
1416
const std::string diff_path{argv[2]};
1517
const std::string output{argv[3]};
1618

1719
const DocumentFile document_file{input};
1820

1921
if (document_file.password_encrypted()) {
20-
std::cerr << "encrypted documents are not supported" << std::endl;
22+
ODR_FATAL(*logger, "encrypted documents are not supported");
2123
return 1;
2224
}
2325

cli/src/meta.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@
1010
using namespace odr;
1111

1212
int main(const int argc, char **argv) {
13+
const std::shared_ptr logger =
14+
Logger::create_stdio("odr-meta", LogLevel::verbose);
15+
1316
const std::string input{argv[1]};
1417

15-
const bool has_password = argc >= 4;
16-
std::string password;
17-
if (has_password) {
18+
std::optional<std::string> password;
19+
if (argc >= 3) {
1820
password = argv[2];
1921
}
2022

2123
DocumentFile document_file{input};
2224

23-
if (document_file.password_encrypted() && has_password) {
25+
if (document_file.password_encrypted() && !password) {
26+
ODR_FATAL(*logger, "document encrypted but no password given");
27+
return 2;
28+
}
29+
if (document_file.password_encrypted()) {
2430
try {
25-
document_file = document_file.decrypt(password);
31+
document_file = document_file.decrypt(*password);
2632
} catch (const WrongPasswordError &) {
27-
std::cerr << "wrong password" << std::endl;
33+
ODR_FATAL(*logger, "wrong password");
2834
return 1;
2935
}
3036
}

cli/src/server.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#include <odr/archive.hpp>
12
#include <odr/exceptions.hpp>
23
#include <odr/file.hpp>
4+
#include <odr/filesystem.hpp>
35
#include <odr/html.hpp>
46
#include <odr/http_server.hpp>
57

6-
#include <iostream>
78
#include <string>
89

910
using namespace odr;
1011

1112
int main(const int argc, char **argv) {
12-
auto logger = Logger::create_stdio("odr-server", LogLevel::verbose);
13+
const std::shared_ptr logger =
14+
Logger::create_stdio("odr-server", LogLevel::verbose);
1315

1416
std::string input{argv[1]};
1517

@@ -48,15 +50,36 @@ int main(const int argc, char **argv) {
4850
html_config.editable = true;
4951

5052
{
51-
std::string prefix = "one_file";
52-
HtmlViews views = server.serve_file(decoded_file, prefix, html_config);
53+
const std::string prefix = "file";
54+
const HtmlViews views =
55+
server.serve_file(decoded_file, prefix, html_config);
5356
ODR_INFO(*logger, "hosted decoded file with id: " << prefix);
5457
for (const auto &view : views) {
5558
ODR_INFO(*logger,
5659
"http://localhost:8080/file/" << prefix << "/" << view.path());
5760
}
5861
}
5962

63+
if (decoded_file.is_document_file() || decoded_file.is_archive_file()) {
64+
std::optional<Filesystem> filesystem;
65+
if (decoded_file.is_document_file()) {
66+
filesystem = decoded_file.as_document_file().document().as_filesystem();
67+
} else if (decoded_file.is_archive_file()) {
68+
filesystem = decoded_file.as_archive_file().archive().as_filesystem();
69+
}
70+
71+
const std::string prefix = "filesystem";
72+
const HtmlService filesystem_service = html::translate(
73+
filesystem.value(), server_config.cache_path + "/" + prefix,
74+
html_config, logger);
75+
server.connect_service(filesystem_service, prefix);
76+
ODR_INFO(*logger, "hosted filesystem with id: " << prefix);
77+
for (const auto &view : filesystem_service.list_views()) {
78+
ODR_INFO(*logger,
79+
"http://localhost:8080/file/" << prefix << "/" << view.path());
80+
}
81+
}
82+
6083
server.listen("localhost", 8080);
6184

6285
return 0;

cli/src/translate.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include <odr/html.hpp>
44

55
#include <filesystem>
6-
#include <iostream>
76
#include <string>
87

98
using namespace odr;
109

1110
int main(const int argc, char **argv) {
11+
const std::shared_ptr logger =
12+
Logger::create_stdio("odr-translate", LogLevel::verbose);
13+
1214
const std::string input{argv[1]};
1315
const std::string output{argv[2]};
1416

@@ -20,14 +22,14 @@ int main(const int argc, char **argv) {
2022
DecodedFile decoded_file{input};
2123

2224
if (decoded_file.password_encrypted() && !password) {
23-
std::cerr << "document encrypted but no password given" << std::endl;
25+
ODR_FATAL(*logger, "document encrypted but no password given");
2426
return 2;
2527
}
2628
if (decoded_file.password_encrypted()) {
2729
try {
2830
decoded_file = decoded_file.decrypt(*password);
2931
} catch (const WrongPasswordError &) {
30-
std::cerr << "wrong password" << std::endl;
32+
ODR_FATAL(*logger, "wrong password");
3133
return 1;
3234
}
3335
}

src/odr/definitions.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace odr {
6+
7+
using ElementIdentifier = std::uint64_t;
8+
9+
static constexpr ElementIdentifier null_element_id{0};
10+
11+
} // namespace odr

src/odr/document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ DocumentType Document::document_type() const noexcept {
3939
}
4040

4141
Element Document::root_element() const {
42-
return {m_impl.get(), m_impl->root_element()};
42+
return {m_impl->element_adapter(), m_impl->root_element()};
4343
}
4444

4545
Filesystem Document::as_filesystem() const {

0 commit comments

Comments
 (0)