001/* 002 * Copyright 2006 - 2013 003 * Stefan Balev <stefan.balev@graphstream-project.org> 004 * Julien Baudry <julien.baudry@graphstream-project.org> 005 * Antoine Dutot <antoine.dutot@graphstream-project.org> 006 * Yoann Pigné <yoann.pigne@graphstream-project.org> 007 * Guilhelm Savin <guilhelm.savin@graphstream-project.org> 008 * 009 * This file is part of GraphStream <http://graphstream-project.org>. 010 * 011 * GraphStream is a library whose purpose is to handle static or dynamic 012 * graph, create them from scratch, file or any source and display them. 013 * 014 * This program is free software distributed under the terms of two licenses, the 015 * CeCILL-C license that fits European law, and the GNU Lesser General Public 016 * License. You can use, modify and/ or redistribute the software under the terms 017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following 018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by 019 * the Free Software Foundation, either version 3 of the License, or (at your 020 * option) any later version. 021 * 022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 024 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 025 * 026 * You should have received a copy of the GNU Lesser General Public License 027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 028 * 029 * The fact that you are presently reading this means that you have had 030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. 031 */ 032package org.graphstream.stream.file; 033 034import java.io.IOException; 035import java.io.Reader; 036 037import org.graphstream.stream.file.gml.GMLParser; 038 039import org.graphstream.util.parser.ParseException; 040import org.graphstream.util.parser.Parser; 041import org.graphstream.util.parser.ParserFactory; 042 043/** 044 * A GML parser. 045 * 046 * This parser should understand the whole GML syntax. It transforms any 047 * unknown tag into an attribute. Depending on the location of the unknown 048 * tag, the attribute is added to the graph, to nodes or to the edges. 049 * 050 * The "graphics" attributes are, as far as possible, transformed into 051 * "ui.style" attributes that are merged with the style sheet. The understood 052 * graphics tags are "x", "y", "z", "w", "h", "d" for position and size, 053 * "fill" for the background color (becomes "fill-color"), "outline" (becomes 054 * "stroke-color"), "type" (becomes "shape", the known shapes being 055 * the ones of the GraphStream CSS, plus the "ellipse" tag wich maps 056 * to "circle" and the "rectangle" tag that maps to "box"), "outline_width" (becomes 057 * "stroke-width", in pixels). 058 * 059 * If edges have no "id" tag, the id is the concatenation of the source 060 * and target node identifiers separated by a "_" character and a random 061 * number. 062 * 063 * You can declare nodes either with the full declaration: 064 * <pre> 065 * node [ Id "foo" ] 066 * </pre> 067 * Which is useful when adding attributes to it. Or you can use a lighter 068 * declaration with: 069 * <pre> 070 * node "foo" 071 * </pre> 072 * 073 * You can also remove nodes and edges by using: 074 * <pre> 075 * -node "foo" 076 * del-node "foo" 077 * -node [ Id "foo" ] 078 * del-node [ Id "foo" ] 079 * </pre> 080 * And the same for edges with "-edge" or "del-edge". 081 * 082 * All the dynamic events of GraphStream are supported as an extension. 083 * 084 * You can add or remove attributes to or from a node or edge using a 085 * minus sign in front of the attribute name and following the attribute 086 * name by []. 087 * 088 * You can remove a node or edge using a minus sign in front of the 089 * node and edge tags: 090 * <pre> 091 * -node [ id "foo" ] 092 * </pre> 093 * Or 094 * <pre> 095 * -node "foo" 096 * </pre> 097 * 098 * You can change the attributes of a node or edge using a plus sign 099 * in front of the node and edge tags: 100 * <pre> 101 * +node [ id "foo" someAttribute "added" -removedAttribute [] ] 102 * </pre> 103 * 104 * Be careful, that files exported with the dynamic extensions will not 105 * be compatible with most GML readers of other programs. 106 * 107 * The standard extension for GML files is ".gml". If your file contains 108 * dynamic additions, you can use the ".dgml" (Dynamic GML) extensions. 109 * The parser will handle both dynamic and non dynamic files with the 110 * extension ".gml". 111 */ 112public class FileSourceGML extends FileSourceParser { 113 114 /* 115 * (non-Javadoc) 116 * @see org.graphstream.stream.file.FileSourceParser#nextStep() 117 */ 118 public boolean nextStep() throws IOException { 119 try { 120 return ((GMLParser) parser).step(); 121 } catch(ParseException e) { 122 throw new IOException(e); 123 } 124 } 125 126 /* 127 * (non-Javadoc) 128 * @see org.graphstream.stream.file.FileSourceParser#getNewParserFactory() 129 */ 130 public ParserFactory getNewParserFactory() { 131 return new ParserFactory() { 132 public Parser newParser(Reader reader) { 133 return new GMLParser(FileSourceGML.this, reader); 134 } 135 }; 136 } 137}