use of org.eclipse.wst.xsl.core.model.StylesheetModel in project webtools.sourceediting by eclipse.
the class XSLValidator method validate.
/**
* Validate the given XSL file using the specified report.
*
* @param xslFile
* the XSL file
* @param report
* the report to use for reporting validation errors
* @param forceBuild
* true if build should always be forced
* @return the validation report
* @throws CoreException
* if any exception occurs while validating
*/
public void validate(IFile xslFile, XSLValidationReport report, boolean forceBuild) throws CoreException {
StylesheetModel stylesheet;
if (forceBuild)
stylesheet = XSLCore.getInstance().buildStylesheet(xslFile);
else
stylesheet = XSLCore.getInstance().getStylesheet(xslFile);
project = xslFile.getProject();
long start;
if (Debug.debugXSLModel) {
start = System.currentTimeMillis();
}
if (stylesheet != null) {
try {
calculateProblems(stylesheet, report);
} catch (MaxErrorsExceededException e) {
// do nothing
}
}
if (Debug.debugXSLModel) {
long end = System.currentTimeMillis();
System.out.println(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"VALIDATE " + xslFile + " in " + (end - start) + "ms");
}
}
use of org.eclipse.wst.xsl.core.model.StylesheetModel 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.StylesheetModel in project webtools.sourceediting by eclipse.
the class AbstractModelTest method validate.
/**
* Validate the file
*
* @param file
* @return
* @throws CoreException
* @throws XPathExpressionException
* @throws IOException
*/
protected XSLValidationReport validate(IFile file) throws CoreException, XPathExpressionException, IOException {
XSLValidationReport report = new XSLValidationReport(file.getLocationURI().toString());
XSLValidator.getInstance().validate(file, report, true);
StylesheetModel model = XSLCore.getInstance().getStylesheet(file);
assertFalse("Stylesheet model is null", model == null);
Map<Integer, String> expectedErrors = calculateErrorsAndWarnings(file);
validateErrors(model, report, expectedErrors);
return report;
}
use of org.eclipse.wst.xsl.core.model.StylesheetModel in project webtools.sourceediting by eclipse.
the class AbstractXSLContentAssistRequest method getStylesheetModel.
protected StylesheetModel getStylesheetModel() {
IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
StylesheetModel model = XSLCore.getInstance().getStylesheet(editorFile);
return model;
}
use of org.eclipse.wst.xsl.core.model.StylesheetModel 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;
}
Aggregations