use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class JsValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model, boolean inBatch) {
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
JsTranslationAdapterFactory.setupAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
// translationAdapter.resourceChanged();
IJsTranslation translation = translationAdapter.getJsTranslation(false);
if (!reporter.isCancelled()) {
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// only update task markers if the model is the same as what's on disk
boolean updateTasks = !domModel.isDirty() && f != null && f.isAccessible();
if (updateTasks) {
// remove old JavaScript task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVASCRIPT_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateTasks) {
// add new JavaScript task marker
try {
IMarker task = f.createMarker(JAVASCRIPT_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);
}
}
}
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class CleanupActionHTMLDelegate method isXHTML.
private boolean isXHTML() {
boolean isxhtml = false;
if (fEditor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) fEditor;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model instanceof IDOMModel) {
IDOMDocument domDocument = ((IDOMModel) model).getDocument();
if (domDocument != null)
isxhtml = domDocument.isXMLType();
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
return isxhtml;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method checkExternalSchema.
protected CMElementDeclaration checkExternalSchema(Element element) {
final Document document = element.getOwnerDocument();
if (document instanceof IDOMDocument) {
final String baseLocation = ((IDOMDocument) document).getModel().getBaseLocation();
if (baseLocation != null) {
final IPath basePath = new Path(baseLocation);
IFile file = null;
if (basePath.segmentCount() > 1) {
file = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
}
final URI uri = (file == null || !file.isAccessible()) ? new File(baseLocation).toURI() : file.getLocationURI();
if (uri != null) {
IExternalSchemaLocationProvider[] providers = ExternalSchemaLocationProviderRegistry.getInstance().getProviders();
for (int i = 0; i < providers.length; i++) {
long time = _trace ? System.currentTimeMillis() : 0;
final Map locations = providers[i].getExternalSchemaLocation(uri);
if (_trace) {
long diff = System.currentTimeMillis() - time;
if (diff > 250)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Logger.log(Logger.INFO, "Schema location provider took [" + diff + "ms] for URI [" + uri + "]");
}
if (locations != null && !locations.isEmpty()) {
Object location = locations.get(IExternalSchemaLocationProvider.NO_NAMESPACE_SCHEMA_LOCATION);
if (location != null)
return getCMElementDeclaration(element, NamespaceTable.getElementLineage(element), uri.toString(), location.toString());
}
}
}
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class AutoImportProposal method getInsertPosition.
/**
* @param doc
* @param isXml
* @return position after <jsp:root> if xml, otherwise right before the document element
*/
private int getInsertPosition(IDocument doc, boolean isXml) {
int pos = 0;
IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc);
try {
if (sModel != null) {
if (sModel instanceof IDOMModel) {
IDOMDocument documentNode = ((IDOMModel) sModel).getDocument();
/*
* document element must be sole Element child of Document
* to remain valid
*/
Node targetElement = null;
if (isXml) {
targetElement = documentNode.getDocumentElement();
}
if (targetElement == null)
targetElement = getInsertNode(documentNode);
if (targetElement != null) {
IStructuredDocumentRegion sdRegion = ((IDOMNode) targetElement).getFirstStructuredDocumentRegion();
if (isXml) {
/*
* document Element must be sole Element child of
* Document to remain valid, so insert after
*/
pos = sdRegion.getEndOffset();
try {
while (pos < doc.getLength() && (doc.getChar(pos) == '\r' || doc.getChar(pos) == '\n')) {
pos++;
}
} catch (BadLocationException e) {
// not important, use pos as determined earlier
}
} else {
// insert before target element
pos = sdRegion.getStartOffset();
}
} else {
pos = 0;
}
}
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
return pos;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class AutoImportProposal method isXmlFormat.
/**
* @param doc
* @return true if this document is xml-jsp syntax, otherwise false
*/
private boolean isXmlFormat(IDocument doc) {
boolean isXml = false;
IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc);
try {
if (sModel != null) {
if (!isXml) {
if (sModel instanceof IDOMModel) {
IDOMDocument documentNode = ((IDOMModel) sModel).getDocument();
Element docElement = documentNode.getDocumentElement();
// $NON-NLS-1$ //$NON-NLS-2$
isXml = docElement != null && ((docElement.getNodeName().equals("jsp:root")) || docElement.getAttributeNode("xmlns:jsp") != null || ((((IDOMNode) docElement).getStartStructuredDocumentRegion() == null && ((IDOMNode) docElement).getEndStructuredDocumentRegion() == null)));
}
}
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
return isXml;
}
Aggregations