Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.uberfire.mvp.impl;
 
 import java.util.Map;
 import java.util.Set;
 
 
 public class DefaultPlaceRequest
 implements
 
     protected final String identifier;
 
     protected final Map<StringStringparameters = new HashMap<StringString>();
 
     private final boolean updateLocationBar;
 
     public DefaultPlaceRequest() {
         this"" );
     }
 
     public DefaultPlaceRequestfinal String identifier ) {
         thisidentifier, Collections.<StringString>emptyMap(), true );
     }
 
     public DefaultPlaceRequestfinal String identifier,
                                 final Map<StringStringparameters ) {
         thisidentifierparameterstrue );
     }

    
Creates a place request for the given place ID, with the given state parameters for that place, and the given preference of whether or not the browser's location bar should be updated.

Parameters:
identifier The place ID, or an empty string for the default place.
parameters Place-specific parameters to pass to the place. Must not be null.
updateLocationBar If true, the browser's history will be updated with this place request. If false, the location bar will not be modified as a result of this place request.
 
     public DefaultPlaceRequestfinal String identifier,
                                 final Map<StringStringparameters,
                                 final boolean updateLocationBar ) {
         this. = identifier;
         this..putAllparameters );
         this. = updateLocationBar;
     }

    
Creates a new place request from a string that encodes a place ID and optional parameters in standard URL query syntax.

For example, the following returns a PlaceRequest with identifier MyPlaceID and two parameters, param1 and param2.

   DefaultPlaceRequest.parse("MyPlaceID?param1=val1&param2=val2")
 

Parameters:
partNameAndParams specification of the place ID and optional parameter map. Special characters in the identifier, key name, or key value can be escaped using URL encoding: for '%' use '%25'; for '&' use '%26'; for '=' use '%3d'; for '?' use '%3f'.
Returns:
a new PlaceRequest configured according to the given string.
 
     public static PlaceRequest parseCharSequence partNameAndParams ) {
         Map<StringStringparameters = new LinkedHashMap<StringString>();
 
         StringBuilder nextToken = new StringBuilder( 50 );
         String foundPartName = null;
         String key = null;
         for ( int i = 0; i < partNameAndParams.length(); i++ ) {
             char ch = partNameAndParams.charAti );
             switch ( ch ) {
                 case '%':
                     StringBuilder hexVal = new StringBuilder( 2 );
                     hexVal.appendpartNameAndParams.charAti + 1 ) );
                    hexVal.appendpartNameAndParams.charAti + 2 ) );
                    nextToken.append( (char) Integer.parseInthexVal.toString(), 16 ) );
                    i += 2;
                    break;
                case '?':
                    if ( foundPartName == null ) {
                        foundPartName = nextToken.toString();
                        nextToken = new StringBuilder( 50 );
                    } else {
                        nextToken.append'?' );
                    }
                    break;
                case '=':
                    if ( foundPartName == null ) {
                        nextToken.append'=' );
                    } else {
                        key = nextToken.toString();
                        nextToken = new StringBuilder( 50 );
                    }
                    break;
                case '&':
                    parameters.putkeynextToken.toString() );
                    nextToken = new StringBuilder( 50 );
                    key = null;
                    break;
                default:
                    nextToken.appendch );
            }
        }
        if ( foundPartName == null ) {
            foundPartName = nextToken.toString();
        } else if ( key != null ) {
            parameters.putkeynextToken.toString() );
        } else if ( nextToken.length() > 0 ) {
            parameters.putnextToken.toString(), "" );
        }
        return new DefaultPlaceRequestfoundPartNameparameters );
    }
    @Override
    public String getIdentifier() {
        return ;
    }
    @Override
    public String getFullIdentifier() {
        StringBuilder fullIdentifier = new StringBuilder();
        fullIdentifier.appendthis.getIdentifier() );
        if ( this.getParameterNames().size() > 0 ) {
            fullIdentifier.append"?" );
        }
        for ( String name : this.getParameterNames() ) {
            fullIdentifier.appendname ).append"=" ).appendthis.getParameternamenull ).toString() );
            fullIdentifier.append"&" );
        }
        if ( fullIdentifier.length() != 0 && fullIdentifier.lastIndexOf"&" ) + 1 == fullIdentifier.length() ) {
            fullIdentifier.deleteCharAtfullIdentifier.length() - 1 );
        }
        return fullIdentifier.toString();
    }
    //TODO: Throw ValueFormatException if conversion to a String is not possible
    @Override
    public String getParameterfinal String key,
                                final String defaultValue ) {
        final String value = .getkey );
        if ( value == null ) {
            return defaultValue;
        }
        return value;
    }
    @Override
    public Set<StringgetParameterNames() {
        return .keySet();
    }
    @Override
    public Map<StringStringgetParameters() {
        return ;
    }
    @Override
    public PlaceRequest addParameterfinal String name,
                                      final String value ) {
        this..putnamevalue );
        return this;
    }
    @Override
    public PlaceRequest clone() {
        return new DefaultPlaceRequest );
    }
    @Override
    public boolean equalsObject o ) {
        if ( this == o ) {
            return true;
        }
        if ( !( o instanceof DefaultPlaceRequest ) ) {
            return false;
        }
        final DefaultPlaceRequest that = (DefaultPlaceRequesto;
        if ( !.equalsthat.identifier ) ) {
            return false;
        }
        return .equalsthat.parameters );
    }
    @Override
    public boolean isUpdateLocationBarAllowed() {
        return ;
    }
    @Override
    public int hashCode() {
        int result = .hashCode();
        result = 31 * result + .hashCode();
        return result;
    }
    @Override
    public String toString() {
        return "PlaceRequest[\"" +  + "\" " +  + "]";
    }
New to GrepCode? Check out our FAQ X