use of org.eclipse.wst.xsl.core.model.Parameter in project webtools.sourceediting by eclipse.
the class XSLValidator method checkCallTemplates.
private void checkCallTemplates(StylesheetModel stylesheetComposed, XSLValidationReport report) throws MaxErrorsExceededException {
for (CallTemplate calledTemplate : stylesheetComposed.getStylesheet().getCalledTemplates()) {
if (calledTemplate.getName() != null) {
// get the list of templates that might be being called by this
// template call
List<Template> templateList = stylesheetComposed.getTemplatesByName(calledTemplate.getName());
if (templateList.size() == 0) {
Object[] messageArgs = { calledTemplate.getName() };
createMarker(report, calledTemplate.getAttribute("name"), getPreference(ValidationPreferences.CALL_TEMPLATES), // $NON-NLS-1$
MessageFormat.format(Messages.XSLValidator_18, messageArgs));
} else {
Template namedTemplate = templateList.get(0);
for (Parameter calledTemplateParam : calledTemplate.getParameters()) {
boolean found = false;
for (Parameter namedTemplateParam : namedTemplate.getParameters()) {
if (calledTemplateParam.getName().equals(namedTemplateParam.getName())) {
found = true;
if (!namedTemplateParam.isValue() && !calledTemplateParam.isValue()) {
Object[] messageArgs = { calledTemplateParam.getName() };
createMarker(report, calledTemplateParam, getPreference(ValidationPreferences.EMPTY_PARAM), MessageFormat.format(Messages.XSLValidator_20, messageArgs));
}
break;
}
}
if (!found) {
Object[] messageArgs = { calledTemplateParam.getName() };
createMarker(report, calledTemplateParam.getAttribute("name"), getPreference(ValidationPreferences.MISSING_PARAM), // $NON-NLS-1$
MessageFormat.format(Messages.XSLValidator_22, messageArgs));
}
}
if (getPreference(ValidationPreferences.MISSING_PARAM) > IMarker.SEVERITY_INFO) {
for (Parameter namedTemplateParam : namedTemplate.getParameters()) {
if (!namedTemplateParam.isValue()) {
boolean found = false;
for (Parameter calledTemplateParam : calledTemplate.getParameters()) {
if (calledTemplateParam.getName().equals(namedTemplateParam.getName())) {
found = true;
break;
}
}
if (!found) {
Object[] messageArgs = { namedTemplateParam.getName() };
createMarker(report, calledTemplate, getPreference(ValidationPreferences.MISSING_PARAM), MessageFormat.format(Messages.XSLValidator_3, messageArgs));
}
}
}
}
}
}
}
}
use of org.eclipse.wst.xsl.core.model.Parameter in project webtools.sourceediting by eclipse.
the class XSLValidator method checkParameters.
private void checkParameters(XSLValidationReport report, Template template) throws MaxErrorsExceededException {
List<Parameter> parameters = new ArrayList<Parameter>(template.getParameters());
// reverse the parameters order for checking - for duplicate parameters
// the first one is valid
Collections.reverse(parameters);
Set<Parameter> duplicateParameters = new HashSet<Parameter>();
// check parameters
for (Parameter param : parameters) {
if (param.getName() == null) {
// name is required
createMarker(report, param, getPreference(ValidationPreferences.NAME_ATTRIBUTE_MISSING), Messages.XSLValidator_14);
} else if (param.getName().trim().length() == 0) {
// name value is
// required
createMarker(report, param, getPreference(ValidationPreferences.NAME_ATTRIBUTE_EMPTY), Messages.XSLValidator_15);
} else if (duplicateParameters.contains(param)) {
// the parameter
continue;
} else {
// check a parameter with the same name does not exist
for (Parameter checkParam : parameters) {
if (param != checkParam) {
if (param.getName().equals(checkParam.getName())) {
duplicateParameters.add(checkParam);
createMarker(report, param, getPreference(ValidationPreferences.DUPLICATE_PARAMETER), Messages.XSLValidator_16);
}
}
}
}
}
}
use of org.eclipse.wst.xsl.core.model.Parameter in project webtools.sourceediting by eclipse.
the class XSLHyperlinkDetector method createWithParamHyperLink.
private IHyperlink createWithParamHyperLink(IFile currentFile, Element elem, Attr attr, IRegion hyperlinkRegion) {
IHyperlink hyperlink = null;
StylesheetModel sf = XSLCore.getInstance().getStylesheet(currentFile);
if (sf != null) {
Node parentNode = elem.getParentNode();
Attr parentAttribute = (Attr) parentNode.getAttributes().getNamedItem(ATTR_NAME);
String templateName = parentAttribute.getValue();
List<Template> templates = sf.getTemplatesByName(templateName);
if (templates != null && templates.size() == 1) {
Template template = templates.get(0);
List<Parameter> parameters = template.getParameters();
for (Parameter param : parameters) {
String paramName = attr.getValue();
XSLAttribute parameterNameAttr = param.getAttribute(ATTR_NAME);
if (parameterNameAttr != null && parameterNameAttr.getValue().equals(paramName)) {
hyperlink = new SourceFileHyperlink(hyperlinkRegion, template.getStylesheet().getFile(), param);
}
}
}
}
return hyperlink;
}
use of org.eclipse.wst.xsl.core.model.Parameter in project webtools.sourceediting by eclipse.
the class XSLElementFactory method createParamater.
public XSLElement createParamater() {
Parameter param = new Parameter(stylesheetParserData.getStylesheet());
// determine whether param has a value
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
param.setValue(true);
break;
}
}
if (stylesheetParserData.getParentEl() != null) {
if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.FUNCTION) {
Function function = (Function) stylesheetParserData.getParentEl();
function.addParameter(param);
} else if (stylesheetParserData.getParentEl().getModelType() == XSLModelObject.Type.TEMPLATE && stylesheetParserData.getElementStack().size() == 2 && stylesheetParserData.getCurrentTemplate() != null) {
Template template = (Template) stylesheetParserData.getParentEl();
template.addParameter(param);
}
}
return param;
}
use of org.eclipse.wst.xsl.core.model.Parameter in project webtools.sourceediting by eclipse.
the class XSLElementFactory method createWithParamParm.
public XSLElement createWithParamParm() {
Parameter param = new Parameter(stylesheetParserData.getStylesheet());
// determine whether param has a value
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() != Node.ATTRIBUTE_NODE) {
param.setValue(true);
break;
}
}
// get the previous call-template
CallTemplate currentCallTemplate = stylesheetParserData.getCallTemplates().peek();
currentCallTemplate.addParameter(param);
return param;
}
Aggregations