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.Nullable;
21 import javax.annotation.concurrent.NotThreadSafe;
22
23 import com.helger.commons.ValueEnforcer;
24 import com.helger.commons.annotation.Nonempty;
25 import com.helger.commons.annotation.ReturnsMutableCopy;
26 import com.helger.commons.collection.CollectionHelper;
27 import com.helger.commons.collection.ext.CommonsArrayList;
28 import com.helger.commons.collection.ext.ICommonsList;
29 import com.helger.commons.string.StringHelper;
30 import com.helger.commons.string.ToStringGenerator;
31 import com.helger.schematron.CSchematron;
32 import com.helger.schematron.CSchematronXML;
33 import com.helger.schematron.pure.errorhandler.IPSErrorHandler;
34 import com.helger.xml.microdom.IMicroElement;
35 import com.helger.xml.microdom.MicroElement;
36
37
38
39
40
41
42
43
44 @NotThreadSafe
45 public class PSEmph implements IPSClonableElement <PSEmph>, IPSOptionalElement, IPSHasTexts
46 {
47 private final ICommonsList <String> m_aContent = new CommonsArrayList <> ();
48
49 public PSEmph ()
50 {}
51
52 public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
53 {
54 if (m_aContent.isEmpty ())
55 {
56 aErrorHandler.error (this, "<emph> has no content");
57 return false;
58 }
59 return true;
60 }
61
62 public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
63 {
64 if (m_aContent.isEmpty ())
65 aErrorHandler.error (this, "<emph> has no content");
66 }
67
68 public boolean isMinimal ()
69 {
70 return true;
71 }
72
73 public void addText (@Nonnull @Nonempty final String sText)
74 {
75 ValueEnforcer.notEmpty (sText, "Text");
76 m_aContent.add (sText);
77 }
78
79 public boolean hasAnyText ()
80 {
81 return m_aContent.isNotEmpty ();
82 }
83
84 @Nonnull
85 @ReturnsMutableCopy
86 public ICommonsList <String> getAllTexts ()
87 {
88 return m_aContent.getClone ();
89 }
90
91 @Nullable
92 public String getAsText ()
93 {
94 return StringHelper.getImploded (m_aContent);
95 }
96
97 @Nonnull
98 public IMicroElement getAsMicroElement ()
99 {
100 final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_EMPH);
101 for (final String sContent : m_aContent)
102 ret.appendText (sContent);
103 return ret;
104 }
105
106 @Nonnull
107 public PSEmph getClone ()
108 {
109 final PSEmph ret = new PSEmph ();
110 for (final String sContent : m_aContent)
111 ret.addText (sContent);
112 return ret;
113 }
114
115 @Override
116 public String toString ()
117 {
118 return new ToStringGenerator (this).appendIf ("content", m_aContent, CollectionHelper::isNotEmpty).toString ();
119 }
120 }