blob: 851ab71dc3d6143a09c72c9a5b84d44762851ac8 [file] [log] [blame]
package org.eclipse.m2e.editor.pom;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits;
public final class ElementValueProvider {
private String[] path;
private String defaultValue;
public ElementValueProvider(String... path) {
this.path = path;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public String getDefaultValue() {
return defaultValue;
}
public Element find(Document document) {
Element toRet = null;
Element parent = document.getDocumentElement();
for(String pathEl : path) {
toRet = PomEdits.findChild(parent, pathEl);
if(toRet == null) {
return null;
}
parent = toRet;
}
return toRet;
}
public Element get(Document document) {
return PomEdits.getChild(document.getDocumentElement(), path);
}
public String getValue(Document document) {
return PomEdits.getTextValue(find(document));
}
}