1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.pure.model;
18
19 import javax.annotation.Nonnull;
20 import javax.annotation.concurrent.NotThreadSafe;
21
22 import com.helger.commons.ValueEnforcer;
23 import com.helger.commons.annotation.Nonempty;
24 import com.helger.commons.annotation.ReturnsMutableCopy;
25 import com.helger.commons.collection.CollectionHelper;
26 import com.helger.commons.collection.ext.CommonsArrayList;
27 import com.helger.commons.collection.ext.ICommonsList;
28 import com.helger.commons.string.ToStringGenerator;
29 import com.helger.schematron.CSchematron;
30 import com.helger.schematron.CSchematronXML;
31 import com.helger.schematron.pure.errorhandler.IPSErrorHandler;
32 import com.helger.xml.microdom.IMicroElement;
33 import com.helger.xml.microdom.MicroElement;
34
35
36
37
38
39
40
41
42
43 @NotThreadSafe
44 public class PSTitle implements IPSClonableElement <PSTitle>, IPSOptionalElement, IPSHasMixedContent
45 {
46 private final ICommonsList <Object> m_aContent = new CommonsArrayList <> ();
47
48 public PSTitle ()
49 {}
50
51 public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
52 {
53 for (final Object aContent : m_aContent)
54 if (aContent instanceof IPSElement)
55 if (!((IPSElement) aContent).isValid (aErrorHandler))
56 return false;
57 return true;
58 }
59
60 public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
61 {
62 for (final Object aContent : m_aContent)
63 if (aContent instanceof IPSElement)
64 ((IPSElement) aContent).validateCompletely (aErrorHandler);
65 }
66
67 public boolean isMinimal ()
68 {
69 return false;
70 }
71
72 public void addText (@Nonnull @Nonempty final String sText)
73 {
74 ValueEnforcer.notEmpty (sText, "Text");
75 m_aContent.add (sText);
76 }
77
78 public boolean hasAnyText ()
79 {
80 return m_aContent.containsAny (e -> e instanceof String);
81 }
82
83 @Nonnull
84 @ReturnsMutableCopy
85 public ICommonsList <String> getAllTexts ()
86 {
87 return m_aContent.getAllInstanceOf (String.class);
88 }
89
90 public void addDir (@Nonnull final PSDir aDir)
91 {
92 ValueEnforcer.notNull (aDir, "Dir");
93 m_aContent.add (aDir);
94 }
95
96 @Nonnull
97 @ReturnsMutableCopy
98 public ICommonsList <PSDir> getAllDirs ()
99 {
100 return m_aContent.getAllInstanceOf (PSDir.class);
101 }
102
103
104
105
106 @Nonnull
107 @ReturnsMutableCopy
108 public ICommonsList <Object> getAllContentElements ()
109 {
110 return m_aContent.getClone ();
111 }
112
113 @Nonnull
114 public IMicroElement getAsMicroElement ()
115 {
116 final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_TITLE);
117 for (final Object aContent : m_aContent)
118 if (aContent instanceof String)
119 ret.appendText ((String) aContent);
120 else
121 ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
122 return ret;
123 }
124
125 @Nonnull
126 public PSTitle getClone ()
127 {
128 final PSTitle ret = new PSTitle ();
129 for (final Object aContent : m_aContent)
130 if (aContent instanceof String)
131 ret.addText ((String) aContent);
132 else
133 if (aContent instanceof PSDir)
134 ret.addDir (((PSDir) aContent).getClone ());
135 return ret;
136 }
137
138 @Override
139 public String toString ()
140 {
141 return new ToStringGenerator (this).appendIf ("content", m_aContent, CollectionHelper::isNotEmpty).getToString ();
142 }
143 }