Search in sources :

Example 1 with ModelHandlerForJSP

use of org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP in project webtools.sourceediting by eclipse.

the class ScannerUnitTests method setUpJSP.

protected IStructuredDocumentRegionList setUpJSP(String text) {
    setupModel(new ModelHandlerForJSP());
    parser.addBlockMarker(new BlockMarker("script", null, DOMRegionContext.BLOCK_TEXT, false));
    parser.addBlockMarker(new BlockMarker("style", null, DOMRegionContext.BLOCK_TEXT, false));
    parser.addBlockMarker(new BlockMarker("disallowJSP", null, DOMRegionContext.BLOCK_TEXT, true, false));
    /*
		 * IStructuredDocumentRegionList nodes = setUpJSP("content <script>
		 * <%= expression %> </script> <a> </a> <foo:disallowJSP> <%= %>
		 * </foo:disallowJSP> >"); parser.addBlockMarker(new
		 * BlockMarker("jsp:declaration", null,
		 * XMLJSPRegionContexts.JSP_CONTENT, true)); parser.addBlockMarker(new
		 * BlockMarker("jsp:expression", null,
		 * XMLJSPRegionContexts.JSP_CONTENT, true)); parser.addBlockMarker(new
		 * BlockMarker("jsp:scriptlet", null,
		 * XMLJSPRegionContexts.JSP_CONTENT, true));
		 */
    input = text;
    fModel.set(input);
    return fModel.getRegionList();
}
Also used : BlockMarker(org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) ModelHandlerForJSP(org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP)

Example 2 with ModelHandlerForJSP

use of org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP in project webtools.sourceediting by eclipse.

the class CMDocumentFactoryTLD method loadTagFile.

