Search in sources :

Example 56 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class FileUtil method createModel.

public static ICSSModel createModel() {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        // $NON-NLS-1$
        model = modelManager.getModelForEdit("test" + uniqueNum++ + ".css", new NullInputStream(), null);
        // always use the same line delimiter for these tests, regardless
        // of plaform or preference settings
        model.getStructuredDocument().setLineDelimiter(commonEOL);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (ICSSModel) model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 57 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class CSSTextNodeCleanupHandler method getCSSContent.

/**
 */
private String getCSSContent(Node text) {
    ICSSModel model = getCSSModel(text);
    if (model == null)
        return null;
    ICSSNode document = model.getDocument();
    if (document == null)
        return null;
    INodeNotifier notifier = (INodeNotifier) document;
    CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
    // try another way to get formatter
    if (formatter == null)
        formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
    if (formatter == null)
        return null;
    StringBuffer buffer = formatter.cleanup(document);
    if (buffer == null)
        return null;
    return buffer.toString();
}
Also used : CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 58 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class AbstractCSSSourceFormatter method getCleanupStrategy.

/**
 * Insert the method's description here.
 *
 * @return org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy
 * @param node
 *            org.eclipse.wst.css.core.model.interfaces.ICSSNode
 */
protected CSSCleanupStrategy getCleanupStrategy(ICSSNode node) {
    CSSCleanupStrategy currentStrategy = CSSCleanupStrategyImpl.getInstance();
    ICSSDocument doc = node.getOwnerDocument();
    if (doc == null)
        return currentStrategy;
    ICSSModel model = doc.getModel();
    if (model == null)
        return currentStrategy;
    if (model.getStyleSheetType() != ICSSModel.EXTERNAL) {
    // TODO - TRANSITION Nakamori-san, or Kit, how can we move to
    // "HTML" plugin?
    // can we subclass?
    // currentStrategy = CSSInHTMLCleanupStrategyImpl.getInstance();
    }
    return currentStrategy;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 59 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class FormatProcessorCSS method formatModel.

public void formatModel(IStructuredModel structuredModel, int start, int length) {
    CSSFormatUtil formatUtil = CSSFormatUtil.getInstance();
    if (structuredModel instanceof ICSSModel) {
        // BUG102822 take advantage of IDocumentExtension4
        IDocumentExtension4 docExt4 = null;
        if (structuredModel.getStructuredDocument() instanceof IDocumentExtension4) {
            docExt4 = (IDocumentExtension4) structuredModel.getStructuredDocument();
        }
        DocumentRewriteSession rewriteSession = null;
        try {
            DocumentRewriteSessionType rewriteType = (length > MAX_SMALL_FORMAT_SIZE) ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession = (docExt4 == null || docExt4.getActiveRewriteSession() != null) ? null : docExt4.startRewriteSession(rewriteType);
            ICSSDocument doc = ((ICSSModel) structuredModel).getDocument();
            IStructuredDocumentRegion startRegion = structuredModel.getStructuredDocument().getRegionAtCharacterOffset(start);
            IStructuredDocumentRegion endRegion = structuredModel.getStructuredDocument().getRegionAtCharacterOffset(start + length);
            if (startRegion != null && endRegion != null) {
                start = startRegion.getStart();
                CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) doc);
                StringBuffer buf = formatter.format(doc, new Region(start, (endRegion.getEnd() - start)));
                if (buf != null) {
                    formatUtil.replaceSource(doc.getModel(), start, endRegion.getEnd() - start, buf.toString());
                }
            }
        } finally {
            // BUG102822 take advantage of IDocumentExtension4
            if (docExt4 != null && rewriteSession != null)
                docExt4.stopRewriteSession(rewriteSession);
        }
    } else if (structuredModel instanceof IDOMModel) {
        List cssnodes = formatUtil.collectCSSNodes(structuredModel, start, length);
        if (cssnodes != null && !cssnodes.isEmpty()) {
            ICSSModel model = null;
            // BUG102822 take advantage of IDocumentExtension4
            IDocumentExtension4 docExt4 = null;
            if (structuredModel.getStructuredDocument() instanceof IDocumentExtension4) {
                docExt4 = (IDocumentExtension4) structuredModel.getStructuredDocument();
            }
            DocumentRewriteSession rewriteSession = null;
            try {
                DocumentRewriteSessionType rewriteType = (length > MAX_SMALL_FORMAT_SIZE) ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
                rewriteSession = (docExt4 == null || docExt4.getActiveRewriteSession() != null) ? null : docExt4.startRewriteSession(rewriteType);
                for (int i = 0; i < cssnodes.size(); i++) {
                    ICSSNode node = (ICSSNode) cssnodes.get(i);
                    CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) node);
                    StringBuffer buf = formatter.format(node);
                    if (buf != null) {
                        int startOffset = ((IndexedRegion) node).getStartOffset();
                        int endOffset = ((IndexedRegion) node).getEndOffset();
                        if (model == null) {
                            model = node.getOwnerDocument().getModel();
                        }
                        formatUtil.replaceSource(model, startOffset, endOffset - startOffset, buf.toString());
                    }
                }
            } finally {
                // BUG102822 take advantage of IDocumentExtension4
                if (docExt4 != null && rewriteSession != null)
                    docExt4.stopRewriteSession(rewriteSession);
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) DocumentRewriteSessionType(org.eclipse.jface.text.DocumentRewriteSessionType) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSFormatUtil(org.eclipse.wst.css.core.internal.formatter.CSSFormatUtil) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) List(java.util.List) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 60 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class HTMLElementFormatter method getCSSValue.

/**
 */
private String getCSSValue(Attr attr) {
    ICSSModel model = getCSSModel(attr);
    if (model == null)
        return null;
    ICSSNode document = model.getDocument();
    if (document == null)
        return null;
    INodeNotifier notifier = (INodeNotifier) document;
    CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
    // try another way to get formatter
    if (formatter == null)
        formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
    if (formatter == null)
        return null;
    StringBuffer buffer = formatter.format(document);
    if (buffer == null)
        return null;
    return buffer.toString();
}
Also used : CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)82 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)41 CSSRule (org.w3c.dom.css.CSSRule)21 CSSRuleList (org.w3c.dom.css.CSSRuleList)20 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)14 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)14 CSSValue (org.w3c.dom.css.CSSValue)14 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)8 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)7 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)7 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Element (org.w3c.dom.Element)6