use of org.eclipse.wst.xsl.core.model.Template 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.Template in project webtools.sourceediting by eclipse.
the class CallTemplateContentAssistRequest method getCompletionProposals.
/**
* (non-Javadoc)
* @see org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest#getCompletionProposals()
*/
@Override
public ArrayList<ICompletionProposal> getCompletionProposals() {
proposals.clear();
IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
StylesheetModel model = XSLCore.getInstance().getStylesheet(editorFile);
List<Template> templates = model.getTemplates();
for (Template template : templates) {
XSLAttribute attribute = template.getAttribute(ATTR_NAME);
if (attribute != null) {
String proposalInfo = getAdditionalInfo(template);
CustomCompletionProposal proposal = new CustomCompletionProposal(attribute.getValue(), getStartOffset() + 1, 0, attribute.getValue().length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_TEMPLATE), attribute.getValue(), null, proposalInfo, 0);
addProposal(proposal);
}
}
return getAllCompletionProposals();
}
use of org.eclipse.wst.xsl.core.model.Template in project webtools.sourceediting by eclipse.
the class TemplateModeAttributeContentAssist method addModeProposals.
/**
* @param model
*/
protected void addModeProposals(StylesheetModel model) {
List<Template> templates = model.getTemplates();
ArrayList<String> modes = new ArrayList<String>();
for (Template template : templates) {
XSLAttribute attribute = template.getAttribute(MODE_ATTRIBUTE);
IDOMNode xmlNode = (IDOMNode) node;
if (attribute != null && xmlNode.getStartOffset() != template.getOffset()) {
CustomCompletionProposal proposal = new CustomCompletionProposal(attribute.getValue(), getStartOffset() + 1, 0, attribute.getValue().length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_MODE), attribute.getValue(), null, null, 0);
if (modes.indexOf(attribute.getValue()) == -1) {
proposals.add(proposal);
modes.add(attribute.getValue());
}
}
}
modes.clear();
}
use of org.eclipse.wst.xsl.core.model.Template in project webtools.sourceediting by eclipse.
the class TestStylesheetModel method testFindAvailableTemplateModes.
@Test
public void testFindAvailableTemplateModes() {
ArrayList<String> modes = new ArrayList();
model = XSLCore.getInstance().getStylesheet(getFile("modeTest.xsl"));
List<Template> templates = model.getTemplates();
assertTrue("No templates returned.", templates.size() > 0);
for (Template template : templates) {
XSLAttribute attribute = template.getAttribute("mode");
if (attribute != null) {
if (modes.indexOf(attribute.getValue()) == -1) {
modes.add(attribute.getValue());
}
}
}
assertEquals("Wrong number of mode templates returned.", 3, modes.size());
}
use of org.eclipse.wst.xsl.core.model.Template 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;
}
Aggregations