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 207763
Collapse All | Expand All

(-)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/internal/util/EventHandler.java (-8 / +8 lines)
Lines 25-31 Link Here
25
import org.xml.sax.helpers.DefaultHandler;
25
import org.xml.sax.helpers.DefaultHandler;
26
26
27
/**********************************************************************
27
/**********************************************************************
28
 * Copyright (c) 2005, 2006 IBM Corporation and others.
28
 * Copyright (c) 2005, 2007 IBM Corporation and others.
29
 * All rights reserved.   This program and the accompanying materials
29
 * All rights reserved.   This program and the accompanying materials
30
 * are made available under the terms of the Eclipse Public License v1.0
30
 * are made available under the terms of the Eclipse Public License v1.0
31
 * which accompanies this distribution, and is available at
31
 * which accompanies this distribution, and is available at
Lines 356-362 Link Here
356
356
357
        String elementName = getLocalElementName(localName, qualifiedName);
357
        String elementName = getLocalElementName(localName, qualifiedName);
358
358
359
        if ((!elementName.equals("CommonBaseEvents")) && (!elementName.equals("TemplateEvent"))) {
359
        if ((!elementName.equals("CommonBaseEvents")) && (!elementName.equals("TemplateEvent")) || anyElementNestingDepth > 0) {
360
360
361
            //The EMF class and object for this XML element:
361
            //The EMF class and object for this XML element:
362
            EObject emfObj = null;
362
            EObject emfObj = null;
Lines 390-396 Link Here
390
390
391
                //This element is assumed to be an any element if no structural
391
                //This element is assumed to be an any element if no structural
392
                // feature was found:
392
                // feature was found:
393
                if (objStructuralFeature == null) {
393
                if (objStructuralFeature == null || anyElementNestingDepth > 0) {
394
394
395
                    if ((containerName.equals(COMMON_BASE_EVENT_CLASS)) || (containerName.equals(OTHER_SITUATION_CLASS))) {
395
                    if ((containerName.equals(COMMON_BASE_EVENT_CLASS)) || (containerName.equals(OTHER_SITUATION_CLASS))) {
396
396
Lines 473-479 Link Here
473
            }
473
            }
474
474
475
            //Fill instance attributes:
475
            //Fill instance attributes:
476
            if (emfObj != null) {
476
            if (emfObj != null && emfObjClass != null) {
477
477
478
                HashMap featureSubMap = (HashMap) FEATURE_MAP.get(emfObjClass.getName());
478
                HashMap featureSubMap = (HashMap) FEATURE_MAP.get(emfObjClass.getName());
479
                EAttribute feature = null;
479
                EAttribute feature = null;
Lines 542-548 Link Here
542
542
543
        String elementName = getLocalElementName(localName, qualifiedName);
543
        String elementName = getLocalElementName(localName, qualifiedName);
544
544
545
        if ((!elementName.equals("CommonBaseEvents")) && (!elementName.equals("TemplateEvent"))) {
545
        if ((!elementName.equals("CommonBaseEvents")) && (!elementName.equals("TemplateEvent")) || anyElementNestingDepth > 0) {
546
546
547
            if (stack.isEmpty()) {
547
            if (stack.isEmpty()) {
548
                throw new SAXException(LoggingCoreResourceBundle.getString("LOG_EVENT_SAX_PARSER_UNEXPECTED_XML_ELEMENT_EXC_", elementName, String.valueOf(line), String.valueOf(column)));
548
                throw new SAXException(LoggingCoreResourceBundle.getString("LOG_EVENT_SAX_PARSER_UNEXPECTED_XML_ELEMENT_EXC_", elementName, String.valueOf(line), String.valueOf(column)));
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/org/eclipse/hyades/logging/core/XmlUtility.java (+29 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.helpers.DefaultHandler;
32
35
33
/**********************************************************************
36
/**********************************************************************
34
 * Copyright (c) 2005, 2006 IBM Corporation and others.
37
 * Copyright (c) 2005, 2006 IBM Corporation and others.
Lines 1099-1104 Link Here
1099
    }
1102
    }
1100
    
1103
    
1101
    /**
1104
    /**
1105
     * 
1106
     * Verifies if the specified XML fragment is valid wrt the syntax.
1107
     * 
1108
     * @param string The string to be normalized.
1109
     * @return "true" is the specified string is a valid XML fragment, "false" otherwise.
1110
     */
1111
    
1112
    public static boolean isValidXML(String xml)
1113
    {
1114
        StringReader xmlStream = new StringReader(xml); 
1115
        SAXParserFactory factory = SAXParserFactory.newInstance();
1116
        try {
1117
            SAXParser saxParser = factory.newSAXParser();
1118
            InputSource source = new InputSource(xmlStream);
1119
            saxParser.parse(source, new DefaultHandler());
1120
        } catch (Throwable t) {
1121
            return false;
1122
        } finally {
1123
            if (xmlStream != null) {
1124
                xmlStream.close();
1125
            }
1126
        }
1127
        return true;
1128
    }
1129
    
1130
    /**
1102
     * Normalizes the parameter string according to the XML specification for
1131
     * Normalizes the parameter string according to the XML specification for
1103
     * attribute-value normalization 
1132
     * attribute-value normalization 
1104
     * (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>)
1133
     * (<a href="http://www.w3.org/TR/REC-xml">http://www.w3.org/TR/REC-xml</a>)
(-)src.events/org/eclipse/tptp/logging/events/cbe/internal/util/EventHandler.java (-22 / +22 lines)
Lines 316-322 Link Here
316
        }
316
        }
317
        
317
        
318
        //CommonBaseEvents/TemplateEvent: 1
318
        //CommonBaseEvents/TemplateEvent: 1
319
        else if(parentElement == 1){
319
        else if(parentElement == 1 && anyElementNestingDepth == 0){
320
            
320
            
321
            if(elementName.equals("CommonBaseEvent")){
321
            if(elementName.equals("CommonBaseEvent")){
322
322
Lines 453-459 Link Here
453
        //CommonBaseEvent: 2
453
        //CommonBaseEvent: 2
454
        else if(parentElement == 2){
454
        else if(parentElement == 2){
455
455
456
            if(elementName.equals("contextDataElements")){
456
            if(elementName.equals("contextDataElements") && anyElementNestingDepth == 0){
457
457
458
                ContextDataElement contextDataElement = EventFactory.eINSTANCE.createContextDataElement();
458
                ContextDataElement contextDataElement = EventFactory.eINSTANCE.createContextDataElement();
459
                
459
                
Lines 474-480 Link Here
474
                
474
                
475
                parentElement = 3;
475
                parentElement = 3;
476
            }
476
            }
477
            else if(elementName.equals("extendedDataElements")){
477
            else if(elementName.equals("extendedDataElements") && anyElementNestingDepth == 0){
478
                
478
                
479
                ExtendedDataElement extendedDataElement = EventFactory.eINSTANCE.createExtendedDataElement();
479
                ExtendedDataElement extendedDataElement = EventFactory.eINSTANCE.createExtendedDataElement();
480
                
480
                
Lines 495-501 Link Here
495
                
495
                
496
                parentElement = 4;
496
                parentElement = 4;
497
            }
497
            }
498
            else if(elementName.equals("associatedEvents")){
498
            else if(elementName.equals("associatedEvents") && anyElementNestingDepth == 0){
499
                
499
                
500
                AssociatedEvent associatedEvent = EventFactory.eINSTANCE.createAssociatedEvent();
500
                AssociatedEvent associatedEvent = EventFactory.eINSTANCE.createAssociatedEvent();
501
                
501
                
Lines 513-519 Link Here
513
                
513
                
514
                parentElement = 6;
514
                parentElement = 6;
515
            }
515
            }
516
            else if(elementName.equals("reporterComponentId")){
516
            else if(elementName.equals("reporterComponentId") && anyElementNestingDepth == 0){
517
                                
517
                                
518
                ComponentIdentification reporterComponentId = EventFactory.eINSTANCE.createComponentIdentification();
518
                ComponentIdentification reporterComponentId = EventFactory.eINSTANCE.createComponentIdentification();
519
                
519
                
Lines 559-565 Link Here
559
                
559
                
560
                ((CommonBaseEvent)(parsedElements.get(parsedElements.size() - 1))).setReporterComponentId(reporterComponentId);
560
                ((CommonBaseEvent)(parsedElements.get(parsedElements.size() - 1))).setReporterComponentId(reporterComponentId);
561
            }
561
            }
562
            else if(elementName.equals("sourceComponentId")){
562
            else if(elementName.equals("sourceComponentId") && anyElementNestingDepth == 0){
563
                
563
                
564
                ComponentIdentification sourceComponentId = EventFactory.eINSTANCE.createComponentIdentification();
564
                ComponentIdentification sourceComponentId = EventFactory.eINSTANCE.createComponentIdentification();
565
                
565
                
Lines 605-611 Link Here
605
                
605
                
606
                ((CommonBaseEvent)(parsedElements.get(parsedElements.size() - 1))).setSourceComponentId(sourceComponentId);
606
                ((CommonBaseEvent)(parsedElements.get(parsedElements.size() - 1))).setSourceComponentId(sourceComponentId);
607
            }
607
            }
608
            else if(elementName.equals("msgDataElement")){
608
            else if(elementName.equals("msgDataElement") && anyElementNestingDepth == 0){
609
                
609
                
610
                MsgDataElement msgDataElement = EventFactory.eINSTANCE.createMsgDataElement();
610
                MsgDataElement msgDataElement = EventFactory.eINSTANCE.createMsgDataElement();
611
                
611
                
Lines 623-629 Link Here
623
                
623
                
624
                parentElement = 7;
624
                parentElement = 7;
625
            }
625
            }
626
            else if(elementName.equals("situation")){
626
            else if(elementName.equals("situation") && anyElementNestingDepth == 0){
627
                
627
                
628
                Situation situation = EventFactory.eINSTANCE.createSituation();
628
                Situation situation = EventFactory.eINSTANCE.createSituation();
629
                
629
                
Lines 675-681 Link Here
675
675
676
        //extendedDataElements: 4
676
        //extendedDataElements: 4
677
        //children: 5
677
        //children: 5
678
        else if((parentElement == 4) || (parentElement == 5)){
678
        else if((parentElement == 4) || (parentElement == 5) && anyElementNestingDepth == 0){
679
            
679
            
680
            //Validate the remaining child elements when processing the ExtendedDataElements end element:
680
            //Validate the remaining child elements when processing the ExtendedDataElements end element:
681
            if(elementName.equals("children")){
681
            if(elementName.equals("children")){
Lines 702-708 Link Here
702
        }
702
        }
703
703
704
        //associatedEvents: 6
704
        //associatedEvents: 6
705
        else if(parentElement == 6){
705
        else if(parentElement == 6 && anyElementNestingDepth == 0){
706
            
706
            
707
            //Validate the remaining child elements when processing the msgDataElement end element:
707
            //Validate the remaining child elements when processing the msgDataElement end element:
708
            if(elementName.equals("associationEngineInfo")){
708
            if(elementName.equals("associationEngineInfo")){
Lines 730-736 Link Here
730
        }
730
        }
731
731
732
        //msgDataElement: 7
732
        //msgDataElement: 7
733
        else if(parentElement == 7){
733
        else if(parentElement == 7 && anyElementNestingDepth == 0){
734
            
734
            
735
            //Validate the remaining child elements when processing the msgDataElement end element:
735
            //Validate the remaining child elements when processing the msgDataElement end element:
736
            if(elementName.equals("msgCatalogTokens")){
736
            if(elementName.equals("msgCatalogTokens")){
Lines 752-758 Link Here
752
        }
752
        }
753
753
754
        //situation: 8
754
        //situation: 8
755
        else if(parentElement == 8){
755
        else if(parentElement == 8 && anyElementNestingDepth == 0){
756
756
757
            if(elementName.equals("situationType")){
757
            if(elementName.equals("situationType")){
758
758
Lines 1050-1056 Link Here
1050
        
1050
        
1051
        //Validate the child elements of the following elements when processing their end element:
1051
        //Validate the child elements of the following elements when processing their end element:
1052
        //-ContextDataElements
1052
        //-ContextDataElements
1053
        else if(parentElement != 3){
1053
        else if(parentElement != 3 && anyElementNestingDepth == 0){
1054
            throw new SAXException(LoggingCoreResourceBundle.getString("LOG_EVENT_SAX_PARSER_UNEXPECTED_XML_ELEMENT_EXC_", elementName, String.valueOf(line), String.valueOf(column)));                             
1054
            throw new SAXException(LoggingCoreResourceBundle.getString("LOG_EVENT_SAX_PARSER_UNEXPECTED_XML_ELEMENT_EXC_", elementName, String.valueOf(line), String.valueOf(column)));                             
1055
        }
1055
        }
1056
        
1056
        
Lines 1074-1086 Link Here
1074
        //CommonBaseEvent: 2
1074
        //CommonBaseEvent: 2
1075
        if(parentElement == 2){
1075
        if(parentElement == 2){
1076
1076
1077
            if(elementName.equals("CommonBaseEvent")){
1077
            if(elementName.equals("CommonBaseEvent") && anyElementNestingDepth == 0){
1078
                
1078
                
1079
                CommonBaseEvent commonBaseEvent = ((CommonBaseEvent)(parsedElements.remove(parsedElements.size() - 1)));
1079
                CommonBaseEvent commonBaseEvent = ((CommonBaseEvent)(parsedElements.remove(parsedElements.size() - 1)));
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 1112-1118 Link Here
1112
        }
1112
        }
1113
1113
1114
        //contextDataElements: 3
1114
        //contextDataElements: 3
1115
        else if(parentElement == 3){
1115
        else if(parentElement == 3 && anyElementNestingDepth == 0){
1116
1116
1117
            if(elementName.equals("contextValue")){
1117
            if(elementName.equals("contextValue")){
1118
                ((ContextDataElement)(parsedElements.get(parsedElements.size() - 1))).setContextValue(charactersBuffer.toString());
1118
                ((ContextDataElement)(parsedElements.get(parsedElements.size() - 1))).setContextValue(charactersBuffer.toString());
Lines 1135-1141 Link Here
1135
        
1135
        
1136
        //extendedDataElements: 4
1136
        //extendedDataElements: 4
1137
        //children: 5
1137
        //children: 5
1138
        else if((parentElement == 4) || (parentElement == 5)){
1138
        else if((parentElement == 4) || (parentElement == 5) && anyElementNestingDepth == 0){
1139
            
1139
            
1140
            if(elementName.equals("values")){
1140
            if(elementName.equals("values")){
1141
                ((ExtendedDataElement)(parsedElements.get(parsedElements.size() - 1))).getValues().add(charactersBuffer.toString());
1141
                ((ExtendedDataElement)(parsedElements.get(parsedElements.size() - 1))).getValues().add(charactersBuffer.toString());
Lines 1165-1171 Link Here
1165
        }
1165
        }
1166
1166
1167
        //associatedEvents: 6
1167
        //associatedEvents: 6
1168
        else if(parentElement == 6){
1168
        else if(parentElement == 6 && anyElementNestingDepth == 0){
1169
            
1169
            
1170
            if(elementName.equals("associationEngine")){
1170
            if(elementName.equals("associationEngine")){
1171
                ((AssociatedEvent)(parsedElements.get(parsedElements.size() - 1))).setAssociationEngine(charactersBuffer.toString());
1171
                ((AssociatedEvent)(parsedElements.get(parsedElements.size() - 1))).setAssociationEngine(charactersBuffer.toString());
Lines 1184-1190 Link Here
1184
        }
1184
        }
1185
1185
1186
        //msgDataElement: 7
1186
        //msgDataElement: 7
1187
        else if(parentElement == 7){
1187
        else if(parentElement == 7 && anyElementNestingDepth == 0){
1188
            
1188
            
1189
            if(elementName.equals("msgId")){
1189
            if(elementName.equals("msgId")){
1190
                ((MsgDataElement)(parsedElements.get(parsedElements.size() - 1))).setMsgId(charactersBuffer.toString());
1190
                ((MsgDataElement)(parsedElements.get(parsedElements.size() - 1))).setMsgId(charactersBuffer.toString());
Lines 1215-1221 Link Here
1215
        }
1215
        }
1216
1216
1217
        //situation: 8
1217
        //situation: 8
1218
        else if(parentElement == 8){
1218
        else if(parentElement == 8 && anyElementNestingDepth == 0){
1219
1219
1220
            if(elementName.equals("situation")){
1220
            if(elementName.equals("situation")){
1221
1221
Lines 1233-1239 Link Here
1233
        //OtherSituation: 9
1233
        //OtherSituation: 9
1234
        else if(parentElement == 9){
1234
        else if(parentElement == 9){
1235
1235
1236
            if(elementName.equals("situationType")){
1236
            if(elementName.equals("situationType") && anyElementNestingDepth == 0){
1237
                
1237
                
1238
                OtherSituation otherSituation = ((OtherSituation)(parsedElements.remove(parsedElements.size() - 1)));
1238
                OtherSituation otherSituation = ((OtherSituation)(parsedElements.remove(parsedElements.size() - 1)));
1239
1239
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);
(-)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

Return to bug 207763