Search in sources :

Example 11 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class FormatProcessorsExtensionReader method getFormatProcessor.

public IStructuredFormatProcessor getFormatProcessor(String contentTypeId) {
    if (contentTypeId == null)
        return null;
    IStructuredFormatProcessor formatProcessor = null;
    if (map.containsKey(contentTypeId)) {
        formatProcessor = (IStructuredFormatProcessor) map.get(contentTypeId);
    } else {
        IContentTypeManager manager = Platform.getContentTypeManager();
        IContentType queryContentType = manager.getContentType(contentTypeId);
        boolean found = false;
        for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
            String elementContentTypeId = (String) iter.next();
            IContentType elementContentType = manager.getContentType(elementContentTypeId);
            if (queryContentType.isKindOf(elementContentType)) {
                formatProcessor = (IStructuredFormatProcessor) map.get(elementContentTypeId);
                map.put(contentTypeId, formatProcessor);
                found = true;
                break;
            }
        }
        if (!found)
            map.put(contentTypeId, null);
    }
    return formatProcessor;
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) Iterator(java.util.Iterator) IContentType(org.eclipse.core.runtime.content.IContentType)

Example 12 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class FormatProcessorsExtensionReader method readElement.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.sse.ui.internal.extension.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
	 */
protected boolean readElement(IConfigurationElement element) {
    if (element.getName().equals("processor")) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String contentTypeId = element.getAttribute("contentTypeId");
        // $NON-NLS-1$
        String processorClassName = element.getAttribute("class");
        String pluginID = element.getDeclaringExtension().getNamespace();
        Bundle bundle = Platform.getBundle(pluginID);
        try {
            IStructuredFormatProcessor processor = (IStructuredFormatProcessor) bundle.loadClass(processorClassName).newInstance();
            map.put(contentTypeId, processor);
            return true;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) Bundle(org.osgi.framework.Bundle)

Example 13 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class FormatActionDelegate method format.

protected void format(IProgressMonitor monitor, IFile file) {
    if (monitor == null || monitor.isCanceled())
        return;
    try {
        monitor.beginTask("", 100);
        IContentDescription contentDescription = file.getContentDescription();
        monitor.worked(5);
        if (contentDescription != null) {
            IContentType contentType = contentDescription.getContentType();
            IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId());
            if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) {
                String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[] { file.getFullPath().toString().substring(1) });
                monitor.subTask(message);
                formatProcessor.setProgressMonitor(monitor);
                formatProcessor.formatFile(file);
            }
        }
        monitor.worked(95);
        monitor.done();
    } catch (MalformedInputExceptionWithDetail e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    } catch (IOException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    } catch (CoreException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) MalformedInputExceptionWithDetail(org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail) IContentType(org.eclipse.core.runtime.content.IContentType) IOException(java.io.IOException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 14 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class BaseCommand method formatChild.

protected void formatChild(Element child) {
    if (child instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) child).getModel();
        try {
            // tell the model that we are about to make a big model change
            model.aboutToChangeModel();
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(child);
        } finally {
            // tell the model that we are done with the big model change
            model.changedModel();
        }
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 15 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class FormatHandler method format.

protected void format(IProgressMonitor monitor, IFile file) {
    if (monitor == null || monitor.isCanceled())
        return;
    try {
        monitor.beginTask("", 100);
        IContentDescription contentDescription = file.getContentDescription();
        monitor.worked(5);
        if (contentDescription != null) {
            IContentType contentType = contentDescription.getContentType();
            IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId());
            if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) {
                String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[] { file.getFullPath().toString().substring(1) });
                monitor.subTask(message);
                formatProcessor.setProgressMonitor(new SubProgressMonitor(monitor, 95));
                formatProcessor.formatFile(file);
            }
        }
        monitor.done();
    } catch (MalformedInputExceptionWithDetail e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    } catch (IOException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    } catch (CoreException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) MalformedInputExceptionWithDetail(org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail) IContentType(org.eclipse.core.runtime.content.IContentType) IOException(java.io.IOException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)16 FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)6 IContentType (org.eclipse.core.runtime.content.IContentType)5 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)5 CoreException (org.eclipse.core.runtime.CoreException)4 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)4 IOException (java.io.IOException)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Status (org.eclipse.core.runtime.Status)2 MalformedInputExceptionWithDetail (org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail)2 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)1