Coverage Report - org.apache.any23.filter.IgnoreTitlesOfEmptyDocuments
 
Classes in this File Line Coverage Branch Coverage Complexity
IgnoreTitlesOfEmptyDocuments
0%
0/23
0%
0/4
1.2
 
 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.filter;
 19  
 
 20  
 import org.apache.any23.extractor.ExtractionContext;
 21  
 import org.apache.any23.extractor.html.TitleExtractor;
 22  
 import org.apache.any23.writer.TripleHandler;
 23  
 import org.apache.any23.writer.TripleHandlerException;
 24  
 import org.openrdf.model.Resource;
 25  
 import org.openrdf.model.URI;
 26  
 import org.openrdf.model.Value;
 27  
 
 28  
 /**
 29  
  * A {@link TripleHandler} that suppresses output of the
 30  
  * {@link TitleExtractor} unless some other triples could
 31  
  * be parsed from the document. This is used when we don't
 32  
  * want to have single-triple RDF documents around that
 33  
  * contain only the title triple.
 34  
  *
 35  
  * @author Richard Cyganiak (richard@cyganiak.de)
 36  
  */
 37  
 public class IgnoreTitlesOfEmptyDocuments implements TripleHandler {
 38  
     
 39  
     private final ExtractionContextBlocker blocker;
 40  
 
 41  0
     public IgnoreTitlesOfEmptyDocuments(TripleHandler wrapped) {
 42  0
         blocker = new ExtractionContextBlocker(wrapped);
 43  0
     }
 44  
 
 45  
     public void startDocument(URI documentURI) throws TripleHandlerException {
 46  0
         blocker.startDocument(documentURI);
 47  0
     }
 48  
 
 49  
     public void openContext(ExtractionContext context) throws TripleHandlerException {
 50  0
         blocker.openContext(context);
 51  0
         if (isTitleContext(context)) {
 52  0
             blocker.blockContext(context);
 53  
         }
 54  0
     }
 55  
 
 56  
     public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
 57  
     throws TripleHandlerException {
 58  0
         if (!isTitleContext(context)) {
 59  0
             blocker.unblockDocument();
 60  
         }
 61  0
         blocker.receiveTriple(s, p, o, g, context);
 62  0
     }
 63  
 
 64  
     public void receiveNamespace(String prefix, String uri,
 65  
                                  ExtractionContext context) throws TripleHandlerException {
 66  0
         blocker.receiveNamespace(prefix, uri, context);
 67  0
     }
 68  
 
 69  
     public void closeContext(ExtractionContext context) {
 70  0
         blocker.closeContext(context);
 71  0
     }
 72  
 
 73  
     public void close() throws TripleHandlerException {
 74  0
         blocker.close();
 75  0
     }
 76  
 
 77  
     private boolean isTitleContext(ExtractionContext context) {
 78  0
         return context.getExtractorName().equals(TitleExtractor.NAME);
 79  
     }
 80  
 
 81  
     public void endDocument(URI documentURI) throws TripleHandlerException {
 82  0
         blocker.endDocument(documentURI);
 83  0
     }
 84  
 
 85  
     public void setContentLength(long contentLength) {
 86  
         //Ignore.
 87  0
     }
 88  
 }