001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.dsmlv2.actions; 021 022 023import java.io.IOException; 024 025import org.apache.directory.api.dsmlv2.Dsmlv2Container; 026import org.apache.directory.api.dsmlv2.Dsmlv2StatesEnum; 027import org.apache.directory.api.dsmlv2.GrammarAction; 028import org.xmlpull.v1.XmlPullParser; 029import org.xmlpull.v1.XmlPullParserException; 030 031 032/** 033 * The action used to read the SOAP Header 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037public class ReadSoapHeader extends GrammarAction 038{ 039 /** 040 * Instantiates the action. 041 */ 042 public ReadSoapHeader() 043 { 044 super( "Reads SOAP header" ); 045 } 046 047 048 /** 049 * {@inheritDoc} 050 */ 051 @Override 052 public void action( Dsmlv2Container container ) throws XmlPullParserException 053 { 054 try 055 { 056 XmlPullParser xpp = container.getParser(); 057 StringBuilder sb = new StringBuilder(); 058 059 String startTag = xpp.getText(); 060 sb.append( startTag ); 061 062 // string '<' and '>' 063 startTag = startTag.substring( 1, startTag.length() - 1 ); 064 065 int tagType; 066 String endTag = ""; 067 068 // continue parsing till we get to the end tag of SOAP header 069 // and match the tag values including the namespace 070 while ( !startTag.equals( endTag ) ) 071 { 072 tagType = xpp.next(); 073 endTag = xpp.getText(); 074 sb.append( endTag ); 075 076 if ( tagType == XmlPullParser.END_TAG ) 077 { 078 // strip '<', '/' and '>' 079 endTag = endTag.substring( 2, endTag.length() - 1 ); 080 } 081 } 082 083 // change the state to header end 084 container.setState( Dsmlv2StatesEnum.SOAP_HEADER_END_TAG ); 085 } 086 catch ( IOException e ) 087 { 088 e.printStackTrace(); 089 } 090 } 091}