/src/libetonyek/src/lib/contexts/IWORKTextStorageElement.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libetonyek project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include "IWORKTextStorageElement.h" |
11 | | |
12 | | #include "IWORKCollector.h" |
13 | | #include "IWORKDictionary.h" |
14 | | #include "IWORKRefContext.h" |
15 | | #include "IWORKTextBodyElement.h" |
16 | | #include "IWORKToken.h" |
17 | | #include "IWORKXMLParserState.h" |
18 | | |
19 | | namespace libetonyek |
20 | | { |
21 | | |
22 | | IWORKTextStorageElement::IWORKTextStorageElement(IWORKXMLParserState &state) |
23 | 0 | : IWORKXMLElementContextBase(state) |
24 | 0 | , m_stylesheetId() |
25 | 0 | , m_hasStylesheet(false) |
26 | 0 | , m_stylesheet(nullptr) |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | IWORKTextStorageElement::IWORKTextStorageElement(IWORKXMLParserState &state, IWORKStylesheetPtr_t &mainMap) |
31 | 0 | : IWORKXMLElementContextBase(state) |
32 | 0 | , m_stylesheetId() |
33 | 0 | , m_hasStylesheet(false) |
34 | 0 | , m_stylesheet(&mainMap) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | IWORKXMLContextPtr_t IWORKTextStorageElement::element(const int name) |
39 | 0 | { |
40 | 0 | sendStylesheet(); |
41 | |
|
42 | 0 | switch (name) |
43 | 0 | { |
44 | 0 | case IWORKToken::NS_URI_SF | IWORKToken::stylesheet_ref : |
45 | 0 | return std::make_shared<IWORKRefContext>(getState(), m_stylesheetId); |
46 | 0 | case IWORKToken::NS_URI_SF | IWORKToken::text_body : |
47 | 0 | return std::make_shared<IWORKTextBodyElement>(getState()); |
48 | 0 | default: |
49 | 0 | ETONYEK_DEBUG_MSG(("IWORKTextStorageElement::element: find some unknown element\n")); |
50 | 0 | } |
51 | | |
52 | 0 | return IWORKXMLContextPtr_t(); |
53 | 0 | } |
54 | | |
55 | | void IWORKTextStorageElement::endOfElement() |
56 | 0 | { |
57 | 0 | if (isCollector() && m_hasStylesheet) |
58 | 0 | { |
59 | 0 | getCollector().popStylesheet(); |
60 | 0 | getState().m_stylesheet=getCollector().getStylesheet(); |
61 | 0 | m_hasStylesheet=false; |
62 | 0 | } |
63 | 0 | } |
64 | | |
65 | | void IWORKTextStorageElement::sendStylesheet() |
66 | 0 | { |
67 | 0 | if (!isCollector()) |
68 | 0 | return; |
69 | | |
70 | 0 | if (m_stylesheetId) // a stylesheet has been found |
71 | 0 | { |
72 | 0 | const IWORKStylesheetMap_t::iterator it = getState().getDictionary().m_stylesheets.find(get(m_stylesheetId)); |
73 | 0 | if (it != getState().getDictionary().m_stylesheets.end()) |
74 | 0 | { |
75 | 0 | getCollector().pushStylesheet(it->second); |
76 | 0 | getState().m_stylesheet=it->second; |
77 | 0 | if (m_stylesheet) *m_stylesheet=it->second; |
78 | 0 | m_hasStylesheet = true; |
79 | 0 | } |
80 | 0 | else |
81 | 0 | { |
82 | 0 | ETONYEK_DEBUG_MSG(("IWORKTextStorageElement::sendStylesheet: can not find stylesheet %s\n", get(m_stylesheetId).c_str())); |
83 | 0 | } |
84 | 0 | m_stylesheetId.reset(); |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | | } |
89 | | |
90 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |