/plugins/XQuery/branches/axe/xquery/xquery/XQueryGUI.java

#
Java | 705 lines | 411 code | 94 blank | 200 comment | 41 complexity | 5a7c62a6fa8c984e44b6bdfa51aae659 MD5 | raw file

✨ Summary
  1. /*
  2. * Created on Dec 8, 2003
  3. * @author Wim Le Page
  4. * @author Pieter Wellens
  5. *
  6. *
  7. */
  8. package xquery;
  9. import java.awt.BorderLayout;
  10. import java.awt.Dimension;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.io.File;
  14. import java.io.FileWriter;
  15. import java.io.IOException;
  16. import java.lang.reflect.Constructor;
  17. import java.lang.reflect.InvocationTargetException;
  18. import java.net.URI;
  19. import java.net.URISyntaxException;
  20. import java.net.URL;
  21. import java.util.Properties;
  22. import javax.swing.ButtonGroup;
  23. import javax.swing.ImageIcon;
  24. import javax.swing.JButton;
  25. import javax.swing.JFileChooser;
  26. import javax.swing.JLabel;
  27. import javax.swing.JOptionPane;
  28. import javax.swing.JPanel;
  29. import javax.swing.JRadioButton;
  30. import javax.swing.JScrollPane;
  31. import javax.swing.JTextArea;
  32. import javax.swing.JTextField;
  33. import org.gjt.sp.jedit.Buffer;
  34. import org.gjt.sp.jedit.GUIUtilities;
  35. import org.gjt.sp.jedit.JARClassLoader;
  36. import org.gjt.sp.jedit.View;
  37. import org.gjt.sp.jedit.jEdit;
  38. import xmlindenter.XmlIndenterPlugin;
  39. import errorlist.DefaultErrorSource;
  40. import errorlist.ErrorSource;
  41. /**
  42. * @author Wim Le Page
  43. * @author Pieter Wellens
  44. * @version 0.6.0
  45. *
  46. */
  47. public class XQueryGUI extends JPanel {
  48. private View view;
  49. private final SelectXmlInputPanel inputPanel = new SelectXmlInputPanel();
  50. private final SelectXQueryInputPanel queryPanel = new SelectXQueryInputPanel();
  51. private final EvaluatePanel evaluatePanel = new EvaluatePanel();
  52. private DefaultErrorSource errorSource = new DefaultErrorSource("XQuery plugin");
  53. /**
  54. * @param view from jEdit
  55. *
  56. * This constructor just creates a SelectXmlInputPanel, a SelectXQueryInputPanel and a EvaluatePanel
  57. * In other words it creates the complete GUI
  58. */
  59. public XQueryGUI (View view)
  60. {
  61. super(new BorderLayout(0,30));
  62. this.view = view;
  63. add(inputPanel, BorderLayout.NORTH);
  64. add(queryPanel);
  65. add(evaluatePanel, BorderLayout.SOUTH);
  66. }
  67. /**
  68. * @author Wim Le Page
  69. * @author Pieter Wellens
  70. *
  71. * This class represents the GUI for XML input selection panel
  72. */
  73. private class SelectXmlInputPanel extends JPanel {
  74. public JButton browseButton;
  75. private JRadioButton noContextRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.noContext"));
  76. private JRadioButton bufferRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.buffer"));
  77. private JRadioButton fileRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.file"));
  78. private FileSelectionPanel browsePanel = new FileSelectionPanel(view, "xquery.selectXmlInput");
  79. private FolderSelectionPanel uriSelectionPanel = new FolderSelectionPanel(view, "xquery.selectBaseUriInput");
  80. private final JTextField sourceField = new JTextField();
  81. public SelectXmlInputPanel() {
  82. super(new BorderLayout());
  83. createRadioButtons();
  84. JPanel docPanel = new JPanel(new BorderLayout());
  85. docPanel.add(uriSelectionPanel, BorderLayout.SOUTH);
  86. uriSelectionPanel.setSelectionEnabled(true);
  87. JPanel radioPanel = new JPanel(new BorderLayout());
  88. JPanel noContextPanel = new JPanel(new BorderLayout());
  89. noContextPanel.add(new JLabel(jEdit.getProperty("xquery.selectXmlInput.label")), BorderLayout.NORTH);
  90. noContextPanel.add(noContextRadio, BorderLayout.CENTER);
  91. JPanel bufferPanel = new JPanel(new BorderLayout());
  92. bufferPanel.add(bufferRadio, BorderLayout.CENTER);
  93. radioPanel.add(noContextPanel,BorderLayout.NORTH);
  94. radioPanel.add(bufferPanel,BorderLayout.CENTER);
  95. JPanel filePanel = new JPanel(new BorderLayout());
  96. filePanel.add(fileRadio, BorderLayout.NORTH);
  97. filePanel.add(browsePanel);
  98. add(docPanel, BorderLayout.NORTH);
  99. add(radioPanel, BorderLayout.CENTER);
  100. add(filePanel, BorderLayout.SOUTH);
  101. }
  102. /**
  103. * This is a helper function that creates and inits all the radiobuttons.
  104. * It also creates the necessary ActionListeners
  105. */
  106. private void createRadioButtons() {
  107. ActionListener noContextSelected = new ActionListener(){
  108. public void actionPerformed(ActionEvent e) {
  109. browsePanel.setSelectionEnabled(false);
  110. queryPanel.setBufferButtonState(true);
  111. }};
  112. noContextRadio.addActionListener(noContextSelected);
  113. noContextRadio.setSelected(true);
  114. ActionListener bufferSelected = new ActionListener(){
  115. public void actionPerformed(ActionEvent e) {
  116. browsePanel.setSelectionEnabled(false);
  117. queryPanel.setBufferButtonState(false);
  118. }};
  119. bufferRadio.addActionListener(bufferSelected);
  120. ActionListener fileSelected = new ActionListener(){
  121. public void actionPerformed(ActionEvent e) {
  122. browsePanel.setSelectionEnabled(true);
  123. queryPanel.setBufferButtonState(true);
  124. }};
  125. fileRadio.addActionListener(fileSelected);
  126. ButtonGroup radioGroup = new ButtonGroup();
  127. radioGroup.add(noContextRadio);
  128. radioGroup.add(bufferRadio);
  129. radioGroup.add(fileRadio);
  130. }
  131. /**
  132. * @param b is a boolean that enables/disables the bufferButton
  133. *
  134. * This is needed because buffer must be disabled if chosen in XQueryInputPane and vice versa
  135. */
  136. public void setBufferButtonState(boolean b) {
  137. bufferRadio.setEnabled(b);
  138. }
  139. /**
  140. * @return true if file is selected, else false
  141. */
  142. public boolean isFileSelected() {
  143. return fileRadio.isSelected();
  144. };
  145. /**
  146. * @return true if buffer is selected, else false
  147. */
  148. public boolean isBufferSelected() {
  149. return bufferRadio.isSelected();
  150. };
  151. }
  152. /**
  153. * @author Wim Le Page
  154. * @author Pieter Wellens
  155. *
  156. * This class represents the GUI to select the XQuery Input
  157. */
  158. private class SelectXQueryInputPanel extends JPanel{
  159. private JRadioButton bufferRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.buffer"));
  160. private JRadioButton fileRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.file"));
  161. private JRadioButton paneRadio = new JRadioButton(jEdit.getProperty("xquery.selectInput.pane"));
  162. private FileSelectionPanel browsePanel = new FileSelectionPanel(view, "xquery.selectXQueryInput");
  163. private JTextArea queryTextArea = new JTextArea(6,6);
  164. private JButton evalButton;
  165. public SelectXQueryInputPanel() {
  166. super(new BorderLayout());
  167. createRadioButtons();
  168. JPanel bufferPanel = new JPanel(new BorderLayout());
  169. bufferPanel.add(new JLabel(jEdit.getProperty("xquery.selectXQueryInput.label")), BorderLayout.NORTH);
  170. bufferPanel.add(bufferRadio);
  171. JPanel filePanel = new JPanel(new BorderLayout());
  172. filePanel.add(fileRadio, BorderLayout.NORTH);
  173. filePanel.add(browsePanel);
  174. JPanel panePanel = new JPanel(new BorderLayout());
  175. panePanel.add(paneRadio, BorderLayout.NORTH);
  176. panePanel.add(new JScrollPane(queryTextArea));
  177. JPanel upperPanel = new JPanel(new BorderLayout());
  178. upperPanel.add(bufferPanel, BorderLayout.NORTH);
  179. upperPanel.add(filePanel);
  180. add(upperPanel, BorderLayout.NORTH);
  181. add(panePanel);
  182. }
  183. /**
  184. * This is a helper function that creates and inits all the radiobuttons.
  185. * It also creates the necessary ActionListeners
  186. */
  187. private void createRadioButtons() {
  188. ActionListener bufferSelected = new ActionListener(){
  189. public void actionPerformed(ActionEvent e) {
  190. browsePanel.setSelectionEnabled(false);
  191. setPaneSelectionEnabled(false);
  192. inputPanel.setBufferButtonState(false);
  193. }};
  194. bufferRadio.addActionListener(bufferSelected);
  195. ActionListener paneSelected = new ActionListener(){
  196. public void actionPerformed(ActionEvent e) {
  197. setPaneSelectionEnabled(true);
  198. browsePanel.setSelectionEnabled(false);
  199. inputPanel.setBufferButtonState(true);
  200. }};
  201. paneRadio.addActionListener(paneSelected);
  202. ActionListener fileSelected = new ActionListener(){
  203. public void actionPerformed(ActionEvent e) {
  204. browsePanel.setSelectionEnabled(true);
  205. setPaneSelectionEnabled(false);
  206. inputPanel.setBufferButtonState(true);
  207. }};
  208. fileRadio.addActionListener(fileSelected);
  209. fileRadio.setSelected(true);
  210. browsePanel.setSelectionEnabled(true);
  211. setPaneSelectionEnabled(false);
  212. ButtonGroup radioGroup = new ButtonGroup();
  213. radioGroup.add(bufferRadio);
  214. radioGroup.add(fileRadio);
  215. radioGroup.add(paneRadio);
  216. };
  217. /**
  218. * @param b is a boolean that deselectes/selects the Pane
  219. */
  220. private void setPaneSelectionEnabled(boolean b) {
  221. queryTextArea.setEnabled(b);
  222. };
  223. /**
  224. * @param b is a boolean that enables/disables the bufferButton
  225. *
  226. * This is needed because buffer must be disabled if chosen in ContextInputPane and vice versa
  227. */
  228. public void setBufferButtonState(boolean b) {
  229. bufferRadio.setEnabled(b);
  230. }
  231. /**
  232. * @return true if file is selected, else false
  233. */
  234. public boolean isFileSelected() {
  235. return fileRadio.isSelected();
  236. };
  237. /**
  238. * @return true if buffer is selected, else false
  239. */
  240. public boolean isBufferSelected() {
  241. return bufferRadio.isSelected();
  242. };
  243. /**
  244. * @return true if pane is selected, else false
  245. */
  246. public boolean isPaneSelected() {
  247. return paneRadio.isSelected();
  248. };
  249. }
  250. /**
  251. * @author Wim Le Page
  252. * @author Pieter Wellens
  253. *
  254. * This class represents the GUI for the evaluationPanel at the bottom
  255. */
  256. public class EvaluatePanel extends JPanel implements ActionListener {
  257. private JButton evalButton;
  258. /**
  259. * Constructor for the EvaluatePanel, it creates the GUI
  260. */
  261. public EvaluatePanel() {
  262. String iconName = jEdit.getProperty("xquery.evaluate.button.icon");
  263. String toolTipText = jEdit.getProperty("xquery.evaluate.button.tooltip");
  264. String shortcut = jEdit.getProperty("xquery.evaluate.shortcut");
  265. if(shortcut != null) {
  266. toolTipText += " (" + shortcut + ")";
  267. }
  268. URL url = XQueryGUI.class.getResource(iconName);
  269. evalButton = new JButton(new ImageIcon(url));
  270. evalButton.setToolTipText(toolTipText);
  271. evalButton.addActionListener(this);
  272. Dimension dimension = new Dimension(90, 30);
  273. evalButton.setMinimumSize(dimension);
  274. evalButton.setPreferredSize(dimension);
  275. add(evalButton);
  276. }
  277. /* (non-Javadoc)
  278. * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  279. */
  280. public void actionPerformed(ActionEvent e) {
  281. evaluate();
  282. }
  283. /**
  284. * This method creates the adapter, sets the baseURI, sets all the chosen general options (Performance, Indent,...) and
  285. * finally evaluates the Query. After this the performance output is displayed as chosen
  286. */
  287. private void evaluate() {
  288. saveInputSettings();
  289. errorSource.clear();
  290. ErrorSource.unregisterErrorSource(errorSource);
  291. String contextURI = "";
  292. String baseURI = "";
  293. try {
  294. /* constructing the adapter */
  295. Properties props = getProperties();
  296. Adapter adapter = getAdapter(props);
  297. /* enabling/disabling performance monitoring */
  298. adapter.setPerformanceEnabled(jEdit.getBooleanProperty("xquery.performance.selected"));
  299. /* setting base uri */
  300. baseURI = getURI();
  301. if(!baseURI.trim().equals("")) {
  302. adapter.setBaseUri(baseURI);
  303. }
  304. /* setting the context */
  305. setContext(adapter);
  306. /* evaluating the query */
  307. String result = evaluateQuery(adapter);
  308. /* displaying results */
  309. if (!result.trim().equals("")) {
  310. Buffer buffer = jEdit.newFile(view);
  311. buffer.insert(0, result);
  312. buffer.setMode("xml");
  313. if (jEdit.getBooleanProperty("xquery.indent.selected")){
  314. XmlIndenterPlugin.indentXml(view);
  315. }
  316. } else {
  317. JOptionPane.showMessageDialog(null, "Empty result from adapter." , "Adapter warning", JOptionPane.WARNING_MESSAGE);
  318. }
  319. /* displaying performance output */
  320. if (jEdit.getBooleanProperty("xquery.performance.selected")) {
  321. System.err.println("handlePerformanceOutput call with performance: " + adapter.getPerformance());
  322. handlePerformanceOutput(adapter.getPerformance());
  323. }
  324. } catch (NonContextualAdapterException ae) {
  325. //ae.printStackTrace();
  326. JOptionPane.showMessageDialog(null, ae.toString() , "Error executing Adapter", JOptionPane.ERROR_MESSAGE );
  327. } catch (ContextualAdapterException ae) {
  328. /*JOptionPane.showMessageDialog(null,ae.toString() , "THE PATH IS:" + getXQueryPath(),
  329. JOptionPane.ERROR_MESSAGE );*/
  330. ErrorSource.registerErrorSource(errorSource);
  331. errorSource.addError(new DefaultErrorSource.DefaultError(errorSource, ErrorSource.ERROR, getXQueryPath(), ae.getLine(),
  332. ae.getStart(), ae.getEnd() ,ae.getMessage()));
  333. //ae.printStackTrace();
  334. } catch (AdapterException ae) {
  335. //ae.printStackTrace();
  336. JOptionPane.showMessageDialog(null, ae.getMessage() , "Error executing Adapter", JOptionPane.ERROR_MESSAGE );
  337. } catch (URISyntaxException urie) {
  338. //e.printStackTrace();
  339. JOptionPane.showMessageDialog(null, urie.getMessage() , "Error in the base uri", JOptionPane.ERROR_MESSAGE );
  340. } catch (NoClassDefFoundError cnf) {
  341. //cnf.printStackTrace();
  342. JOptionPane.showMessageDialog(null, cnf.getMessage() ,"Error executing Adapter", JOptionPane.ERROR_MESSAGE );
  343. } catch (ClassNotFoundException e) {
  344. //e.printStackTrace();
  345. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error finding Adapter", JOptionPane.ERROR_MESSAGE );
  346. } catch (SecurityException e) {
  347. //e.printStackTrace();
  348. JOptionPane.showMessageDialog(null, e.getMessage() ,"Security error in Adapter",JOptionPane.ERROR_MESSAGE );
  349. } catch (NoSuchMethodException e) {
  350. //e.printStackTrace();
  351. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error calling Adapter", JOptionPane.ERROR_MESSAGE );
  352. } catch (IllegalArgumentException e) {
  353. //e.printStackTrace();
  354. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error calling Adapter", JOptionPane.ERROR_MESSAGE );
  355. } catch (InstantiationException e) {
  356. //e.printStackTrace();
  357. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error instantiating Adapter", JOptionPane.ERROR_MESSAGE );
  358. } catch (IllegalAccessException e) {
  359. //e.printStackTrace();
  360. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error accessing Adapter", JOptionPane.ERROR_MESSAGE );
  361. } catch (InvocationTargetException e) {
  362. //e.printStackTrace();
  363. JOptionPane.showMessageDialog(null, e.getMessage() ,"Error invocing Adapter", JOptionPane.ERROR_MESSAGE );
  364. }
  365. }
  366. /**
  367. * to save settings for next session
  368. */
  369. private void saveInputSettings() {
  370. jEdit.setProperty("xquery.selectXmlInput.last-source", inputPanel.browsePanel.getSourceFieldText());
  371. jEdit.setProperty("xquery.selectBaseUriInput.last-source", inputPanel.uriSelectionPanel.getSourceFieldText());
  372. jEdit.setProperty("xquery.selectXQueryInput.last-source", queryPanel.browsePanel.getSourceFieldText());
  373. }
  374. /**
  375. * @return the properties
  376. */
  377. private Properties getProperties() {
  378. Properties props = new Properties();
  379. return props;
  380. }
  381. /**
  382. * @param props that are needed for constructing the adapter
  383. * @return the newly created adapter
  384. * @throws ClassNotFoundException
  385. * @throws SecurityException
  386. * @throws NoSuchMethodException
  387. * @throws IllegalArgumentException
  388. * @throws InstantiationException
  389. * @throws IllegalAccessException
  390. * @throws InvocationTargetException
  391. *
  392. * This method dynamically creates an instance of teh selected adapter
  393. */
  394. private Adapter getAdapter(Properties props) throws ClassNotFoundException, SecurityException,
  395. NoSuchMethodException, IllegalArgumentException,
  396. InstantiationException, IllegalAccessException,
  397. InvocationTargetException
  398. {
  399. JARClassLoader loader = new JARClassLoader();
  400. Class adapterClass = null;
  401. Constructor adapterConstructor = null;
  402. Adapter adapter = null;
  403. String adapterString = jEdit.getProperty("xquery.adapter.selection");
  404. System.err.println("adapter in lowercase is: " + adapterString.toLowerCase());
  405. System.err.println("adapter normal is: " + adapterString);
  406. adapterClass = loader.loadClass(adapterString.toLowerCase() + "." + adapterString);
  407. //adapterClass = loader.loadClass(adapterString);
  408. adapterConstructor = adapterClass.getConstructor( new Class[] {Properties.class});
  409. adapter = (Adapter)adapterConstructor.newInstance(new Object[] { props } );
  410. return adapter;
  411. }
  412. /**
  413. * @return the String representing the baseURI
  414. * @throws URISyntaxException
  415. *
  416. */
  417. private String getURI() throws URISyntaxException
  418. {
  419. String uri = "";
  420. uri = inputPanel.uriSelectionPanel.getSourceFieldText();
  421. if (uri.trim().equals(jEdit.getProperty("xquery.selectBaseUriInput.prompt").trim())) {
  422. return "";
  423. } else if(!uri.trim().equals("")) {
  424. File base = new File(uri);
  425. if (!base.isDirectory()) {
  426. throw new URISyntaxException(
  427. "The path '"
  428. + uri
  429. + "' does not point to a directory", uri);
  430. }
  431. URI urii = new URI(uri.toString());
  432. return urii.toString();
  433. }
  434. return "";
  435. }
  436. /**
  437. * @return the path to the Context file
  438. *
  439. * This method returns the path to the Context, this is different depending on buffer of file input
  440. */
  441. private String getContextPath() {
  442. String context = "";
  443. if (inputPanel.isBufferSelected()) {
  444. View activeView = jEdit.getActiveView();
  445. Buffer activeBuffer = activeView.getBuffer();
  446. context = activeBuffer.getPath();
  447. } else if (inputPanel.isFileSelected()) {
  448. context = inputPanel.browsePanel.getSourceFieldText();
  449. }
  450. return context;
  451. }
  452. /**
  453. * @return the path of the Xquery
  454. *
  455. * This method returns the path to the XQuery, this is different depending on buffer of file input
  456. */
  457. private String getXQueryPath(){
  458. String path = "";
  459. if (queryPanel.isBufferSelected()) {
  460. View activeView = jEdit.getActiveView();
  461. Buffer activeBuffer = activeView.getBuffer();
  462. path = activeBuffer.getPath();
  463. } else if (queryPanel.isFileSelected()) {
  464. path = queryPanel.browsePanel.getSourceFieldText();
  465. }
  466. return path;
  467. }
  468. private void setContext(Adapter adapter) {
  469. String contextURI = "";
  470. contextURI = getContextPath();
  471. if(!contextURI.trim().equals("")) {
  472. adapter.loadContextFromFile(contextURI);
  473. }
  474. if (inputPanel.isBufferSelected()) {
  475. View activeView = jEdit.getActiveView();
  476. Buffer activeBuffer = activeView.getBuffer();
  477. if (activeBuffer.isDirty()){
  478. /*String context = activeBuffer.getText(0,activeBuffer.getLength());
  479. adapter.loadContexFromString(context);*/
  480. JOptionPane.showMessageDialog(null, "Dirty buffer" ,"Error loading context", JOptionPane.ERROR_MESSAGE );
  481. } else {
  482. adapter.loadContextFromFile(getContextPath());
  483. }
  484. } else if (inputPanel.isFileSelected()) {
  485. adapter.loadContextFromFile(getContextPath());
  486. }
  487. }
  488. /**
  489. * @param adapter that is needed for further evaluation, it communicates with the API
  490. * @return the result String
  491. *
  492. * This method is called in evaluate to finally evaluate the Query
  493. */
  494. private String evaluateQuery(Adapter adapter) {
  495. if (queryPanel.isPaneSelected()){
  496. String xq = queryPanel.queryTextArea.getText();
  497. return adapter.evaluateFromString(xq);
  498. } else if (queryPanel.isBufferSelected() ) {
  499. View activeView = jEdit.getActiveView();
  500. Buffer activeBuffer = activeView.getBuffer();
  501. if (activeBuffer.isDirty()){
  502. String xq = activeBuffer.getText(0,activeBuffer.getLength());
  503. return adapter.evaluateFromString(xq);
  504. } else {
  505. String queryPath = getXQueryPath();
  506. return adapter.evaluateFromFile(queryPath);
  507. }
  508. } else if (queryPanel.isFileSelected()) {
  509. String queryPath = getXQueryPath();
  510. return adapter.evaluateFromFile(queryPath);
  511. /*
  512. File file = new File(path);
  513. try {
  514. FileReader reader = new FileReader(file);
  515. BufferedReader breader = new BufferedReader(reader);
  516. while (breader.ready()) {
  517. xq += breader.readLine() + "\n";
  518. }
  519. } catch (Exception e2) {
  520. JOptionPane.showMessageDialog(null, e2.toString() ,"Error reading XQuery", JOptionPane.ERROR_MESSAGE );
  521. //e2.printStackTrace();
  522. }
  523. */
  524. }
  525. return "";
  526. }
  527. /**
  528. * @param performance String that needs to be displayed as chosen in the options
  529. *
  530. * This method displays the performance as chosen in the optionspane
  531. */
  532. private void handlePerformanceOutput(String performance) {
  533. try {
  534. File perfFile;
  535. if (jEdit.getBooleanProperty("xquery.performance.save")){
  536. //create file from filename asked in popup
  537. String[] selections = GUIUtilities.showVFSFileDialog(jEdit.getActiveView(), "performance_output", JFileChooser.SAVE_DIALOG, false);
  538. if (selections != null) {
  539. //System.err.println(selections[0]);
  540. perfFile = new File(selections[0]);
  541. } else {
  542. //selection failed, create temporary file
  543. perfFile = File.createTempFile("XQuery","");
  544. }
  545. } else {
  546. //create temporary file
  547. perfFile = File.createTempFile("XQuery","");
  548. }
  549. perfFile.createNewFile();
  550. FileWriter fw = new FileWriter(perfFile);
  551. fw.write(performance);
  552. fw.close();
  553. if (jEdit.getBooleanProperty("xquery.performance.tobuffer")) {
  554. //open file in buffer
  555. jEdit.openFile(view, perfFile.getAbsolutePath());
  556. } else if (jEdit.getBooleanProperty("xquery.performance.toinfoviewer")) {
  557. //open (html) file with infoviewer
  558. //System.err.println("opening in viewer : " + perfFile.toURL().toString());
  559. infoviewer.InfoViewerPlugin.openURL(view, perfFile.toURL().toString());
  560. } else if (jEdit.getBooleanProperty("xquery.performance.toexternal")) {
  561. //open file with external program
  562. String command = jEdit.getProperty("xquery.performance.external.text");
  563. command = command.replaceAll("<p>", perfFile.getAbsolutePath());
  564. //System.err.println("exec command: " + command);
  565. Runtime.getRuntime().exec(command);
  566. } else {
  567. //do nothing
  568. }
  569. } catch (IOException e) {
  570. JOptionPane.showMessageDialog(null, e.toString() ,"Error writing Performance", JOptionPane.ERROR_MESSAGE );
  571. //e.printStackTrace();
  572. }
  573. }
  574. }
  575. /**
  576. * @param prop
  577. * @return the valuefield(true or false) of the property
  578. *
  579. * static method that allows adapter writers to use jEdit functionality without importing jEdit
  580. */
  581. public static boolean getBooleanProperty(String prop){
  582. return jEdit.getBooleanProperty("xquery.adapter." + prop);
  583. }
  584. /**
  585. * @param prop
  586. * @return the valuefield of the property
  587. *
  588. * static method that allows adapter writers to use jEdit functionality without importing jEdit
  589. */
  590. public static String getProperty(String prop){
  591. return jEdit.getProperty("xquery.adapter." + prop);
  592. }
  593. /**
  594. * @param prop
  595. * @param bool
  596. *
  597. * static method that allows adapter writers to use jEdit functionality without importing jEdit
  598. */
  599. public static void setBooleanProperty(String prop, boolean bool){
  600. jEdit.setBooleanProperty("xquery.adapter." + prop, bool);
  601. }
  602. /**
  603. * @param property String
  604. * @param string that you wish to set
  605. *
  606. * static method that allows adapter writers to use jEdit functionality without importing jEdit
  607. */
  608. public static void setProperty(String prop, String string){
  609. jEdit.setProperty("xquery.adapter." + prop, string);
  610. }
  611. }