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 static com.terradue.jcatalogue.client.internal.digester.Namespaces.ATOM;
20  import static com.terradue.jcatalogue.client.internal.digester.Namespaces.OPEN_SEARCH;
21  
22  import org.apache.commons.digester3.binder.AbstractNamespaceURIBasedRulesModule;
23  
24  public final class AtomRulesModule
25      extends AbstractNamespaceURIBasedRulesModule
26  {
27  
28      private final Class<?> mappedEntity;
29  
30      public AtomRulesModule( Class<?> mappedEntity )
31      {
32          super( ATOM );
33          this.mappedEntity = mappedEntity;
34      }
35  
36      @Override
37      protected void configure()
38      {
39          forPattern( "feed" ).createObject().ofType( mappedEntity );
40          forPattern( "feed/title" ).setBeanProperty();
41          forPattern( "feed/subtitle" ).setBeanProperty();
42          forPattern( "feed/updated" ).setBeanProperty();
43          forPattern( "feed/id" ).setBeanProperty();
44          forPattern( "feed/totalResults" ).withNamespaceURI( OPEN_SEARCH ).setBeanProperty().withName( "totalResults" );
45          forPattern( "feed/startIndex" ).withNamespaceURI( OPEN_SEARCH ).setBeanProperty().withName( "startIndex" );
46          forPattern( "feed/itemsPerPage" ).withNamespaceURI( OPEN_SEARCH ).setBeanProperty().withName( "itemsPerPage" );
47  
48          forPattern( "feed/link" ).callMethod( "addLink" )
49                                       .withParamTypes( String.class, String.class, String.class, Integer.class )
50                                   .then()
51                                   .callParam()
52                                       .fromAttribute( "rel" )
53                                       .ofIndex( 0 )
54                                       .then()
55                                   .callParam()
56                                       .fromAttribute( "type" )
57                                       .ofIndex( 1 )
58                                       .then()
59                                   .callParam()
60                                       .fromAttribute( "href" )
61                                       .ofIndex( 2 )
62                                       .then()
63                                   .addRuleCreatedBy( new PriorityParamRule.PriorityParamRuleProvider( 3 ) );
64      }
65  
66  }