View Javadoc

1   /*
2   Copyright (c) 2005 The European Bioinformatics Institute, and others.
3   All rights reserved. Please see the file LICENSE
4   in the root directory of this distribution.
5   */
6   package uk.ac.ebi.intenz.tools.release.helper;
7   
8   import uk.ac.ebi.intenz.tools.release.helper.EnzymeEntryHelper;
9   import uk.ac.ebi.intenz.domain.reference.Book;
10  import uk.ac.ebi.intenz.domain.reference.Journal;
11  import uk.ac.ebi.intenz.domain.reference.Patent;
12  import uk.ac.ebi.intenz.domain.reference.Reference;
13  import uk.ac.ebi.xchars.SpecialCharacters;
14  import uk.ac.ebi.xchars.domain.EncodingType;
15  
16  
17  /**
18   * EnzymeReferenceHelper used to display the XML text version.
19   *
20   * @author Paula
21   * @version $id 06-Jun-2005 10:18:25
22   *          <p/>
23   *          History:
24   *          Developer          Date              Description<br>
25   *          Paula            06-Jun-2005         Created class<br>
26   */
27  public class EnzymeReferenceHelper {
28  
29     /**
30      * Used to transform the reference object into the IntEnz text XML used in
31      * the search engine.
32      * 
33      * @param reference
34      * @param number
35      * @param encoding
36      * @return
37      */
38     public static String referenceToIntEnzTextXML (Reference reference, int number, SpecialCharacters encoding) {
39        StringBuffer buffer = new StringBuffer();
40        buffer.append(referenceXML(reference, number, encoding));
41        if ( reference instanceof Book ) {
42           Book book = (Book) reference;
43           buffer.append(bookXML(book, encoding));
44        } else if ( reference instanceof Journal ) {
45           Journal journal = (Journal) reference;
46           buffer.append(journalXML(journal, encoding));
47        } else if ( reference instanceof Patent ) {
48           Patent patent = (Patent) reference;
49           buffer.append(patentXML(patent, encoding));
50        }
51        return buffer.toString();
52     }
53  
54     /** PRIVATE METHODS **/
55  
56     /**
57      * Private method to display the XML data.
58      * @param reference
59      * @param number
60      * @param encoding
61      * @return
62      */
63     private static String referenceXML (Reference reference, int number, SpecialCharacters encoding) {
64        StringBuffer xmlStringBuffer = new StringBuffer();
65  
66        xmlStringBuffer.append("<number>");
67        xmlStringBuffer.append(number + ".");
68        xmlStringBuffer.append("</number>");
69        xmlStringBuffer.append("<authors>");
70        xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(reference.getAuthors())));
71        xmlStringBuffer.append("</authors>");
72  //      if (encoding.isSpecialCharactersElement(authors)) { // Store text only version as well.
73        xmlStringBuffer.append("<authors>");
74        xmlStringBuffer.append(EnzymeEntryHelper.
75              removeFormatting(encoding.xml2Display(reference.getAuthors(), EncodingType.SWISSPROT_CODE)));
76        xmlStringBuffer.append("</authors>");
77  //      }
78        xmlStringBuffer.append("<title>");
79        xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(reference.getTitle())));
80        xmlStringBuffer.append("</title>");
81  //      if (encoding.isSpecialCharactersElement(title)) { // Store text only version as well.
82        xmlStringBuffer.append("<title>");
83        xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(reference.getTitle(), EncodingType.SWISSPROT_CODE)));
84        xmlStringBuffer.append("</title>");
85  //      }
86        xmlStringBuffer.append("<year>");
87        xmlStringBuffer.append(reference.getYear());
88        xmlStringBuffer.append("</year>");
89  
90        return xmlStringBuffer.toString();
91     }
92  
93     private static String bookXML (Book book, SpecialCharacters encoding) {
94        StringBuffer xmlStringBuffer = new StringBuffer();
95        xmlStringBuffer.append("<pubName>");
96        xmlStringBuffer.append(book.getPubName());
97        xmlStringBuffer.append("</pubName>");
98        xmlStringBuffer.append("<patent_no>");
99        xmlStringBuffer.append("</patent_no>");
100       xmlStringBuffer.append("<first_page>");
101       xmlStringBuffer.append(book.getFirstPage());
102       xmlStringBuffer.append("</first_page>");
103       xmlStringBuffer.append("<last_page>");
104       xmlStringBuffer.append(book.getLastPage());
105       xmlStringBuffer.append("</last_page>");
106       xmlStringBuffer.append("<edition>");
107       xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(book.getEdition(false))));
108       xmlStringBuffer.append("</edition>");
109 //      if (encoding.isSpecialCharactersElement(edition)) { // Store text only version as well.
110       xmlStringBuffer.append("<edition>");
111       xmlStringBuffer.append(EnzymeEntryHelper.
112             removeFormatting(encoding.xml2Display(book.getEdition(false), EncodingType.SWISSPROT_CODE)));
113       xmlStringBuffer.append("</edition>");
114 //      }
115       xmlStringBuffer.append("<editor>");
116       xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(book.getEditor(false))));
117       xmlStringBuffer.append("</editor>");
118 //      if (encoding.isSpecialCharactersElement(editor)) { // Store text only version as well.
119       xmlStringBuffer.append("<editor>");
120       xmlStringBuffer.append(EnzymeEntryHelper.
121             removeFormatting(encoding.xml2Display(book.getEditor(false), EncodingType.SWISSPROT_CODE)));
122       xmlStringBuffer.append("</editor>");
123 //      }
124       xmlStringBuffer.append("<volume>");
125       xmlStringBuffer.append(book.getVolume());
126       xmlStringBuffer.append("</volume>");
127       xmlStringBuffer.append("<pub_place>");
128       xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(book.getPublisherPlace())));
129       xmlStringBuffer.append("</pub_place>");
130 //      if (encoding.isSpecialCharactersElement(publisherPlace)) { // Store text only version as well.
131       xmlStringBuffer.append("<pub_place>");
132       xmlStringBuffer.append(EnzymeEntryHelper.
133             removeFormatting(encoding.xml2Display(book.getPublisherPlace(), EncodingType.SWISSPROT_CODE)));
134       xmlStringBuffer.append("</pub_place>");
135 //      }
136       xmlStringBuffer.append("<pub_company>");
137       xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(book.getPublisher())));
138       xmlStringBuffer.append("</pub_company>");
139 //      if (encoding.isSpecialCharactersElement(publisher)) { // Store text only version as well.
140       xmlStringBuffer.append("<pub_company>");
141       xmlStringBuffer.append(EnzymeEntryHelper.removeFormatting(encoding.xml2Display(book.getPublisher(), EncodingType.SWISSPROT_CODE)));
142       xmlStringBuffer.append("</pub_company>");
143 //      }
144       xmlStringBuffer.append("<pub_med>");
145       xmlStringBuffer.append("</pub_med>");
146       xmlStringBuffer.append("<medline>");
147       xmlStringBuffer.append("</medline>");
148 
149       return xmlStringBuffer.toString();
150    }
151 
152    private static String journalXML (Journal journal, SpecialCharacters encoding) {
153       StringBuffer xmlStringBuffer = new StringBuffer();
154       xmlStringBuffer.append("<pubName>");
155       xmlStringBuffer.append(journal.getPubName());
156       xmlStringBuffer.append("</pubName>");
157       xmlStringBuffer.append("<patent_no>");
158       xmlStringBuffer.append("</patent_no>");
159       xmlStringBuffer.append("<first_page>");
160       xmlStringBuffer.append(journal.getFirstPage());
161       xmlStringBuffer.append("</first_page>");
162       xmlStringBuffer.append("<last_page>");
163       xmlStringBuffer.append(journal.getLastPage());
164       xmlStringBuffer.append("</last_page>");
165       xmlStringBuffer.append("<edition>");
166       xmlStringBuffer.append("</edition>");
167       xmlStringBuffer.append("<editor>");
168       xmlStringBuffer.append("</editor>");
169       xmlStringBuffer.append("<volume>");
170       xmlStringBuffer.append("</volume>");
171       xmlStringBuffer.append("<pub_place>");
172       xmlStringBuffer.append("</pub_place>");
173       xmlStringBuffer.append("<pub_company>");
174       xmlStringBuffer.append("</pub_company>");
175       xmlStringBuffer.append("<pub_med>");
176       xmlStringBuffer.append(journal.getPubMedId());
177       xmlStringBuffer.append("</pub_med>");
178       xmlStringBuffer.append("<medline>");
179       xmlStringBuffer.append(journal.getMedlineId());
180       xmlStringBuffer.append("</medline>");
181       return xmlStringBuffer.toString();
182    }
183 
184    private static String patentXML (Patent patent, SpecialCharacters encoding) {
185       StringBuffer xmlStringBuffer = new StringBuffer();
186       xmlStringBuffer.append("<issue>");
187       xmlStringBuffer.append("</issue>");
188       xmlStringBuffer.append("<patent_no>");
189       xmlStringBuffer.append(patent.getPatentNumber());
190       xmlStringBuffer.append("</patent_no>");
191       xmlStringBuffer.append("<first_page>");
192       xmlStringBuffer.append("</first_page>");
193       xmlStringBuffer.append("<last_page>");
194       xmlStringBuffer.append("</last_page>");
195       xmlStringBuffer.append("<edition>");
196       xmlStringBuffer.append("</edition>");
197       xmlStringBuffer.append("<editor>");
198       xmlStringBuffer.append("</editor>");
199       xmlStringBuffer.append("<volume>");
200       xmlStringBuffer.append("</volume>");
201       xmlStringBuffer.append("<pub_place>");
202       xmlStringBuffer.append("</pub_place>");
203       xmlStringBuffer.append("<pub_company>");
204       xmlStringBuffer.append("</pub_company>");
205       xmlStringBuffer.append("<pub_med>");
206       xmlStringBuffer.append("</pub_med>");
207       xmlStringBuffer.append("<medline>");
208       xmlStringBuffer.append("</medline>");
209       return xmlStringBuffer.toString();
210    }
211 
212 }