1 19 20 package org.netbeans.spi.editor.guards.support; 21 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 import java.io.Reader ; 25 import java.io.UnsupportedEncodingException ; 26 import java.io.Writer ; 27 import java.util.List ; 28 import javax.swing.text.BadLocationException ; 29 import org.netbeans.api.editor.guards.GuardedSection; 30 import org.netbeans.api.editor.guards.InteriorSection; 31 import org.netbeans.api.editor.guards.SimpleSection; 32 import org.netbeans.modules.editor.guards.GuardedSectionsImpl; 33 import org.netbeans.modules.editor.guards.PositionBounds; 34 import org.netbeans.spi.editor.guards.GuardedEditorSupport; 35 import org.netbeans.spi.editor.guards.GuardedSectionsProvider; 36 37 44 public abstract class AbstractGuardedSectionsProvider implements GuardedSectionsProvider { 45 46 private final GuardedSectionsImpl impl; 47 48 protected AbstractGuardedSectionsProvider(GuardedEditorSupport editor) { 49 this.impl = new GuardedSectionsImpl(editor); 50 } 51 52 public final Reader createGuardedReader(InputStream stream, String encoding) throws UnsupportedEncodingException { 53 return impl.createGuardedReader(this, stream, encoding); 54 } 55 56 public final Writer createGuardedWriter(OutputStream stream, String encoding) throws UnsupportedEncodingException { 57 return impl.createGuardedWriter(this, stream, encoding); 58 } 59 60 67 public abstract char[] writeSections(List <GuardedSection> sections, char[] content); 68 69 75 public abstract Result readSections(char[] content); 76 77 87 public final SimpleSection createSimpleSection(String name, int begin, int end) throws BadLocationException { 88 return impl.createSimpleSectionObject(name, PositionBounds.createUnresolved(begin, end, impl)); 89 } 90 91 103 public final InteriorSection createInteriorSection(String name, int headerBegin, int headerEnd, int footerBegin, int footerEnd) throws BadLocationException { 104 return impl.createInteriorSectionObject( 105 name, 106 PositionBounds.createUnresolved(headerBegin, headerEnd, impl), 107 PositionBounds.createBodyUnresolved(headerEnd + 1, footerBegin - 1, impl), 108 PositionBounds.createUnresolved(footerBegin, footerEnd, impl) 109 ); 110 } 111 112 public final class Result { 113 114 private final char[] content; 115 116 private final List <GuardedSection> sections; 117 118 public Result (char[] content, List <GuardedSection> sections) { 119 this.content = content; 120 this.sections = sections; 121 } 122 123 public char[] getContent() { 124 return this.content; 125 } 126 127 public List <GuardedSection> getGuardedSections() { 128 return this.sections; 129 } 130 } 131 } 132 | Popular Tags |