1- /**
2- * Copyright (c) 2006-2010 MoVe - Laboratoire d'Informatique de Paris 6 (LIP6).
3- * All rights reserved. This program and the accompanying materials
4- * are made available under the terms of the Eclipse Public License v1.0
5- * which accompanies this distribution, and is available at
6- * http://www.eclipse.org/legal/epl-v10.html
7- *
8- * Contributors:
9- * Jean-Baptiste VORON (LIP6) - Project Head / Initial contributor
10- * Clément DÉMOULINS (LIP6) - Project Manager
11- * Yann THIERRY-MIEG (LIP6)
12- *
13- * Official contacts:
14- 15- * http://coloane.lip6.fr
16- */
171package fr .lip6 .move .gal .structural .pnml ;
182
193import java .util .ArrayList ;
20- import java .util .Arrays ;
214import java .util .LinkedHashMap ;
225import java .util .List ;
236import java .util .Map ;
@@ -74,9 +57,9 @@ public Arc(String source, String target, int value) {
7457
7558 private String lastseen = null ;
7659 private boolean readtext = false ;
77-
7860 private Long lastint = null ;
7961 private boolean readint = false ;
62+ private StringBuilder textBuffer = new StringBuilder (); // Added for text accumulation
8063
8164 // private NupnHandler nupnHandler;
8265
@@ -89,14 +72,8 @@ public Arc(String source, String target, int value) {
8972 public void characters (char [] chars , int beg , int length ) throws SAXException {
9073 if (inOpaqueToolSpecific ) {
9174 return ;
92- } else if (doIt ) {
93- if (readtext ) {
94- String laststr = new String (Arrays .copyOfRange (chars , beg , beg + length ));
95- lastseen = laststr ;
96- } else if (readint ) {
97- String laststr = new String (Arrays .copyOfRange (chars , beg , beg + length ));
98- lastint = Long .parseLong (laststr );
99- }
75+ } else if (doIt && (readtext || readint )) {
76+ textBuffer .append (chars , beg , length ); // Accumulate text
10077 }
10178 }
10279
@@ -116,7 +93,7 @@ public final void startElement(String uri, String localName, String baliseName,
11693 stack .push (net );
11794 } else if ("name" .equals (baliseName )) {
11895 readtext = true ;
119-
96+ textBuffer . setLength ( 0 ); // Clear buffer
12097 } else if ("page" .equals (baliseName )) {
12198 // ignore pages
12299 } else if ("place" .equals (baliseName )) {
@@ -127,8 +104,10 @@ public final void startElement(String uri, String localName, String baliseName,
127104 stack .push (place );
128105 } else if ("initialMarking" .equals (baliseName )) {
129106 readint = true ;
107+ textBuffer .setLength (0 ); // Clear buffer
130108 } else if ("inscription" .equals (baliseName )) {
131109 readint = true ;
110+ textBuffer .setLength (0 ); // Clear buffer
132111 } else if ("transition" .equals (baliseName )) {
133112 String id = normalizeName (attributes .getValue ("id" ));
134113 int tindex = net .addTransition (id );
@@ -180,6 +159,7 @@ public final void endElement(String uri, String localName, String baliseName) th
180159 assert (stack .isEmpty ());
181160 } else if ("name" .equals (baliseName )) { //$NON-NLS-1$
182161 Object context = stack .peek ();
162+ lastseen = textBuffer .toString ().trim ();
183163 if (context instanceof SparsePetriNet spn ) {
184164 spn .setName (lastseen );
185165 } else if (context instanceof Node node ) {
@@ -196,6 +176,7 @@ public final void endElement(String uri, String localName, String baliseName) th
196176 }
197177 readtext = false ;
198178 lastseen = null ;
179+ textBuffer .setLength (0 );
199180 } else if ("page" .equals (baliseName )) { //$NON-NLS-1$
200181 } else if ("place" .equals (baliseName )) {
201182 stack .pop ();
@@ -207,14 +188,18 @@ public final void endElement(String uri, String localName, String baliseName) th
207188 doIt = false ;
208189 } else if ("initialMarking" .equals (baliseName )) {
209190 Node p = (Node ) stack .peek ();
191+ lastint = Long .parseLong (textBuffer .toString ().trim ());
210192 net .getMarks ().set (p .index , Math .toIntExact (lastint ));
211193 readint = false ;
212194 lastint = null ;
195+ textBuffer .setLength (0 );
213196 } else if ("inscription" .equals (baliseName )) {
214197 Arc p = (Arc ) stack .peek ();
198+ lastint = Long .parseLong (textBuffer .toString ().trim ());
215199 p .value = Math .toIntExact (lastint );
216200 readint = false ;
217201 lastint = null ;
202+ textBuffer .setLength (0 );
218203 } else if ("graphics" .equals (baliseName ) || "offset" .equals (baliseName ) || "position" .equals (baliseName )
219204 || "fill" .equals (baliseName ) || "line" .equals (baliseName ) || "dimension" .equals (baliseName )) {
220205 // skip
@@ -244,4 +229,4 @@ public final void endElement(String uri, String localName, String baliseName) th
244229 public SparsePetriNet getParseResult () {
245230 return net ;
246231 }
247- }
232+ }
0 commit comments