blob: 8e49a516e7ba766fa2c59b37095decf0fd42cfa4 [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.core.format;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.sse.core.format.IStructuredFormatPreferences;
import org.eclipse.wst.sse.core.format.IStructuredFormatter;
import org.eclipse.wst.sse.core.internal.SSECorePlugin;
import org.eclipse.wst.sse.core.preferences.CommonModelPreferenceNames;
import org.eclipse.wst.xml.core.format.FormatProcessorXML;
import org.eclipse.wst.xml.core.format.IStructuredFormatPreferencesXML;
import org.eclipse.wst.xml.core.format.StructuredFormatPreferencesXML;
import org.w3c.dom.Node;
public class HTMLFormatProcessorImpl extends FormatProcessorXML {
protected String getFileExtension() {
return "html"; //$NON-NLS-1$
}
protected IStructuredFormatter getFormatter(Node node) {
IStructuredFormatter formatter = HTMLFormatterFactory.getInstance().createFormatter(node, getFormatPreferences());
return formatter;
}
public IStructuredFormatPreferences getFormatPreferences() {
if (fFormatPreferences == null) {
fFormatPreferences = new StructuredFormatPreferencesXML();
Preferences preferences = HTMLCorePlugin.getDefault().getPluginPreferences();
if (preferences != null) {
fFormatPreferences.setLineWidth(preferences.getInt(CommonModelPreferenceNames.LINE_WIDTH));
((IStructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(CommonModelPreferenceNames.SPLIT_MULTI_ATTRS));
fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(CommonModelPreferenceNames.CLEAR_ALL_BLANK_LINES));
if (preferences.getBoolean(CommonModelPreferenceNames.INDENT_USING_TABS))
fFormatPreferences.setIndent("\t"); //$NON-NLS-1$
else {
int tabWidth = SSECorePlugin.getDefault().getPluginPreferences().getInt(CommonModelPreferenceNames.TAB_WIDTH);
String indent = ""; //$NON-NLS-1$
for (int i = 0; i < tabWidth; i++) {
indent += " "; //$NON-NLS-1$
}
fFormatPreferences.setIndent(indent);
}
}
}
return fFormatPreferences;
}
}