MCPcopy Create free account
hub / github.com/GateNLP/gate-core / init

Method init

src/main/java/gate/corpora/DocumentImpl.java:245–347  ·  view source on GitHub ↗

Initialise this resource, and return it.

()

Source from the content-addressed store, hash-verified

243
244 /** Initialise this resource, and return it. */
245 @Override
246 public Resource init() throws ResourceInstantiationException {
247 // set up the source URL and create the content
248 if(sourceUrl == null) {
249 if(stringContent == null) { throw new ResourceInstantiationException(
250 "The sourceURL and document's content were null."); }
251 content = new DocumentContentImpl(stringContent);
252 getFeatures().put("gate.SourceURL", "created from String");
253 } else {
254 try {
255 URL resolved = gate.Utils.resolveURL(sourceUrl);
256 getFeatures().put("gate.OriginalURL", sourceUrl.toExternalForm());
257 sourceUrl = resolved;
258 }
259 catch (IOException e) {
260 System.err.println("Unable to resolve URL");
261 e.printStackTrace();
262 }
263
264 try {
265 if(!DocumentFormat.willReadFromUrl(mimeType, sourceUrl)) {
266 content = new DocumentContentImpl(sourceUrl, getEncoding(),
267 sourceUrlStartOffset, sourceUrlEndOffset);
268 }
269 getFeatures().put("gate.SourceURL", sourceUrl.toExternalForm());
270 } catch(IOException e) {
271 throw new ResourceInstantiationException("DocumentImpl.init: " + e);
272 }
273 }
274 if(preserveOriginalContent && content != null) {
275 String originalContent = ((DocumentContentImpl)content)
276 .getOriginalContent();
277 getFeatures().put(GateConstants.ORIGINAL_DOCUMENT_CONTENT_FEATURE_NAME,
278 originalContent);
279 } // if
280 // set up a DocumentFormat if markup unpacking required
281 if(getMarkupAware()) {
282 DocumentFormat docFormat = null;
283 // if a specific MIME type has been given, use it
284 if(this.mimeType != null && this.mimeType.length() > 0) {
285 MimeType theType = DocumentFormat.getMimeTypeForString(mimeType);
286 if(theType == null) {
287 throw new ResourceInstantiationException("MIME type \""
288 + this.mimeType + " has no registered DocumentFormat");
289 }
290
291 docFormat = DocumentFormat.getDocumentFormat(this, theType);
292 }
293 else {
294 docFormat = DocumentFormat.getDocumentFormat(this, sourceUrl);
295 }
296 try {
297 if(docFormat != null) {
298 StatusListener sListener = (StatusListener)gate.Gate
299 .getListeners().get("gate.event.StatusListener");
300 if(sListener != null) docFormat.addStatusListener(sListener);
301 // set the flag if true and if the document format support collecting
302 docFormat.setShouldCollectRepositioning(collectRepositioningInfo);

Callers

nothing calls this directly

Calls 15

getFeaturesMethod · 0.95
willReadFromUrlMethod · 0.95
getEncodingMethod · 0.95
getMarkupAwareMethod · 0.95
getMimeTypeForStringMethod · 0.95
getDocumentFormatMethod · 0.95
addStatusListenerMethod · 0.95
getMimeTypeMethod · 0.95

Tested by

no test coverage detected