Changeset 347


Ignore:
Timestamp:
01/05/12 15:42:48 (12 years ago)
Author:
sherbold
Message:
  • strings in the output written by the JFCMonitor are now sanitized for usage with XML, i.e., <,>,&,'," are replaced by their respective XML entities
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JFCMonitor/src/de/ugoe/cs/eventbench/jfcmonitor/JFCListener.java

    r303 r347  
    1010import java.lang.reflect.InvocationTargetException; 
    1111import java.lang.reflect.Method; 
     12 
     13import de.ugoe.cs.util.StringTools; 
    1214 
    1315/** 
     
    3941                this.outputWriter = outputWriter; 
    4042                try { 
    41                         outputWriter.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" + ENDLINE); 
     43                        outputWriter.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" 
     44                                        + ENDLINE); 
    4245                        outputWriter.write("<sessions>" + ENDLINE); 
    4346                } catch (IOException e) { 
     
    111114                builder.append(" <source>" + ENDLINE); 
    112115                builder.append("  <param name=\"toString\" value=\"" 
    113                                 + event.getSource().toString() + "\" />" + ENDLINE); 
     116                                + StringTools 
     117                                                .xmlEntityReplacement(event.getSource().toString()) 
     118                                + "\" />" + ENDLINE); 
    114119                if (event.getSource() instanceof Component) { 
    115120                        Component source = (Component) event.getSource(); 
     
    135140        private void addComponentInfo(StringBuilder builder, Component component) { 
    136141                builder.append("  <param name=\"getName\" value=\"" 
    137                                 + component.getName() + "\" />" + ENDLINE); 
     142                                + StringTools.xmlEntityReplacement(component.getName()) 
     143                                + "\" />" + ENDLINE); 
    138144                for (Method method : component.getClass().getMethods()) { 
    139145                        try { 
     
    141147                                        String text = (String) method.invoke(component, 
    142148                                                        new Object[] {}); 
    143                                         if( text!=null ) { 
    144                                                 builder.append("  <param name=\"getText\" value=\"" + text + "\" />" + ENDLINE); 
     149                                        if (text != null) { 
     150                                                builder.append("  <param name=\"getText\" value=\"" 
     151                                                                + StringTools.xmlEntityReplacement(text) 
     152                                                                + "\" />" + ENDLINE); 
    145153                                        } 
    146154                                } 
     
    148156                                        String title = (String) method.invoke(component, 
    149157                                                        new Object[] {}); 
    150                                         if( title!=null ) { 
    151                                                 builder.append("  <param name=\"getTitle\" value=\"" + title + "\" />" + ENDLINE); 
     158                                        if (title != null) { 
     159                                                builder.append("  <param name=\"getTitle\" value=\"" 
     160                                                                + StringTools.xmlEntityReplacement(title) 
     161                                                                + "\" />" + ENDLINE); 
    152162                                        } 
    153163                                } 
     
    155165                        } catch (IllegalAccessException e) { 
    156166                        } catch (InvocationTargetException e) { 
    157                                 System.err.println("Found method with name " + method.getName() + " but could not access it."); 
     167                                System.err.println("Found method with name " + method.getName() 
     168                                                + " but could not access it."); 
    158169                        } 
    159170                } 
Note: See TracChangeset for help on using the changeset viewer.