Coverage Report - org.apache.any23.extractor.ExtractionContext
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtractionContext
0%
0/23
0%
0/6
1.417
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *  http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.any23.extractor;
 19  
 
 20  
 import org.openrdf.model.URI;
 21  
 
 22  
 /**
 23  
  * This class provides the context for the processing of
 24  
  * a single {@link Extractor}.
 25  
  */
 26  
 public class ExtractionContext {
 27  
 
 28  
     public static final String ROOT_EXTRACTION_RESULT_ID = "root-extraction-result-id";
 29  
 
 30  
     /**
 31  
      * Name of the extractor.
 32  
      */
 33  
     private final String extractorName;
 34  
 
 35  
     /**
 36  
      * URI of the document.
 37  
      */
 38  
     private final URI documentURI;
 39  
 
 40  
     /**
 41  
      * The document default language.
 42  
      */
 43  
     private String defaultLanguage;
 44  
 
 45  
     /**
 46  
      * ID identifying the document.
 47  
      */
 48  
     private final String uniqueID;
 49  
 
 50  0
     public ExtractionContext(String extractorName, URI documentURI, String defaultLanguage, String localID) {
 51  0
         checkNotNull(extractorName  , "extractor name");
 52  0
         checkNotNull(documentURI    , "document URI");
 53  0
         this.extractorName   = extractorName;
 54  0
         this.documentURI     = documentURI;
 55  0
         this.defaultLanguage = defaultLanguage;
 56  0
         this.uniqueID      =
 57  
                 "urn:x-any23:" + extractorName + ":" +
 58  
                 (localID == null ? "" : localID) + ":" + documentURI;
 59  0
     }
 60  
 
 61  
     public ExtractionContext(String extractorName, URI documentURI, String defaultLanguage) {
 62  0
         this(extractorName, documentURI, defaultLanguage, ROOT_EXTRACTION_RESULT_ID);
 63  0
     }
 64  
 
 65  
     public ExtractionContext(String extractorName, URI documentURI) {
 66  0
         this(extractorName, documentURI, null);
 67  0
     }
 68  
 
 69  
     public ExtractionContext copy(String localID) {
 70  0
         return new ExtractionContext(
 71  
                 getExtractorName(),
 72  
                 getDocumentURI(),
 73  
                 getDefaultLanguage(),
 74  
                 localID
 75  
         );
 76  
     }
 77  
 
 78  
     public String getExtractorName() {
 79  0
         return extractorName;
 80  
     }
 81  
 
 82  
     public URI getDocumentURI() {
 83  0
         return documentURI;
 84  
     }
 85  
 
 86  
     public String getDefaultLanguage() {
 87  0
         return defaultLanguage;
 88  
     }
 89  
 
 90  
     public String getUniqueID() {
 91  0
         return uniqueID;
 92  
     }
 93  
 
 94  
     public int hashCode() {
 95  0
         return uniqueID.hashCode();
 96  
     }
 97  
 
 98  
     public boolean equals(Object other) {
 99  0
         if (!(other instanceof ExtractionContext)) return false;
 100  0
         return ((ExtractionContext) other).uniqueID.equals(uniqueID);
 101  
     }
 102  
 
 103  
     public String toString() {
 104  0
         return String.format("ExtractionContext(%s)", uniqueID);
 105  
     }
 106  
 
 107  
     private void checkNotNull(Object data, String desc) {
 108  0
         if(data == null) throw new NullPointerException(desc + " cannot be null.");
 109  0
     }
 110  
     
 111  
 }