private void loadTagFile(CMElementDeclarationImpl ed, IFile tagFile, boolean allowIncludes, InputStream inputStream) {
    try {
        if (allowIncludes) {
            ed.setPath(tagFile.getFullPath().toString());
            ed.setTagSource(TLDElementDeclaration.SOURCE_TAG_FILE);
            ed.setLocationString(tagFile.getFullPath().toString());
        }
        IStructuredDocument document = null;
        if (inputStream != null) {
            document = (IStructuredDocument) new ModelHandlerForJSP().getDocumentLoader().createNewStructuredDocument(tagFile.getName(), inputStream);
        } else if (tagFile.isAccessible()) {
            document = (IStructuredDocument) new ModelHandlerForJSP().getDocumentLoader().createNewStructuredDocument(tagFile);
        }
        if (document == null)
            return;
        IStructuredDocumentRegion documentRegion = document.getFirstStructuredDocumentRegion();
        while (documentRegion != null) {
            if (documentRegion.getType().equals(DOMJSPRegionContexts.JSP_DIRECTIVE_NAME)) {
                if (documentRegion.getNumberOfRegions() > 2) {
                    ITextRegionList regions = documentRegion.getRegions();
                    String directiveName = documentRegion.getText(regions.get(1));
                    if (JSP12TLDNames.TAG.equals(directiveName)) {
                        // 8.5.1
                        String attrName = null;
                        for (int i = 2; i < documentRegion.getNumberOfRegions(); i++) {
                            ITextRegion region = regions.get(i);
                            String text = documentRegion.getText(region);
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
                                attrName = text;
                            } else // process value
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                                text = StringUtils.strip(text);
                                if (JSP12TLDNames.DISPLAY_NAME.equals(attrName)) {
                                    ed.setDisplayName(text);
                                } else if (JSP12TLDNames.BODY_CONTENT.equals(attrName)) {
                                    ed.setBodycontent(text);
                                } else if (JSP20TLDNames.DYNAMIC_ATTRIBUTES.equals(attrName)) {
                                    ed.setDynamicAttributes(text);
                                } else if (JSP12TLDNames.SMALL_ICON.equals(attrName)) {
                                    ed.setSmallIcon(text);
                                } else if (JSP12TLDNames.LARGE_ICON.equals(attrName)) {
                                    ed.setLargeIcon(text);
                                } else if (JSP12TLDNames.DESCRIPTION.equals(attrName)) {
                                    ed.setDescription(text);
                                } else if (JSP20TLDNames.EXAMPLE.equals(attrName)) {
                                    ed.setExample(text);
                                } else if (JSP20TLDNames.SCRIPTING_LANGUAGE.equals(attrName)) {
                                    ed.setScriptingLanguage(text);
                                } else if (JSP20TLDNames.IMPORT.equals(attrName)) {
                                    ed.setImport(text);
                                } else if (JSP20TLDNames.PAGE_ENCODING.equals(attrName)) {
                                    ed.setPageEncoding(text);
                                } else if (JSP20TLDNames.IS_EL_IGNORED.equals(attrName)) {
                                    ed.setIsELIgnored(text);
                                }
                            }
                        }
                    } else if (JSP12TLDNames.ATTRIBUTE.equals(directiveName)) {
                        CMAttributeDeclarationImpl attribute = new CMAttributeDeclarationImpl(ed.getOwnerDocument(), JSP11Namespace.ATTR_VALUE_TRUE);
                        // 8.5.2
                        String attrName = null;
                        for (int i = 2; i < documentRegion.getNumberOfRegions(); i++) {
                            ITextRegion region = regions.get(i);
                            String text = documentRegion.getText(region);
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
                                attrName = text;
                            } else // process value
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE && attrName != null) {
                                text = StringUtils.strip(text);
                                if (JSP12TLDNames.NAME.equals(attrName)) {
                                    attribute.setNodeName(text);
                                } else if (JSP20TLDNames.FRAGMENT.equals(attrName)) {
                                    attribute.setFragment(Boolean.valueOf(text).booleanValue());
                                } else if (JSP12TLDNames.RTEXPRVALUE.equals(attrName)) {
                                    attribute.setRtexprvalue(text);
                                } else if (JSP20TLDNames.TYPE.equals(attrName)) {
                                    attribute.setType(text);
                                } else if (JSP12TLDNames.DESCRIPTION.equals(attrName)) {
                                    attribute.setDescription(text);
                                } else if (JSP12TLDNames.REQUIRED.equals(attrName)) {
                                    attribute.setRequiredString(text);
                                }
                            }
                        }
                        if (attribute.getNodeName() != null) {
                            ed.fAttributes.setNamedItem(attribute.getNodeName(), attribute);
                        }
                    } else if (JSP12TLDNames.VARIABLE.equals(directiveName)) {
                        TLDVariableImpl variable = new TLDVariableImpl();
                        String attrName = null;
                        for (int i = 2; i < documentRegion.getNumberOfRegions(); i++) {
                            ITextRegion region = regions.get(i);
                            String text = documentRegion.getText(region);
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
                                attrName = text;
                            } else // process value
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE && attrName != null) {
                                text = StringUtils.strip(text);
                                if (JSP12TLDNames.VARIABLE_NAME_GIVEN.equals(attrName)) {
                                    variable.setNameGiven(text);
                                } else if (JSP12TLDNames.VARIABLE_NAME_FROM_ATTRIBUTE.equals(attrName)) {
                                    variable.setNameFromAttribute(text);
                                } else if (JSP20TLDNames.VARIABLE_ALIAS.equals(attrName)) {
                                    variable.setAlias(text);
                                } else if (JSP12TLDNames.VARIABLE_CLASS.equals(attrName)) {
                                    variable.setVariableClass(text);
                                } else if (JSP12TLDNames.VARIABLE_DECLARE.equals(attrName)) {
                                    variable.setDeclareString(text);
                                } else if (JSP11Namespace.ATTR_NAME_SCOPE.equals(attrName)) {
                                    variable.setScope(text);
                                } else if (JSP12TLDNames.DESCRIPTION.equals(attrName)) {
                                    variable.setDescription(text);
                                }
                            }
                        }
                        if (variable.getAlias() != null || variable.getNameFromAttribute() != null || variable.getNameGiven() != null) {
                            ed.getVariables().add(variable);
                        }
                    } else if ("include".equals(directiveName) && allowIncludes) {
                        String attrName = null;
                        for (int i = 2; i < documentRegion.getNumberOfRegions(); i++) {
                            ITextRegion region = regions.get(i);
                            String text = documentRegion.getText(region);
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
                                attrName = text;
                            } else // process value
                            if (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE && attrName != null) {
                                text = StringUtils.strip(text);
                                if (JSP11Namespace.ATTR_NAME_FILE.equals(attrName)) {
                                    IPath filePath = FacetModuleCoreSupport.resolve(new Path(((CMDocumentImpl) ed.getOwnerDocument()).getBaseLocation()), text);
                                    IFile includedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
                                    if (includedFile.isAccessible()) {
                                        loadTagFile(ed, includedFile, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            documentRegion = documentRegion.getNext();
        }
    } catch (IOException e) {
    // Logger.logException("problem parsing " + tagFile, e); // can be caused by a still-in-development file
    } catch (CoreException e) {
    // Logger.logException("problem parsing " + tagFile, e); // frequently out of sync
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IOException(java.io.IOException) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CoreException(org.eclipse.core.runtime.CoreException) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ModelHandlerForJSP(org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP)

Aggregations

ModelHandlerForJSP (org.eclipse.jst.jsp.core.internal.modelhandler.ModelHandlerForJSP)2 IOException (java.io.IOException)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1