blob: 1e4f2335f73c1d2516d08e7a4c5cfa1cdc49ed08 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.html.ui.internal.edit.ui;
import java.util.ResourceBundle;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl;
import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.ui.internal.actions.CleanupAction;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
public class CleanupActionHTML extends CleanupAction {
protected IStructuredCleanupProcessor fCleanupProcessor;
public CleanupActionHTML(ResourceBundle bundle, String prefix, ITextEditor editor) {
super(bundle, prefix, editor);
}
protected Dialog getCleanupDialog(Shell shell) {
if (fCleanupDialog == null) {
fCleanupDialog = new CleanupDialogHTML(shell);
}
((CleanupDialogHTML)fCleanupDialog).setisXHTMLType(isXHTML());
return fCleanupDialog;
}
protected IStructuredCleanupProcessor getCleanupProcessor() {
if (fCleanupProcessor == null)
fCleanupProcessor = new HTMLCleanupProcessorImpl();
return fCleanupProcessor;
}
private boolean isXHTML() {
boolean isxhtml = false;
ITextEditor textEditor = getTextEditor();
if (textEditor != null) {
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;
}
}