Bug 8085 template pref page: exception while importing incorrect file
i tried to import this: <?xml version="1.0" encoding="UTF-8"?> <templatfes><template context="javadoc" description="author name" enabled="true" name="@author">@author ${user}</template></templates> which has an error i got an error dialog and this: 4 org.eclipse.jdt.ui 1 Internal Error org.eclipse.jdt.internal.ui.JavaUIException[2]: org.xml.sax.SAXParseException: The element type "templatfes" must be terminated by the matching end- tag "</templatfes>". at org.apache.xerces.framework.XMLParser.reportError (XMLParser.java:1196) at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError (XMLDocumentScanner.java:579) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch (XMLDocumentScanner.java(Compiled Code)) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch (XMLDocumentScanner.java(Compiled Code)) at org.apache.xerces.framework.XMLDocumentScanner.parseSome (XMLDocumentScanner.java(Compiled Code)) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse (DocumentBuilderImpl.java:195) at org.eclipse.jdt.internal.ui.text.template.TemplateSet.addFromStream (TemplateSet.java:103) at org.eclipse.jdt.internal.ui.text.template.TemplateSet.addFromFile (TemplateSet.java:83) at org.eclipse.jdt.internal.ui.preferences.TemplatePreferencePage.import_ (TemplatePreferencePage.java:389) at org.eclipse.jdt.internal.ui.preferences.TemplatePreferencePage.access$4 (TemplatePreferencePage.java:379) at org.eclipse.jdt.internal.ui.preferences.TemplatePreferencePage$8.handleEvent (TemplatePreferencePage.java:212) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.jface.window.Window.runEventLoop(Window.java(Compiled Code)) at org.eclipse.jface.window.Window.open(Window.java:523) at org.eclipse.ui.internal.OpenPreferencesAction.run (OpenPreferencesAction.java:47) at org.eclipse.jface.action.Action.runWithEvent(Action.java:452) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java(Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:827) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:878) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:321) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:502) at org.eclipse.core.launcher.Main.main(Main.java:362)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/TemplateSet.java
DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
			DocumentBuilder parser= factory.newDocumentBuilder();		
			Document document= parser.parse(new InputSource(stream));
			NodeList elements= document.getElementsByTagName(TEMPLATE_TAG);
			
			int count= elements.getLength();
			for (int i= 0; i != count; i++) {
				Node node= elements.item(i);					
				NamedNodeMap attributes= node.getAttributes();
				if (attributes == null)
					continue;
				String name= attributes.getNamedItem(NAME_ATTRIBUTE).getNodeValue();
				String description= attributes.getNamedItem(DESCRIPTION_ATTRIBUTE).getNodeValue();
				String context= attributes.getNamedItem(CONTEXT_ATTRIBUTE).getNodeValue();
				Node enabledNode= attributes.getNamedItem(ENABLED_ATTRIBUTE);
				boolean enabled= (enabledNode == null) || (enabledNode.getNodeValue().equals("true")); 
				StringBuffer buffer= new StringBuffer();
				NodeList children= node.getChildNodes();
				for (int j= 0; j != children.getLength(); j++) {
					String value= children.item(j).getNodeValue();
					if (value != null)
						buffer.append(value);
				}
				String pattern= buffer.toString().trim();
				Template template= new Template(name, description, context, pattern);	
				template.setEnabled(enabled);
				add(template);
			}
	
			sort();