| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | package org.pathvisio.example; |
|---|
| 18 | |
|---|
| 19 | import java.io.File; |
|---|
| 20 | import java.io.FileWriter; |
|---|
| 21 | import java.io.IOException; |
|---|
| 22 | |
|---|
| 23 | import org.pathvisio.biopax.reflect.BiopaxElement; |
|---|
| 24 | import org.pathvisio.biopax.reflect.PublicationXref; |
|---|
| 25 | import org.pathvisio.gui.swing.PvDesktop; |
|---|
| 26 | import org.pathvisio.model.ConverterException; |
|---|
| 27 | import org.pathvisio.model.Pathway; |
|---|
| 28 | import org.pathvisio.model.PathwayExporter; |
|---|
| 29 | import org.pathvisio.plugin.Plugin; |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | public class ExExporter implements Plugin |
|---|
| 40 | { |
|---|
| 41 | private PvDesktop desktop; |
|---|
| 42 | |
|---|
| 43 | public void init(PvDesktop desktop) |
|---|
| 44 | { |
|---|
| 45 | this.desktop = desktop; |
|---|
| 46 | |
|---|
| 47 | desktop.getSwingEngine().getEngine().addPathwayExporter(new BibliographyExporter()); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | private static class BibliographyExporter implements PathwayExporter |
|---|
| 57 | { |
|---|
| 58 | |
|---|
| 59 | public void doExport(File file, Pathway pathway) |
|---|
| 60 | throws ConverterException { |
|---|
| 61 | |
|---|
| 62 | try { |
|---|
| 63 | |
|---|
| 64 | FileWriter fos = new FileWriter(file); |
|---|
| 65 | int i = 0; |
|---|
| 66 | |
|---|
| 67 | for (BiopaxElement be : pathway.getBiopaxElementManager().getElements()) |
|---|
| 68 | { |
|---|
| 69 | fos.write ("BIBLIOGRAPHY\n"); |
|---|
| 70 | fos.write ("============\n"); |
|---|
| 71 | |
|---|
| 72 | if (be instanceof PublicationXref) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | PublicationXref pxref = (PublicationXref)be; |
|---|
| 76 | fos.write ("\n"); |
|---|
| 77 | i++; |
|---|
| 78 | fos.write ("#" + i + ":\n"); |
|---|
| 79 | fos.write("Authors: " + pxref.getAuthors() + "\n"); |
|---|
| 80 | fos.write("Title: " + pxref.getTitle() + "\n"); |
|---|
| 81 | fos.write("Source: " + pxref.getSource() + "\n"); |
|---|
| 82 | fos.write("Year: " + pxref.getYear() + "\n"); |
|---|
| 83 | fos.write("PMID: " + pxref.getPubmedId() + "\n"); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | if (i == 0) |
|---|
| 88 | { |
|---|
| 89 | fos.write ("\nNo publication references found\n"); |
|---|
| 90 | } |
|---|
| 91 | fos.close(); |
|---|
| 92 | } |
|---|
| 93 | catch (IOException e) |
|---|
| 94 | { |
|---|
| 95 | throw new ConverterException (e); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | private static final String[] EXTENSIONS = new String[] { "txt" }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | public String[] getExtensions() |
|---|
| 107 | { |
|---|
| 108 | return EXTENSIONS; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | public String getName() |
|---|
| 115 | { |
|---|
| 116 | return "Text Bibliography Exporter"; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | public void done() {} |
|---|
| 121 | } |
|---|