AdditionalTextOutput.java revision dd4bff62b54033bedc254f517397ae8f954d0dc9
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.dumprendertree2; 18 19import android.util.Log; 20import android.webkit.ConsoleMessage; 21 22import java.net.MalformedURLException; 23import java.net.URL; 24 25/** 26 * A class that stores consoles messages, database callbacks, alert messages, etc. 27 */ 28public class AdditionalTextOutput { 29 private static final String LOG_TAG = "AdditionalTextOutput"; 30 31 private enum OutputType { 32 EXCEEDED_DB_QUOTA_MESSAGE, 33 CONSOLE_MESSAGE; 34 } 35 36 StringBuilder[] mOutputs = new StringBuilder[OutputType.values().length]; 37 38 public void appendExceededDbQuotaMessage(String urlString, String databaseIdentifier) { 39 int index = OutputType.EXCEEDED_DB_QUOTA_MESSAGE.ordinal(); 40 if (mOutputs[index] == null) { 41 mOutputs[index] = new StringBuilder(); 42 } 43 44 String protocol = ""; 45 String host = ""; 46 int port = 0; 47 48 try { 49 URL url = new URL(urlString); 50 protocol = url.getProtocol(); 51 host = url.getHost(); 52 if (url.getPort() > -1) { 53 port = url.getPort(); 54 } 55 } catch (MalformedURLException e) { 56 Log.e(LOG_TAG + "::appendDatabaseCallback", e.getMessage()); 57 } 58 59 mOutputs[index].append("UI DELEGATE DATABASE CALLBACK: "); 60 mOutputs[index].append("exceededDatabaseQuotaForSecurityOrigin:{"); 61 mOutputs[index].append(protocol + ", " + host + ", " + port + "} "); 62 mOutputs[index].append("database:" + databaseIdentifier + "\n"); 63 } 64 65 public void appendConsoleMessage(ConsoleMessage consoleMessage) { 66 int index = OutputType.CONSOLE_MESSAGE.ordinal(); 67 if (mOutputs[index] == null) { 68 mOutputs[index] = new StringBuilder(); 69 } 70 71 mOutputs[index].append("CONSOLE MESSAGE: line " + consoleMessage.lineNumber()); 72 mOutputs[index].append(": " + consoleMessage.message() + "\n"); 73 } 74 75 @Override 76 public String toString() { 77 StringBuilder result = new StringBuilder(); 78 for (int i = 0; i < mOutputs.length; i++) { 79 if (mOutputs[i] != null) { 80 result.append(mOutputs[i].toString()); 81 } 82 } 83 return result.toString(); 84 } 85}