##### Coverage Report - org.apache.any23.writer.URIListWriter

Classes in this File | Line Coverage | Branch Coverage | Complexity
URIListWriter |
0% | 0/23
0% | 0/6
| 1.2727272727272727;1.273

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.writer;
19 |  |
20 |  |
     import org.apache.any23.extractor.ExtractionContext;
21 |  |
     import org.openrdf.model.Resource;
22 |  |
     import org.openrdf.model.URI;
23 |  |
     import org.openrdf.model.Value;
24 |  |
25 |  |
     import java.io.OutputStream;
26 |  |
     import java.io.PrintStream;
27 |  |
     import java.util.ArrayList;
28 |  |
     import java.util.List;
29 |  |
30 |  |
     /**
31 |  |
      * This writer simply produces a list of unique <i>URI</i> present in the
32 |  |
      * subject or in the object of every single extracted <i>RDF Statement</i>.
33 |  |
      *
34 |  |
      * @author Davide Palmisano (palmisano@fbk.eu)
35 |  |
      */
36 |  |
     @Writer(identifier = "uri", mimeType = "text/plain")
37 |  |
     public class URIListWriter implements FormatWriter {
38 |  |
39 |  |
         private List<Resource> resources;
40 |  |
41 |  |
         private PrintStream printStream;
42 |  |
43 |  |
         private ExtractionContext extractionContext;
44 |  |
45 |  |
         private long contentLength;
46 |  |
47 | 0 |
         public URIListWriter(OutputStream outputStream) {
48 | 0 |
             this.resources = new ArrayList<Resource>();
49 | 0 |
             this.printStream = new PrintStream(outputStream);
50 | 0 |
         }
51 |  |
52 | 0 |
         public void startDocument(URI documentURI) throws TripleHandlerException {}
53 |  |
54 |  |
         public void openContext(ExtractionContext context) throws TripleHandlerException {
55 | 0 |
             this.extractionContext = context;
56 | 0 |
         }
57 |  |
58 |  |
         public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context)
59 |  |
                 throws TripleHandlerException {
60 | 0 |
             if(!this.resources.contains(s)) {
61 | 0 |
                 this.resources.add(s);
62 | 0 |
                 this.printStream.println(s.stringValue());
63 |  |
             }
64 | 0 |
             if(o instanceof Resource && !this.resources.contains(o)) {
65 | 0 |
                 this.resources.add((Resource) o);
66 | 0 |
                 this.printStream.println(o.stringValue());
67 |  |
             }
68 | 0 |
         }
69 |  |
70 |  |
         public void receiveNamespace(String prefix, String uri, ExtractionContext context)
71 |  |
                 throws TripleHandlerException {
72 | 0 |
         }
73 |  |
74 |  |
         public void closeContext(ExtractionContext context) throws TripleHandlerException {
75 | 0 |
         }
76 |  |
77 |  |
         public void endDocument(URI documentURI) throws TripleHandlerException {
78 | 0 |
         }
79 |  |
80 |  |
         public void setContentLength(long contentLength) {
81 | 0 |
             this.contentLength = contentLength;
82 | 0 |
         }
83 |  |
84 |  |
         public void close() throws TripleHandlerException {
85 | 0 |
             this.printStream.close();
86 | 0 |
         }
87 |  |
88 |  |
         @Override
89 |  |
         public boolean isAnnotated() {
90 | 0 |
             return false;
91 |  |
         }
92 |  |
93 |  |
         @Override
94 |  |
         public void setAnnotated(boolean f) {
95 |  |
             // Empty.
96 | 0 |
         }
97 |  |
     }