Search in sources :

Example 76 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class JSPJavaValidator method performValidation.

void performValidation(IFile f, IReporter reporter, IStructuredModel model) {
    for (int i = 0; i < DEPEND_ONs.length; i++) {
        addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
    }
    if (model instanceof IDOMModel) {
        IDOMModel domModel = (IDOMModel) model;
        ModelHandlerForJSP.ensureTranslationAdapterFactory(domModel);
        IDOMDocument xmlDoc = domModel.getDocument();
        JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
        IJSPTranslation translation = translationAdapter.getJSPTranslation();
        if (!reporter.isCancelled()) {
            loadPreferences(f);
            // only update task markers if the model is the same as what's on disk
            boolean updateJavaTasks = UPDATE_JAVA_TASKS && !domModel.isDirty() && f != null && f.isAccessible();
            if (updateJavaTasks) {
                // remove old Java task markers
                try {
                    IMarker[] foundMarkers = f.findMarkers(JAVA_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
                    for (int i = 0; i < foundMarkers.length; i++) {
                        foundMarkers[i].delete();
                    }
                } catch (CoreException e) {
                    Logger.logException(e);
                }
            }
            translation.setProblemCollectingActive(true);
            translation.reconcileCompilationUnit();
            List problems = translation.getProblems();
            // add new messages
            for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
                IProblem problem = (IProblem) problems.get(i);
                /*
					 * Possible error in problem collection; EL translation is
					 * extensible, so we must be paranoid about this.
					 */
                if (problem == null)
                    continue;
                IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
                if (m != null) {
                    if (problem.getID() == IProblem.Task) {
                        if (updateJavaTasks) {
                            // add new Java task marker
                            try {
                                IMarker task = f.createMarker(JAVA_TASK_MARKER_TYPE);
                                task.setAttribute(IMarker.LINE_NUMBER, new Integer(m.getLineNumber()));
                                task.setAttribute(IMarker.CHAR_START, new Integer(m.getOffset()));
                                task.setAttribute(IMarker.CHAR_END, new Integer(m.getOffset() + m.getLength()));
                                task.setAttribute(IMarker.MESSAGE, m.getText());
                                task.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE);
                                switch(m.getSeverity()) {
                                    case IMessage.HIGH_SEVERITY:
                                        {
                                            task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
                                            task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
                                        }
                                        break;
                                    case IMessage.LOW_SEVERITY:
                                        {
                                            task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_LOW));
                                            task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
                                        }
                                        break;
                                    default:
                                        {
                                            task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_NORMAL));
                                            task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
                                        }
                                }
                            } catch (CoreException e) {
                                Logger.logException(e);
                            }
                        }
                    } else {
                        reporter.addMessage(fMessageOriginator, m);
                    }
                }
            }
        }
    }
    unloadPreferences();
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IProblem(org.eclipse.jdt.core.compiler.IProblem) CoreException(org.eclipse.core.runtime.CoreException) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker)

Example 77 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class JSPJavaValidator method validateFile.

/**
 * Validate one file. It's assumed that the file has JSP content type.
 *
 * @param f
 * @param reporter
 */
protected void validateFile(IFile f, IReporter reporter) {
    if (DEBUG) {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, getClass().getName() + " validating: " + f);
    }
    IStructuredModel model = null;
    try {
        // get jsp model, get tranlsation
        model = StructuredModelManager.getModelManager().getModelForRead(f);
        if (!reporter.isCancelled() && model != null) {
            for (int i = 0; i < DEPEND_ONs.length; i++) {
                addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
            }
            // get jsp model, get translation
            if (model instanceof IDOMModel) {
                reporter.removeAllMessages(fMessageOriginator, f);
                performValidation(f, reporter, model);
            }
        }
    } catch (IOException e) {
        Logger.logException(e);
    } catch (CoreException e) {
        Logger.logException(e);
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 78 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method replaceData.

/**
 * Apply changes from CSS sub-model to HTML model
 */
private void replaceData(int offset, int length, String data) {
    IDOMNode element = (IDOMNode) getElement();
    if (element == null)
        return;
    IDOMModel ownerModel = element.getModel();
    if (ownerModel == null)
        return;
    IStructuredDocument structuredDocument = ownerModel.getStructuredDocument();
    if (structuredDocument == null)
        return;
    IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
    if (flatNode == null)
        return;
    int contentOffset = flatNode.getEndOffset();
    if (data == null)
        // $NON-NLS-1$
        data = "";
    this.ignoreNotification = true;
    structuredDocument.replaceText(getRequesterC2H(), contentOffset + offset, length, data);
    this.ignoreNotification = false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 79 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class HTMLConverter method readModel.

/**
 */
private IDOMModel readModel(InputStream input) throws IOException, UnsupportedEncodingException {
    if (input == null)
        return null;
    // create temporary model
    // $NON-NLS-1$
    String id = input.toString() + ".html";
    IModelManager manager = StructuredModelManager.getModelManager();
    IStructuredModel model = manager.getModelForEdit(id, input, null);
    if (!(model instanceof IDOMModel)) {
        if (model != null)
            model.releaseFromEdit();
        return null;
    }
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 80 with IDOMModel

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.

the class HTMLConverter method readModel.

/**
 */
private IDOMModel readModel(IFile file) throws IOException, CoreException {
    if (file == null)
        return null;
    IModelManager manager = StructuredModelManager.getModelManager();
    IStructuredModel model = manager.getModelForEdit(file);
    if (!(model instanceof IDOMModel)) {
        if (model != null)
            model.releaseFromEdit();
        return null;
    }
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25