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   *    https://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      @Override
52      public void action( Dsmlv2Container container ) throws XmlPullParserException
53      {
54          try
55          {
56              XmlPullParser xpp = container.getParser();
57              StringBuilder sb = new StringBuilder();
58  
59              String startTag = xpp.getText();
60              sb.append( startTag );
61  
62              // string '<' and '>'
63              startTag = startTag.substring( 1, startTag.length() - 1 );
64  
65              int tagType;
66              String endTag = "";
67  
68              // continue parsing till we get to the end tag of SOAP header
69              // and match the tag values including the namespace
70              while ( !startTag.equals( endTag ) )
71              {
72                  tagType = xpp.next();
73                  endTag = xpp.getText();
74                  sb.append( endTag );
75  
76                  if ( tagType == XmlPullParser.END_TAG )
77                  {
78                      // strip '<', '/' and '>'
79                      endTag = endTag.substring( 2, endTag.length() - 1 );
80                  }
81              }
82  
83              // change the state to header end
84              container.setState( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG );
85          }
86          catch ( IOException e )
87          {
88              e.printStackTrace();
89          }
90      }
91  }