View Javadoc

1   package com.terradue.jcatalogue.client.internal.digester;
2   
3   /*
4    *    Copyright 2011-2012 Terradue srl
5    *
6    *    Licensed under the Apache License, Version 2.0 (the "License");
7    *    you may not use this file except in compliance with the License.
8    *    You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *    Unless required by applicable law or agreed to in writing, software
13   *    distributed under the License is distributed on an "AS IS" BASIS,
14   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *    See the License for the specific language governing permissions and
16   *    limitations under the License.
17   */
18  
19  import org.apache.commons.digester3.Rule;
20  import org.apache.commons.digester3.binder.RuleProvider;
21  import org.xml.sax.Attributes;
22  
23  final class PriorityParamRule
24      extends Rule
25  {
26  
27      private static final Integer MIN_PRIORITY = 999999;
28  
29      private final int paramIndex;
30  
31      private PriorityParamRule( int paramIndex )
32      {
33          this.paramIndex = paramIndex;
34      }
35  
36      @Override
37      public void begin( String namespace, String name, Attributes attributes )
38          throws Exception
39      {
40          Integer priority = MIN_PRIORITY;
41          String priorityValue = attributes.getValue( "urn:ietf:params:xml:ns:metalink", "priority" );
42  
43          if ( priorityValue != null )
44          {
45              priority = Integer.valueOf( priorityValue );
46          }
47  
48          getDigester().peekParams()[paramIndex] = priority;
49      }
50  
51      public static final class PriorityParamRuleProvider
52          implements RuleProvider<PriorityParamRule>
53      {
54  
55          private final int paramIndex;
56  
57          public PriorityParamRuleProvider( int paramIndex )
58          {
59              this.paramIndex = paramIndex;
60          }
61  
62          @Override
63          public PriorityParamRule get()
64          {
65              return new PriorityParamRule( paramIndex );
66          }
67  
68      }
69  
70  }