<commit_before>/*
 * Copyright 2010 the original author or authors.
 *
 * 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.springframework.social.facebook.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * <p>
 * Web argument resolver that resolves arguments annotated with
 * {@link FacebookAccessToken} or {@link FacebookUserId}.
 * </p>
 * 
 * <p>
 * After a user has authenticated with Facebook via the XFBML
 * &lt;fb:login-button&gt; tag, their user ID and an access token are stored in
 * a cookie whose name is "fbs_{application key}". This web argument resolver
 * extracts that information from the cookie (if available) and supplies it to a
 * controller handler method as String values.
 * </p>
 * 
 * <p>
 * Both {@link FacebookAccessToken} and {@link FacebookUserId} are required by
 * default. If the access token or user ID cannot be resolved and if the
 * annotation is set to be required, an exception will be thrown indicating an
 * illegal state. If the annotation is set to not be required, a null will be
 * returned.
 * </p>
 * 
 * @author <NAME>
 */
public class FacebookWebArgumentResolver implements WebArgumentResolver {

	private final String apiKey;
	private final String appSecret;

	public FacebookWebArgumentResolver(String apiKey, String appSecret) {
		this.apiKey = apiKey;
		this.appSecret = appSecret;
	}
	
	public Object resolveArgument(MethodParameter parameter, NativeWebRequest request) throws Exception {
		FacebookCookieValue annotation = parameter.getParameterAnnotation(FacebookCookieValue.class);<commit_msg>Revised JavaDoc in FacebookWebArgumentResolver to more accurately describe when the cookie is set.<commit_after>/*
 * Copyright 2010 the original author or authors.
 *
 * 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.springframework.social.facebook.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * Web argument resolver that resolves arguments annotated with {@link FacebookCookieValue}. 
 * When using Facebook's JavaScript API, the FB.init() call will set a cookie whose name is "fbs_{api key}" if the user is signed into Facebook and if 
 * they have granted the application permission to access their profile. 
 * This web argument resolver extracts that information from the cookie (if available) and supplies it to a controller handler method as String values. 
 * {@link FacebookCookieValue} is required by default. If the access token or user ID cannot be resolved and if the annotation is set to be 
 * required, an exception will be thrown indicating an illegal state. If the annotation is set to not be required, a null will be returned.
 * @author <NAME>
 */
public class FacebookWebArgumentResolver implements WebArgumentResolver {

	private final String apiKey;
	private final String appSecret;

	public FacebookWebArgumentResolver(String apiKey, String appSecret) {
		this.apiKey = apiKey;
		this.appSecret = appSecret;
	}
	
	public Object resolveArgument(MethodParameter parameter, NativeWebRequest request) throws Exception {
		FacebookCookieValue annotation = parameter.getParameterAnnotation(FacebookCookieValue.class);
{'fraction_non_alphanumeric': 0.06864035087719299, 'fraction_numerical': 0.0035087719298245615, 'mean_word_length': 4.6239210850801475, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116052', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1096, 'n_words': 519}