Line data Source code
1 : /* File: document_link_provider.c; Copyright and License: see below */
2 :
3 : #include "document/document_link_provider.h"
4 : #include "utf8stringbuf/utf8stringview.h"
5 : #include "u8/u8_trace.h"
6 : #include "u8/u8_log.h"
7 : #include <stdio.h>
8 : #include <stdbool.h>
9 : #include <assert.h>
10 :
11 0 : void document_link_provider_init( document_link_provider_t *this_,
12 : data_database_reader_t *db_reader,
13 : const char * tag_xref_separator,
14 : const char * tag_xref_start,
15 : const char * tag_xref_middle,
16 : const char * tag_xref_end,
17 : io_xml_writer_t *xml_writer )
18 : {
19 0 : U8_TRACE_BEGIN();
20 0 : assert( NULL != db_reader );
21 0 : assert( NULL != tag_xref_separator );
22 0 : assert( NULL != tag_xref_start );
23 0 : assert( NULL != tag_xref_middle );
24 0 : assert( NULL != tag_xref_end );
25 0 : assert( NULL != xml_writer );
26 :
27 0 : (*this_).db_reader = db_reader;
28 0 : (*this_).tag_xref_separator = tag_xref_separator;
29 0 : (*this_).tag_xref_start = tag_xref_start;
30 0 : (*this_).tag_xref_middle = tag_xref_middle;
31 0 : (*this_).tag_xref_end = tag_xref_end;
32 0 : (*this_).xml_writer = xml_writer;
33 :
34 0 : U8_TRACE_END();
35 0 : }
36 :
37 0 : void document_link_provider_destroy( document_link_provider_t *this_ )
38 : {
39 0 : U8_TRACE_BEGIN();
40 :
41 0 : (*this_).db_reader = NULL;
42 0 : (*this_).xml_writer = NULL;
43 :
44 0 : U8_TRACE_END();
45 0 : }
46 :
47 0 : u8_error_t document_link_provider_write_occurrences( document_link_provider_t *this_,
48 : data_id_t classifier_id )
49 : {
50 0 : U8_TRACE_BEGIN();
51 0 : assert ( NULL != (*this_).db_reader );
52 0 : assert ( DATA_TABLE_CLASSIFIER == data_id_get_table( &classifier_id ) );
53 0 : u8_error_t db_err = U8_ERROR_NONE;
54 0 : u8_error_t export_err = U8_ERROR_NONE;
55 :
56 : /* read from database */
57 : data_diagram_iterator_t diagram_iterator;
58 0 : db_err |= data_diagram_iterator_init_empty( &diagram_iterator );
59 0 : db_err |= data_database_reader_get_diagrams_by_classifier_id( (*this_).db_reader,
60 : data_id_get_row_id( &classifier_id ),
61 : &diagram_iterator
62 : );
63 0 : bool is_first = true;
64 0 : while( data_diagram_iterator_has_next( &diagram_iterator ) )
65 : {
66 0 : db_err |= data_diagram_iterator_next( &diagram_iterator, &((*this_).temp_diagram) );
67 :
68 : /* write to sink */
69 0 : if ( is_first )
70 : {
71 0 : is_first = false;
72 : }
73 : else
74 : {
75 0 : export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_separator );
76 : }
77 0 : const data_id_t diag_ref_id = data_diagram_get_data_id( &((*this_).temp_diagram) );
78 0 : const char *const diag_ref_name = data_diagram_get_name_const( &((*this_).temp_diagram) );
79 0 : export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_start );
80 0 : export_err |= io_xml_writer_write_plain_id( (*this_).xml_writer, diag_ref_id );
81 0 : export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_middle );
82 0 : export_err |= io_xml_writer_write_xml_enc( (*this_).xml_writer, diag_ref_name );
83 0 : export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_end );
84 : }
85 0 : db_err |= data_diagram_iterator_destroy( &diagram_iterator );
86 :
87 0 : U8_TRACE_END_ERR( db_err || export_err );
88 0 : return ( db_err || export_err );
89 : }
90 :
91 :
92 : /*
93 : Copyright 2023-2025 Andreas Warnke
94 :
95 : Licensed under the Apache License, Version 2.0 (the "License");
96 : you may not use this file except in compliance with the License.
97 : You may obtain a copy of the License at
98 :
99 : http://www.apache.org/licenses/LICENSE-2.0
100 :
101 : Unless required by applicable law or agreed to in writing, software
102 : distributed under the License is distributed on an "AS IS" BASIS,
103 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104 : See the License for the specific language governing permissions and
105 : limitations under the License.
106 : */
|