public void setStructuredDocument(IStructuredDocument newDocument) { resetNodes(); getStructuredDocumentRegionHandlers().remove(this); if (newDocument != null && newDocument.getParser() instanceof StructuredDocumentRegionParser) { ((StructuredDocumentRegionParser) newDocument.getParser()).addStructuredDocumentRegionHandler(this); } } }
private boolean isCustomTag(ITextRegionCollection containerRegion) { String tagName = getRegionName(containerRegion); if (tagName == null) return false; JSPSourceParser parser = (JSPSourceParser) fStructuredDocument.getParser(); int colonIndex = tagName.indexOf(":"); if (colonIndex > 0) { String prefix = tagName.substring(0, colonIndex); if (prefix.equals("jsp")) { //$NON-NLS-1$ return false; } TagMarker[] prefixes = (TagMarker[]) parser.getNestablePrefixes().toArray(new TagMarker[0]); for (int i = 0; i < prefixes.length; i++) { if (prefix.equals(prefixes[i].getTagName())) { return true; } } } return false; }
public void setStructuredDocument(IStructuredDocument newDocument) { Assert.isTrue(newDocument != null, "null document"); //$NON-NLS-1$ Assert.isTrue(newDocument.getParser() != null, "null document parser"); //$NON-NLS-1$ Assert.isTrue(newDocument.getParser() instanceof JSPSourceParser, "can only listen to document with a JSPSourceParser"); //$NON-NLS-1$ getSourceParser().removeStructuredDocumentRegionHandler(this); setSourceParser((JSPSourceParser) newDocument.getParser()); getSourceParser().addStructuredDocumentRegionHandler(this); } }
synchronized public IEncodedDocument createNewStructuredDocument(IFile iFile) throws IOException, CoreException { IStructuredDocument structuredDocument = null; try { structuredDocument = createCodedDocument(iFile); EmbeddedTypeHandler embeddedType = getEmbeddedType(iFile); if (embeddedType != null) embeddedType.initializeParser((JSPCapableParser) structuredDocument.getParser()); fFullPreparedReader.reset(); setDocumentContentsFromReader(structuredDocument, fFullPreparedReader); } finally { if (fFullPreparedReader != null) { fFullPreparedReader.close(); } } return structuredDocument; }
private CSSDocumentImpl createDocument() { CSSDocumentImpl doc = null; int parserMode = CSSSourceParser.MODE_STYLESHEET; if (ownerNode == null) { // this case is external CSS file doc = (CSSStyleSheetImpl) DOMCSSImpl.createCSSStyleSheet(null, null); // parameters // are // for // STYLE-tag parserMode = CSSSourceParser.MODE_STYLESHEET; } else if (ownerNode instanceof org.w3c.dom.Element && ((Element) ownerNode).getTagName().toUpperCase().equals("STYLE")) {//$NON-NLS-1$ // this case is STYLE-tag Element style = (Element) ownerNode; doc = (CSSStyleSheetImpl) DOMCSSImpl.createCSSStyleSheet(style.getAttribute("TITLE"), //$NON-NLS-1$ style.getAttribute("MEDIA"));//$NON-NLS-1$ parserMode = CSSSourceParser.MODE_STYLESHEET; } else if (ownerNode instanceof org.w3c.dom.Element || ownerNode instanceof org.w3c.dom.Attr) { // Inline attributes doc = (CSSStyleDeclarationImpl) DOMCSSImpl.createCSSStyleDeclaration(); parserMode = CSSSourceParser.MODE_DECLARATION; } RegionParser regionParser = getStructuredDocument().getParser(); if (regionParser instanceof CSSSourceParser) { ((CSSSourceParser) regionParser).setParserMode(parserMode); } return doc; }
/** * @param sdRegion * @param offset * @return */ private boolean isAction(IStructuredDocumentRegion sdRegion, int offset) { if (!sdRegion.getType().equals(DOMRegionContext.XML_TAG_NAME)) return false; /* * shouldn't get a tag name region type unless a tag name region * exists at [1] */ ITextRegion tagNameRegion = sdRegion.getRegions().get(1); String tagName = sdRegion.getText(tagNameRegion); RegionParser parser = fStructuredDocument.getParser(); if (parser instanceof JSPSourceParser) { if (tagName.equals(fLastCheckedPrefix)) return true; List fCustomActionPrefixes = ((JSPSourceParser) parser).getNestablePrefixes(); for (int i = 0; i < fCustomActionPrefixes.size(); i++) if (tagName.startsWith(((TagMarker) fCustomActionPrefixes.get(i)).getTagName())) { fLastCheckedPrefix = tagName; return true; } } return false; }
public void bufferCreated(IFileBuffer buffer) { if (buffer instanceof ITextFileBuffer) { IDocument document = ((ITextFileBuffer) buffer).getDocument(); // ignore non-JSP documents synchronized (_instance.fJSPdocuments) { if (!_instance.fJSPdocuments.contains(document)) return; } Assert.isTrue(document instanceof IStructuredDocument, getClass().getName() + " SetupParticipant was called for non-IStructuredDocument"); //$NON-NLS-1$ DocumentInfo info = new DocumentInfo(); info.document = (IStructuredDocument) document; info.textFileBuffer = (ITextFileBuffer) buffer; info.tldDocumentManager = new TLDCMDocumentManager(); info.tldDocumentManager.setSourceParser((JSPSourceParser) info.document.getParser()); synchronized (_instance.fDocumentMap) { _instance.fDocumentMap.put(document, info); } TaglibIndex.addTaglibIndexListener(info); if (document instanceof BasicStructuredDocument) { ((BasicStructuredDocument) document).reparse(this); } } }
/** */ protected boolean isCDATAContainer() { // use BlockMaker instead of CMElementDeclaration // because <style> and <script> in XHTML is not CDATA content type IDOMModel model = getModel(); if (model == null) return false; // error IStructuredDocument structuredDocument = model.getStructuredDocument(); if (structuredDocument == null) return false; // eror RegionParser parser = structuredDocument.getParser(); if (parser == null || !(parser instanceof XMLSourceParser)) return false; return (((XMLSourceParser) parser).getBlockMarker(this.tagName) != null); /* * CMElementDeclaration decl = getDeclaration(); if (decl == null) * return false; if (decl instanceof CMNodeWrapper) { decl = * (CMElementDeclaration)((CMNodeWrapper)decl).getOriginNode(); if * (decl == null) return false; } if (decl instanceof * TLDElementDeclaration) { String content = * ((TLDElementDeclaration)decl).getBodycontent(); if (content == * null) return false; return * content.equals(JSP11TLDNames.CONTENT_TAGDEPENDENT); } if * (!isGlobalTag()) return false; return (decl.getContentType() == * CMElementDeclaration.CDATA); */ }
protected void setupPicker(StyledTextColorPicker picker) { IModelManager mmanager = StructuredModelManager.getModelManager(); picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML).getParser()); Dictionary descriptions = new Hashtable(); initDescriptions(descriptions); Dictionary contextStyleMap = new Hashtable(); initContextStyleMap(contextStyleMap); ArrayList styleList = new ArrayList(); initStyleList(styleList); picker.setContextStyleMap(contextStyleMap); picker.setDescriptions(descriptions); picker.setStyleList(styleList); }
public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException { if (filename == null && inputStream == null) { throw new IllegalArgumentException("can not have both null filename and inputstream"); //$NON-NLS-1$ } IEncodedDocument structuredDocument = createNewStructuredDocument(); CodedReaderCreator codedReaderCreator = new CodedReaderCreator(); try { codedReaderCreator.set(filename, inputStream); fFullPreparedReader = codedReaderCreator.getCodedReader(); fEncodingMemento = codedReaderCreator.getEncodingMemento(); structuredDocument.setEncodingMemento(fEncodingMemento); // the fact that file is null means this method/code path is no // good for JSP fragments EmbeddedTypeHandler embeddedType = getEmbeddedType((IFile) null); fFullPreparedReader.reset(); if (embeddedType != null) embeddedType.initializeParser((JSPCapableParser) ((IStructuredDocument) structuredDocument).getParser()); setDocumentContentsFromReader(structuredDocument, fFullPreparedReader); } catch (CoreException e) { // impossible in this context throw new Error(e); } finally { if (fFullPreparedReader != null) { fFullPreparedReader.close(); } } return structuredDocument; }
/** * This method must return a new instance of IStructuredDocument, that has * been initialized with appropriate parser. For many loaders, the * (default) parser used is known for any input. For others, the correct * parser (and its initialization) is normall dependent on the content of * the file. This no-argument method should assume "empty input" and would * therefore return the default parser for the default contentType. * * If the parser is to handle tag libraries, it must have a TaglibSupport * object with a valid URIResolver and this IStructuredDocument attached * to it before the contents are set on the IStructuredDocument. */ public IStructuredDocument newStructuredDocument() { IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser()); ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser()); // structuredDocument.setDocumentPartitioner(new // JSPJavaDocumentPartioner()); // even though this is an "empty model" ... we want it to have at // least the // default embeddeded content type handler EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType(null); embeddedType.initializeParser((JSPCapableParser) structuredDocument.getParser()); return structuredDocument; }
/** * This method must return a new instance of IStructuredDocument, that has * been initialized with appropriate parser. For many loaders, the * (default) parser used is known for any input. For others, the correct * parser (and its initialization) is normall dependent on the content of * the file. This no-argument method should assume "empty input" and would * therefore return the default parser for the default contentType. If the * parser is to handle tag libraries, it must have a TaglibSupport object * with a valid URIResolver and this IStructuredDocument attached to it * before the contents are set on the IStructuredDocument. */ protected IEncodedDocument newEncodedDocument() { IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser()); ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser()); // structuredDocument.setDocumentPartitioner(new // JSPJavaDocumentPartioner()); // even though this is an "empty model" ... we want it to have at // least // the // default embeddeded content type handler EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType(); embeddedType.initializeParser((JSPCapableParser) structuredDocument.getParser()); return structuredDocument; }
oldEmbeddedContentType.uninitializeParser((JSPCapableParser) structuredDocument.getParser()); if (newEmbeddedContentType != null) { newEmbeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry()); newEmbeddedContentType.initializeParser((JSPCapableParser) structuredDocument.getParser());
/** */ public ICSSModel getModel() { ICSSModel model = getExistingModel(); if (model == null && isModelNecessary()) { model = createModel(); if (model == null) return null; IStructuredDocument structuredDocument = model.getStructuredDocument(); if (structuredDocument == null) return null; RegionParser parser = structuredDocument.getParser(); if (parser instanceof CSSSourceParser) { ((CSSSourceParser)parser).setParserMode(CSSSourceParser.MODE_DECLARATION); } else { return null; } structuredDocument.addDocumentChangedListener(this); setModel(model); // need to set before valueChanged() valueChanged(); } if (model != null && !isModelNecessary()) { model = null; valueChanged(); } return model; }
private void setCssValueTextCore(String value) throws DOMException { // use temporary document synchronized (CSSStyleDeclarationImpl.class) { if (sharedStructuredDocument == null) { IDocumentLoader loader = new CSSDocumentLoader(); sharedStructuredDocument = (IStructuredDocument) loader.createNewStructuredDocument(); ((CSSSourceParser) sharedStructuredDocument.getParser()).setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE); } sharedStructuredDocument.set(value); IStructuredDocumentRegion node = sharedStructuredDocument.getFirstStructuredDocumentRegion(); if (node == null) { return; } if (node.getNext() != null) { throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "");//$NON-NLS-1$ } CSSDeclarationItemParser itemParser = new CSSDeclarationItemParser(getOwnerDocument()); itemParser.setStructuredDocumentTemporary(true); // make a copy of nodelist because setupValues will destroy list ITextRegionList nodeList = new TextRegionListImpl(node.getRegions()); itemParser.setupValues(this, node, nodeList); } }