1
2
3
4
5
6
7
8
9
10 package de.funfried.netbeans.plugins.external.formatter.html.base;
11
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.SortedSet;
15
16 import javax.swing.text.BadLocationException;
17 import javax.swing.text.StyledDocument;
18
19 import org.apache.commons.lang3.tuple.Pair;
20 import org.netbeans.api.annotations.common.CheckForNull;
21
22 import de.funfried.netbeans.plugins.external.formatter.FormatJob;
23 import de.funfried.netbeans.plugins.external.formatter.FormatterService;
24 import de.funfried.netbeans.plugins.external.formatter.MimeType;
25 import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException;
26
27
28
29
30
31
32 public abstract class AbstractHtmlFormatterService implements FormatterService {
33
34
35
36
37
38 protected abstract FormatJob getFormatJob(StyledDocument document);
39
40
41
42
43 @Override
44 public boolean format(StyledDocument document, SortedSet<Pair<Integer, Integer>> changedElements) throws BadLocationException, FormattingFailedException {
45 if (!canHandle(document)) {
46 throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported");
47 }
48
49 getFormatJob(document).format();
50
51 return true;
52 }
53
54
55
56
57 @Override
58 public List<MimeType> getSupportedMimeTypes() {
59 return Collections.singletonList(MimeType.HTML);
60 }
61
62
63
64
65 @Override
66 @CheckForNull
67 public Boolean organizeImports(StyledDocument document, boolean afterFixImports) throws BadLocationException {
68 return null;
69 }
70 }