Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 207806 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/hyades/logging/core/XmlUtility.java (+30 lines)
Lines 15-20 Link Here
15
import java.nio.charset.Charset;
15
import java.nio.charset.Charset;
16
16
17
import javax.xml.parsers.DocumentBuilderFactory;
17
import javax.xml.parsers.DocumentBuilderFactory;
18
import javax.xml.parsers.SAXParser;
19
import javax.xml.parsers.SAXParserFactory;
18
import javax.xml.transform.OutputKeys;
20
import javax.xml.transform.OutputKeys;
19
import javax.xml.transform.Transformer;
21
import javax.xml.transform.Transformer;
20
import javax.xml.transform.TransformerConfigurationException;
22
import javax.xml.transform.TransformerConfigurationException;
Lines 29-34 Link Here
29
import org.w3c.dom.DocumentType;
31
import org.w3c.dom.DocumentType;
30
import org.w3c.dom.Node;
32
import org.w3c.dom.Node;
31
import org.xml.sax.InputSource;
33
import org.xml.sax.InputSource;
34
import org.xml.sax.SAXException;
35
import org.xml.sax.helpers.DefaultHandler;
32
36
33
/**********************************************************************
37
/**********************************************************************
34
 * Copyright (c) 2005, 2006 IBM Corporation and others.
38
 * Copyright (c) 2005, 2006 IBM Corporation and others.
Lines 1099-1104 Link Here
1099
    }
1103
    }
1100
    
1104
    
1101
    /**
1105
    /**
1106
     * 
1107
     * Verifies if the specified XML fragment is valid wrt the syntax.
1108
     * 
1109
     * @param string The string to be normalized.
1110
     * @return "true" is the specified string is a valid XML fragment, "false" otherwise.
1111
     */
1112
    
1113
    public static boolean isValidXML(String xml)
1114
    {
1115
        StringReader xmlStream = new StringReader(xml); 
1116
        SAXParserFactory factory = SAXParserFactory.newInstance();
1117
        try {
1118
            SAXParser saxParser = factory.newSAXParser();
1119
            InputSource source = new InputSource(xmlStream);
1120
            saxParser.parse(source, new DefaultHandler());
1121
        } catch (Throwable t) {
1122
            return false;
1123
        } finally {
1124
            if (xmlStream != null) {
1125
                xmlStream.close();
1126
            }
1127
        }
1128
        return true;
1129
    }
1130
    
