/plugins/XSLT/tags/xslt_0_5_2/xslt/XSLTPlugin.java

# · Java · 111 lines · 54 code · 22 blank · 35 comment · 0 complexity · 2ed6b97d410176600b0663690cbe5633 MD5 · raw file

  1. /*
  2. * XSLTPlugin.java - XSLT Plugin
  3. *
  4. * Copyright (c) 2002 Greg Merrill
  5. * 2003 Robert McKinnon
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package xslt;
  22. import org.gjt.sp.jedit.EditPlugin;
  23. import org.gjt.sp.jedit.GUIUtilities;
  24. import org.gjt.sp.jedit.jEdit;
  25. import org.gjt.sp.jedit.MiscUtilities;
  26. import org.gjt.sp.util.Log;
  27. import javax.swing.JOptionPane;
  28. import java.awt.Component;
  29. import java.io.PrintWriter;
  30. import java.io.StringWriter;
  31. import java.text.MessageFormat;
  32. import java.util.Vector;
  33. /**
  34. * EditPlugin implementation for the XSLT plugin.
  35. *
  36. * @author Greg Merrill
  37. * @author Robert McKinnon - robmckinnon@users.sourceforge.net
  38. */
  39. public class XSLTPlugin extends EditPlugin {
  40. private static XSLTProcessor processor;
  41. /**
  42. * Register xerces as the SAX Parser provider
  43. */
  44. public void start () {
  45. String transformerFactory = jEdit.getProperty(XSLTUtilities.TRANSFORMER_FACTORY);
  46. String saxParserFactory = jEdit.getProperty(XSLTUtilities.SAX_PARSER_FACTORY);
  47. String saxDriver = jEdit.getProperty(XSLTUtilities.SAX_DRIVER);
  48. String indentAmount = jEdit.getProperty("xslt.transform.indent-amount");
  49. XSLTUtilities.setXmlSystemProperties(transformerFactory, saxParserFactory, saxDriver);
  50. XSLTUtilities.setIndentAmount(indentAmount);
  51. }
  52. /**
  53. * Adds appropriate actions to the plugins menu
  54. */
  55. public void createMenuItems (Vector menuItems) {
  56. menuItems.addElement(GUIUtilities.loadMenu("xslt-menu"));
  57. }
  58. /**
  59. * Displays a user-friendly error message to go with the supplied exception.
  60. */
  61. static void processException(Exception e, String message, Component component) {
  62. StringWriter writer = new StringWriter();
  63. e.printStackTrace(new PrintWriter(writer));
  64. Log.log(Log.DEBUG, Thread.currentThread(), writer.toString());
  65. String msg = MessageFormat.format(jEdit.getProperty("xslt.message.error"),
  66. new Object[]{message, e.getMessage()});
  67. JOptionPane.showMessageDialog(component, msg.toString());
  68. }
  69. static void showMessageDialog(String property, Component component) {
  70. String message = jEdit.getProperty(property);
  71. JOptionPane.showMessageDialog(component, message);
  72. }
  73. static void setProcessor(XSLTProcessor processor) {
  74. XSLTPlugin.processor = processor;
  75. }
  76. static void displayOldXalanJarMessage() {
  77. String message = getOldXalanJarMessage();
  78. JOptionPane.showMessageDialog(XSLTPlugin.processor, message);
  79. }
  80. static String getOldXalanJarMessage() {
  81. String userPluginsDir = MiscUtilities.constructPath(jEdit.getSettingsDirectory(),"jars");
  82. String userEndorsedDir = MiscUtilities.constructPath(userPluginsDir, "endorsed");
  83. String systemPluginsDir = MiscUtilities.constructPath(jEdit.getJEditHome(),"jars");
  84. String systemEndorsedDir = MiscUtilities.constructPath(systemPluginsDir, "endorsed");
  85. String[] args = {userPluginsDir, systemPluginsDir, userEndorsedDir, systemEndorsedDir};
  86. String message = jEdit.getProperty("xslt.old-jar.message", args);
  87. return message;
  88. }
  89. }