1 package org.apache.archiva.redback.struts2.result;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
25 import org.apache.archiva.redback.struts2.interceptor.SavedActionInvocation;
26 import org.apache.struts2.dispatcher.ServletActionRedirectResult;
27 import org.apache.archiva.redback.struts2.interceptor.ActionInvocationTracker;
28 import com.opensymphony.xwork2.ActionInvocation;
30 @SuppressWarnings("serial")
31 public class AbstractBackTrackingResult
32 extends ServletActionRedirectResult
34 public static final int PREVIOUS = 1;
36 public static final int CURRENT = 2;
38 protected boolean setupBackTrackPrevious( ActionInvocation invocation )
40 return setupBackTrack( invocation, PREVIOUS );
43 protected boolean setupBackTrackCurrent( ActionInvocation invocation )
45 return setupBackTrack( invocation, CURRENT );
48 @SuppressWarnings("unchecked")
49 protected boolean setupBackTrack( ActionInvocation invocation, int order )
51 Map session = invocation.getInvocationContext().getSession();
52 ActionInvocationTracker tracker = (ActionInvocationTracker) session.get( ActionInvocationTracker.SESSION_KEY );
54 if ( tracker != null && tracker.isBackTracked() )
56 SavedActionInvocation savedInvocation;
58 if ( order == PREVIOUS )
60 savedInvocation = tracker.getPrevious();
64 savedInvocation = tracker.getCurrent();
67 if ( savedInvocation != null )
69 setNamespace( savedInvocation.getNamespace() );
70 setActionName( savedInvocation.getActionName() );
71 setMethod( savedInvocation.getMethodName() );
73 invocation.getInvocationContext().getParameters().clear();
74 invocation.getInvocationContext().getParameters().putAll( savedInvocation.getParametersMap() );
76 // hack for REDBACK-188
77 String resultCode = invocation.getResultCode();
79 if( resultCode != null )
81 // hack for REDBACK-262
82 // set this to null so the ResultConfig parameters won't be added in the ServletActionRedirectResult
83 // because we can't clear the parameters of ResultConfig since it's read-only
84 invocation.setResultCode( null );
86 Set<String> keys = savedInvocation.getParametersMap().keySet();
88 for( String key : keys )
90 if ( !getProhibitedResultParams().contains( key ) )
92 String value = ( (String[]) savedInvocation.getParametersMap().get( key ) )[0];
93 if ( value != null && value.length() > 0 )
95 addParameter( key, conditionalParse( value, invocation ) );
101 tracker.unsetBackTrack();