1 /* 2 * Copyright (C) 2016 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.googlecode.android_scripting.language; 18 19 import com.googlecode.android_scripting.rpc.ParameterDescriptor; 20 21 public class HtmlLanguage extends Language { 22 23 /** Returns the Android package import statement. */ 24 @Override 25 protected String getImportStatement() { 26 return "<html>\n<head>\n<script>"; 27 } 28 29 @Override 30 protected String getRpcReceiverDeclaration(String rpcReceiver) { 31 return String.format("var %s = new Android();\n</script>\n</head>\n<body>\n\n</body>\n</html>", 32 rpcReceiver); 33 } 34 35 @Override 36 protected String getMethodCallText(String receiver, String method, 37 ParameterDescriptor[] parameters) { 38 StringBuilder result = 39 new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) 40 .append(method); 41 if (parameters.length > 0) { 42 result.append(getLeftParametersText()); 43 } else { 44 result.append(getQuote()); 45 } 46 String separator = ""; 47 for (ParameterDescriptor parameter : parameters) { 48 result.append(separator).append(getValueText(parameter)); 49 separator = getParameterSeparator(); 50 } 51 result.append(getRightParametersText()); 52 53 return result.toString(); 54 } 55 56 @Override 57 protected String getApplyOperatorText() { 58 return ".call('"; 59 } 60 61 @Override 62 protected String getLeftParametersText() { 63 return "', "; 64 } 65 66 @Override 67 protected String getRightParametersText() { 68 return ")"; 69 } 70 71 @Override 72 protected String getQuote() { 73 return "'"; 74 } 75 76 } 77