/shell/src/com/google/marvin/shell/MenuItem.java
Java | 65 lines | 28 code | 13 blank | 24 comment | 2 complexity | 77887ced61cb6c4f4cf6c244727f2a67 MD5 | raw file
1/* 2 * Copyright (C) 2008 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 17package com.google.marvin.shell; 18 19/** 20 * Holds the information for an application in the shell that is needed to start 21 * that application from the shell. 22 * 23 * @author clchen@google.com (Charles L. Chen) 24 */ 25 26public class MenuItem { 27 28 private static String XML_ITEM_OPEN_TAG = 29 30 31 "<item gesture='%s' label='%s' action='%s' data='%s'>\n"; 32 33 private static String XML_ITEM_CLOSE_TAG = "</item>\n"; 34 35 public String label; 36 37 public String action; 38 39 public String data; 40 41 public AppInfo appInfo; 42 43 public MenuItem(String itemLabel, String itemAction, String itemData, AppInfo applicationInfo) { 44 label = itemLabel; 45 action = itemAction; 46 data = itemData; 47 appInfo = applicationInfo; 48 } 49 50 /** 51 * Returns a string XML representation of this item element. 52 */ 53 public String toXml(int gesture) { 54 StringBuilder xmlBuilder = new StringBuilder(); 55 xmlBuilder.append( 56 String.format(XML_ITEM_OPEN_TAG, String.valueOf(gesture), 57 MenuManager.escapeEntities(label), MenuManager.escapeEntities(action), 58 MenuManager.escapeEntities(data))); 59 if (appInfo != null) { 60 xmlBuilder.append(appInfo.toXml()); 61 } 62 xmlBuilder.append(XML_ITEM_CLOSE_TAG); 63 return xmlBuilder.toString(); 64 } 65}