View Javadoc
1   /**
2    * Copyright (C) 2014-2018 Philip Helger (www.helger.com)
3    * philip[at]helger[dot]com
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *         http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package com.helger.schematron.pure.model;
18  
19  import java.io.Serializable;
20  
21  import javax.annotation.Nonnull;
22  import javax.annotation.Nullable;
23  import javax.annotation.concurrent.NotThreadSafe;
24  import javax.xml.XMLConstants;
25  
26  import com.helger.commons.annotation.Nonempty;
27  import com.helger.commons.id.IHasID;
28  import com.helger.commons.lang.EnumHelper;
29  import com.helger.commons.lang.ICloneable;
30  import com.helger.commons.string.ToStringGenerator;
31  import com.helger.schematron.CSchematronXML;
32  import com.helger.xml.microdom.IMicroElement;
33  
34  /**
35   * A single "rich" group
36   *
37   * @author Philip Helger
38   */
39  @NotThreadSafe
40  public class PSRichGroup implements ICloneable <PSRichGroup>, Serializable
41  {
42    public static enum ESpace implements IHasID <String>
43    {
44      PRESERVE ("preserve"),
45      DEFAULT ("default");
46  
47      private final String m_sID;
48  
49      private ESpace (@Nonnull @Nonempty final String sID)
50      {
51        m_sID = sID;
52      }
53  
54      @Nonnull
55      @Nonempty
56      public String getID ()
57      {
58        return m_sID;
59      }
60  
61      @Nullable
62      public static ESpace getFromIDOrNull (@Nullable final String sID)
63      {
64        return EnumHelper.getFromIDOrNull (ESpace.class, sID);
65      }
66    }
67  
68    private String m_sIcon;
69    private String m_sSee;
70    private String m_sFPI;
71    private String m_sXmlLang;
72    private ESpace m_eXmlSpace;
73  
74    public PSRichGroup ()
75    {}
76  
77    public void setIcon (@Nullable final String sIcon)
78    {
79      m_sIcon = sIcon;
80    }
81  
82    /**
83     * The location of a graphics file containing some visible representation of
84     * the severity, significance or other grouping of the associated element.<br>
85     * An implementation is not required to make use of this attribute.
86     *
87     * @return The icon value
88     */
89    @Nullable
90    public String getIcon ()
91    {
92      return m_sIcon;
93    }
94  
95    public void setSee (@Nullable final String sSee)
96    {
97      m_sSee = sSee;
98    }
99  
100   /**
101    * The URI of external information of interest to maintainers and users of the
102    * schema.<br>
103    * An implementation is not required to make use of this attribute.
104    *
105    * @return The see value
106    */
107   @Nullable
108   public String getSee ()
109   {
110     return m_sSee;
111   }
112 
113   public void setFPI (@Nullable final String sFPI)
114   {
115     m_sFPI = sFPI;
116   }
117 
118   /**
119    * A formal public identifier for the schema, phase or other element.<br>
120    * An implementation is not required to make use of this attribute.
121    *
122    * @return The FPI value
123    */
124   @Nullable
125   public String getFPI ()
126   {
127     return m_sFPI;
128   }
129 
130   public void setXmlLang (@Nullable final String sXmlLang)
131   {
132     m_sXmlLang = sXmlLang;
133   }
134 
135   @Nullable
136   public String getXmlLang ()
137   {
138     return m_sXmlLang;
139   }
140 
141   public void setXmlSpace (@Nullable final ESpace eXmlSpace)
142   {
143     m_eXmlSpace = eXmlSpace;
144   }
145 
146   @Nullable
147   public ESpace getXmlSpace ()
148   {
149     return m_eXmlSpace;
150   }
151 
152   public static boolean isRichAttribute (@Nullable final String sAttrName)
153   {
154     return CSchematronXML.ATTR_ICON.equals (sAttrName) ||
155            CSchematronXML.ATTR_SEE.equals (sAttrName) ||
156            CSchematronXML.ATTR_FPI.equals (sAttrName) ||
157            CSchematronXML.ATTR_XML_LANG.equals (sAttrName) ||
158            CSchematronXML.ATTR_XML_SPACE.equals (sAttrName);
159   }
160 
161   public void fillMicroElement (@Nonnull final IMicroElement aElement)
162   {
163     aElement.setAttribute (CSchematronXML.ATTR_ICON, m_sIcon);
164     aElement.setAttribute (CSchematronXML.ATTR_SEE, m_sSee);
165     aElement.setAttribute (CSchematronXML.ATTR_FPI, m_sFPI);
166     aElement.setAttribute (XMLConstants.XML_NS_URI, CSchematronXML.ATTR_XML_LANG, m_sXmlLang);
167     if (m_eXmlSpace != null)
168       aElement.setAttribute (XMLConstants.XML_NS_URI, CSchematronXML.ATTR_XML_SPACE, m_eXmlSpace.getID ());
169   }
170 
171   @Nonnull
172   public PSRichGroup getClone ()
173   {
174     final PSRichGroupmodel/PSRichGroup.html#PSRichGroup">PSRichGroup ret = new PSRichGroup ();
175     ret.setIcon (m_sIcon);
176     ret.setSee (m_sSee);
177     ret.setFPI (m_sFPI);
178     ret.setXmlLang (m_sXmlLang);
179     ret.setXmlSpace (m_eXmlSpace);
180     return ret;
181   }
182 
183   @Override
184   public String toString ()
185   {
186     return new ToStringGenerator (this).appendIfNotNull ("icon", m_sIcon)
187                                        .appendIfNotNull ("see", m_sSee)
188                                        .appendIfNotNull ("fpi", m_sFPI)
189                                        .appendIfNotNull ("xml:lang", m_sXmlLang)
190                                        .appendIfNotNull ("xml:space", m_eXmlSpace)
191                                        .getToString ();
192   }
193 }