View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  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,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.api.dsmlv2.actions;
21  
22  
23  import java.io.IOException;
24  
25  import org.apache.directory.api.dsmlv2.Dsmlv2Container;
26  import org.apache.directory.api.dsmlv2.Dsmlv2StatesEnum;
27  import org.apache.directory.api.dsmlv2.GrammarAction;
28  import org.xmlpull.v1.XmlPullParser;
29  import org.xmlpull.v1.XmlPullParserException;
30  
31  
32  /**
33   * The action used to read the SOAP Header
34   *
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   */
37  public class ReadSoapHeader extends GrammarAction
38  {
39      /**
40       * Instantiates the action.
41       */
42      public ReadSoapHeader()
43      {
44          super( "Reads SOAP header" );
45      }
46  
47  
48      /**
49       * {@inheritDoc}
50       */
51      public void action( Dsmlv2Container container ) throws XmlPullParserException
52      {
53          try
54          {
55              XmlPullParser xpp = container.getParser();
56              StringBuilder sb = new StringBuilder();
57  
58              String startTag = xpp.getText();
59              sb.append( startTag );
60  
61              // string '<' and '>'
62              startTag = startTag.substring( 1, startTag.length() - 1 );
63  
64              int tagType = -1;
65              String endTag = "";
66  
67              // continue parsing till we get to the end tag of SOAP header
68              // and match the tag values including the namespace
69              while ( !startTag.equals( endTag ) )
70              {
71                  tagType = xpp.next();
72                  endTag = xpp.getText();
73                  sb.append( endTag );
74  
75                  if ( tagType == XmlPullParser.END_TAG )
76                  {
77                      // strip '<', '/' and '>'
78                      endTag = endTag.substring( 2, endTag.length() - 1 );
79                  }
80              }
81  
82              // change the state to header end
83              container.setState( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG );
84          }
85          catch ( IOException e )
86          {
87              e.printStackTrace();
88          }
89      }
90  }