Search in sources :

Example 6 with TLDElementDeclaration

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration in project webtools.sourceediting by eclipse.

the class TaglibHelper method addVariables.

/**
 * Adds 1.2 style TaglibVariables to the results list.
 *
 * @param results
 *            list where the <code>TaglibVariable</code> s are added
 * @param node
 */
private void addVariables(List results, CMNode node, ITextRegionCollection customTag) {
    List list = ((TLDElementDeclaration) node).getVariables();
    Iterator it = list.iterator();
    while (it.hasNext()) {
        TLDVariable var = (TLDVariable) it.next();
        if (!var.getDeclare())
            continue;
        String varName = var.getNameGiven();
        if (varName == null) {
            // 2.0
            varName = var.getAlias();
        }
        if (varName == null) {
            String attrName = var.getNameFromAttribute();
            /*
				 * Iterate through the document region to find the
				 * corresponding attribute name, and then use its value
				 */
            ITextRegionList regions = customTag.getRegions();
            boolean attrNameFound = false;
            for (int i = 2; i < regions.size(); i++) {
                ITextRegion region = regions.get(i);
                if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(region.getType())) {
                    attrNameFound = attrName.equals(customTag.getText(region));
                }
                if (attrNameFound && DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(region.getType())) {
                    varName = StringUtils.strip(customTag.getText(region));
                }
            }
        }
        if (varName != null) {
            // the default
            String varClass = "java.lang.String";
            // class...//$NON-NLS-1$
            if (var.getVariableClass() != null) {
                varClass = getVariableClass(var.getVariableClass());
            }
            results.add(new TaglibVariable(varClass, varName, var.getScope(), var.getDescription()));
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) TLDVariable(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDVariable)

Example 7 with TLDElementDeclaration

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration in project webtools.sourceediting by eclipse.

the class TestModelIncludes method testContentModelSingleLineIncludedFileWithNoSpacesButWithTaglibInInclude.

/**
 * Tests the custom tag content model when single line fragments are used
 * without trailing white space
 *
 * @throws Exception
 */
public void testContentModelSingleLineIncludedFileWithNoSpacesButWithTaglibInInclude() throws Exception {
    String projectName = "prj119576_a";
    BundleResourceUtil.createSimpleProject(projectName, null, null);
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
    assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/prj119576_a/WebContent/body2.jsp"));
    IDOMModel model = null;
    try {
        model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
        assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
        Element element = (Element) model.getIndexedRegion(75);
        CMElementDeclaration ed = ModelQueryUtil.getModelQuery(model).getCMElementDeclaration(element);
        assertNotNull("no (TLD) element declaration found for " + element.getNodeName(), ed);
        assertTrue("not a wrapping content model element declaration: " + ed.getNodeName(), ed instanceof CMNodeWrapper);
        assertTrue("not a taglib content model element declaration: " + ed.getNodeName(), ((CMNodeWrapper) ed).getOriginNode() instanceof TLDElementDeclaration);
        String tagClassName = ((TLDElementDeclaration) ((CMNodeWrapper) ed).getOriginNode()).getTagclass();
        assertNotNull("no tag class name found", tagClassName);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element)

Example 8 with TLDElementDeclaration

use of org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration in project webtools.sourceediting by eclipse.

the class JSPTranslator method addBlockMarkers.

/*
	 * adds block markers to JSPTranslator's block marker list for all
	 * elements in doc @param doc
	 */
protected void addBlockMarkers(String prefix, CMDocument doc) {
    if (doc.getElements().getLength() > 0) {
        Iterator elements = doc.getElements().iterator();
        CMNode node = null;
        while (elements.hasNext()) {
            node = (CMNode) elements.next();
            if (node instanceof TLDElementDeclaration && ((TLDElementDeclaration) node).getBodycontent().equals(JSP12TLDNames.CONTENT_TAGDEPENDENT))
                getBlockMarkers().add(new BlockMarker(prefix + node.getNodeName(), null, DOMRegionContext.BLOCK_TEXT, true));
            else
                getBlockMarkers().add(new BlockMarker(prefix + node.getNodeName(), null, DOMJSPRegionContexts.JSP_CONTENT, true));
        }
    }
}
Also used : TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) Iterator(java.util.Iterator) BlockMarker(org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Aggregations

TLDElementDeclaration (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration)8 CMNodeWrapper (org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper)6 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)5 Iterator (java.util.Iterator)4 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)3 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)3 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)3 Element (org.w3c.dom.Element)3 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)2 TaglibTracker (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 IProject (org.eclipse.core.resources.IProject)1 TLDAttributeDeclaration (org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration)1