1 11 package org.eclipse.help.internal.dynamic; 12 13 import java.util.Map ; 14 15 import org.eclipse.help.ITocContribution; 16 import org.eclipse.help.internal.HelpPlugin; 17 import org.eclipse.help.internal.UAElement; 18 19 23 public class ValidationHandler extends ProcessorHandler { 24 25 private Map requiredAttributes; 26 private Map deprecatedElements; 27 28 32 public ValidationHandler(Map requiredAttributes) { 33 this(requiredAttributes, null); 34 } 35 36 41 public ValidationHandler(Map requiredAttributes, Map deprecatedElements) { 42 this.requiredAttributes = requiredAttributes; 43 this.deprecatedElements = deprecatedElements; 44 } 45 46 public short handle(UAElement element, String id) { 47 if (deprecatedElements != null) { 48 String suggestion = (String )deprecatedElements.get(element.element.getNodeName()); 49 if (suggestion != null) { 50 String msg = "The \"" + element.element.getNodeName() + "\" element is deprecated in \"" + id + "\"; use \"" + suggestion + "\" instead."; HelpPlugin.logWarning(msg); 52 } 53 } 54 String [] attributes = (String [])requiredAttributes.get(element.element.getNodeName()); 55 if (attributes != null) { 56 for (int i=0;i<attributes.length;++i) { 57 if (element.getAttribute(attributes[i]) == null) { 58 String msg = "Required attribute \"" + attributes[i] + "\" missing from \"" + element.element.getNodeName() + "\" element"; if (id != null) { 60 msg += " in \"" + id + '"'; } 62 UAElement parent = element.getParentElement(); 63 if (parent != null && !(parent instanceof ITocContribution)) { 64 msg += " (skipping element)"; parent.removeChild(element); 66 HelpPlugin.logError(msg); 67 return HANDLED_SKIP; 68 } 69 else { 70 throw new IllegalArgumentException (msg); 71 } 72 } 73 } 74 } 75 return UNHANDLED; 76 } 77 } 78 | Popular Tags |