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