| @ -1,15 +1,21 @@ | |||
| ## Prerequisite: | |||
| ### Linux | |||
| #### Install the Appengine SDK. | |||
| `$ sudo apt-get install google-cloud-sdk-app-engine-java` | |||
| ### Mac | |||
| #### Install the Google Cloud SDK. | |||
| `$ brew install google-cloud-sdk` | |||
| #### Use GCloud CLI to install the Java Appengine | |||
| `$ gcloud components install app-engine-java` | |||
| ## How to regenerate the WAR, deploy and run in appengine? | |||
| `$ mvn appengine:run` | |||
| `$ mvn appengine:run` | |||
| @ -1,441 +0,0 @@ | |||
| /* | |||
| * Copyright (C) 2011 The Libphonenumber 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. | |||
| * | |||
| * @author Shaopeng Jia | |||
| */ | |||
| package com.google.phonenumbers; | |||
| import static java.nio.charset.StandardCharsets.UTF_8; | |||
| import static java.util.Locale.ENGLISH; | |||
| import com.google.i18n.phonenumbers.AsYouTypeFormatter; | |||
| import com.google.i18n.phonenumbers.NumberParseException; | |||
| import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper; | |||
| import com.google.i18n.phonenumbers.PhoneNumberToTimeZonesMapper; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberType; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil.ValidationResult; | |||
| import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; | |||
| import com.google.i18n.phonenumbers.ShortNumberInfo; | |||
| import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URLEncoder; | |||
| import java.util.Locale; | |||
| import java.util.StringTokenizer; | |||
| import javax.servlet.http.HttpServlet; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import org.apache.commons.fileupload.FileItemIterator; | |||
| import org.apache.commons.fileupload.FileItemStream; | |||
| import org.apache.commons.fileupload.FileUploadException; | |||
| import org.apache.commons.fileupload.servlet.ServletFileUpload; | |||
| import org.apache.commons.fileupload.util.Streams; | |||
| import org.apache.commons.io.IOUtils; | |||
| import org.apache.commons.lang.StringEscapeUtils; | |||
| /** | |||
| * A servlet that accepts requests that contain strings representing a phone number and a default | |||
| * country, and responds with results from parsing, validating and formatting the number. The | |||
| * default country is a two-letter region code representing the country that we are expecting the | |||
| * number to be from. | |||
| */ | |||
| @SuppressWarnings("serial") | |||
| public class PhoneNumberParserServlet extends HttpServlet { | |||
| private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); | |||
| private ShortNumberInfo shortInfo = ShortNumberInfo.getInstance(); | |||
| public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |||
| String phoneNumber = null; | |||
| String defaultCountry = null; | |||
| String languageCode = "en"; // Default languageCode to English if nothing is entered. | |||
| String regionCode = ""; | |||
| String fileContents = null; | |||
| ServletFileUpload upload = new ServletFileUpload(); | |||
| upload.setSizeMax(50000); | |||
| try { | |||
| FileItemIterator iterator = upload.getItemIterator(req); | |||
| while (iterator.hasNext()) { | |||
| FileItemStream item = iterator.next(); | |||
| InputStream in = item.openStream(); | |||
| if (item.isFormField()) { | |||
| String fieldName = item.getFieldName(); | |||
| if (fieldName.equals("phoneNumber")) { | |||
| phoneNumber = Streams.asString(in, UTF_8.name()); | |||
| } else if (fieldName.equals("defaultCountry")) { | |||
| defaultCountry = Streams.asString(in).toUpperCase(); | |||
| } else if (fieldName.equals("languageCode")) { | |||
| String languageEntered = Streams.asString(in).toLowerCase(); | |||
| if (languageEntered.length() > 0) { | |||
| languageCode = languageEntered; | |||
| } | |||
| } else if (fieldName.equals("regionCode")) { | |||
| regionCode = Streams.asString(in).toUpperCase(); | |||
| } | |||
| } else { | |||
| try { | |||
| fileContents = IOUtils.toString(in); | |||
| } finally { | |||
| IOUtils.closeQuietly(in); | |||
| } | |||
| } | |||
| } | |||
| } catch (FileUploadException e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| StringBuilder output; | |||
| resp.setContentType("text/html"); | |||
| resp.setCharacterEncoding(UTF_8.name()); | |||
| if (fileContents == null || fileContents.length() == 0) { | |||
| // Redirect to a URL with the given input encoded in the query parameters. | |||
| Locale geocodingLocale = new Locale(languageCode, regionCode); | |||
| resp.sendRedirect( | |||
| getPermaLinkURL(phoneNumber, defaultCountry, geocodingLocale, false /* absoluteURL */)); | |||
| } else { | |||
| resp.getWriter().println(getOutputForFile(defaultCountry, fileContents)); | |||
| } | |||
| } | |||
| /** Handle the get request to get information about a number based on query parameters. */ | |||
| public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |||
| String phoneNumber = req.getParameter("number"); | |||
| if (phoneNumber == null) { | |||
| phoneNumber = ""; | |||
| } | |||
| String defaultCountry = req.getParameter("country"); | |||
| if (defaultCountry == null) { | |||
| defaultCountry = ""; | |||
| } | |||
| String geocodingParam = req.getParameter("geocodingLocale"); | |||
| Locale geocodingLocale; | |||
| if (geocodingParam == null) { | |||
| geocodingLocale = ENGLISH; // Default languageCode to English if nothing is entered. | |||
| } else { | |||
| geocodingLocale = Locale.forLanguageTag(geocodingParam); | |||
| } | |||
| resp.setContentType("text/html"); | |||
| resp.setCharacterEncoding(UTF_8.name()); | |||
| resp.getWriter() | |||
| .println(getOutputForSingleNumber(phoneNumber, defaultCountry, geocodingLocale)); | |||
| } | |||
| private StringBuilder getOutputForFile(String defaultCountry, String fileContents) { | |||
| StringBuilder output = | |||
| new StringBuilder( | |||
| "<HTML><HEAD><TITLE>Results generated from phone numbers in the file provided:" | |||
| + "</TITLE></HEAD><BODY>"); | |||
| output.append("<TABLE align=center border=1>"); | |||
| output.append("<TH align=center>ID</TH>"); | |||
| output.append("<TH align=center>Raw phone number</TH>"); | |||
| output.append("<TH align=center>Pretty formatting</TH>"); | |||
| output.append("<TH align=center>International format</TH>"); | |||
| int phoneNumberId = 0; | |||
| StringTokenizer tokenizer = new StringTokenizer(fileContents, ","); | |||
| while (tokenizer.hasMoreTokens()) { | |||
| String numberStr = tokenizer.nextToken(); | |||
| phoneNumberId++; | |||
| output.append("<TR>"); | |||
| output.append("<TD align=center>").append(phoneNumberId).append(" </TD> \n"); | |||
| output | |||
| .append("<TD align=center>") | |||
| .append(StringEscapeUtils.escapeHtml(numberStr)) | |||
| .append(" </TD> \n"); | |||
| try { | |||
| PhoneNumber number = phoneUtil.parseAndKeepRawInput(numberStr, defaultCountry); | |||
| boolean isNumberValid = phoneUtil.isValidNumber(number); | |||
| String prettyFormat = | |||
| isNumberValid ? phoneUtil.formatInOriginalFormat(number, defaultCountry) : "invalid"; | |||
| String internationalFormat = | |||
| isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL) : "invalid"; | |||
| output | |||
| .append("<TD align=center>") | |||
| .append(StringEscapeUtils.escapeHtml(prettyFormat)) | |||
| .append(" </TD> \n"); | |||
| output | |||
| .append("<TD align=center>") | |||
| .append(StringEscapeUtils.escapeHtml(internationalFormat)) | |||
| .append(" </TD> \n"); | |||
| } catch (NumberParseException e) { | |||
| output | |||
| .append("<TD align=center colspan=2>") | |||
| .append(StringEscapeUtils.escapeHtml(e.toString())) | |||
| .append(" </TD> \n"); | |||
| } | |||
| output.append("</TR>"); | |||
| } | |||
| output.append("</BODY></HTML>"); | |||
| return output; | |||
| } | |||
| private void appendLine(String title, String data, StringBuilder output) { | |||
| output.append("<TR>"); | |||
| output.append("<TH>").append(title).append("</TH>"); | |||
| output.append("<TD>").append(data.length() > 0 ? data : " ").append("</TD>"); | |||
| output.append("</TR>"); | |||
| } | |||
| /** Returns a stable URL pointing to the result page for the given input. */ | |||
| private String getPermaLinkURL( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale, boolean absoluteURL) { | |||
| // If absoluteURL is false, generate a relative path. Otherwise, produce an absolute URL. | |||
| StringBuilder permaLink = | |||
| new StringBuilder( | |||
| absoluteURL | |||
| ? "http://libphonenumber.appspot.com/phonenumberparser" | |||
| : "/phonenumberparser"); | |||
| try { | |||
| permaLink.append( | |||
| "?number=" + URLEncoder.encode(phoneNumber != null ? phoneNumber : "", UTF_8.name())); | |||
| if (defaultCountry != null && !defaultCountry.isEmpty()) { | |||
| permaLink.append("&country=" + URLEncoder.encode(defaultCountry, UTF_8.name())); | |||
| } | |||
| if (!geocodingLocale.getLanguage().equals(ENGLISH.getLanguage()) | |||
| || !geocodingLocale.getCountry().isEmpty()) { | |||
| permaLink.append( | |||
| "&geocodingLocale=" + URLEncoder.encode(geocodingLocale.toLanguageTag(), UTF_8.name())); | |||
| } | |||
| } catch (UnsupportedEncodingException e) { | |||
| // UTF-8 is guaranteed in Java, so this should be impossible. | |||
| throw new AssertionError(e); | |||
| } | |||
| return permaLink.toString(); | |||
| } | |||
| private static final String NEW_ISSUE_BASE_URL = | |||
| "https://issuetracker.google.com/issues/new?component=192347&title="; | |||
| /** Returns a link to create a new github issue with the relevant information. */ | |||
| private String getNewIssueLink( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale) { | |||
| boolean hasDefaultCountry = !defaultCountry.isEmpty() && defaultCountry != "ZZ"; | |||
| String issueTitle = | |||
| "Validation issue with " | |||
| + phoneNumber | |||
| + (hasDefaultCountry ? " (" + defaultCountry + ")" : ""); | |||
| String newIssueLink = NEW_ISSUE_BASE_URL; | |||
| try { | |||
| newIssueLink += URLEncoder.encode(issueTitle, UTF_8.name()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| // UTF-8 is guaranteed in Java, so this should be impossible. | |||
| throw new AssertionError(e); | |||
| } | |||
| return newIssueLink; | |||
| } | |||
| /** | |||
| * The defaultCountry here is used for parsing phoneNumber. The geocodingLocale is used to specify | |||
| * the language used for displaying the area descriptions generated from phone number geocoding. | |||
| */ | |||
| private StringBuilder getOutputForSingleNumber( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale) { | |||
| StringBuilder output = new StringBuilder("<HTML><HEAD>"); | |||
| output.append("<LINK type=\"text/css\" rel=\"stylesheet\" href=\"/stylesheets/main.css\" />"); | |||
| output.append("</HEAD>"); | |||
| output.append("<BODY>"); | |||
| output.append("Phone Number entered: " + StringEscapeUtils.escapeHtml(phoneNumber) + "<BR>"); | |||
| output.append( | |||
| "defaultCountry entered: " + StringEscapeUtils.escapeHtml(defaultCountry) + "<BR>"); | |||
| output.append( | |||
| "Language entered: " | |||
| + StringEscapeUtils.escapeHtml(geocodingLocale.toLanguageTag()) | |||
| + "<BR>"); | |||
| try { | |||
| PhoneNumber number = phoneUtil.parseAndKeepRawInput(phoneNumber, defaultCountry); | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>Parsing Result (parseAndKeepRawInput())</TD></TR>"); | |||
| appendLine("country_code", Integer.toString(number.getCountryCode()), output); | |||
| appendLine("national_number", Long.toString(number.getNationalNumber()), output); | |||
| appendLine("extension", number.getExtension(), output); | |||
| appendLine("country_code_source", number.getCountryCodeSource().toString(), output); | |||
| appendLine("italian_leading_zero", Boolean.toString(number.isItalianLeadingZero()), output); | |||
| appendLine("raw_input", number.getRawInput(), output); | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| boolean isPossible = phoneUtil.isPossibleNumber(number); | |||
| boolean isNumberValid = phoneUtil.isValidNumber(number); | |||
| PhoneNumberType numberType = phoneUtil.getNumberType(number); | |||
| boolean hasDefaultCountry = !defaultCountry.isEmpty() && defaultCountry != "ZZ"; | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>Validation Results</TD></TR>"); | |||
| appendLine("Result from isPossibleNumber()", Boolean.toString(isPossible), output); | |||
| if (isPossible) { | |||
| if (phoneUtil.isPossibleNumberWithReason(number) | |||
| == ValidationResult.IS_POSSIBLE_LOCAL_ONLY) { | |||
| appendLine("Result from isPossibleNumberWithReason()", "IS_POSSIBLE_LOCAL_ONLY", output); | |||
| output.append( | |||
| "<TR><TD colspan=2>Number is considered invalid as it is " | |||
| + "not a possible national number.</TD></TR>"); | |||
| } else { | |||
| appendLine("Result from isValidNumber()", Boolean.toString(isNumberValid), output); | |||
| if (isNumberValid && hasDefaultCountry) { | |||
| appendLine( | |||
| "Result from isValidNumberForRegion()", | |||
| Boolean.toString(phoneUtil.isValidNumberForRegion(number, defaultCountry)), | |||
| output); | |||
| } | |||
| String region = phoneUtil.getRegionCodeForNumber(number); | |||
| appendLine("Phone Number region", region == null ? "" : region, output); | |||
| appendLine("Result from getNumberType()", numberType.toString(), output); | |||
| } | |||
| } else { | |||
| appendLine( | |||
| "Result from isPossibleNumberWithReason()", | |||
| phoneUtil.isPossibleNumberWithReason(number).toString(), | |||
| output); | |||
| output.append( | |||
| "<TR><TD colspan=2>Note: Numbers that are not possible have type UNKNOWN," | |||
| + " an unknown region, and are considered invalid.</TD></TR>"); | |||
| } | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| if (!isNumberValid) { | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>Short Number Results</TD></TR>"); | |||
| boolean isPossibleShort = shortInfo.isPossibleShortNumber(number); | |||
| appendLine( | |||
| "Result from isPossibleShortNumber()", Boolean.toString(isPossibleShort), output); | |||
| if (isPossibleShort) { | |||
| appendLine( | |||
| "Result from isValidShortNumber()", | |||
| Boolean.toString(shortInfo.isValidShortNumber(number)), | |||
| output); | |||
| if (hasDefaultCountry) { | |||
| boolean isPossibleShortForRegion = | |||
| shortInfo.isPossibleShortNumberForRegion(number, defaultCountry); | |||
| appendLine( | |||
| "Result from isPossibleShortNumberForRegion()", | |||
| Boolean.toString(isPossibleShortForRegion), | |||
| output); | |||
| if (isPossibleShortForRegion) { | |||
| appendLine( | |||
| "Result from isValidShortNumberForRegion()", | |||
| Boolean.toString(shortInfo.isValidShortNumberForRegion(number, defaultCountry)), | |||
| output); | |||
| } | |||
| } | |||
| } | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| } | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>Formatting Results</TD></TR>"); | |||
| appendLine( | |||
| "E164 format", | |||
| isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.E164) : "invalid", | |||
| output); | |||
| appendLine( | |||
| "Original format", phoneUtil.formatInOriginalFormat(number, defaultCountry), output); | |||
| appendLine("National format", phoneUtil.format(number, PhoneNumberFormat.NATIONAL), output); | |||
| appendLine( | |||
| "International format", | |||
| isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL) : "invalid", | |||
| output); | |||
| appendLine( | |||
| "Out-of-country format from US", | |||
| isNumberValid ? phoneUtil.formatOutOfCountryCallingNumber(number, "US") : "invalid", | |||
| output); | |||
| appendLine( | |||
| "Out-of-country format from CH", | |||
| isNumberValid ? phoneUtil.formatOutOfCountryCallingNumber(number, "CH") : "invalid", | |||
| output); | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter(defaultCountry); | |||
| int rawNumberLength = phoneNumber.length(); | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>AsYouTypeFormatter Results</TD></TR>"); | |||
| for (int i = 0; i < rawNumberLength; i++) { | |||
| // Note this doesn't handle supplementary characters, but it shouldn't be a big deal as | |||
| // there are no dial-pad characters in the supplementary range. | |||
| char inputChar = phoneNumber.charAt(i); | |||
| appendLine( | |||
| "Char entered: '" + inputChar + "' Output: ", formatter.inputDigit(inputChar), output); | |||
| } | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| if (isNumberValid) { | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>PhoneNumberOfflineGeocoder Results</TD></TR>"); | |||
| appendLine( | |||
| "Location", | |||
| PhoneNumberOfflineGeocoder.getInstance() | |||
| .getDescriptionForNumber(number, geocodingLocale), | |||
| output); | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>PhoneNumberToTimeZonesMapper Results</TD></TR>"); | |||
| appendLine( | |||
| "Time zone(s)", | |||
| PhoneNumberToTimeZonesMapper.getInstance().getTimeZonesForNumber(number).toString(), | |||
| output); | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| if (numberType == PhoneNumberType.MOBILE | |||
| || numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE | |||
| || numberType == PhoneNumberType.PAGER) { | |||
| output.append("<DIV>"); | |||
| output.append("<TABLE border=1>"); | |||
| output.append("<TR><TD colspan=2>PhoneNumberToCarrierMapper Results</TD></TR>"); | |||
| appendLine( | |||
| "Carrier", | |||
| PhoneNumberToCarrierMapper.getInstance().getNameForNumber(number, geocodingLocale), | |||
| output); | |||
| output.append("</TABLE>"); | |||
| output.append("</DIV>"); | |||
| } | |||
| } | |||
| String newIssueLink = getNewIssueLink(phoneNumber, defaultCountry, geocodingLocale); | |||
| String guidelinesLink = | |||
| "https://github.com/google/libphonenumber/blob/master/CONTRIBUTING.md"; | |||
| output.append( | |||
| "<b style=\"color:red\">File an issue</b>: by clicking on " | |||
| + "<a target=\"_blank\" href=\"" | |||
| + newIssueLink | |||
| + "\">this link</a>, I confirm that I " | |||
| + "have read the <a target=\"_blank\" href=\"" | |||
| + guidelinesLink | |||
| + "\">contributor's guidelines</a>."); | |||
| } catch (NumberParseException e) { | |||
| output.append(StringEscapeUtils.escapeHtml(e.toString())); | |||
| } | |||
| output.append("</BODY></HTML>"); | |||
| return output; | |||
| } | |||
| } | |||
| @ -0,0 +1,44 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Shaopeng Jia | |||
| */ | |||
| package com.google.phonenumbers.demo; | |||
| import static java.nio.charset.StandardCharsets.UTF_8; | |||
| import com.google.phonenumbers.demo.render.InputFormRenderer; | |||
| import java.io.IOException; | |||
| import javax.servlet.http.HttpServlet; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| /** | |||
| * A servlet that accepts requests that contain strings representing a phone number and a default | |||
| * country, and responds with results from parsing, validating and formatting the number. The | |||
| * default country is a two-letter region code representing the country that we are expecting the | |||
| * number to be from. | |||
| */ | |||
| @SuppressWarnings("serial") | |||
| public class InputServlet extends HttpServlet { | |||
| /** Handle the get request to get information about a number based on query parameters. */ | |||
| public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |||
| resp.setContentType("text/html"); | |||
| resp.setCharacterEncoding(UTF_8.name()); | |||
| resp.getWriter().println(new InputFormRenderer().genHtml()); | |||
| } | |||
| } | |||
| @ -0,0 +1,144 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Shaopeng Jia | |||
| */ | |||
| package com.google.phonenumbers.demo; | |||
| import static java.nio.charset.StandardCharsets.UTF_8; | |||
| import static java.util.Locale.ENGLISH; | |||
| import com.google.i18n.phonenumbers.NumberParseException; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil; | |||
| import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; | |||
| import com.google.phonenumbers.demo.helper.WebHelper; | |||
| import com.google.phonenumbers.demo.render.ErrorRenderer; | |||
| import com.google.phonenumbers.demo.render.ResultFileRenderer; | |||
| import com.google.phonenumbers.demo.render.ResultRenderer; | |||
| import java.io.IOException; | |||
| import java.io.InputStream; | |||
| import java.util.Locale; | |||
| import javax.servlet.http.HttpServlet; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import org.apache.commons.fileupload.FileItemIterator; | |||
| import org.apache.commons.fileupload.FileItemStream; | |||
| import org.apache.commons.fileupload.FileUploadException; | |||
| import org.apache.commons.fileupload.servlet.ServletFileUpload; | |||
| import org.apache.commons.fileupload.util.Streams; | |||
| import org.apache.commons.io.IOUtils; | |||
| /** | |||
| * A servlet that accepts requests that contain strings representing a phone number and a default | |||
| * country, and responds with results from parsing, validating and formatting the number. The | |||
| * default country is a two-letter region code representing the country that we are expecting the | |||
| * number to be from. | |||
| */ | |||
| @SuppressWarnings("serial") | |||
| public class ResultServlet extends HttpServlet { | |||
| private final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); | |||
| public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |||
| String phoneNumber = null; | |||
| String defaultCountry = null; | |||
| String languageCode = "en"; // Default languageCode to English if nothing is entered. | |||
| String regionCode = ""; | |||
| String fileContents = null; | |||
| ServletFileUpload upload = new ServletFileUpload(); | |||
| upload.setSizeMax(50000); | |||
| try { | |||
| FileItemIterator iterator = upload.getItemIterator(req); | |||
| while (iterator.hasNext()) { | |||
| FileItemStream item = iterator.next(); | |||
| InputStream in = item.openStream(); | |||
| if (item.isFormField()) { | |||
| String fieldName = item.getFieldName(); | |||
| if (fieldName.equals("phoneNumber")) { | |||
| phoneNumber = Streams.asString(in, UTF_8.name()); | |||
| } else if (fieldName.equals("defaultCountry")) { | |||
| defaultCountry = Streams.asString(in).toUpperCase(); | |||
| } else if (fieldName.equals("languageCode")) { | |||
| String languageEntered = Streams.asString(in).toLowerCase(); | |||
| if (languageEntered.length() > 0) { | |||
| languageCode = languageEntered; | |||
| } | |||
| } else if (fieldName.equals("regionCode")) { | |||
| regionCode = Streams.asString(in).toUpperCase(); | |||
| } | |||
| } else { | |||
| try { | |||
| fileContents = IOUtils.toString(in); | |||
| } finally { | |||
| IOUtils.closeQuietly(in); | |||
| } | |||
| } | |||
| } | |||
| } catch (FileUploadException e1) { | |||
| e1.printStackTrace(); | |||
| } | |||
| resp.setContentType("text/html"); | |||
| resp.setCharacterEncoding(UTF_8.name()); | |||
| if (fileContents == null || fileContents.length() == 0) { | |||
| // Redirect to a URL with the given input encoded in the query parameters. | |||
| Locale geocodingLocale = new Locale(languageCode, regionCode); | |||
| resp.sendRedirect( | |||
| WebHelper.getPermaLinkURL( | |||
| phoneNumber, defaultCountry, geocodingLocale, false /* absoluteURL */)); | |||
| } else { | |||
| resp.getWriter().println(new ResultFileRenderer(defaultCountry, fileContents).genHtml()); | |||
| } | |||
| } | |||
| /** Handle the get request to get information about a number based on query parameters. */ | |||
| public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |||
| String phoneNumber = req.getParameter("number"); | |||
| if (phoneNumber == null) { | |||
| phoneNumber = ""; | |||
| } | |||
| String defaultCountry = req.getParameter("country"); | |||
| if (defaultCountry == null) { | |||
| defaultCountry = ""; | |||
| } | |||
| String geocodingParam = req.getParameter("geocodingLocale"); | |||
| Locale geocodingLocale; | |||
| if (geocodingParam == null) { | |||
| geocodingLocale = ENGLISH; // Default languageCode to English if nothing is entered. | |||
| } else { | |||
| geocodingLocale = Locale.forLanguageTag(geocodingParam); | |||
| } | |||
| resp.setContentType("text/html"); | |||
| resp.setCharacterEncoding(UTF_8.name()); | |||
| resp.getWriter() | |||
| .println(getOutputForSingleNumber(phoneNumber, defaultCountry, geocodingLocale)); | |||
| } | |||
| /** | |||
| * The defaultCountry here is used for parsing phoneNumber. The geocodingLocale is used to specify | |||
| * the language used for displaying the area descriptions generated from phone number geocoding. | |||
| */ | |||
| private String getOutputForSingleNumber( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale) { | |||
| try { | |||
| PhoneNumber number = phoneUtil.parseAndKeepRawInput(phoneNumber, defaultCountry); | |||
| return new ResultRenderer(phoneNumber, defaultCountry, geocodingLocale, number).genHtml(); | |||
| } catch (NumberParseException e) { | |||
| return new ErrorRenderer(phoneNumber, defaultCountry, geocodingLocale, e.toString()) | |||
| .genHtml(); | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,76 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Shaopeng Jia | |||
| */ | |||
| package com.google.phonenumbers.demo.helper; | |||
| import static java.nio.charset.StandardCharsets.UTF_8; | |||
| import static java.util.Locale.ENGLISH; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URLEncoder; | |||
| import java.util.Locale; | |||
| public class WebHelper { | |||
| private static final String NEW_ISSUE_BASE_URL = | |||
| "https://issuetracker.google.com/issues/new?component=192347&title="; | |||
| /** Returns a stable URL pointing to the result page for the given input. */ | |||
| public static String getPermaLinkURL( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale, boolean absoluteURL) { | |||
| // If absoluteURL is false, generate a relative path. Otherwise, produce an absolute URL. | |||
| StringBuilder permaLink = | |||
| new StringBuilder( | |||
| absoluteURL | |||
| ? "http://libphonenumber.appspot.com/phonenumberparser" | |||
| : "/phonenumberparser"); | |||
| try { | |||
| permaLink.append( | |||
| "?number=" + URLEncoder.encode(phoneNumber != null ? phoneNumber : "", UTF_8.name())); | |||
| if (defaultCountry != null && !defaultCountry.isEmpty()) { | |||
| permaLink.append("&country=" + URLEncoder.encode(defaultCountry, UTF_8.name())); | |||
| } | |||
| if (!geocodingLocale.getLanguage().equals(ENGLISH.getLanguage()) | |||
| || !geocodingLocale.getCountry().isEmpty()) { | |||
| permaLink.append( | |||
| "&geocodingLocale=" + URLEncoder.encode(geocodingLocale.toLanguageTag(), UTF_8.name())); | |||
| } | |||
| } catch (UnsupportedEncodingException e) { | |||
| // UTF-8 is guaranteed in Java, so this should be impossible. | |||
| throw new AssertionError(e); | |||
| } | |||
| return permaLink.toString(); | |||
| } | |||
| /** Returns a link to create a new github issue with the relevant information. */ | |||
| public static String getNewIssueLink( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale) { | |||
| boolean hasDefaultCountry = !defaultCountry.isEmpty() && defaultCountry != "ZZ"; | |||
| String issueTitle = | |||
| "Validation issue with " | |||
| + phoneNumber | |||
| + (hasDefaultCountry ? " (" + defaultCountry + ")" : ""); | |||
| String newIssueLink = NEW_ISSUE_BASE_URL; | |||
| try { | |||
| newIssueLink += URLEncoder.encode(issueTitle, UTF_8.name()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| // UTF-8 is guaranteed in Java, so this should be impossible. | |||
| throw new AssertionError(e); | |||
| } | |||
| return newIssueLink; | |||
| } | |||
| } | |||
| @ -0,0 +1,50 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Tobias Rogg | |||
| */ | |||
| package com.google.phonenumbers.demo.render; | |||
| import com.google.phonenumbers.demo.template.ResultErrorTemplates; | |||
| import com.google.phonenumbers.demo.template.ResultErrorTemplates.Error; | |||
| import java.util.Locale; | |||
| public class ErrorRenderer extends LibPhoneNumberRenderer<Error> { | |||
| private final String phoneNumber; | |||
| private final String defaultCountry; | |||
| private final Locale geocodingLocale; | |||
| private final String error; | |||
| public ErrorRenderer( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale, String error) { | |||
| super("result_error.soy", "com.google.phonenumbers.demo.error"); | |||
| this.phoneNumber = phoneNumber; | |||
| this.defaultCountry = defaultCountry; | |||
| this.geocodingLocale = geocodingLocale; | |||
| this.error = error; | |||
| } | |||
| @Override | |||
| public String genHtml() { | |||
| return super.render( | |||
| ResultErrorTemplates.Error.builder() | |||
| .setPhoneNumber(phoneNumber) | |||
| .setDefaultCountry(defaultCountry) | |||
| .setGeocodingLocale(geocodingLocale.toLanguageTag()) | |||
| .setError(error) | |||
| .build()); | |||
| } | |||
| } | |||
| @ -0,0 +1,37 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Tobias Rogg | |||
| */ | |||
| package com.google.phonenumbers.demo.render; | |||
| import com.google.phonenumbers.demo.template.InputFormTemplates; | |||
| import com.google.phonenumbers.demo.template.InputFormTemplates.InputForm; | |||
| public class InputFormRenderer extends LibPhoneNumberRenderer<InputForm> { | |||
| public InputFormRenderer() { | |||
| super("input_form.soy", "com.google.phonenumbers.demo.inputForm"); | |||
| } | |||
| @Override | |||
| public String genHtml() { | |||
| return super.render( | |||
| InputFormTemplates.InputForm.builder() | |||
| .setWelcomeTitle("Phone Number Parser Demo for LibPhoneNumber") | |||
| .build()); | |||
| } | |||
| } | |||
| @ -0,0 +1,50 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Tobias Rogg | |||
| */ | |||
| package com.google.phonenumbers.demo.render; | |||
| import com.google.template.soy.SoyFileSet; | |||
| import com.google.template.soy.data.SoyTemplate; | |||
| import com.google.template.soy.tofu.SoyTofu; | |||
| import java.net.URL; | |||
| public abstract class LibPhoneNumberRenderer<T extends SoyTemplate> { | |||
| private final String template; | |||
| private final String namespace; | |||
| public LibPhoneNumberRenderer(String template, String namespace) { | |||
| this.template = template; | |||
| this.namespace = namespace; | |||
| } | |||
| private URL getResource() { | |||
| return LibPhoneNumberRenderer.class.getResource("../" + template); | |||
| } | |||
| String render(T soyTemplate) { | |||
| SoyFileSet sfs = SoyFileSet.builder().add(getResource()).build(); | |||
| SoyTofu tofu = sfs.compileToTofu(); | |||
| // For convenience, create another SoyTofu object that has a | |||
| // namespace specified, so you can pass partial template names to | |||
| // the newRenderer() method. | |||
| SoyTofu simpleTofu = tofu.forNamespace(namespace); | |||
| return simpleTofu.newRenderer(soyTemplate).render(); | |||
| } | |||
| public abstract String genHtml(); | |||
| } | |||
| @ -0,0 +1,62 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Tobias Rogg | |||
| */ | |||
| package com.google.phonenumbers.demo.render; | |||
| import com.google.i18n.phonenumbers.NumberParseException; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; | |||
| import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; | |||
| import com.google.phonenumbers.demo.template.ResultFileTemplates.File; | |||
| import java.util.StringTokenizer; | |||
| public class ResultFileRenderer extends LibPhoneNumberRenderer<File> { | |||
| private final String defaultCountry; | |||
| private final String fileContents; | |||
| private final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); | |||
| public ResultFileRenderer(String defaultCountry, String fileContents) { | |||
| super("result_file.soy", "com.google.phonenumbers.demo.file"); | |||
| this.fileContents = fileContents; | |||
| this.defaultCountry = defaultCountry; | |||
| } | |||
| @Override | |||
| public String genHtml() { | |||
| File.Builder soyTemplate = File.builder(); | |||
| int phoneNumberId = 0; | |||
| StringTokenizer tokenizer = new StringTokenizer(fileContents, ","); | |||
| while (tokenizer.hasMoreTokens()) { | |||
| String numberStr = tokenizer.nextToken(); | |||
| phoneNumberId++; | |||
| try { | |||
| PhoneNumber number = phoneUtil.parseAndKeepRawInput(numberStr, defaultCountry); | |||
| boolean isNumberValid = phoneUtil.isValidNumber(number); | |||
| soyTemplate.addRows( | |||
| phoneNumberId, | |||
| numberStr, | |||
| isNumberValid ? phoneUtil.formatInOriginalFormat(number, defaultCountry) : "invalid", | |||
| isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL) : "invalid", | |||
| null); | |||
| } catch (NumberParseException e) { | |||
| soyTemplate.addRows(phoneNumberId, numberStr, null, null, e.toString()); | |||
| } | |||
| } | |||
| return super.render(soyTemplate.build()); | |||
| } | |||
| } | |||
| @ -0,0 +1,137 @@ | |||
| /* | |||
| * Copyright (C) 2022 The Libphonenumber 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. | |||
| * | |||
| * @author Tobias Rogg | |||
| */ | |||
| package com.google.phonenumbers.demo.render; | |||
| import com.google.common.collect.ImmutableList; | |||
| import com.google.i18n.phonenumbers.AsYouTypeFormatter; | |||
| import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper; | |||
| import com.google.i18n.phonenumbers.PhoneNumberToTimeZonesMapper; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil; | |||
| import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; | |||
| import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; | |||
| import com.google.i18n.phonenumbers.ShortNumberInfo; | |||
| import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; | |||
| import com.google.phonenumbers.demo.helper.WebHelper; | |||
| import com.google.phonenumbers.demo.template.ResultTemplates.SingleNumber; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Locale; | |||
| public class ResultRenderer extends LibPhoneNumberRenderer<SingleNumber> { | |||
| private final String phoneNumber; | |||
| private final String defaultCountry; | |||
| private final Locale geocodingLocale; | |||
| private final PhoneNumber number; | |||
| private final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); | |||
| private final ShortNumberInfo shortInfo = ShortNumberInfo.getInstance(); | |||
| public ResultRenderer( | |||
| String phoneNumber, String defaultCountry, Locale geocodingLocale, PhoneNumber number) { | |||
| super("result.soy", "com.google.phonenumbers.demo.singleNumber"); | |||
| this.phoneNumber = phoneNumber; | |||
| this.defaultCountry = defaultCountry; | |||
| this.geocodingLocale = geocodingLocale; | |||
| this.number = number; | |||
| } | |||
| @Override | |||
| public String genHtml() { | |||
| // Header info at Start of Page | |||
| SingleNumber.Builder soyTemplate = | |||
| SingleNumber.builder() | |||
| .setPhoneNumber(phoneNumber) | |||
| .setDefaultCountry(defaultCountry) | |||
| .setGeocodingLocale(geocodingLocale.toLanguageTag()); | |||
| soyTemplate | |||
| .setCountryCode(number.getCountryCode()) | |||
| .setNationalNumber(number.getNationalNumber()) | |||
| .setExtension(number.getExtension()) | |||
| .setCountryCodeSource(number.getCountryCodeSource().toString()) | |||
| .setItalianLeadingZero(number.isItalianLeadingZero()) | |||
| .setRawInput(number.getRawInput()); | |||
| boolean isNumberValid = phoneUtil.isValidNumber(number); | |||
| boolean hasDefaultCountry = !defaultCountry.isEmpty() && !defaultCountry.equals("ZZ"); | |||
| // Validation Results Table | |||
| soyTemplate | |||
| .setIsPossibleNumber(phoneUtil.isPossibleNumber(number)) | |||
| .setIsValidNumber(isNumberValid) | |||
| .setIsValidNumberForRegion( | |||
| isNumberValid && hasDefaultCountry | |||
| ? phoneUtil.isValidNumberForRegion(number, defaultCountry) | |||
| : null) | |||
| .setPhoneNumberRegion(phoneUtil.getRegionCodeForNumber(number)) | |||
| .setNumberType(phoneUtil.getNumberType(number).toString()) | |||
| .setValidationResult(phoneUtil.isPossibleNumberWithReason(number).toString()); | |||
| // Short Number Results Table | |||
| soyTemplate | |||
| .setIsPossibleShortNumber(shortInfo.isPossibleShortNumber(number)) | |||
| .setIsValidShortNumber(shortInfo.isValidShortNumber(number)) | |||
| .setIsPossibleShortNumberForRegion( | |||
| hasDefaultCountry | |||
| ? shortInfo.isPossibleShortNumberForRegion(number, defaultCountry) | |||
| : null) | |||
| .setIsValidShortNumberForRegion( | |||
| hasDefaultCountry | |||
| ? shortInfo.isValidShortNumberForRegion(number, defaultCountry) | |||
| : null); | |||
| // Formatting Results Table | |||
| soyTemplate | |||
| .setE164Format(isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.E164) : "invalid") | |||
| .setOriginalFormat(phoneUtil.formatInOriginalFormat(number, defaultCountry)) | |||
| .setNationalFormat(phoneUtil.format(number, PhoneNumberFormat.NATIONAL)) | |||
| .setInternationalFormat( | |||
| isNumberValid ? phoneUtil.format(number, PhoneNumberFormat.INTERNATIONAL) : "invalid") | |||
| .setOutOfCountryFormatFromUs( | |||
| isNumberValid ? phoneUtil.formatOutOfCountryCallingNumber(number, "US") : "invalid") | |||
| .setOutOfCountryFormatFromCh( | |||
| isNumberValid ? phoneUtil.formatOutOfCountryCallingNumber(number, "CH") : "invalid"); | |||
| // Get As You Type Formatter Table | |||
| List<List<String>> rows = new ArrayList<>(); | |||
| AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter(defaultCountry); | |||
| int rawNumberLength = phoneNumber.length(); | |||
| for (int i = 0; i < rawNumberLength; i++) { | |||
| // Note this doesn't handle supplementary characters, but it shouldn't be a big deal as | |||
| // there are no dial-pad characters in the supplementary range. | |||
| char inputChar = phoneNumber.charAt(i); | |||
| rows.add(ImmutableList.of(String.valueOf(inputChar), formatter.inputDigit(inputChar))); | |||
| } | |||
| soyTemplate.setRows(rows); | |||
| // Geo Info Tables | |||
| String guidelinesLink = "https://github.com/google/libphonenumber/blob/master/CONTRIBUTING.md"; | |||
| soyTemplate | |||
| .setDescriptionForNumber( | |||
| PhoneNumberOfflineGeocoder.getInstance() | |||
| .getDescriptionForNumber(number, geocodingLocale)) | |||
| .setTimeZonesForNumber( | |||
| PhoneNumberToTimeZonesMapper.getInstance().getTimeZonesForNumber(number).toString()) | |||
| .setNameForNumber( | |||
| PhoneNumberToCarrierMapper.getInstance().getNameForNumber(number, geocodingLocale)) | |||
| .setNewIssueLink(WebHelper.getNewIssueLink(phoneNumber, defaultCountry, geocodingLocale)) | |||
| .setGuidelinesLink(guidelinesLink); | |||
| return super.render(soyTemplate.build()); | |||
| } | |||
| } | |||
| @ -0,0 +1,95 @@ | |||
| // This file was automatically generated by the Soy compiler. | |||
| // Please don't edit this file by hand. | |||
| // source: src/main/resources/com/google/phonenumbers/demo/input_form.soy | |||
| package com.google.phonenumbers.demo.template; | |||
| /** | |||
| * Wrapper class containing {@link com.google.template.soy.data.SoyTemplate} builders for each | |||
| * template in: input_form.soy. | |||
| */ | |||
| @javax.annotation.Generated("com.google.template.soy.SoyParseInfoGenerator") | |||
| public final class InputFormTemplates { | |||
| /** A map of filepath to symbol used for CSS resolution on server edit-refresh. */ | |||
| private static final com.google.common.collect.ImmutableMap<java.lang.String, java.lang.String> __PROVIDED_CSS_MAP__ = com.google.common.collect.ImmutableMap.<java.lang.String, java.lang.String>of(); | |||
| /** A list of provided symbols used for css validation on edit refresh. */ | |||
| private static final com.google.common.collect.ImmutableList<java.lang.String> __PROVIDED_CSS__ = com.google.common.collect.ImmutableList.<java.lang.String>of(); | |||
| /** Template params for com.google.phonenumbers.demo.inputForm.inputForm. */ | |||
| public static final class InputForm extends com.google.template.soy.data.BaseSoyTemplateImpl { | |||
| private static final java.lang.String __NAME__ = "com.google.phonenumbers.demo.inputForm.inputForm"; | |||
| /** Wraps a ListenableFuture<InputForm> as a SoyTemplate.AsyncWrapper<InputForm> */ | |||
| public static com.google.template.soy.data.SoyTemplate.AsyncWrapper<InputForm> wrapFuture(com.google.common.util.concurrent.ListenableFuture<InputForm> paramsFuture) { | |||
| return new com.google.template.soy.data.SoyTemplate.AsyncWrapper<>(__NAME__, paramsFuture); | |||
| } | |||
| private InputForm(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| super(data); | |||
| } | |||
| @java.lang.Override | |||
| public final java.lang.String getTemplateName() { | |||
| return __NAME__; | |||
| } | |||
| /** Creates a new Builder instance. */ | |||
| public static Builder builder() { | |||
| return new Builder(); | |||
| } | |||
| /** {@param welcomeTitle} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| WELCOME_TITLE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "welcomeTitle", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@inject csp_style_nonce} Created by ContentSecurityPolicyNonceInjectionPass. */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Object> | |||
| CSP_STYLE_NONCE = | |||
| com.google.template.soy.data.SoyTemplateParam.injected( | |||
| "csp_style_nonce", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Object.class)); | |||
| private static final com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> __PARAMS__ = com.google.common.collect.ImmutableSet.of( | |||
| WELCOME_TITLE); | |||
| public static final class Builder extends com.google.template.soy.data.BaseSoyTemplateImpl.AbstractBuilder<Builder, InputForm> { | |||
| private Builder() { | |||
| super(1); | |||
| } | |||
| @java.lang.Override | |||
| protected com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> allParams() { | |||
| return __PARAMS__; | |||
| } | |||
| @java.lang.Override | |||
| protected InputForm buildInternal(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| return new InputForm(data); | |||
| } | |||
| /** Sets welcomeTitle. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setWelcomeTitle(java.lang.String value) { | |||
| return setParamInternal(WELCOME_TITLE, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setWelcomeTitle(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setWelcomeTitleFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(WELCOME_TITLE, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,158 @@ | |||
| // This file was automatically generated by the Soy compiler. | |||
| // Please don't edit this file by hand. | |||
| // source: src/main/resources/com/google/phonenumbers/demo/result_error.soy | |||
| package com.google.phonenumbers.demo.template; | |||
| /** | |||
| * Wrapper class containing {@link com.google.template.soy.data.SoyTemplate} builders for each | |||
| * template in: result_error.soy. | |||
| */ | |||
| @javax.annotation.Generated("com.google.template.soy.SoyParseInfoGenerator") | |||
| public final class ResultErrorTemplates { | |||
| /** A map of filepath to symbol used for CSS resolution on server edit-refresh. */ | |||
| private static final com.google.common.collect.ImmutableMap<java.lang.String, java.lang.String> __PROVIDED_CSS_MAP__ = com.google.common.collect.ImmutableMap.<java.lang.String, java.lang.String>of(); | |||
| /** A list of provided symbols used for css validation on edit refresh. */ | |||
| private static final com.google.common.collect.ImmutableList<java.lang.String> __PROVIDED_CSS__ = com.google.common.collect.ImmutableList.<java.lang.String>of(); | |||
| /** Template params for com.google.phonenumbers.demo.error.error. */ | |||
| public static final class Error extends com.google.template.soy.data.BaseSoyTemplateImpl { | |||
| private static final java.lang.String __NAME__ = "com.google.phonenumbers.demo.error.error"; | |||
| /** Wraps a ListenableFuture<Error> as a SoyTemplate.AsyncWrapper<Error> */ | |||
| public static com.google.template.soy.data.SoyTemplate.AsyncWrapper<Error> wrapFuture(com.google.common.util.concurrent.ListenableFuture<Error> paramsFuture) { | |||
| return new com.google.template.soy.data.SoyTemplate.AsyncWrapper<>(__NAME__, paramsFuture); | |||
| } | |||
| private Error(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| super(data); | |||
| } | |||
| @java.lang.Override | |||
| public final java.lang.String getTemplateName() { | |||
| return __NAME__; | |||
| } | |||
| /** Creates a new Builder instance. */ | |||
| public static Builder builder() { | |||
| return new Builder(); | |||
| } | |||
| /** {@param phoneNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| PHONE_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "phoneNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param defaultCountry} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| DEFAULT_COUNTRY = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "defaultCountry", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param geocodingLocale} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| GEOCODING_LOCALE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "geocodingLocale", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param error} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| ERROR = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "error", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@inject csp_style_nonce} Created by ContentSecurityPolicyNonceInjectionPass. */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Object> | |||
| CSP_STYLE_NONCE = | |||
| com.google.template.soy.data.SoyTemplateParam.injected( | |||
| "csp_style_nonce", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Object.class)); | |||
| private static final com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> __PARAMS__ = com.google.common.collect.ImmutableSet.of( | |||
| PHONE_NUMBER, | |||
| DEFAULT_COUNTRY, | |||
| GEOCODING_LOCALE, | |||
| ERROR); | |||
| public static final class Builder extends com.google.template.soy.data.BaseSoyTemplateImpl.AbstractBuilder<Builder, Error> { | |||
| private Builder() { | |||
| super(4); | |||
| } | |||
| @java.lang.Override | |||
| protected com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> allParams() { | |||
| return __PARAMS__; | |||
| } | |||
| @java.lang.Override | |||
| protected Error buildInternal(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| return new Error(data); | |||
| } | |||
| /** Sets phoneNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumber(java.lang.String value) { | |||
| return setParamInternal(PHONE_NUMBER, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setPhoneNumber(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumberFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(PHONE_NUMBER, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets defaultCountry. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDefaultCountry(java.lang.String value) { | |||
| return setParamInternal(DEFAULT_COUNTRY, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setDefaultCountry(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDefaultCountryFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(DEFAULT_COUNTRY, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets geocodingLocale. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGeocodingLocale(java.lang.String value) { | |||
| return setParamInternal(GEOCODING_LOCALE, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setGeocodingLocale(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGeocodingLocaleFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(GEOCODING_LOCALE, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets error. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setError(java.lang.String value) { | |||
| return setParamInternal(ERROR, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setError(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setErrorFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(ERROR, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,90 @@ | |||
| // This file was automatically generated by the Soy compiler. | |||
| // Please don't edit this file by hand. | |||
| // source: src/main/resources/com/google/phonenumbers/demo/result_file.soy | |||
| package com.google.phonenumbers.demo.template; | |||
| /** | |||
| * Wrapper class containing {@link com.google.template.soy.data.SoyTemplate} builders for each | |||
| * template in: result_file.soy. | |||
| */ | |||
| @javax.annotation.Generated("com.google.template.soy.SoyParseInfoGenerator") | |||
| public final class ResultFileTemplates { | |||
| /** A map of filepath to symbol used for CSS resolution on server edit-refresh. */ | |||
| private static final com.google.common.collect.ImmutableMap<java.lang.String, java.lang.String> __PROVIDED_CSS_MAP__ = com.google.common.collect.ImmutableMap.<java.lang.String, java.lang.String>of(); | |||
| /** A list of provided symbols used for css validation on edit refresh. */ | |||
| private static final com.google.common.collect.ImmutableList<java.lang.String> __PROVIDED_CSS__ = com.google.common.collect.ImmutableList.<java.lang.String>of(); | |||
| /** Template params for com.google.phonenumbers.demo.file.file. */ | |||
| public static final class File extends com.google.template.soy.data.BaseSoyTemplateImpl { | |||
| private static final java.lang.String __NAME__ = "com.google.phonenumbers.demo.file.file"; | |||
| /** Wraps a ListenableFuture<File> as a SoyTemplate.AsyncWrapper<File> */ | |||
| public static com.google.template.soy.data.SoyTemplate.AsyncWrapper<File> wrapFuture(com.google.common.util.concurrent.ListenableFuture<File> paramsFuture) { | |||
| return new com.google.template.soy.data.SoyTemplate.AsyncWrapper<>(__NAME__, paramsFuture); | |||
| } | |||
| private File(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| super(data); | |||
| } | |||
| @java.lang.Override | |||
| public final java.lang.String getTemplateName() { | |||
| return __NAME__; | |||
| } | |||
| /** Creates a new Builder instance. */ | |||
| public static Builder builder() { | |||
| return new Builder(); | |||
| } | |||
| /** {@param rows} */ | |||
| private static final com.google.template.soy.data.SoyTemplateParam<?> | |||
| ROWS = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "rows", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Object.class)); | |||
| /** {@inject csp_style_nonce} Created by ContentSecurityPolicyNonceInjectionPass. */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Object> | |||
| CSP_STYLE_NONCE = | |||
| com.google.template.soy.data.SoyTemplateParam.injected( | |||
| "csp_style_nonce", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Object.class)); | |||
| private static final com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> __PARAMS__ = com.google.common.collect.ImmutableSet.of( | |||
| ROWS); | |||
| public static final class Builder extends com.google.template.soy.data.BaseSoyTemplateImpl.AbstractBuilderWithAccumulatorParameters<Builder, File> { | |||
| private Builder() { | |||
| super(1); | |||
| initListParam(ROWS); | |||
| } | |||
| @java.lang.Override | |||
| protected com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> allParams() { | |||
| return __PARAMS__; | |||
| } | |||
| @java.lang.Override | |||
| protected File buildInternal(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| return new File(data); | |||
| } | |||
| /** Sets rows. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder addRows(long id, java.lang.String numberStr, @javax.annotation.Nullable java.lang.String prettyFormat, @javax.annotation.Nullable java.lang.String internationalFormat, @javax.annotation.Nullable java.lang.String error) { | |||
| return addToListParam(ROWS, asRecord("id", asInt(id), "numberStr", asString(numberStr), "prettyFormat", asNullableString(prettyFormat), "internationalFormat", asNullableString(internationalFormat), "error", asNullableString(error))); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,731 @@ | |||
| // This file was automatically generated by the Soy compiler. | |||
| // Please don't edit this file by hand. | |||
| // source: src/main/resources/com/google/phonenumbers/demo/result.soy | |||
| package com.google.phonenumbers.demo.template; | |||
| /** | |||
| * Wrapper class containing {@link com.google.template.soy.data.SoyTemplate} builders for each | |||
| * template in: result.soy. | |||
| */ | |||
| @javax.annotation.Generated("com.google.template.soy.SoyParseInfoGenerator") | |||
| public final class ResultTemplates { | |||
| /** A map of filepath to symbol used for CSS resolution on server edit-refresh. */ | |||
| private static final com.google.common.collect.ImmutableMap<java.lang.String, java.lang.String> __PROVIDED_CSS_MAP__ = com.google.common.collect.ImmutableMap.<java.lang.String, java.lang.String>of(); | |||
| /** A list of provided symbols used for css validation on edit refresh. */ | |||
| private static final com.google.common.collect.ImmutableList<java.lang.String> __PROVIDED_CSS__ = com.google.common.collect.ImmutableList.<java.lang.String>of(); | |||
| /** Template params for com.google.phonenumbers.demo.singleNumber.singleNumber. */ | |||
| public static final class SingleNumber extends com.google.template.soy.data.BaseSoyTemplateImpl { | |||
| private static final java.lang.String __NAME__ = "com.google.phonenumbers.demo.singleNumber.singleNumber"; | |||
| /** Wraps a ListenableFuture<SingleNumber> as a SoyTemplate.AsyncWrapper<SingleNumber> */ | |||
| public static com.google.template.soy.data.SoyTemplate.AsyncWrapper<SingleNumber> wrapFuture(com.google.common.util.concurrent.ListenableFuture<SingleNumber> paramsFuture) { | |||
| return new com.google.template.soy.data.SoyTemplate.AsyncWrapper<>(__NAME__, paramsFuture); | |||
| } | |||
| private SingleNumber(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| super(data); | |||
| } | |||
| @java.lang.Override | |||
| public final java.lang.String getTemplateName() { | |||
| return __NAME__; | |||
| } | |||
| /** Creates a new Builder instance. */ | |||
| public static Builder builder() { | |||
| return new Builder(); | |||
| } | |||
| /** {@param phoneNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| PHONE_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "phoneNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param defaultCountry} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| DEFAULT_COUNTRY = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "defaultCountry", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param geocodingLocale} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| GEOCODING_LOCALE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "geocodingLocale", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param countryCode} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Long> | |||
| COUNTRY_CODE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "countryCode", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Long.class)); | |||
| /** {@param nationalNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Long> | |||
| NATIONAL_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "nationalNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Long.class)); | |||
| /** {@param extension} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| EXTENSION = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "extension", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param countryCodeSource} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| COUNTRY_CODE_SOURCE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "countryCodeSource", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param italianLeadingZero} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| ITALIAN_LEADING_ZERO = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "italianLeadingZero", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param rawInput} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| RAW_INPUT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "rawInput", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param isPossibleNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_POSSIBLE_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isPossibleNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param isValidNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_VALID_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isValidNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param isValidNumberForRegion} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_VALID_NUMBER_FOR_REGION = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isValidNumberForRegion", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param phoneNumberRegion} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| PHONE_NUMBER_REGION = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "phoneNumberRegion", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param numberType} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| NUMBER_TYPE = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "numberType", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param validationResult} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| VALIDATION_RESULT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "validationResult", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param isPossibleShortNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_POSSIBLE_SHORT_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isPossibleShortNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param isValidShortNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_VALID_SHORT_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isValidShortNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param isPossibleShortNumberForRegion} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_POSSIBLE_SHORT_NUMBER_FOR_REGION = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isPossibleShortNumberForRegion", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param isValidShortNumberForRegion} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Boolean> | |||
| IS_VALID_SHORT_NUMBER_FOR_REGION = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "isValidShortNumberForRegion", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Boolean.class)); | |||
| /** {@param e164Format} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| E_164_FORMAT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "e164Format", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param originalFormat} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| ORIGINAL_FORMAT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "originalFormat", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param nationalFormat} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| NATIONAL_FORMAT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "nationalFormat", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param internationalFormat} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| INTERNATIONAL_FORMAT = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "internationalFormat", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param outOfCountryFormatFromUs} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| OUT_OF_COUNTRY_FORMAT_FROM_US = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "outOfCountryFormatFromUs", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param outOfCountryFormatFromCh} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| OUT_OF_COUNTRY_FORMAT_FROM_CH = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "outOfCountryFormatFromCh", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param rows} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Iterable<? extends java.util.Collection<java.lang.String>>> | |||
| ROWS = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "rows", | |||
| /* required= */ true, | |||
| new com.google.common.reflect.TypeToken<java.lang.Iterable<? extends java.util.Collection<java.lang.String>>>() {}); | |||
| /** {@param descriptionForNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| DESCRIPTION_FOR_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "descriptionForNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param timeZonesForNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| TIME_ZONES_FOR_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "timeZonesForNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param nameForNumber} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| NAME_FOR_NUMBER = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "nameForNumber", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param newIssueLink} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| NEW_ISSUE_LINK = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "newIssueLink", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@param guidelinesLink} */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.String> | |||
| GUIDELINES_LINK = | |||
| com.google.template.soy.data.SoyTemplateParam.standard( | |||
| "guidelinesLink", | |||
| /* required= */ true, | |||
| com.google.common.reflect.TypeToken.of(java.lang.String.class)); | |||
| /** {@inject csp_style_nonce} Created by ContentSecurityPolicyNonceInjectionPass. */ | |||
| public static final com.google.template.soy.data.SoyTemplateParam<java.lang.Object> | |||
| CSP_STYLE_NONCE = | |||
| com.google.template.soy.data.SoyTemplateParam.injected( | |||
| "csp_style_nonce", | |||
| /* required= */ false, | |||
| com.google.common.reflect.TypeToken.of(java.lang.Object.class)); | |||
| private static final com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> __PARAMS__ = com.google.common.collect.ImmutableSet.of( | |||
| PHONE_NUMBER, | |||
| DEFAULT_COUNTRY, | |||
| GEOCODING_LOCALE, | |||
| COUNTRY_CODE, | |||
| NATIONAL_NUMBER, | |||
| EXTENSION, | |||
| COUNTRY_CODE_SOURCE, | |||
| ITALIAN_LEADING_ZERO, | |||
| RAW_INPUT, | |||
| IS_POSSIBLE_NUMBER, | |||
| IS_VALID_NUMBER, | |||
| IS_VALID_NUMBER_FOR_REGION, | |||
| PHONE_NUMBER_REGION, | |||
| NUMBER_TYPE, | |||
| VALIDATION_RESULT, | |||
| IS_POSSIBLE_SHORT_NUMBER, | |||
| IS_VALID_SHORT_NUMBER, | |||
| IS_POSSIBLE_SHORT_NUMBER_FOR_REGION, | |||
| IS_VALID_SHORT_NUMBER_FOR_REGION, | |||
| E_164_FORMAT, | |||
| ORIGINAL_FORMAT, | |||
| NATIONAL_FORMAT, | |||
| INTERNATIONAL_FORMAT, | |||
| OUT_OF_COUNTRY_FORMAT_FROM_US, | |||
| OUT_OF_COUNTRY_FORMAT_FROM_CH, | |||
| ROWS, | |||
| DESCRIPTION_FOR_NUMBER, | |||
| TIME_ZONES_FOR_NUMBER, | |||
| NAME_FOR_NUMBER, | |||
| NEW_ISSUE_LINK, | |||
| GUIDELINES_LINK); | |||
| public static final class Builder extends com.google.template.soy.data.BaseSoyTemplateImpl.AbstractBuilder<Builder, SingleNumber> { | |||
| private Builder() { | |||
| super(31); | |||
| } | |||
| @java.lang.Override | |||
| protected com.google.common.collect.ImmutableSet<com.google.template.soy.data.SoyTemplateParam<?>> allParams() { | |||
| return __PARAMS__; | |||
| } | |||
| @java.lang.Override | |||
| protected SingleNumber buildInternal(com.google.common.collect.ImmutableMap<java.lang.String, com.google.template.soy.data.SoyValueProvider> data) { | |||
| return new SingleNumber(data); | |||
| } | |||
| /** Sets phoneNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumber(java.lang.String value) { | |||
| return setParamInternal(PHONE_NUMBER, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setPhoneNumber(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumberFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(PHONE_NUMBER, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets defaultCountry. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDefaultCountry(java.lang.String value) { | |||
| return setParamInternal(DEFAULT_COUNTRY, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setDefaultCountry(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDefaultCountryFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(DEFAULT_COUNTRY, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets geocodingLocale. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGeocodingLocale(java.lang.String value) { | |||
| return setParamInternal(GEOCODING_LOCALE, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setGeocodingLocale(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGeocodingLocaleFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(GEOCODING_LOCALE, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets countryCode. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setCountryCode(long value) { | |||
| return setParamInternal(COUNTRY_CODE, asInt(value)); | |||
| } | |||
| /** Future compatible version of {@link #setCountryCode(long)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setCountryCodeFuture(java.util.concurrent.Future<? extends java.lang.Number> future) { | |||
| return setParamInternal(COUNTRY_CODE, asFuture(future, AbstractBuilder::asBoxedInt)); | |||
| } | |||
| /** Sets nationalNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNationalNumber(long value) { | |||
| return setParamInternal(NATIONAL_NUMBER, asInt(value)); | |||
| } | |||
| /** Future compatible version of {@link #setNationalNumber(long)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNationalNumberFuture(java.util.concurrent.Future<? extends java.lang.Number> future) { | |||
| return setParamInternal(NATIONAL_NUMBER, asFuture(future, AbstractBuilder::asBoxedInt)); | |||
| } | |||
| /** Sets extension. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setExtension(java.lang.String value) { | |||
| return setParamInternal(EXTENSION, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setExtension(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setExtensionFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(EXTENSION, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets countryCodeSource. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setCountryCodeSource(java.lang.String value) { | |||
| return setParamInternal(COUNTRY_CODE_SOURCE, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setCountryCodeSource(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setCountryCodeSourceFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(COUNTRY_CODE_SOURCE, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets italianLeadingZero. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setItalianLeadingZero(boolean value) { | |||
| return setParamInternal(ITALIAN_LEADING_ZERO, asBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setItalianLeadingZero(boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setItalianLeadingZeroFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(ITALIAN_LEADING_ZERO, asFuture(future, AbstractBuilder::asBool)); | |||
| } | |||
| /** Sets rawInput. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setRawInput(java.lang.String value) { | |||
| return setParamInternal(RAW_INPUT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setRawInput(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setRawInputFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(RAW_INPUT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets isPossibleNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleNumber(boolean value) { | |||
| return setParamInternal(IS_POSSIBLE_NUMBER, asBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setIsPossibleNumber(boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleNumberFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_POSSIBLE_NUMBER, asFuture(future, AbstractBuilder::asBool)); | |||
| } | |||
| /** Sets isValidNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidNumber(boolean value) { | |||
| return setParamInternal(IS_VALID_NUMBER, asBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setIsValidNumber(boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidNumberFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_VALID_NUMBER, asFuture(future, AbstractBuilder::asBool)); | |||
| } | |||
| /** Sets isValidNumberForRegion. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidNumberForRegion(@javax.annotation.Nullable java.lang.Boolean value) { | |||
| return setParamInternal(IS_VALID_NUMBER_FOR_REGION, asNullableBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setIsValidNumberForRegion(java.lang.Boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidNumberForRegionFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_VALID_NUMBER_FOR_REGION, asFuture(future, AbstractBuilder::asNullableBool)); | |||
| } | |||
| /** Sets phoneNumberRegion. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumberRegion(@javax.annotation.Nullable java.lang.String value) { | |||
| return setParamInternal(PHONE_NUMBER_REGION, asNullableString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setPhoneNumberRegion(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setPhoneNumberRegionFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(PHONE_NUMBER_REGION, asFuture(future, AbstractBuilder::asNullableString)); | |||
| } | |||
| /** Sets numberType. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNumberType(java.lang.String value) { | |||
| return setParamInternal(NUMBER_TYPE, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setNumberType(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNumberTypeFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(NUMBER_TYPE, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets validationResult. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setValidationResult(java.lang.String value) { | |||
| return setParamInternal(VALIDATION_RESULT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setValidationResult(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setValidationResultFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(VALIDATION_RESULT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets isPossibleShortNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleShortNumber(boolean value) { | |||
| return setParamInternal(IS_POSSIBLE_SHORT_NUMBER, asBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setIsPossibleShortNumber(boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleShortNumberFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_POSSIBLE_SHORT_NUMBER, asFuture(future, AbstractBuilder::asBool)); | |||
| } | |||
| /** Sets isValidShortNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidShortNumber(boolean value) { | |||
| return setParamInternal(IS_VALID_SHORT_NUMBER, asBool(value)); | |||
| } | |||
| /** Future compatible version of {@link #setIsValidShortNumber(boolean)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidShortNumberFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_VALID_SHORT_NUMBER, asFuture(future, AbstractBuilder::asBool)); | |||
| } | |||
| /** Sets isPossibleShortNumberForRegion. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleShortNumberForRegion(@javax.annotation.Nullable java.lang.Boolean value) { | |||
| return setParamInternal(IS_POSSIBLE_SHORT_NUMBER_FOR_REGION, asNullableBool(value)); | |||
| } | |||
| /** | |||
| * Future compatible version of {@link | |||
| * #setIsPossibleShortNumberForRegion(java.lang.Boolean)}. | |||
| */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsPossibleShortNumberForRegionFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_POSSIBLE_SHORT_NUMBER_FOR_REGION, asFuture(future, AbstractBuilder::asNullableBool)); | |||
| } | |||
| /** Sets isValidShortNumberForRegion. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidShortNumberForRegion(@javax.annotation.Nullable java.lang.Boolean value) { | |||
| return setParamInternal(IS_VALID_SHORT_NUMBER_FOR_REGION, asNullableBool(value)); | |||
| } | |||
| /** | |||
| * Future compatible version of {@link | |||
| * #setIsValidShortNumberForRegion(java.lang.Boolean)}. | |||
| */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setIsValidShortNumberForRegionFuture(java.util.concurrent.Future<java.lang.Boolean> future) { | |||
| return setParamInternal(IS_VALID_SHORT_NUMBER_FOR_REGION, asFuture(future, AbstractBuilder::asNullableBool)); | |||
| } | |||
| /** Sets e164Format. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setE164Format(java.lang.String value) { | |||
| return setParamInternal(E_164_FORMAT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setE164Format(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setE164FormatFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(E_164_FORMAT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets originalFormat. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOriginalFormat(java.lang.String value) { | |||
| return setParamInternal(ORIGINAL_FORMAT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setOriginalFormat(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOriginalFormatFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(ORIGINAL_FORMAT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets nationalFormat. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNationalFormat(java.lang.String value) { | |||
| return setParamInternal(NATIONAL_FORMAT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setNationalFormat(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNationalFormatFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(NATIONAL_FORMAT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets internationalFormat. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setInternationalFormat(java.lang.String value) { | |||
| return setParamInternal(INTERNATIONAL_FORMAT, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setInternationalFormat(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setInternationalFormatFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(INTERNATIONAL_FORMAT, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets outOfCountryFormatFromUs. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOutOfCountryFormatFromUs(java.lang.String value) { | |||
| return setParamInternal(OUT_OF_COUNTRY_FORMAT_FROM_US, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setOutOfCountryFormatFromUs(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOutOfCountryFormatFromUsFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(OUT_OF_COUNTRY_FORMAT_FROM_US, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets outOfCountryFormatFromCh. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOutOfCountryFormatFromCh(java.lang.String value) { | |||
| return setParamInternal(OUT_OF_COUNTRY_FORMAT_FROM_CH, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setOutOfCountryFormatFromCh(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setOutOfCountryFormatFromChFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(OUT_OF_COUNTRY_FORMAT_FROM_CH, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets rows. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setRows(java.lang.Iterable<? extends java.util.Collection<java.lang.String>> value) { | |||
| return setParamInternal(ROWS, asList(value, v -> asList(v, AbstractBuilder::asString))); | |||
| } | |||
| /** Future compatible version of {@link #setRows(java.lang.Iterable>)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setRowsFuture(java.util.concurrent.Future<? extends java.util.Collection<? extends java.util.Collection<java.lang.String>>> future) { | |||
| return setParamInternal(ROWS, asFuture(future, v -> asList(v, v1 -> asList(v1, AbstractBuilder::asString)))); | |||
| } | |||
| /** Sets descriptionForNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDescriptionForNumber(java.lang.String value) { | |||
| return setParamInternal(DESCRIPTION_FOR_NUMBER, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setDescriptionForNumber(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setDescriptionForNumberFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(DESCRIPTION_FOR_NUMBER, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets timeZonesForNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setTimeZonesForNumber(java.lang.String value) { | |||
| return setParamInternal(TIME_ZONES_FOR_NUMBER, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setTimeZonesForNumber(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setTimeZonesForNumberFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(TIME_ZONES_FOR_NUMBER, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets nameForNumber. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNameForNumber(java.lang.String value) { | |||
| return setParamInternal(NAME_FOR_NUMBER, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setNameForNumber(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNameForNumberFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(NAME_FOR_NUMBER, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets newIssueLink. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNewIssueLink(java.lang.String value) { | |||
| return setParamInternal(NEW_ISSUE_LINK, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setNewIssueLink(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setNewIssueLinkFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(NEW_ISSUE_LINK, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| /** Sets guidelinesLink. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGuidelinesLink(java.lang.String value) { | |||
| return setParamInternal(GUIDELINES_LINK, asString(value)); | |||
| } | |||
| /** Future compatible version of {@link #setGuidelinesLink(java.lang.String)}. */ | |||
| @com.google.errorprone.annotations.CanIgnoreReturnValue | |||
| public Builder setGuidelinesLinkFuture(java.util.concurrent.Future<java.lang.String> future) { | |||
| return setParamInternal(GUIDELINES_LINK, asFuture(future, AbstractBuilder::asString)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,253 @@ | |||
| {namespace com.google.phonenumbers.demo.singleNumber} | |||
| {template singleNumber} | |||
| {@param phoneNumber: string} | |||
| {@param defaultCountry: string} | |||
| {@param geocodingLocale: string} | |||
| {@param countryCode: int} | |||
| {@param nationalNumber: int} | |||
| {@param extension: string} | |||
| {@param countryCodeSource: string} | |||
| {@param italianLeadingZero: bool} | |||
| {@param rawInput: string} | |||
| {@param isPossibleNumber: bool} | |||
| {@param isValidNumber: bool} | |||
| {@param isValidNumberForRegion: bool|null} | |||
| {@param phoneNumberRegion: string|null} | |||
| {@param numberType: string} | |||
| {@param validationResult: string} | |||
| {@param isPossibleShortNumber: bool} | |||
| {@param isValidShortNumber: bool} | |||
| {@param isPossibleShortNumberForRegion: bool|null} | |||
| {@param isValidShortNumberForRegion: bool|null} | |||
| {@param e164Format: string} | |||
| {@param originalFormat: string} | |||
| {@param nationalFormat: string} | |||
| {@param internationalFormat: string} | |||
| {@param outOfCountryFormatFromUs: string} | |||
| {@param outOfCountryFormatFromCh: string} | |||
| {@param rows: list<list<string>>} | |||
| {@param descriptionForNumber: string} | |||
| {@param timeZonesForNumber: string} | |||
| {@param nameForNumber: string} | |||
| {@param newIssueLink: string} | |||
| {@param guidelinesLink: string} | |||
| <!DOCTYPE html> | |||
| <HTML lang="en"> | |||
| <HEAD> | |||
| <LINK type="text/css" rel="stylesheet" href="/stylesheets/main.css"/> | |||
| <title>Results for {$phoneNumber}</title> | |||
| </HEAD> | |||
| <BODY> | |||
| <p>Phone Number entered: {$phoneNumber}</p> | |||
| <p>Default Country entered: {$defaultCountry}</p> | |||
| <p>Language entered: {$geocodingLocale}</p> | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>Parsing Result (parseAndKeepRawInput())</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>country_code</TH> | |||
| <TD>{$countryCode}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>national_number</TH> | |||
| <TD>{$nationalNumber}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>extension</TH> | |||
| <TD>{$extension}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>country_code_source</TH> | |||
| <TD>{$countryCodeSource}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>italian_leading_zero</TH> | |||
| <TD>{$italianLeadingZero}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>raw_input</TH> | |||
| <TD>{$rawInput}</TD> | |||
| </TR> | |||
| </TABLE> | |||
| </DIV> | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>Validation Results</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Result from isPossibleNumber()</TH> | |||
| <TD>{$isPossibleNumber}</TD> | |||
| </TR> | |||
| {if $isPossibleNumber} | |||
| {if $validationResult == "IS_POSSIBLE_LOCAL_ONLY"} | |||
| <TR> | |||
| <TH>Result from isPossibleNumberWithReason()</TH> | |||
| <TD>{$validationResult}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TD colspan=2>Number is considered invalid as it is not a possible national number.</TD> | |||
| </TR> | |||
| {else} | |||
| <TR> | |||
| <TH>Result from isValidNumber()</TH> | |||
| <TD>{$isValidNumber}</TD> | |||
| </TR> | |||
| {if $isValidNumberForRegion != null} | |||
| <TR> | |||
| <TH>Result from isValidNumberForRegion()</TH> | |||
| <TD>{$isValidNumberForRegion}</TD> | |||
| </TR> | |||
| {/if} | |||
| <TR> | |||
| <TH>Phone Number region</TH> | |||
| <TD>{$phoneNumberRegion ?: ""}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Result from getNumberType()</TH> | |||
| <TD>{$numberType}</TD> | |||
| </TR> | |||
| {/if} | |||
| {else} | |||
| <TR> | |||
| <TH>Result from isPossibleNumberWithReason()</TH> | |||
| <TD>{$validationResult}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TD colspan=2>Note: Numbers that are not possible have type UNKNOWN, an unknown region, and are considered invalid.</TD> | |||
| </TR> | |||
| {/if} | |||
| </TABLE> | |||
| </DIV> | |||
| {if not $isValidNumber} | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR><TD colspan=2>Short Number Results</TD></TR> | |||
| <TR> | |||
| <TH>Result from isPossibleShortNumber()</TH> | |||
| <TD>{$isPossibleShortNumber}</TD> | |||
| </TR> | |||
| {if $isPossibleShortNumber} | |||
| <TR> | |||
| <TH>Result from isValidShortNumber()</TH> | |||
| <TD>{$isValidShortNumber}</TD> | |||
| </TR> | |||
| {/if} | |||
| {if $isPossibleShortNumberForRegion != null} | |||
| <TR> | |||
| <TH>Result from isPossibleShortNumberForRegion()</TH> | |||
| <TD>{$isPossibleShortNumberForRegion}</TD> | |||
| </TR> | |||
| {if $isPossibleShortNumberForRegion and $isValidShortNumberForRegion != null} | |||
| <TR> | |||
| <TH>Result from isValidShortNumberForRegion()</TH> | |||
| <TD>{$isValidShortNumberForRegion}</TD> | |||
| </TR> | |||
| {/if} | |||
| {/if} | |||
| </TABLE> | |||
| </DIV> | |||
| {/if} | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>Formatting Results</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>E164 format</TH> | |||
| <TD>{$e164Format}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Original format</TH> | |||
| <TD>{$originalFormat}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>National format</TH> | |||
| <TD>{$nationalFormat}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>International format</TH> | |||
| <TD>{$internationalFormat}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Out-of-country format from US</TH> | |||
| <TD>{$outOfCountryFormatFromUs}</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Out-of-country format from CH</TH> | |||
| <TD>{$outOfCountryFormatFromCh}</TD> | |||
| </TR> | |||
| </TABLE> | |||
| </DIV> | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>AsYouTypeFormatter Results</TD> | |||
| </TR> | |||
| {for $row in $rows} | |||
| <TR> | |||
| <TH>Char entered: '{$row[0]}' Output: "</TH> | |||
| <TD>{$row[1]}</TD> | |||
| </TR> | |||
| {/for} | |||
| </TABLE> | |||
| </DIV> | |||
| {if $isValidNumber} | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>PhoneNumberOfflineGeocoder Results</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Location</TH> | |||
| <TD>{$descriptionForNumber}</TD> | |||
| </TR> | |||
| </TABLE> | |||
| </DIV> | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>PhoneNumberToTimeZonesMapper Results</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Time zone(s)</TH> | |||
| <TD>{$timeZonesForNumber}</TD> | |||
| </TR> | |||
| </TABLE> | |||
| </DIV> | |||
| {if ['MOBILE', 'FIXED_LINE_OR_MOBILE', 'PAGER'].contains($numberType)} | |||
| <DIV> | |||
| <TABLE border=1> | |||
| <TR> | |||
| <TD colspan=2>PhoneNumberToCarrierMapper Results</TD> | |||
| </TR> | |||
| <TR> | |||
| <TH>Carrier</TH> | |||
| <TD>{$nameForNumber}</TD> | |||
| </TR> | |||
| </TABLE> | |||
| </DIV> | |||
| {/if} | |||
| {/if} | |||
| <b style="color:red">File an issue</b>: by clicking on <a target="_blank" href="{$newIssueLink}">this link</a>, I confirm that I have read the <a target="_blank" href="{$guidelinesLink}">contributor's guidelines</a>. | |||
| </BODY> | |||
| </HTML> | |||
| {/template} | |||
| @ -0,0 +1,20 @@ | |||
| {namespace com.google.phonenumbers.demo.error} | |||
| {template error} | |||
| {@param phoneNumber: string} | |||
| {@param defaultCountry: string} | |||
| {@param geocodingLocale: string} | |||
| {@param error: string} | |||
| <!DOCTYPE html> | |||
| <HTML lang="en"> | |||
| <HEAD> | |||
| <LINK type="text/css" rel="stylesheet" href="/stylesheets/main.css"/> | |||
| <title>Results for {$phoneNumber}</title> | |||
| </HEAD> | |||
| <BODY> | |||
| <p>Phone Number entered: {$phoneNumber}</p> | |||
| <p>Default Country entered: {$defaultCountry}</p> | |||
| <p>Language entered: {$geocodingLocale}</p> | |||
| <p>An error occurred while parsing the input: {$error} | |||
| </BODY> | |||
| </HTML> | |||
| {/template} | |||
| @ -0,0 +1,44 @@ | |||
| {namespace com.google.phonenumbers.demo.file} | |||
| {template file} | |||
| {@param rows: list<[id: int, numberStr: string, prettyFormat: string|null, internationalFormat: string|null, error: string|null]>} | |||
| <!DOCTYPE html> | |||
| <html lang="en"> | |||
| <head> | |||
| <link rel="stylesheet" href="/stylesheets/main.css" /> | |||
| <title>Results generated from phone numbers in the file provided</title> | |||
| </head> | |||
| <body> | |||
| <h2>Results generated from phone numbers in the file provided:</h2> | |||
| <table> | |||
| <tr> | |||
| <th>Id</th> | |||
| <th>Raw phone number</th> | |||
| <th>Pretty formatting</th> | |||
| <th>International format</th> | |||
| </tr> | |||
| {for $row in $rows} | |||
| <tr> | |||
| <td>{$row.id}</td> | |||
| <td>{$row.numberStr}</td> | |||
| {if $row.error == null} | |||
| <td>{$row.prettyFormat}</td> | |||
| <td>{$row.internationalFormat}</td> | |||
| {else} | |||
| <td colspan=2>{$row.error}</td> | |||
| {/if} | |||
| </tr> | |||
| {ifempty} | |||
| <tr> | |||
| <td colspan=4>No data in file detected!</td> | |||
| </tr> | |||
| {/for} | |||
| </table> | |||
| </body> | |||
| </html> | |||
| {/template} | |||
| @ -1,18 +1,25 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xmlns="http://java.sun.com/xml/ns/javaee" | |||
| xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |||
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | |||
| http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> | |||
| version="2.5" | |||
| xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | |||
| http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | |||
| <servlet> | |||
| <servlet-class>com.google.phonenumbers.demo.ResultServlet</servlet-class> | |||
| <servlet-name>PhoneNumberParser</servlet-name> | |||
| <servlet-class>com.google.phonenumbers.PhoneNumberParserServlet</servlet-class> | |||
| </servlet> | |||
| <servlet> | |||
| <servlet-class>com.google.phonenumbers.demo.InputServlet</servlet-class> | |||
| <servlet-name>Input</servlet-name> | |||
| </servlet> | |||
| <servlet-mapping> | |||
| <servlet-name>PhoneNumberParser</servlet-name> | |||
| <url-pattern>/phonenumberparser</url-pattern> | |||
| </servlet-mapping> | |||
| <servlet-mapping> | |||
| <servlet-name>Input</servlet-name> | |||
| <url-pattern>/inputform</url-pattern> | |||
| </servlet-mapping> | |||
| <welcome-file-list> | |||
| <welcome-file>phonenumberparser.jsp</welcome-file> | |||
| <welcome-file>Input</welcome-file> | |||
| </welcome-file-list> | |||
| </web-app> | |||