Search in sources :

Example 11 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class CSSStyleDeclItemImpl method setCssValueTextCore.

private void setCssValueTextCore(String value) throws DOMException {
    CSSSourceParser parser = new CSSSourceParser();
    parser.setParserMode(CSSSourceParser.MODE_DECLARATION_VALUE);
    parser.reset(value);
    IStructuredDocumentRegion node = parser.getDocumentRegions();
    if (node == null) {
        return;
    }
    if (node.getNext() != null) {
        // $NON-NLS-1$
        throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "");
    }
    CSSDeclarationItemParser itemParser = new CSSDeclarationItemParser(getOwnerDocument());
    itemParser.setStructuredDocumentTemporary(true);
    // make a copy of nodelist because setupValues will destroy list
    ITextRegionList nodeList = new TextRegionListImpl(node.getRegions());
    List nodeValuesList = new ArrayList();
    ;
    for (int i = 0; i < nodeList.size(); i++) {
        ITextRegion textRegion = nodeList.get(i);
        nodeValuesList.add(value.substring(textRegion.getStart(), textRegion.getTextEnd()));
    }
    itemParser.setupValues(this, node, nodeList, nodeValuesList);
}
Also used : DOMException(org.w3c.dom.DOMException) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ArrayList(java.util.ArrayList) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) List(java.util.List) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser)

Example 12 with CSSSourceParser

use of org.eclipse.wst.css.core.internal.parser.CSSSourceParser in project webtools.sourceediting by eclipse.

the class StyleAttrAdapter method getModel.

/**
 */
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);
        // need to set before valueChanged()
        setModel(model);
        valueChanged();
    }
    if (model != null && !isModelNecessary()) {
        model = null;
        valueChanged();
    }
    return model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Aggregations

CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)12 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)10 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)4 CSSDocumentLoader (org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader)3 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)3 RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)1 DOMException (org.w3c.dom.DOMException)1 Element (org.w3c.dom.Element)1