Project

General

Profile

« Previous | Next » 

Revision a897c436

Added by Andreas Müller almost 6 years ago

cleanup

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/openurl/MobotOpenUrlResponseSchemaAdapter.java
1 1
/**
2 2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
49 49
	public URI getIdentifier() {
50 50
		return identifier;
51 51
	}
52
	
52

  
53 53
	/* (non-Javadoc)
54 54
	 * @see eu.etaxonomy.cdm.ext.schema.SchemaAdapter#getShortName()
55 55
	 */
......
57 57
	public String getShortName() {
58 58
		return "MOBOT.OpenUrl.Utilities.OpenUrlResponse";
59 59
	}
60
	
60

  
61 61
	/* (non-Javadoc)
62 62
	 * @see eu.etaxonomy.cdm.ext.schema.SchemaAdapter#getCmdEntities(java.io.Reader)
63 63
	 */
......
75 75
			logger.error(e);
76 76
		}
77 77

  
78
	    
78

  
79 79
		OpenUrlResponseHandler handler = new OpenUrlResponseHandler();
80
	    
80

  
81 81
	    try {
82 82
	    	if(parser != null){
83 83
	    		Reader reader = new InputStreamReader(inputStream, "UTF-8");
......
91 91
	    	}
92 92
		} catch (SAXException e) {
93 93
			logger.error(e);
94
		} 
94
		}
95

  
95 96

  
96
		
97 97
		return handler.referenceList;
98 98
	}
99
	
99

  
100 100
	class OpenUrlResponseHandler extends DefaultHandler {
101
		
101

  
102 102
		/*
103 103
		 * Fields of OpenUrlResponse
104 104
		 *  see http://code.google.com/p/bhl-bits/source/browse/trunk/portal/OpenUrlUtilities/OpenUrlResponse.cs
......
108 108
		private static final String MESSAGE = "Message";
109 109
		private static final String CITATIONS = "citations";
110 110
		private static final String OPENURL_RESPONSE_CITATION = "OpenUrlResponseCitation";
111
		
111

  
112 112
		/*
113 113
		 * Fields of OpenUrlResponseCitation
114 114
		 *  see http://code.google.com/p/bhl-bits/source/browse/trunk/portal/OpenUrlUtilities/OpenUrlResponseCitation.cs
115 115
		 */
116
		
116

  
117 117
		/**
118 118
		 * references the specific page in the title
119 119
		 */
......
149 149
		private static final String SPAGE = "SPage";
150 150
		private static final String EPAGE = "EPage";
151 151
		private static final String PAGES = "Pages";
152
		
153
	
152

  
153

  
154 154
		List<Reference> referenceList = new ArrayList<Reference>();
155 155

  
156 156
		OpenUrlReference reference = null;
157
		
157

  
158 158
		ResponseStatus status = null;
159 159
		Team authorship = null;
160 160
		String message = null;
161
		
161

  
162 162
		String elementName = null;
163 163
		private String elementNameToStore;
164 164
		private StringBuilder textBuffer = new StringBuilder();
165
		
165

  
166 166

  
167 167
		@Override
168
		public void startElement(String uri, String localName, 
168
		public void startElement(String uri, String localName,
169 169
				String qName, Attributes attributes) throws SAXException {
170 170

  
171 171
			if (qName.equals(OPENURL_RESPONSE)) {
......
176 176
			} else if (reference != null && qName.equals(AUTHORS)) {
177 177
				authorship = Team.NewInstance();
178 178
			} else if (reference != null && qName.equals(SUBJECTS)) {
179
				//TODO implement, but no equivalent in the cdm model			
179
				//TODO implement, but no equivalent in the cdm model
180 180
			} else {
181 181
				elementName = qName;
182 182
			}
......
186 186
		public void endElement(String uri, String localName, String qName) throws SAXException {
187 187

  
188 188
			if (qName.equals(OPENURL_RESPONSE)) {
189
				
189

  
190 190
			} else if (qName.equals(OPENURL_RESPONSE_CITATION)) {
191 191
				referenceList.add(reference);
192 192
				reference = null;
......
194 194
				reference.setAuthorship(authorship);
195 195
				authorship = null;
196 196
			} else if (reference != null && qName.equals(SUBJECTS)) {
197
				//TODO implement, but no equivalent in the cdm model		
197
				//TODO implement, but no equivalent in the cdm model
198 198
			}else {
199 199
				elementNameToStore = elementName;
200 200
				elementName = null;
......
205 205
		@Override
206 206
		public void characters(char ch[], int start, int length)
207 207
				throws SAXException {
208
			
208

  
209 209
			if(elementNameToStore  == null){
210
				
210

  
211 211
				textBuffer.append(new String(ch, start, length));
212
				
212

  
213 213
			} else {
214
				
214

  
215 215
				logger.debug("Characters [" + elementNameToStore + "]: " + textBuffer);
216 216
				String trimmedText = textBuffer.toString().trim();
217 217
				// empty the text buffer
218 218
				textBuffer.delete(0, textBuffer.length());
219
				
220
				// --- Reference --- //  
219

  
220
				// --- Reference --- //
221 221
				if(reference != null){
222
					
222

  
223 223
					if(elementNameToStore.equals(URL)){
224 224
						try {
225 225
							reference.setUri(new URI(trimmedText));
......
308 308
						reference.setIssn(trimmedText);
309 309
					}
310 310
				}
311
				
311

  
312 312
				// --- Reference.authorship --- //
313 313
				if(authorship != null && reference != null){
314 314
					if(elementNameToStore.equals("String")){
315 315
						authorship.addTeamMember(Person.NewTitledInstance(trimmedText));
316 316
					}
317 317
				}
318
				
319
				// openUrlResponse // 
318

  
319
				// openUrlResponse //
320 320
				if(reference == null){
321 321
					if(elementNameToStore.equals(STATUS)){
322 322
						status = ResponseStatus.valueOf(trimmedText);
......
326 326
				elementNameToStore = null;
327 327
			}
328 328
		}
329
		
329

  
330 330
	}
331
	
331

  
332 332
	 /**
333 333
	 * @see http://code.google.com/p/bhl-bits/source/browse/trunk/portal/OpenUrlUtilities/IOpenUrlResponse.cs
334 334
	 */
......
337 337
		Success, Error
338 338
	}
339 339

  
340
	
340

  
341 341
}

Also available in: Unified diff