1 | /*
|
---|
2 | * Copyright 2002,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: DOMPrintFilter.cpp,v 1.4 2004/09/08 13:55:31 peiyongz Exp $
|
---|
19 | * $Log: DOMPrintFilter.cpp,v $
|
---|
20 | * Revision 1.4 2004/09/08 13:55:31 peiyongz
|
---|
21 | * Apache License Version 2.0
|
---|
22 | *
|
---|
23 | * Revision 1.3 2002/06/04 14:22:51 peiyongz
|
---|
24 | * Implement setter/getter from DOMWriterFilter
|
---|
25 | *
|
---|
26 | * Revision 1.2 2002/06/03 22:40:07 peiyongz
|
---|
27 | * *** empty log message ***
|
---|
28 | *
|
---|
29 | * Revision 1.1 2002/05/29 13:33:32 peiyongz
|
---|
30 | * DOM3 Save Interface: DOMWriter/DOMWriterFilter
|
---|
31 | *
|
---|
32 | */
|
---|
33 |
|
---|
34 | #include "DOMPrintFilter.hpp"
|
---|
35 | #include <xercesc/util/XMLUniDefs.hpp>
|
---|
36 | #include <xercesc/util/XMLString.hpp>
|
---|
37 |
|
---|
38 | static const XMLCh element_person[]=
|
---|
39 | {
|
---|
40 | chLatin_p, chLatin_e, chLatin_r, chLatin_s, chLatin_o, chLatin_n, chNull
|
---|
41 | };
|
---|
42 |
|
---|
43 | static const XMLCh element_link[]=
|
---|
44 | {
|
---|
45 | chLatin_l, chLatin_i, chLatin_n, chLatin_k, chNull
|
---|
46 | };
|
---|
47 |
|
---|
48 | DOMPrintFilter::DOMPrintFilter(unsigned long whatToShow)
|
---|
49 | :fWhatToShow(whatToShow)
|
---|
50 | {}
|
---|
51 |
|
---|
52 | short DOMPrintFilter::acceptNode(const DOMNode* node) const
|
---|
53 | {
|
---|
54 | //
|
---|
55 | // The DOMWriter shall call getWhatToShow() before calling
|
---|
56 | // acceptNode(), to show nodes which are supposed to be
|
---|
57 | // shown to this filter.
|
---|
58 | //
|
---|
59 | // REVISIT: In case the DOMWriter does not follow the protocol,
|
---|
60 | // Shall the filter honour, or NOT, what it claimes
|
---|
61 | // (when it is constructed/setWhatToShow())
|
---|
62 | // it is interested in ?
|
---|
63 | //
|
---|
64 | // The DOMLS specs does not specify that acceptNode() shall do
|
---|
65 | // this way, or not, so it is up the implementation,
|
---|
66 | // to skip the code below for the sake of performance ...
|
---|
67 | //
|
---|
68 | if ((getWhatToShow() & (1 << (node->getNodeType() - 1))) == 0)
|
---|
69 | return DOMNodeFilter::FILTER_ACCEPT;
|
---|
70 |
|
---|
71 | switch (node->getNodeType())
|
---|
72 | {
|
---|
73 | case DOMNode::ELEMENT_NODE:
|
---|
74 | {
|
---|
75 | // for element whose name is "person", skip it
|
---|
76 | if (XMLString::compareString(node->getNodeName(), element_person)==0)
|
---|
77 | return DOMNodeFilter::FILTER_SKIP;
|
---|
78 | // for element whose name is "line", reject it
|
---|
79 | if (XMLString::compareString(node->getNodeName(), element_link)==0)
|
---|
80 | return DOMNodeFilter::FILTER_REJECT;
|
---|
81 | // for rest, accept it
|
---|
82 | return DOMNodeFilter::FILTER_ACCEPT;
|
---|
83 |
|
---|
84 | break;
|
---|
85 | }
|
---|
86 | case DOMNode::COMMENT_NODE:
|
---|
87 | {
|
---|
88 | // the WhatToShow will make this no effect
|
---|
89 | return DOMNodeFilter::FILTER_REJECT;
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | case DOMNode::TEXT_NODE:
|
---|
93 | {
|
---|
94 | // the WhatToShow will make this no effect
|
---|
95 | return DOMNodeFilter::FILTER_REJECT;
|
---|
96 | break;
|
---|
97 | }
|
---|
98 | case DOMNode::DOCUMENT_TYPE_NODE:
|
---|
99 | {
|
---|
100 | // even we say we are going to process document type,
|
---|
101 | // we are not able be to see this node since
|
---|
102 | // DOMWriterImpl (a XercesC's default implementation
|
---|
103 | // of DOMWriter) will not pass DocumentType node to
|
---|
104 | // this filter.
|
---|
105 | //
|
---|
106 | return DOMNodeFilter::FILTER_REJECT; // no effect
|
---|
107 | break;
|
---|
108 | }
|
---|
109 | case DOMNode::DOCUMENT_NODE:
|
---|
110 | {
|
---|
111 | // same as DOCUMENT_NODE
|
---|
112 | return DOMNodeFilter::FILTER_REJECT; // no effect
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | default :
|
---|
116 | {
|
---|
117 | return DOMNodeFilter::FILTER_ACCEPT;
|
---|
118 | break;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | return DOMNodeFilter::FILTER_ACCEPT;
|
---|
123 | }
|
---|
124 |
|
---|