1131
    /**
1102
     * Normalizes the parameter string according to the XML specification for
1132
     * Normalizes the parameter string according to the XML specification for
1103
     * attribute-value normalization 
1133
     * attribute-value normalization 
1104
     * (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>)
1134
     * (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>)
(-)src.cbe101/org/eclipse/hyades/logging/events/cbe/internal/util/EventHandler.java (-3 / +3 lines)
Lines 597-603 Link Here
597
                        //Do not persist white space (e.g. formatting characters)
597
                        //Do not persist white space (e.g. formatting characters)
598
                        // between elements:
598
                        // between elements:
599
                        if (anyElementCharacters.trim().length() > 0) {
599
                        if (anyElementCharacters.trim().length() > 0) {
600
                            ((CommonBaseEvent) (object)).addAny(XmlUtility.normalize(anyElementCharacters));
600
                            ((CommonBaseEvent) (object)).addAny(anyElementCharacters.trim());
601
                        }
601
                        }
602
                        
602
                        
603
                        if(eventListener != null){
603
                        if(eventListener != null){
Lines 619-628 Link Here
619
                            String currentAnyElement = otherSituation.getAny();
619
                            String currentAnyElement = otherSituation.getAny();
620
620
621
                            if ((currentAnyElement != null) && (currentAnyElement.trim().length() > 0)) {
621
                            if ((currentAnyElement != null) && (currentAnyElement.trim().length() > 0)) {
622
                                otherSituation.setAny(currentAnyElement.concat(XmlUtility.normalize(anyElementCharacters)));
622
                                otherSituation.setAny(currentAnyElement.concat(anyElementCharacters));
623
                            } 
623
                            } 
624
                            else {
624
                            else {
625
                                otherSituation.setAny(XmlUtility.normalize(anyElementCharacters));
625
                                otherSituation.setAny(anyElementCharacters.trim());
626
                            }
626
                            }
627
				        }					
627
				        }					
628
					}
628
					}
(-)src.events/org/eclipse/tptp/logging/events/cbe/util/EventFormatter.java (-8 / +22 lines)
Lines 2089-2098 Link Here
2089
							buffer.append("\t\t\t");
2089
							buffer.append("\t\t\t");
2090
						}
2090
						}
2091
2091
2092
						// Do NOT normalize since this string is assumed to be a
2092
						// Normalizing since this string might not always be
2093
						// valid XML fragment:
2093
		                // a valid XML fragment: Bugzilla 207806
2094
						buffer.append(anyData);
2094
		                if(XmlUtility.isValidXML(anyData))
2095
					}
2095
		                {
2096
		                    buffer.append(anyData);
2097
		                }
2098
		                else
2099
		                {
2100
		                    buffer.append(XmlUtility.normalize(anyData));
2101
		                }					
2102
		            }
2096
2103
2097
					if (format) {
2104
					if (format) {
2098
						buffer.append(Constants.LINE_SEPARATOR);
2105
						buffer.append(Constants.LINE_SEPARATOR);
Lines 2127-2136 Link Here
2127
					buffer.append("\t");
2134
					buffer.append("\t");
2128
				}
2135
				}
2129
2136
2130
				// Do NOT normalize since this string is assumed to be a
2137
        		// Normalizing since this string might not always be
2131
				// valid XML fragment:
2138
                // a valid XML fragment: Bugzilla 207806
2132
				buffer.append(anyElement);
2139
                if(XmlUtility.isValidXML(anyElement))
2133
			}
2140
                {
2141
                    buffer.append(anyElement);
2142
                }
2143
                else
2144
                {
2145
                    buffer.append(XmlUtility.normalize(anyElement));
2146
                }			
2147
		    }
2134
		}
2148
		}
2135
2149
2136
		if (format) {
2150
		if (format) {
(-)src.cbe101/org/eclipse/hyades/logging/events/cbe/util/EventFormatter.java (-6 / +20 lines)
Lines 2091-2099 Link Here
2091
							buffer.append("\t\t\t");
2091
							buffer.append("\t\t\t");
2092
						}
2092
						}
2093
2093
2094
						// Do NOT normalize since this string is assumed to be a
2094
						// Normalizing since this string might not always be
2095
						// valid XML fragment:
2095
		                // a valid XML fragment: Bugzilla 207806
2096
						buffer.append(anyData);
2096
		                if(XmlUtility.isValidXML(anyData))
2097
		                {
2098
		                    buffer.append(anyData);
2099
		                }
2100
		                else
2101
		                {
2102
		                    buffer.append(XmlUtility.normalize(anyData));
2103
		                }
2097
					}
2104
					}
2098
2105
2099
					if (format) {
2106
					if (format) {
Lines 2129-2137 Link Here
2129
					buffer.append("\t");
2136
					buffer.append("\t");
2130
				}
2137
				}
2131
2138
2132
				// Do NOT normalize since this string is assumed to be a
2139
				// Normalizing since this string might not always be
2133
				// valid XML fragment:
2140
				// a valid XML fragment: Bugzilla 207806
2134
				buffer.append(anyElement);
2141
				if(XmlUtility.isValidXML(anyElement))
2142
				{
2143
				    buffer.append(anyElement);
2144
				}
2145
				else
2146
				{
2147
				    buffer.append(XmlUtility.normalize(anyElement));
2148
				}				
2135
			}
2149
			}
2136
		}
2150
		}
2137
2151
(-)src.events/org/eclipse/tptp/logging/events/cbe/internal/util/EventHandler.java (-2 / +2 lines)
Lines 1080-1086 Link Here
1080
1080
1081
                //Do not persist white space (e.g. formatting characters) between elements:
1081
                //Do not persist white space (e.g. formatting characters) between elements:
1082
                if (charactersBuffer.toString().trim().length() > 0) {
1082
                if (charactersBuffer.toString().trim().length() > 0) {
1083
                    commonBaseEvent.addAny(XmlUtility.normalize(charactersBuffer.toString()));
1083
                    commonBaseEvent.addAny(charactersBuffer.toString().trim());
1084
                }
1084
                }
1085
1085
1086
                if(eventListener != null){
1086
                if(eventListener != null){
Lines 1247-1253 Link Here
1247
    
1247
    
1248
                //Do not persist white space (e.g. formatting characters) between elements:
1248
                //Do not persist white space (e.g. formatting characters) between elements:
1249
                if (charactersBuffer.toString().trim().length() > 0) {
1249
                if (charactersBuffer.toString().trim().length() > 0) {
1250
                    otherSituation.setAny(XmlUtility.normalize(charactersBuffer.toString()));
1250
                    otherSituation.setAny(charactersBuffer.toString().trim());
1251
                }                    
1251
                }                    
1252
1252
1253
                ((Situation)(parsedElements.get(parsedElements.size() - 1))).setSituationType(otherSituation);
1253
                ((Situation)(parsedElements.get(parsedElements.size() - 1))).setSituationType(otherSituation);

Return to bug 207806