Changeset 5670 for FCSSimpleEndpoint
- Timestamp:
- 09/23/14 06:53:21 (10 years ago)
- Location:
- FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/DataView.java
r5546 r5670 59 59 60 60 61 /** 62 * Get the identifier of this data view. 63 * 64 * @return the identifier of the data view 65 */ 61 66 public String getIdentifier() { 62 67 return identifier; … … 64 69 65 70 71 /** 72 * Get the MIME type of this data view. 73 * 74 * @return the MIME type of this data view 75 */ 66 76 public String getMimeType() { 67 77 return mimeType; … … 69 79 70 80 81 /** 82 * Get the delivery policy for this data view. 83 * 84 * @return the delivery policy of this data view 85 * @see DeliveryPolicy 86 */ 71 87 public DeliveryPolicy getDeliveryPolicy() { 72 88 return deliveryPolicy; … … 84 100 return sb.toString(); 85 101 } 102 86 103 } // class DataView -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
r5547 r5670 37 37 public abstract class SimpleEndpointSearchEngineBase extends 38 38 SRUSearchEngineBase { 39 private static final String FCS_DISABLE_LEGECY_MODE = 40 "eu.clarin.sru.server.fcs.disableLegacyMode"; 39 41 private static final String X_FCS_ENDPOINT_DESCRIPTION = "x-fcs-endpoint-description"; 40 42 private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info"; … … 51 53 LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class); 52 54 protected EndpointDescription endpointDescription; 55 private boolean disableLegecyMode; 53 56 54 57 … … 78 81 "returned no valid implementation of an EndpointDescription"); 79 82 } 83 84 if (params.containsKey(FCS_DISABLE_LEGECY_MODE)) { 85 logger.info("disabling FCS legacy mode"); 86 this.disableLegecyMode = false; 87 } else { 88 this.disableLegecyMode = true; 89 } 80 90 } 81 91 … … 138 148 SRURequest request, SRUDiagnosticList diagnostics) 139 149 throws SRUException { 140 /* 141 * Check if we got a scan on fcs.resource. If yes, handle it 142 * accordingly, otherwise delegate to user-provided implementation. 143 */ 144 final List<ResourceInfo> result = 145 translateFcsScanResource(request.getScanClause()); 146 if (result != null) { 150 151 if (isLegacyMode()) { 147 152 /* 148 * Make sure, we honor the maximumTerms limit, of the client149 * requests it ...153 * Check if we got a scan on fcs.resource. If yes, handle it 154 * accordingly, otherwise delegate to user-provided implementation. 150 155 */ 151 final int maxTerms 152 = ((result.size() > 0) && (request.getMaximumTerms() > 0)) 153 ? Math.min(result.size(), request.getMaximumTerms()) 154 : result.size(); 155 156 /* 157 * Shall we provide extended resource information ... ? 158 */ 159 final boolean provideResourceInfo = parseBoolean( 160 request.getExtraRequestData(X_CMD_RESOURCE_INFO)); 161 162 return new SRUScanResultSet(diagnostics) { 163 private int idx = -1; 164 165 @Override 166 public boolean nextTerm() { 167 return (result != null) && (++idx < maxTerms); 168 } 169 170 171 @Override 172 public String getValue() { 173 return result.get(idx).getPid(); 174 } 175 176 177 @Override 178 public int getNumberOfRecords() { 179 return -1; 180 } 181 182 183 @Override 184 public String getDisplayTerm() { 185 return result.get(idx).getTitle("en"); 186 } 187 188 189 @Override 190 public WhereInList getWhereInList() { 191 return null; 192 } 193 194 195 @Override 196 public boolean hasExtraTermData() { 197 return provideResourceInfo; 198 } 199 200 201 @Override 202 public void writeExtraTermData(XMLStreamWriter writer) 203 throws XMLStreamException { 204 if (provideResourceInfo) { 205 writeLegacyResourceInfo(writer, result.get(idx)); 206 } 207 } 208 }; 156 final List<ResourceInfo> result = translateFcsScanResource(request 157 .getScanClause()); 158 if (result != null) { 159 /* 160 * Make sure, we honor the maximumTerms limit, of the client 161 * requests it ... 162 */ 163 final int maxTerms = ((result.size() > 0) && (request 164 .getMaximumTerms() > 0)) ? Math.min(result.size(), 165 request.getMaximumTerms()) : result.size(); 166 167 /* 168 * Shall we provide extended resource information ... ? 169 */ 170 final boolean provideResourceInfo = parseBoolean(request 171 .getExtraRequestData(X_CMD_RESOURCE_INFO)); 172 173 return new SRUScanResultSet(diagnostics) { 174 private int idx = -1; 175 176 177 @Override 178 public boolean nextTerm() { 179 return (result != null) && (++idx < maxTerms); 180 } 181 182 183 @Override 184 public String getValue() { 185 return result.get(idx).getPid(); 186 } 187 188 189 @Override 190 public int getNumberOfRecords() { 191 return -1; 192 } 193 194 195 @Override 196 public String getDisplayTerm() { 197 return result.get(idx).getTitle("en"); 198 } 199 200 201 @Override 202 public WhereInList getWhereInList() { 203 return null; 204 } 205 206 207 @Override 208 public boolean hasExtraTermData() { 209 return provideResourceInfo; 210 } 211 212 213 @Override 214 public void writeExtraTermData(XMLStreamWriter writer) 215 throws XMLStreamException { 216 if (provideResourceInfo) { 217 writeLegacyResourceInfo(writer, result.get(idx)); 218 } 219 } 220 }; 221 } else { 222 return doScan(config, request, diagnostics); 223 } 209 224 } else { 210 225 return doScan(config, request, diagnostics); … … 543 558 } 544 559 560 561 /** 562 * Check, if running in legacy mode. Only intended for comparability with 563 * legacy clients until the new CLARIN-FCS specification is deployed on a 564 * larger scale. 565 * 566 * @return <code>true</code> if running in legacy mode, <code>false</code> 567 * otherwise 568 */ 569 protected boolean isLegacyMode() { 570 return !disableLegecyMode; 571 } 572 545 573 } // class SimpleEndpointSearchEngineBase -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/XMLStreamWriterHelper.java
r5546 r5670 16 16 */ 17 17 public final class XMLStreamWriterHelper { 18 private static final String FCS_NS = "http://clarin.eu/fcs/1.0"; 19 private static final String FCS_PREFIX = "fcs"; 18 private static final String FCS_NS = 19 "http://clarin.eu/fcs/resource"; 20 private static final String FCS_PREFIX = 21 "fcs"; 20 22 private static final String FCS_KWIC_NS = 21 23 "http://clarin.eu/fcs/1.0/kwic"; 22 private static final String FCS_KWIC_PREFIX = "kwic"; 24 private static final String FCS_KWIC_PREFIX = 25 "kwic"; 23 26 private static final String FCS_KWIC_MIMETYPE = 24 27 "application/x-clarin-fcs-kwic+xml"; 25 28 private static final String FCS_HITS_NS = 26 29 "http://clarin.eu/fcs/dataview/hits"; 27 private static final String FCS_HITS_PREFIX = "hits"; 30 private static final String FCS_HITS_PREFIX = 31 "hits"; 28 32 private static final String FCS_HITS_MIMETYPE = 29 33 "application/x-clarin-fcs-hits+xml"; … … 354 358 355 359 /** 356 * Convince method for writing a record with a KWICdata view. The following360 * Convince method for writing a record with a HITS data view. The following 357 361 * code (arguments omitted) would accomplish the same result: 358 362 * … … 528 532 } 529 533 534 535 /** 536 * Convince method for writing a record with a HITS and a KWIC data view. 537 * This method is intended for applications that want ensure computability 538 * to legacy CLARIN-FCS clients The following code (arguments omitted) would 539 * accomplish the same result: 540 * 541 * <pre> 542 * ... 543 * writeStartResource(...); 544 * writeHitsDataView(...); 545 * writeKWICDataView(...); 546 * writeEndResource(...); 547 * ... 548 * </pre> 549 * 550 * @param writer 551 * the {@link XMLStreamWriter} to be used 552 * @param pid 553 * the persistent identifier of this resource or 554 * <code>null</code>, if not applicable 555 * @param ref 556 * the reference of this resource or <code>null</code>, if not 557 * applicable 558 * @param left 559 * the left context of the hit or <code>null</code> if not 560 * applicable 561 * @param hit 562 * the actual hit, that will be highlighted 563 * @param right 564 * the right context of the hit or <code>null</code> if not 565 * applicable 566 * @throws XMLStreamException 567 * if an error occurred 568 * @deprecated Only use, if you want compatability to legacy FCS 569 * applications. 570 */ 571 @Deprecated 572 public static void writeResourceWithHitsDataViewLegacy(XMLStreamWriter writer, 573 String pid, String ref, String left, String hit, String right) 574 throws XMLStreamException { 575 if (writer == null) { 576 throw new NullPointerException("writer == null"); 577 } 578 579 writeStartResource(writer, pid, ref); 580 writeHitsDataView(writer, left, hit, right); 581 writeKWICDataView(writer, left, hit, right); 582 writeEndResource(writer); 583 } 584 530 585 } // class XMLStreamWriterHelper -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java
r5546 r5670 36 36 throw new IllegalArgumentException("capabilities are empty"); 37 37 } 38 for (URI capability : capabilities) { 39 if (capability == null) { 40 throw new IllegalArgumentException( 41 "capabilities must not contain a 'null' item"); 42 } 43 } 38 44 this.capabilities = Collections.unmodifiableList(capabilities); 39 45 … … 43 49 if (supportedDataViews.isEmpty()) { 44 50 throw new IllegalArgumentException("supportedDataViews are empty"); 51 } 52 for (DataView supportedDataView : supportedDataViews) { 53 if (supportedDataView == null) { 54 throw new IllegalArgumentException( 55 "supportedDataViews must not contain a 'null' item"); 56 } 45 57 } 46 58 this.supportedDataViews =
Note: See TracChangeset
for help on using the changeset viewer.