@@ -174,6 +174,66 @@ public ValidateResult Validate(string location,
174174 } ;
175175 }
176176
177+ // 2021/1/18
178+ /*
179+ <validator>
180+ <patron>
181+ <CMIS />
182+ <range value='P000001-P999999' />
183+ </patron>
184+ <entity>
185+ <range value='0000001-9999999'></range>
186+ </entity>
187+ <shelf>
188+ <range value='0101-0909'></range>
189+ </shelf>
190+ </validator>
191+ * */
192+ // 单独验证一种类型的号码
193+ // type 为 "patron" "entity" "shelf" 之一
194+ public ValidateResult ValidateByType (
195+ string type ,
196+ string barcode )
197+ {
198+ XmlElement validator = _dom . DocumentElement ;
199+ /*
200+ if (validator.GetAttributeNode("suppress") != null)
201+ {
202+ string comment = validator.GetAttribute("suppress");
203+ if (string.IsNullOrEmpty(comment))
204+ comment = $"馆藏地 '{location}' 不打算定义验证规则";
205+ return new ValidateResult
206+ {
207+ OK = false,
208+ ErrorInfo = comment,
209+ ErrorCode = "suppressed" // 不打算定义验证规则
210+ };
211+ }
212+ */
213+
214+ XmlNodeList patron_or_entitys = validator . SelectNodes ( type ) ;
215+ foreach ( XmlElement patron_or_entity in patron_or_entitys )
216+ {
217+ var ret = ProcessEntry ( patron_or_entity ,
218+ barcode ) ;
219+ if ( ret == true )
220+ {
221+ return new ValidateResult
222+ {
223+ OK = true ,
224+ Type = patron_or_entity . Name ,
225+ } ;
226+ }
227+ }
228+
229+ return new ValidateResult
230+ {
231+ OK = false ,
232+ ErrorInfo = $ "号码 '{ barcode } ' 不是合法的 { type } 类型号码",
233+ ErrorCode = "notMatch"
234+ } ;
235+ }
236+
177237 public TransformResult Transform ( string location ,
178238 string barcode )
179239 {
@@ -470,7 +530,7 @@ static string GetString(Engine engine, string name, string default_value)
470530 // return:
471531 // false barcode 不在定义的范围内
472532 // true barcode 在定义的范围内
473- bool ProcessEntry ( XmlElement container ,
533+ public static bool ProcessEntry ( XmlElement container ,
474534 string barcode )
475535 {
476536 XmlNodeList nodes = container . SelectNodes ( "*" ) ;
0 commit comments