|
Removed
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2001, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.wst.html.internal.validation; |
| 12 |
|
| 13 |
import java.io.IOException; |
| 14 |
import java.io.UnsupportedEncodingException; |
| 15 |
import java.util.ArrayList; |
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.eclipse.core.filebuffers.ITextFileBuffer; |
| 19 |
import org.eclipse.core.resources.IContainer; |
| 20 |
import org.eclipse.core.resources.IFile; |
| 21 |
import org.eclipse.core.resources.IProject; |
| 22 |
import org.eclipse.core.resources.IResource; |
| 23 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 24 |
import org.eclipse.core.runtime.CoreException; |
| 25 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 26 |
import org.eclipse.core.runtime.IExecutableExtension; |
| 27 |
import org.eclipse.core.runtime.IPath; |
| 28 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 29 |
import org.eclipse.core.runtime.IStatus; |
| 30 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 31 |
import org.eclipse.core.runtime.OperationCanceledException; |
| 32 |
import org.eclipse.core.runtime.Path; |
| 33 |
import org.eclipse.core.runtime.Platform; |
| 34 |
import org.eclipse.core.runtime.Status; |
| 35 |
import org.eclipse.core.runtime.content.IContentDescription; |
| 36 |
import org.eclipse.core.runtime.content.IContentType; |
| 37 |
import org.eclipse.core.runtime.content.IContentTypeManager; |
| 38 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
| 39 |
import org.eclipse.jface.text.IDocument; |
| 40 |
import org.eclipse.jface.text.IRegion; |
| 41 |
import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants; |
| 42 |
import org.eclipse.wst.html.core.internal.validate.HTMLValidationAdapterFactory; |
| 43 |
import org.eclipse.wst.html.ui.internal.Logger; |
| 44 |
import org.eclipse.wst.sse.core.StructuredModelManager; |
| 45 |
import org.eclipse.wst.sse.core.internal.FileBufferModelManager; |
| 46 |
import org.eclipse.wst.sse.core.internal.provisional.IModelManager; |
| 47 |
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; |
| 48 |
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
| 49 |
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; |
| 50 |
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; |
| 51 |
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; |
| 52 |
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; |
| 53 |
import org.eclipse.wst.sse.core.internal.util.URIResolver; |
| 54 |
import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter; |
| 55 |
import org.eclipse.wst.sse.core.utils.StringUtils; |
| 56 |
import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator; |
| 57 |
import org.eclipse.wst.validation.AbstractValidator; |
| 58 |
import org.eclipse.wst.validation.ValidationResult; |
| 59 |
import org.eclipse.wst.validation.ValidationState; |
| 60 |
import org.eclipse.wst.validation.internal.core.Message; |
| 61 |
import org.eclipse.wst.validation.internal.core.ValidationException; |
| 62 |
import org.eclipse.wst.validation.internal.operations.IWorkbenchContext; |
| 63 |
import org.eclipse.wst.validation.internal.operations.WorkbenchReporter; |
| 64 |
import org.eclipse.wst.validation.internal.provisional.core.IMessage; |
| 65 |
import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
| 66 |
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; |
| 67 |
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; |
| 68 |
import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; |
| 69 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; |
| 70 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; |
| 71 |
import org.w3c.dom.Text; |
| 72 |
|
| 73 |
public class HTMLValidator extends AbstractValidator implements IValidatorJob, ISourceValidator, IExecutableExtension { |
| 74 |
private static final String ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE = "org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$ |
| 75 |
|
| 76 |
static boolean shouldValidate(IFile file) { |
| 77 |
IResource resource = file; |
| 78 |
do { |
| 79 |
if (resource.isDerived() || resource.isTeamPrivateMember() || !resource.isAccessible() || (resource.getName().charAt(0) == '.' && resource.getType() == IResource.FOLDER)) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
resource = resource.getParent(); |
| 83 |
} |
| 84 |
while ((resource.getType() & IResource.PROJECT) == 0); |
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
private IDocument fDocument; |
| 89 |
private IContentTypeManager fContentTypeManager; |
| 90 |
private IContentType[] fOtherSupportedContentTypes = null; |
| 91 |
private String[] fAdditionalContentTypesIDs = null; |
| 92 |
private IContentType fHTMLContentType; |
| 93 |
|
| 94 |
public HTMLValidator() { |
| 95 |
super(); |
| 96 |
fContentTypeManager = Platform.getContentTypeManager(); |
| 97 |
fHTMLContentType = fContentTypeManager.getContentType(ORG_ECLIPSE_WST_HTML_CORE_HTMLSOURCE); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
*/ |
| 102 |
public void cleanup(IReporter reporter) { |
| 103 |
// nothing to do |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Gets list of content types this validator is interested in |
| 108 |
* |
| 109 |
* @return All HTML-related content types |
| 110 |
*/ |
| 111 |
private IContentType[] getOtherSupportedContentTypes() { |
| 112 |
if (fOtherSupportedContentTypes == null) { |
| 113 |
List contentTypes = new ArrayList(3); |
| 114 |
if (fAdditionalContentTypesIDs != null) { |
| 115 |
for (int i = 0; i < fAdditionalContentTypesIDs.length; i++) { |
| 116 |
IContentType type = Platform.getContentTypeManager().getContentType(fAdditionalContentTypesIDs[i]); |
| 117 |
if (type != null) { |
| 118 |
contentTypes.add(type); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
fOtherSupportedContentTypes = (IContentType[]) contentTypes.toArray(new IContentType[contentTypes.size()]); |
| 123 |
} |
| 124 |
return fOtherSupportedContentTypes; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
/** |
| 129 |
*/ |
| 130 |
protected IDOMModel getModel(IProject project, IFile file) { |
| 131 |
if (project == null || file == null) |
| 132 |
return null; |
| 133 |
if (!file.exists()) |
| 134 |
return null; |
| 135 |
if (!canHandle(file)) |
| 136 |
return null; |
| 137 |
|
| 138 |
IStructuredModel model = null; |
| 139 |
IModelManager manager = StructuredModelManager.getModelManager(); |
| 140 |
try { |
| 141 |
file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor()); |
| 142 |
} |
| 143 |
catch (CoreException e) { |
| 144 |
Logger.logException(e); |
| 145 |
} |
| 146 |
try { |
| 147 |
try { |
| 148 |
model = manager.getModelForRead(file); |
| 149 |
} |
| 150 |
catch (UnsupportedEncodingException ex) { |
| 151 |
// retry ignoring META charset for invalid META charset |
| 152 |
// specification |
| 153 |
// recreate input stream, because it is already partially read |
| 154 |
model = manager.getModelForRead(file, new String(), null); |
| 155 |
} |
| 156 |
} |
| 157 |
catch (UnsupportedEncodingException ex) { |
| 158 |
} |
| 159 |
catch (IOException ex) { |
| 160 |
} |
| 161 |
catch (CoreException e) { |
| 162 |
Logger.logException(e); |
| 163 |
} |
| 164 |
|
| 165 |
if (model == null) |
| 166 |
return null; |
| 167 |
if (!(model instanceof IDOMModel)) { |
| 168 |
releaseModel(model); |
| 169 |
return null; |
| 170 |
} |
| 171 |
return (IDOMModel) model; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
*/ |
| 176 |
protected HTMLValidationReporter getReporter(IReporter reporter, IFile file, IDOMModel model) { |
| 177 |
return new HTMLValidationReporter(this, reporter, file, model); |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Check file extension to validate |
| 182 |
*/ |
| 183 |
private boolean canHandle(IFile file) { |
| 184 |
boolean result = false; |
| 185 |
if (file != null) { |
| 186 |
try { |
| 187 |
IContentDescription contentDescription = file.getContentDescription(); |
| 188 |
if (contentDescription != null) { |
| 189 |
IContentType fileContentType = contentDescription.getContentType(); |
| 190 |
if (fileContentType.isKindOf(fHTMLContentType)) { |
| 191 |
result = true; |
| 192 |
} |
| 193 |
else { |
| 194 |
IContentType[] otherTypes = getOtherSupportedContentTypes(); |
| 195 |
for (int i = 0; i < otherTypes.length; i++) { |
| 196 |
result = result || fileContentType.isKindOf(otherTypes[i]); |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
else if (fHTMLContentType != null) { |
| 201 |
result = fHTMLContentType.isAssociatedWith(file.getName()); |
| 202 |
} |
| 203 |
} |
| 204 |
catch (CoreException e) { |
| 205 |
// should be rare, but will ignore to avoid logging "encoding |
| 206 |
// exceptions" and the like here. |
| 207 |
// Logger.logException(e); |
| 208 |
} |
| 209 |
} |
| 210 |
return result; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
*/ |
| 215 |
private boolean hasHTMLFeature(IDOMDocument document) { |
| 216 |
DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class); |
| 217 |
if (adapter == null) |
| 218 |
return false; |
| 219 |
return adapter.hasFeature(HTMLDocumentTypeConstants.HTML); |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
*/ |
| 224 |
protected void releaseModel(IStructuredModel model) { |
| 225 |
if (model != null) |
| 226 |
model.releaseFromRead(); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
*/ |
| 231 |
public void validate(IValidationContext helper, IReporter reporter) { |
| 232 |
if (helper == null) |
| 233 |
return; |
| 234 |
if ((reporter != null) && (reporter.isCancelled() == true)) { |
| 235 |
throw new OperationCanceledException(); |
| 236 |
} |
| 237 |
String[] deltaArray = helper.getURIs(); |
| 238 |
if (deltaArray != null && deltaArray.length > 0) { |
| 239 |
validateDelta(helper, reporter); |
| 240 |
} |
| 241 |
else { |
| 242 |
validateFull(helper, reporter); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* This validate call is for the ISourceValidator partial document |
| 248 |
* validation approach |
| 249 |
* |
| 250 |
* @param dirtyRegion |
| 251 |
* @param helper |
| 252 |
* @param reporter |
| 253 |
* @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator |
| 254 |
*/ |
| 255 |
public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) { |
| 256 |
|
| 257 |
if (helper == null || fDocument == null) |
| 258 |
return; |
| 259 |
|
| 260 |
if ((reporter != null) && (reporter.isCancelled() == true)) { |
| 261 |
throw new OperationCanceledException(); |
| 262 |
} |
| 263 |
|
| 264 |
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); |
| 265 |
if (model == null) |
| 266 |
return; // error |
| 267 |
|
| 268 |
try { |
| 269 |
|
| 270 |
IDOMDocument document = null; |
| 271 |
if (model instanceof IDOMModel) { |
| 272 |
document = ((IDOMModel) model).getDocument(); |
| 273 |
} |
| 274 |
|
| 275 |
if (document == null || !hasHTMLFeature(document)) { |
| 276 |
// handled in finally clause |
| 277 |
// model.releaseFromRead(); |
| 278 |
return; //ignore |
| 279 |
} |
| 280 |
|
| 281 |
IPath filePath = null; |
| 282 |
IFile file = null; |
| 283 |
|
| 284 |
ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument); |
| 285 |
if (fb != null) { |
| 286 |
filePath = fb.getLocation(); |
| 287 |
|
| 288 |
if (filePath.segmentCount() > 1) { |
| 289 |
file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); |
| 290 |
if (!file.isAccessible()) { |
| 291 |
file = null; |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
else { |
| 296 |
filePath = new Path(model.getId()); |
| 297 |
} |
| 298 |
|
| 299 |
// this will be the wrong region if it's Text (instead of Element) |
| 300 |
// we don't know how to validate Text |
| 301 |
IndexedRegion ir = getCoveringNode(dirtyRegion); // model.getIndexedRegion(dirtyRegion.getOffset()); |
| 302 |
if (ir instanceof Text) { |
| 303 |
while (ir != null && ir instanceof Text) { |
| 304 |
// it's assumed that this gets the IndexedRegion to |
| 305 |
// the right of the end offset |
| 306 |
ir = model.getIndexedRegion(ir.getEndOffset()); |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
if (ir instanceof INodeNotifier) { |
| 311 |
|
| 312 |
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); |
| 313 |
ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir); |
| 314 |
if (adapter == null) |
| 315 |
return; // error |
| 316 |
|
| 317 |
if (reporter != null) { |
| 318 |
HTMLValidationReporter rep = null; |
| 319 |
rep = getReporter(reporter, file, (IDOMModel) model); |
| 320 |
rep.clear(); |
| 321 |
adapter.setReporter(rep); |
| 322 |
|
| 323 |
Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, filePath.toString().substring(1)); |
| 324 |
reporter.displaySubtask(this, mess); |
| 325 |
} |
| 326 |
adapter.validate(ir); |
| 327 |
} |
| 328 |
} |
| 329 |
finally { |
| 330 |
if (model != null) |
| 331 |
model.releaseFromRead(); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
private IndexedRegion getCoveringNode(IRegion dirtyRegion) { |
| 336 |
|
| 337 |
IndexedRegion largestRegion = null; |
| 338 |
if(fDocument instanceof IStructuredDocument) { |
| 339 |
IStructuredDocumentRegion[] regions = ((IStructuredDocument) fDocument).getStructuredDocumentRegions(dirtyRegion.getOffset(), dirtyRegion.getLength()); |
| 340 |
largestRegion = getLargest(regions); |
| 341 |
} |
| 342 |
return largestRegion; |
| 343 |
} |
| 344 |
protected IndexedRegion getLargest(IStructuredDocumentRegion[] sdRegions) { |
| 345 |
|
| 346 |
if(sdRegions == null || sdRegions.length == 0) |
| 347 |
return null; |
| 348 |
|
| 349 |
IndexedRegion currentLargest = getCorrespondingNode(sdRegions[0]); |
| 350 |
for (int i = 0; i < sdRegions.length; i++) { |
| 351 |
if(!sdRegions[i].isDeleted()) { |
| 352 |
IndexedRegion corresponding = getCorrespondingNode(sdRegions[i]); |
| 353 |
|
| 354 |
if(currentLargest instanceof Text) |
| 355 |
currentLargest = corresponding; |
| 356 |
|
| 357 |
if(corresponding != null) { |
| 358 |
if(!(corresponding instanceof Text)) { |
| 359 |
if (corresponding.getStartOffset() <= currentLargest.getStartOffset() |
| 360 |
&& corresponding.getEndOffset() >= currentLargest.getEndOffset() ) |
| 361 |
currentLargest = corresponding; |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
} |
| 366 |
} |
| 367 |
return currentLargest; |
| 368 |
} |
| 369 |
protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) { |
| 370 |
IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); |
| 371 |
IndexedRegion indexedRegion = null; |
| 372 |
try { |
| 373 |
if (sModel != null) |
| 374 |
indexedRegion = sModel.getIndexedRegion(sdRegion.getStart()); |
| 375 |
} finally { |
| 376 |
if (sModel != null) |
| 377 |
sModel.releaseFromRead(); |
| 378 |
} |
| 379 |
return indexedRegion; |
| 380 |
} |
| 381 |
|
| 382 |
/** |
| 383 |
* @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator |
| 384 |
*/ |
| 385 |
public void connect(IDocument document) { |
| 386 |
fDocument = document; |
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator |
| 391 |
*/ |
| 392 |
public void disconnect(IDocument document) { |
| 393 |
fDocument = null; |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
*/ |
| 398 |
protected HTMLValidationResult validate(IDOMModel model, IFile file) { |
| 399 |
IProject prj = null; |
| 400 |
if (file != null) { |
| 401 |
prj = file.getProject(); |
| 402 |
} |
| 403 |
if ((prj == null) && (model != null)) { |
| 404 |
URIResolver res = model.getResolver(); |
| 405 |
if (res != null) { |
| 406 |
prj = res.getProject(); |
| 407 |
} |
| 408 |
} |
| 409 |
final WorkbenchReporter reporter = new WorkbenchReporter(prj, new NullProgressMonitor()); |
| 410 |
return validate(reporter, file, model); |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
*/ |
| 415 |
private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) { |
| 416 |
if (file == null || model == null) |
| 417 |
return null; // error |
| 418 |
IDOMDocument document = model.getDocument(); |
| 419 |
if (document == null) |
| 420 |
return null; // error |
| 421 |
if (!hasHTMLFeature(document)) |
| 422 |
return null; // ignore |
| 423 |
|
| 424 |
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance(); |
| 425 |
ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document); |
| 426 |
if (adapter == null) |
| 427 |
return null; // error |
| 428 |
|
| 429 |
HTMLValidationReporter rep = getReporter(reporter, file, model); |
| 430 |
rep.clear(); |
| 431 |
adapter.setReporter(rep); |
| 432 |
adapter.validate(document); |
| 433 |
return rep.getResult(); |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
*/ |
| 438 |
private void validateContainer(IValidationContext helper, IReporter reporter, IContainer container) { |
| 439 |
try { |
| 440 |
IResource[] resourceArray = container.members(false); |
| 441 |
for (int i = 0; i < resourceArray.length; i++) { |
| 442 |
IResource resource = resourceArray[i]; |
| 443 |
if (resource == null || reporter.isCancelled()) |
| 444 |
continue; |
| 445 |
if (resource instanceof IFile) { |
| 446 |
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString().substring(1)); |
| 447 |
reporter.displaySubtask(this, message); |
| 448 |
validateFile(helper, reporter, (IFile) resource); |
| 449 |
} |
| 450 |
else if (resource instanceof IContainer) { |
| 451 |
validateContainer(helper, reporter, (IContainer) resource); |
| 452 |
} |
| 453 |
} |
| 454 |
} |
| 455 |
catch (CoreException ex) { |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
*/ |
| 461 |
private void validateDelta(IValidationContext helper, IReporter reporter) { |
| 462 |
String[] deltaArray = helper.getURIs(); |
| 463 |
for (int i = 0; i < deltaArray.length; i++) { |
| 464 |
String delta = deltaArray[i]; |
| 465 |
if (delta == null) |
| 466 |
continue; |
| 467 |
|
| 468 |
if (reporter != null) { |
| 469 |
Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1)); |
| 470 |
reporter.displaySubtask(this, message); |
| 471 |
} |
| 472 |
|
| 473 |
IResource resource = getResource(delta); |
| 474 |
if (resource == null || !(resource instanceof IFile)) |
| 475 |
continue; |
| 476 |
validateFile(helper, reporter, (IFile) resource); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
*/ |
| 482 |
private void validateFile(IValidationContext helper, IReporter reporter, IFile file) { |
| 483 |
if ((reporter != null) && (reporter.isCancelled() == true)) { |
| 484 |
throw new OperationCanceledException(); |
| 485 |
} |
| 486 |
if (!shouldValidate(file)) { |
| 487 |
return; |
| 488 |
} |
| 489 |
IDOMModel model = getModel(file.getProject(), file); |
| 490 |
if (model == null) |
| 491 |
return; |
| 492 |
|
| 493 |
try { |
| 494 |
validate(reporter, file, model); |
| 495 |
} |
| 496 |
finally { |
| 497 |
releaseModel(model); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
*/ |
| 503 |
private void validateFull(IValidationContext helper, IReporter reporter) { |
| 504 |
IProject project = null; |
| 505 |
String[] fileDelta = helper.getURIs(); |
| 506 |
if (helper instanceof IWorkbenchContext) { |
| 507 |
IWorkbenchContext wbHelper = (IWorkbenchContext) helper; |
| 508 |
project = wbHelper.getProject(); |
| 509 |
} |
| 510 |
else if(fileDelta.length > 0){ |
| 511 |
// won't work for project validation (b/c nothing in file delta) |
| 512 |
project = getResource(fileDelta[0]).getProject(); |
| 513 |
} |
| 514 |
if (project == null) |
| 515 |
return; |
| 516 |
validateContainer(helper, reporter, project); |
| 517 |
} |
| 518 |
|
| 519 |
/* |
| 520 |
* added to get rid or dependency on IWorkbenchHelper |
| 521 |
* |
| 522 |
*/ |
| 523 |
public IResource getResource(String delta) { |
| 524 |
return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(delta)); |
| 525 |
} |
| 526 |
|
| 527 |
public ISchedulingRule getSchedulingRule(IValidationContext helper) { |
| 528 |
return null; |
| 529 |
} |
| 530 |
|
| 531 |
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException { |
| 532 |
// Exception catching was removed, see |
| 533 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123600 |
| 534 |
IStatus status = Status.OK_STATUS; |
| 535 |
validate(helper, reporter); |
| 536 |
return status; |
| 537 |
} |
| 538 |
|
| 539 |
/** |
| 540 |
* @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, |
| 541 |
* java.lang.String, java.lang.Object) |
| 542 |
*/ |
| 543 |
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { |
| 544 |
fAdditionalContentTypesIDs = new String[0]; |
| 545 |
if (data != null) { |
| 546 |
if (data instanceof String && data.toString().length() > 0) { |
| 547 |
fAdditionalContentTypesIDs = StringUtils.unpack(data.toString()); |
| 548 |
} |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) { |
| 553 |
if (resource.getType() != IResource.FILE) |
| 554 |
return null; |
| 555 |
ValidationResult result = new ValidationResult(); |
| 556 |
IReporter reporter = result.getReporter(monitor); |
| 557 |
validateFile(null, reporter, (IFile) resource); |
| 558 |
return result; |
| 559 |
} |
| 560 |
} |