@@ -73,6 +73,10 @@ public class Topology extends BasePage {
7373
7474 public static final String CONNECTOR_SERVER_LOCATION_PREFIX = "connid://" ;
7575
76+ public static String sanitizeMarkupId (final String input ) {
77+ return input .replaceAll ("[^a-zA-Z0-9._-]" , "_" );
78+ }
79+
7680 @ SpringBean
7781 protected ServiceOps serviceOps ;
7882
@@ -224,7 +228,7 @@ public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
224228 // Add Syncope (root topologynode)
225229 // -----------------------------------------
226230 String rootName = StringUtils .capitalize (Constants .SYNCOPE );
227- final TopologyNode syncopeTopologyNode = new TopologyNode (rootName , rootName , TopologyNode .Kind .SYNCOPE );
231+ TopologyNode syncopeTopologyNode = new TopologyNode (rootName , rootName , TopologyNode .Kind .SYNCOPE );
228232 syncopeTopologyNode .setX (origX );
229233 syncopeTopologyNode .setY (origY );
230234
@@ -234,9 +238,9 @@ public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
234238
235239 body .add (topologyNodePanel (Constants .SYNCOPE , syncopeTopologyNode , false ));
236240
237- Map <Serializable , Map <Serializable , TopologyNode >> connections = new HashMap <>();
238- Map <Serializable , TopologyNode > syncopeConnections = new HashMap <>();
239- connections .put (syncopeTopologyNode .getKey (), syncopeConnections );
241+ Map <String , Map <String , TopologyNode >> connections = new HashMap <>();
242+ Map <String , TopologyNode > syncopeConnections = new HashMap <>();
243+ connections .put (sanitizeMarkupId ( syncopeTopologyNode .getKey () ), syncopeConnections );
240244
241245 // required to retrieve parent positions
242246 Map <String , TopologyNode > servers = new HashMap <>();
@@ -273,8 +277,8 @@ protected void populateItem(final ListItem<URI> item) {
273277
274278 item .add (topologyNodePanel ("cs" , topologynode , false ));
275279
276- syncopeConnections .put (url , topologynode );
277- connections .put (url , new HashMap <>());
280+ syncopeConnections .put (sanitizeMarkupId ( url ) , topologynode );
281+ connections .put (sanitizeMarkupId ( url ) , new HashMap <>());
278282 }
279283 };
280284
@@ -312,8 +316,8 @@ protected void populateItem(final ListItem<URI> item) {
312316
313317 item .add (topologyNodePanel ("fp" , topologynode , false ));
314318
315- syncopeConnections .put (url , topologynode );
316- connections .put (url , new HashMap <>());
319+ syncopeConnections .put (sanitizeMarkupId ( url ) , topologynode );
320+ connections .put (sanitizeMarkupId ( url ) , new HashMap <>());
317321 }
318322 };
319323
@@ -369,7 +373,7 @@ protected void populateItem(final ListItem<ConnInstanceTO> item) {
369373 item .add (topologyNodePanel ("conn" , topologynode , conn .isErrored ()));
370374
371375 // Update connections
372- Map <Serializable , TopologyNode > remoteConnections ;
376+ Map <String , TopologyNode > remoteConnections ;
373377 if (connections .containsKey (conn .getLocation ())) {
374378 remoteConnections = connections .get (conn .getLocation ());
375379 } else {
@@ -404,7 +408,7 @@ protected void populateItem(final ListItem<ConnInstanceTO> item) {
404408 TopologyNode topologynode = new TopologyNode (
405409 resourceTO .getKey (), resourceTO .getKey (), TopologyNode .Kind .RESOURCE );
406410
407- Map <Serializable , TopologyNode > remoteConnections ;
411+ Map <String , TopologyNode > remoteConnections ;
408412 if (connections .containsKey (resourceTO .getConnector ())) {
409413 remoteConnections = connections .get (resourceTO .getConnector ());
410414 } else {
@@ -480,10 +484,11 @@ protected void populateItem(final ListItem<TopologyNode> item) {
480484
481485 @ Override
482486 public void renderHead (final Component component , final IHeaderResponse response ) {
483- final StringBuilder jsPlumbConf = new StringBuilder ();
484- jsPlumbConf .append (String .format (Locale .US , "activate(%.2f);" , 0.68f ));
487+ StringBuilder jsPlumbConf = new StringBuilder (String .format (Locale .US , "activate(%.2f);" , 0.68f ));
488+
489+ connections .forEach ((key , value ) -> value .forEach ((label , node ) -> jsPlumbConf .append (
490+ "connect('%s','%s','%s');" .formatted (sanitizeMarkupId (key ), label , node .getKind ()))));
485491
486- createConnections (connections ).forEach (jsPlumbConf ::append );
487492 jsPlumbConf .append ("restoreTopologyLayout();" );
488493
489494 response .render (OnDomReadyHeaderItem .forScript (jsPlumbConf .toString ()));
@@ -538,18 +543,9 @@ protected void populateItem(final ListItem<TopologyNode> item) {
538543 newlyCreatedContainer .add (newlyCreated );
539544 }
540545
541- private static List <String > createConnections (final Map <Serializable , Map <Serializable , TopologyNode >> targets ) {
542- List <String > list = new ArrayList <>();
543-
544- targets .forEach ((key , value ) -> value .forEach ((label , node ) -> list .add (
545- "connect('%s','%s','%s');" .formatted (key , label , node .getKind ()))));
546-
547- return list ;
548- }
549-
550546 private TopologyNodePanel topologyNodePanel (final String id , final TopologyNode node , final boolean errored ) {
551547 TopologyNodePanel panel = new TopologyNodePanel (id , node , errored );
552- panel .setMarkupId (String . valueOf (node .getKey ()));
548+ panel .setMarkupId (sanitizeMarkupId (node .getKey ()));
553549 panel .setOutputMarkupId (true );
554550
555551 List <Behavior > behaviors = new ArrayList <>();
@@ -561,7 +557,7 @@ private TopologyNodePanel topologyNodePanel(final String id, final TopologyNode
561557 @ Override
562558 public void renderHead (final Component component , final IHeaderResponse response ) {
563559 response .render (OnDomReadyHeaderItem .forScript ("setPosition('%s', %d, %d)" .
564- formatted (node .getKey (), node .getX (), node .getY ())));
560+ formatted (sanitizeMarkupId ( node .getKey () ), node .getX (), node .getY ())));
565561 }
566562 });
567563
0 commit comments