Skip to content

Commit 394e8fd

Browse files
author
Andrei Stryhelski
committed
Move CssContentElementNode.cs to html2pdf module
DEVSIX-6541
1 parent 687c58f commit 394e8fd

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2023 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
using System;
25+
using System.Collections;
26+
using System.Collections.Generic;
27+
using iText.StyledXmlParser.Css;
28+
using iText.StyledXmlParser.Css.Pseudo;
29+
using iText.StyledXmlParser.Node;
30+
31+
namespace iText.Html2pdf.Css.Resolve
32+
{
33+
/// <summary><see cref="IElementNode"/> implementation for content nodes.</summary>
34+
public class CssContentElementNode : CssContextNode, IElementNode, ICustomElementNode
35+
{
36+
/// <summary>The attributes</summary>
37+
private CssContentElementNode.Attributes attributes;
38+
39+
/// <summary>The tag name</summary>
40+
private String tagName;
41+
42+
/// <summary>Creates a new <see cref="CssContentElementNode"/> instance.</summary>
43+
/// <param name="parentNode">the parent node</param>
44+
/// <param name="pseudoElementName">the pseudo element name</param>
45+
/// <param name="attributes">the attributes</param>
46+
public CssContentElementNode(INode parentNode, String pseudoElementName, IDictionary<String, String> attributes)
47+
: base(parentNode)
48+
{
49+
this.tagName = CssPseudoElementUtil.CreatePseudoElementTagName(pseudoElementName);
50+
this.attributes = new CssContentElementNode.Attributes(attributes);
51+
}
52+
53+
/// <summary><inheritDoc/></summary>
54+
public virtual String Name()
55+
{
56+
return tagName;
57+
}
58+
59+
/// <summary><inheritDoc/></summary>
60+
public virtual IAttributes GetAttributes()
61+
{
62+
return attributes;
63+
}
64+
65+
/// <summary><inheritDoc/></summary>
66+
public virtual String GetAttribute(String key)
67+
{
68+
return attributes.GetAttribute(key);
69+
}
70+
71+
/// <summary><inheritDoc/></summary>
72+
public virtual IList<IDictionary<String, String>> GetAdditionalHtmlStyles()
73+
{
74+
return null;
75+
}
76+
77+
/// <summary><inheritDoc/></summary>
78+
public virtual void AddAdditionalHtmlStyles(IDictionary<String, String> styles)
79+
{
80+
throw new NotSupportedException("addAdditionalHtmlStyles");
81+
}
82+
83+
/// <summary><inheritDoc/></summary>
84+
public virtual String GetLang()
85+
{
86+
return null;
87+
}
88+
89+
/// <summary>Simple <see cref="IAttributes"/> implementation.</summary>
90+
private class Attributes : IAttributes
91+
{
92+
/// <summary>The attributes.</summary>
93+
private IDictionary<String, String> attributes;
94+
95+
/// <summary>Creates a new <see cref="Attributes"/> instance.</summary>
96+
/// <param name="attributes">the attributes</param>
97+
public Attributes(IDictionary<String, String> attributes)
98+
{
99+
this.attributes = attributes;
100+
}
101+
102+
/// <summary><inheritDoc/></summary>
103+
public virtual String GetAttribute(String key)
104+
{
105+
return attributes.Get(key);
106+
}
107+
108+
/// <summary><inheritDoc/></summary>
109+
public virtual void SetAttribute(String key, String value)
110+
{
111+
throw new NotSupportedException("setAttribute");
112+
}
113+
114+
/// <summary><inheritDoc/></summary>
115+
public virtual int Size()
116+
{
117+
return this.attributes.Count;
118+
}
119+
120+
/// <summary><inheritDoc/></summary>
121+
public IEnumerator<IAttribute> GetEnumerator()
122+
{
123+
return new CssContentElementNode.AttributeIterator(this.attributes.GetEnumerator());
124+
}
125+
126+
/// <summary><inheritDoc/></summary>
127+
IEnumerator IEnumerable.GetEnumerator()
128+
{
129+
return GetEnumerator();
130+
}
131+
}
132+
133+
/// <summary>Simple <see cref="IAttributes"/> implementation.</summary>
134+
private class Attribute : IAttribute
135+
{
136+
/// <summary>The entry.</summary>
137+
private KeyValuePair<String, String> entry;
138+
139+
/// <summary>Creates a new <see cref="Attribute"/> instance.</summary>
140+
/// <param name="entry">the entry</param>
141+
public Attribute(KeyValuePair<String, String> entry)
142+
{
143+
this.entry = entry;
144+
}
145+
146+
/// <summary><inheritDoc/></summary>
147+
public virtual String GetKey()
148+
{
149+
return this.entry.Key;
150+
}
151+
152+
/// <summary><inheritDoc/></summary>
153+
public virtual String GetValue()
154+
{
155+
return this.entry.Value;
156+
}
157+
}
158+
159+
/// <summary> <see cref="IAttribute"/> iterator.</summary>
160+
private class AttributeIterator : IEnumerator<IAttribute>
161+
{
162+
/// <summary>The iterator.</summary>
163+
private IEnumerator<KeyValuePair<String, String>> iterator;
164+
165+
/// <summary>Creates a new <see cref="AttributeIterator"/> instance.</summary>
166+
/// <param name="iterator">the iterator</param>
167+
public AttributeIterator(IEnumerator<KeyValuePair<String, String>> iterator)
168+
{
169+
this.iterator = iterator;
170+
}
171+
172+
/// <summary><inheritDoc/></summary>
173+
public void Dispose()
174+
{
175+
iterator.Dispose();
176+
}
177+
178+
/// <summary><inheritDoc/></summary>
179+
public bool MoveNext()
180+
{
181+
return iterator.MoveNext();
182+
}
183+
184+
/// <summary><inheritDoc/></summary>
185+
public void Reset()
186+
{
187+
iterator.Reset();
188+
}
189+
190+
/// <summary><inheritDoc/></summary>
191+
public IAttribute Current
192+
{
193+
get { return new Attribute(iterator.Current); }
194+
}
195+
196+
/// <summary><inheritDoc/></summary>
197+
object IEnumerator.Current
198+
{
199+
get { return Current; }
200+
}
201+
}
202+
}
203+
}

0 commit comments

Comments
 (0)