use of org.eclipse.wst.xsl.core.model.Template 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.Template in project webtools.sourceediting by eclipse.
the class XSLElementFactory method createTemplate.
public XSLElement createTemplate() {
stylesheetParserData.setCurrentTemplate(new Template(stylesheetParserData.getStylesheet()));
stylesheetParserData.getStylesheet().addTemplate(stylesheetParserData.getCurrentTemplate());
return stylesheetParserData.getCurrentTemplate();
}
use of org.eclipse.wst.xsl.core.model.Template in project webtools.sourceediting by eclipse.
the class TestStylesheet method testgetLocalTemplatesTemplates.
@Test
public void testgetLocalTemplatesTemplates() {
Stylesheet model = builder.getStylesheet(getFile("style1.xsl"), false);
assertNotNull("Model failed to load, returned NULL", model);
List<Template> templatesList = model.getTemplates();
assertEquals("Wrong number of templates returned.", 2, templatesList.size());
}
use of org.eclipse.wst.xsl.core.model.Template in project webtools.sourceediting by eclipse.
the class OverrideIndicatorManager method updateAnnotations.
/**
* Updates the override and implements annotations based on the given AST.
*
* @param ast
* the compilation unit AST
* @param progressMonitor
* the progress monitor
* @since 1.0
*/
public void updateAnnotations() {
StylesheetModel stylesheetComposed = XSLCore.getInstance().getStylesheet(file);
final Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>(50);
List<Template> nestedTemplates = stylesheetComposed.findAllNestedTemplates();
for (Template template : stylesheetComposed.getStylesheet().getTemplates()) {
// check for overridden stylesheets
for (Template nestedTemplate : nestedTemplates) {
IFile nestedFile = nestedTemplate.getStylesheet().getFile();
if (nestedFile != null) {
if (template.matchesByMatchOrName(nestedTemplate)) {
// the template overrides another templates as its name matches, or its match and mode matches
if (template.getName() != null) {
String text = NLS.bind(Messages.XSLEditorOverrideTemplate, template.getName(), nestedFile.getName());
annotationMap.put(// $NON-NLS-1$
new OverrideIndicator(text, "binding.getKey()"), new Position(template.getOffset(), template.getLength()));
} else {
String[] overrideParms = { template.getMatch(), template.getMode(), nestedFile.getName() };
String text = NLS.bind(Messages.XSLEditorOverrideTemplateMode, overrideParms);
annotationMap.put(// $NON-NLS-1$
new OverrideIndicator(text, "binding.getKey()"), new Position(template.getOffset(), template.getLength()));
}
}
}
}
}
synchronized (fAnnotationModelLockObject) {
if (fAnnotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) fAnnotationModel).replaceAnnotations(fOverrideAnnotations, annotationMap);
} else {
removeAnnotations();
Iterator iter = annotationMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iter.next();
fAnnotationModel.addAnnotation((Annotation) mapEntry.getKey(), (Position) mapEntry.getValue());
}
}
fOverrideAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
}
}
use of org.eclipse.wst.xsl.core.model.Template in project webtools.sourceediting by eclipse.
the class XSLWorkbenchAdapter method getImageDescriptor.
public ImageDescriptor getImageDescriptor(Object object) {
XSLModelObject obj = (XSLModelObject) object;
String path = null;
switch(obj.getModelType()) {
case STYLESHEET:
path = XSLPluginImages.IMG_ELM_STYLESHET;
break;
case IMPORT:
case INCLUDE:
path = XSLPluginImages.IMG_ELM_IMPORT_INCLUDE;
break;
case TEMPLATE:
{
Template template = (Template) obj;
if (template.getName() != null) {
path = XSLPluginImages.IMG_ELM_TEMPLATE_NAME;
} else {
path = XSLPluginImages.IMG_ELM_TEMPLATE;
}
break;
}
case VARIABLE:
path = XSLPluginImages.IMG_ELM_VARIABLE;
break;
case FUNCTION:
path = XSLPluginImages.IMG_ELM_FUNCTION;
break;
}
return path == null ? null : AbstractUIPlugin.imageDescriptorFromPlugin(XSLUIPlugin.PLUGIN_ID, path);
}
Aggregations