1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.io.PrintWriter;
|
---|
5 | import java.util.Objects;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This factory is called by everyone who needs an OsmWriter object,
|
---|
9 | * instead of directly calling the OsmWriter constructor.
|
---|
10 | *
|
---|
11 | * This enables plugins to substitute the original OsmWriter with
|
---|
12 | * their own version, altering the way JOSM writes objects to the
|
---|
13 | * server, and to disk.
|
---|
14 | *
|
---|
15 | * @author Frederik Ramm
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class OsmWriterFactory {
|
---|
19 |
|
---|
20 | private static volatile OsmWriterFactory theFactory;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Creates new {@code OsmWriter}.
|
---|
24 | * @param out print writer
|
---|
25 | * @param osmConform if {@code true}, prevents modification attributes to be written to the common part
|
---|
26 | * @param version OSM API version (0.6)
|
---|
27 | * @return new {@code OsmWriter}
|
---|
28 | */
|
---|
29 | public static OsmWriter createOsmWriter(PrintWriter out, boolean osmConform, String version) {
|
---|
30 | // pre-set factory with this default implementation; can still be overwritten
|
---|
31 | // later. note that the default factory may already be used for constructing
|
---|
32 | // OsmWriters during the startup process.
|
---|
33 | if (theFactory == null) {
|
---|
34 | theFactory = new OsmWriterFactory();
|
---|
35 | }
|
---|
36 | return theFactory.createOsmWriterImpl(out, osmConform, version);
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Sets the default factory.
|
---|
41 | * @param factory new default factory
|
---|
42 | * @since 11851
|
---|
43 | */
|
---|
44 | public static void setDefaultFactory(OsmWriterFactory factory) {
|
---|
45 | theFactory = Objects.requireNonNull(factory);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Creates new {@code OsmWriter}.
|
---|
50 | * @param out print writer
|
---|
51 | * @param osmConform if {@code true}, prevents modification attributes to be written to the common part
|
---|
52 | * @param version OSM API version (0.6)
|
---|
53 | * @return new {@code OsmWriter}
|
---|
54 | */
|
---|
55 | protected OsmWriter createOsmWriterImpl(PrintWriter out, boolean osmConform, String version) {
|
---|
56 | return new OsmWriter(out, osmConform, version);
|
---|
57 | }
|
---|
58 | }
|
---|