View Javadoc
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.configuration.Settings;
21  import org.apache.any23.extractor.ExtractionContext;
22  import org.eclipse.rdf4j.common.lang.FileFormat;
23  import org.eclipse.rdf4j.model.IRI;
24  import org.eclipse.rdf4j.model.Resource;
25  import org.eclipse.rdf4j.model.Value;
26  import org.eclipse.rdf4j.rio.RDFFormat;
27  
28  import java.io.OutputStream;
29  
30  /**
31   * Base interface for constructors of {@link TripleHandler} implementations that write to an {@link OutputStream} using
32   * a particular {@link FileFormat}.
33   * 
34   * @author Hans Brende (hansbrende@apache.org)
35   */
36  public interface TripleWriterFactory extends BaseWriterFactory<OutputStream> {
37  
38      /**
39       * @deprecated since 2.3. Use {@link #getTripleFormat()} instead.
40       */
41      @Override
42      @Deprecated
43      default RDFFormat getRdfFormat() {
44          return getTripleFormat().toRDFFormat();
45      }
46  
47      /**
48       * @return the format used to write to {@link OutputStream}s
49       */
50      TripleFormat getTripleFormat();
51  
52      /**
53       * @deprecated since 2.3. Use {@link #getTripleFormat()}.{@link TripleFormat#getMimeType() getMimeType()} instead.
54       */
55      @Override
56      @Deprecated
57      default String getMimeType() {
58          return getTripleFormat().getMimeType();
59      }
60  
61      /**
62       * @deprecated since 2.3. Use {@link #getTripleWriter(OutputStream, Settings)} instead.
63       */
64      @Override
65      @Deprecated
66      default FormatWriter getRdfWriter(OutputStream os) {
67          TripleHandler th = getTripleWriter(os, Settings.of());
68          return th instanceof FormatWriterriter.html#FormatWriter">FormatWriter"../../../../org/apache/any23/writer/FormatWriter.html#FormatWriter">FormatWriter ? (FormatWriterriter.html#FormatWriter">FormatWriter) th : new FormatWriter() {
69              @Override
70              public boolean isAnnotated() {
71                  return false;
72              }
73  
74              @Override
75              public void setAnnotated(boolean f) {
76              }
77  
78              @Override
79              public void startDocument(IRI documentIRI) throws TripleHandlerException {
80                  th.startDocument(documentIRI);
81              }
82  
83              @Override
84              public void openContext(ExtractionContext context) throws TripleHandlerException {
85                  th.openContext(context);
86              }
87  
88              @Override
89              public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context)
90                      throws TripleHandlerException {
91                  th.receiveTriple(s, p, o, g, context);
92              }
93  
94              @Override
95              public void receiveNamespace(String prefix, String uri, ExtractionContext context)
96                      throws TripleHandlerException {
97                  th.receiveNamespace(prefix, uri, context);
98              }
99  
100             @Override
101             public void closeContext(ExtractionContext context) throws TripleHandlerException {
102                 th.closeContext(context);
103             }
104 
105             @Override
106             public void endDocument(IRI documentIRI) throws TripleHandlerException {
107                 th.endDocument(documentIRI);
108             }
109 
110             @Override
111             public void setContentLength(long contentLength) {
112                 th.setContentLength(contentLength);
113             }
114 
115             @Override
116             public void close() throws TripleHandlerException {
117                 th.close();
118             }
119         };
120     }
121 
122     /**
123      *
124      * @return the settings supported by writers produced by this factory
125      */
126     @Override
127     Settings getSupportedSettings();
128 
129     /**
130      * @param out
131      *            the {@link OutputStream} to write to
132      * @param settings
133      *            the settings with which to configure the writer
134      * 
135      * @return a {@link TripleHandler} which writes to the specified {@link OutputStream}
136      * 
137      * @throws NullPointerException
138      *             if the output stream or settings is null
139      * @throws IllegalArgumentException
140      *             if the settings are not correctly configured
141      */
142     @Override
143     TripleHandler getTripleWriter(OutputStream out, Settings settings);
144 
145 }