| GedcomHandler.java |
1 /****************************************************************************
2 * This demo file is part of yFiles for Java 2.14.
3 * Copyright (c) 2000-2017 by yWorks GmbH, Vor dem Kreuzberg 28,
4 * 72070 Tuebingen, Germany. All rights reserved.
5 *
6 * yFiles demo files exhibit yFiles for Java functionalities. Any redistribution
7 * of demo files in source code or binary form, with or without
8 * modification, is not permitted.
9 *
10 * Owners of a valid software license for a yFiles for Java version that this
11 * demo is shipped with are allowed to use the demo source code as basis
12 * for their own yFiles for Java powered applications. Use of such programs is
13 * governed by the rights and conditions as set out in the yFiles for Java
14 * license agreement.
15 *
16 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 ***************************************************************************/
28 package demo.layout.genealogy.iohandler;
29
30 import y.io.IOHandler;
31 import y.view.Graph2D;
32
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.io.OutputStream;
36
37 /**
38 * Reads GEDCOM files into graphs. GEDCOM is a widely used format to store family trees, see
39 * http://www.phpgedview.net/ged551-5.pdf for the most recent specifications.
40 * <p/>
41 * The reader uses a {@link GedcomInputParser} to fill the data from the GEDCOM file into a graph structure.
42 */
43 public class GedcomHandler extends IOHandler {
44
45 /**
46 * Returns <code>false</code>, since writing of GEDCOM files is not supported.
47 */
48 public boolean canWrite() {
49 return false;
50 }
51
52 /**
53 * Throws an <code>UnsupportedOperationException</code>, since writing of GEDCOM files is not supported.
54 */
55 public void write(Graph2D graph, OutputStream out) throws IOException {
56 throw new UnsupportedOperationException("No Gedcom export");
57 }
58
59 /**
60 * Reads a GEDCOM file into the given graph graph.
61 * <p/>
62 * This implementation calls a <code>GedcomInputParser</code> to read the GEDCOM file into a graph.
63 *
64 * @param graph the graph to be built
65 * @param in the stream from the file
66 * @throws IOException
67 */
68 public void read(final Graph2D graph, InputStream in) throws IOException {
69 new GedcomInputParser().parse(in, createGedcomHandler(graph));
70 }
71
72 /**
73 * Returns a descriptive string of the GEDCOM file format.
74 */
75 public String getFileFormatString() {
76 return "GEDCOM (Genealogical Data)";
77 }
78
79 /**
80 * Returns <code>ged</code>.
81 */
82 public String getFileNameExtension() {
83 return "ged";
84 }
85
86 /**
87 * Creates a handler for the <code>GedcomInputParser</code> that handles the tags from the GEDCOM file.
88 *
89 * @param graph the graph to be built
90 * @return the handler that handles the GEDCOM tags
91 */
92 public GedcomInputHandler createGedcomHandler(final Graph2D graph) {
93 return new GedcomInputHandlerImpl(graph);
94 }
95 }
96