/shell/src/com/google/marvin/shell/MenuItem.java

http://eyes-free.googlecode.com/ · 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. package com.google.marvin.shell;
  17. /**
  18. * Holds the information for an application in the shell that is needed to start
  19. * that application from the shell.
  20. *
  21. * @author clchen@google.com (Charles L. Chen)
  22. */
  23. public class MenuItem {
  24. private static String XML_ITEM_OPEN_TAG =
  25. "<item gesture='%s' label='%s' action='%s' data='%s'>\n";
  26. private static String XML_ITEM_CLOSE_TAG = "</item>\n";
  27. public String label;
  28. public String action;
  29. public String data;
  30. public AppInfo appInfo;
  31. public MenuItem(String itemLabel, String itemAction, String itemData, AppInfo applicationInfo) {
  32. label = itemLabel;
  33. action = itemAction;
  34. data = itemData;
  35. appInfo = applicationInfo;
  36. }
  37. /**
  38. * Returns a string XML representation of this item element.
  39. */
  40. public String toXml(int gesture) {
  41. StringBuilder xmlBuilder = new StringBuilder();
  42. xmlBuilder.append(
  43. String.format(XML_ITEM_OPEN_TAG, String.valueOf(gesture),
  44. MenuManager.escapeEntities(label), MenuManager.escapeEntities(action),
  45. MenuManager.escapeEntities(data)));
  46. if (appInfo != null) {
  47. xmlBuilder.append(appInfo.toXml());
  48. }
  49. xmlBuilder.append(XML_ITEM_CLOSE_TAG);
  50. return xmlBuilder.toString();
  51. }
  52. }