source: icXML/icXML-devel/samples/src/DOMPrint/DOMPrintFilter.cpp @ 2733

Last change on this file since 2733 was 2733, checked in by cameron, 6 years ago

More path fixes.

File size: 3.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: DOMPrintFilter.cpp 671894 2008-06-26 13:29:21Z borisk $
20 */
21
22#include "DOMPrintFilter.hpp"
23#include <xercesc/util/XMLUniDefs.hpp>
24#include <icxercesc/util/XMLString.hpp>
25
26static const XMLCh  element_person[]=
27{
28        chLatin_p, chLatin_e, chLatin_r, chLatin_s, chLatin_o, chLatin_n, chNull
29};
30
31static const XMLCh  element_link[]=
32{
33        chLatin_l, chLatin_i, chLatin_n, chLatin_k, chNull
34};
35
36DOMPrintFilter::DOMPrintFilter(ShowType whatToShow)
37:fWhatToShow(whatToShow)
38{}
39
40DOMNodeFilter::FilterAction DOMPrintFilter::
41acceptNode(const DOMNode* node) const
42{
43        //
44        // The DOMLSSerializer shall call getWhatToShow() before calling
45        // acceptNode(), to show nodes which are supposed to be
46        // shown to this filter.
47        //
48        // REVISIT: In case the DOMLSSerializer does not follow the protocol,
49        //          Shall the filter honour, or NOT, what it claims
50        //          it is interested in ?
51        //
52        // The DOMLS specs does not specify that acceptNode() shall do
53        // this way, or not, so it is up the implementation,
54        // to skip the code below for the sake of performance ...
55        //
56        if ((getWhatToShow() & (1 << (node->getNodeType() - 1))) == 0)
57                return DOMNodeFilter::FILTER_ACCEPT;
58
59        switch (node->getNodeType())
60        {
61        case DOMNode::ELEMENT_NODE:
62                {
63                        // for element whose name is "person", skip it
64                        if (XMLString::compareString(node->getNodeName(), element_person)==0)
65                                return DOMNodeFilter::FILTER_SKIP;
66                        // for element whose name is "line", reject it
67                        if (XMLString::compareString(node->getNodeName(), element_link)==0)
68                                return DOMNodeFilter::FILTER_REJECT;
69                        // for rest, accept it
70                        return DOMNodeFilter::FILTER_ACCEPT;
71
72                        break;
73                }
74        case DOMNode::COMMENT_NODE:
75                {
76                        // the WhatToShow will make this no effect
77                        return DOMNodeFilter::FILTER_REJECT;
78                        break;
79                }
80        case DOMNode::TEXT_NODE:
81                {
82                        // the WhatToShow will make this no effect
83                        return DOMNodeFilter::FILTER_REJECT;
84                        break;
85                }
86        case DOMNode::DOCUMENT_TYPE_NODE:
87                {
88                        // even we say we are going to process document type,
89                        // we are not able be to see this node since
90                        // DOMLSSerializerImpl (a XercesC's default implementation
91                        // of DOMLSSerializer) will not pass DocumentType node to
92                        // this filter.
93                        //
94                        return DOMNodeFilter::FILTER_REJECT;  // no effect
95                        break;
96                }
97        case DOMNode::DOCUMENT_NODE:
98                {
99                        // same as DOCUMENT_NODE
100                        return DOMNodeFilter::FILTER_REJECT;  // no effect
101                        break;
102                }
103        default :
104                {
105                        return DOMNodeFilter::FILTER_ACCEPT;
106                        break;
107                }
108        }
109
110        return DOMNodeFilter::FILTER_ACCEPT;
111}
Note: See TracBrowser for help on using the repository browser.