File: parser.h

package info (click to toggle)
libkode 0.0~git20241211.68f9908-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: cpp: 6,612; makefile: 5
file content (154 lines) | stat: -rw-r--r-- 5,833 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
    This file is part of KDE Schema Parser

    Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
    Copyright (c) 2006 Michaƫl Larouche <michael.larouche@kdemail.net>
                       based on wsdlpull parser by Vivek Krishna

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
 */

#ifndef SCHEMA_PARSER_H
#define SCHEMA_PARSER_H

#include <QDomElement>
#include <QList>
#include <QLoggingCategory>
#include <QFile>

#include "types.h"
#include "annotation.h"
#include <kode_export.h>

QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE

class ParserContext;

Q_DECLARE_LOGGING_CATEGORY(parser)

namespace XSD {

class SCHEMA_EXPORT Parser
{
public:
    enum { UNBOUNDED = 100000 };

    explicit Parser(ParserContext *context, const QString &nameSpace = QString(),
                    bool useLocalFilesOnly = false,
                    const QStringList &includePathList = QStringList());
    explicit Parser(const QString &nameSpace = QString());
    Parser(const Parser &other);
    Parser(Parser &&other);

    ~Parser();

    Parser &operator=(const Parser &other);
    Parser &operator=(Parser &&other) noexcept;

    /**
     * Configures the parser to use some local files instead of downloading specific schemas.
     * @param localSchemas a map where the key is the schema URI and the value is the local path
     * The local path can start with :/ to use the Qt resource system.
     */
    void setLocalSchemas(const QMap<QUrl, QString> &localSchemas);

    Types types() const;

    Annotation::List annotations() const;

    bool parseString(ParserContext *context, const QByteArray &data);
    bool parseFile(ParserContext *context, QFile &file);
    bool parseSchemaTag(ParserContext *context, const QDomElement &element);

    QString targetNamespace() const;

    /**
     * Resolve all references for elements and attributes
     * @return false if one of references has no declaration (error)
     */
    bool resolveForwardDeclarations();

    /**
      Returns the default schema URI.
     */
    static QString schemaUri();

private:
    bool parse(ParserContext *context, QIODevice *sourceDevice);

    void parseImport(ParserContext *context, const QDomElement &);
    /**
     * @brief Parse include element.
     * The <include> element must include a external schema within the same target namespace
     * of the current document. Use <import> if you want to refer to a external namespace.
     * @param context Current parser context.
     * @param element DOM element to parse.
     */
    void parseInclude(ParserContext *context, const QDomElement &element);
    void addGlobalElement(const Element &);
    void addGlobalAttribute(const Attribute &);
    AttributeGroup parseAttributeGroup(ParserContext *context, const QDomElement &,
                                       const QString &nameSpace);
    Group parseGroup(ParserContext *context, const QDomElement &, const QString &nameSpace);

    Annotation::List parseAnnotation(ParserContext *context, const QDomElement &);
    ComplexType parseComplexType(ParserContext *context, const QDomElement &);

    void all(ParserContext *context, const QDomElement &, ComplexType &);
    void parseCompositor(ParserContext *context, const QDomElement &element,
                         const QString &nameSpace, Element::List *elements, Group::List *groups);

    void setOccurrenceAttributes(Element &newElement, const QDomElement &element);

    Element parseElement(ParserContext *context, const QDomElement &, const QString &nameSpace,
                         const QDomElement &occurrenceElement);
    void setSubstitutionElementName(const QName &typeName, const QName &elemName);

    Attribute parseAttribute(ParserContext *context, const QDomElement &, const QString &nameSpace);
    Element parseAny(ParserContext *context, const QDomElement &, const QString &nameSpace);
    void addAnyAttribute(ParserContext *context, const QDomElement &, ComplexType &);

    SimpleType parseSimpleType(ParserContext *context, const QDomElement &);
    void parseRestriction(ParserContext *context, const QDomElement &, SimpleType &);
    void parseComplexContent(ParserContext *context, const QDomElement &, ComplexType &);
    void parseSimpleContent(ParserContext *context, const QDomElement &, ComplexType &);

    void importSchema(ParserContext *context, const QString &location);
    /**
     * @brief Read and include the given schema into the current schema.
     * @param context Current parser context.
     * @param location Schema location.
     */
    void includeSchema(ParserContext *context, const QString &location);

    bool importOrIncludeSchema(ParserContext *context, const QDomElement &element,
                               const QUrl &schemaLocation);

    Element findElement(const QName &name) const;
    Group findGroup(const QName &name) const;
    Attribute findAttribute(const QName &name) const;
    AttributeGroup findAttributeGroup(const QName &name) const;
    void init(ParserContext *context);
    void clear();

    class Private;
    std::unique_ptr<Private> d;
};
}

#endif