<!-- <questionid="arch-overall"when="init"> Describetheoverallarchitecture. <hint> WhatwillbeAPIfor <ahref="http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi"> clientsandwhatsupportAPI</a>? Whatpartswillbepluggable? Howwillplug-insberegistered?Pleaseuse<code><apitype="export"/></code> todescribeyourgeneralAPIsandspecifytheir <ahref="http://openide.netbeans.org/tutorial/api-design.html#category-private"> stabilitycategories</a>. Ifpossiblepleaseprovidesimplediagrams. </hint> </question>
-->
<answer id="arch-overall">
<p>
<api group="java" name="GuardedSectionsAPI"type="export" category="official">
The Guarded Sections module is supposed to operate over the Swing's <a href="@JDK@@JDKMODULE_JAVA_DESKTOP@/javax/swing/text/StyledDocument.html"><code>StyledDocument</code></a>.
It allows clients to manipulate named guarded sections that prevents user to
modify the content. So if you like to create, modify or delete guarded sections the <a href="@org-netbeans-modules-editor-guards@/org/netbeans/api/editor/guards/GuardedSectionManager.html">
<code>GuardedSectionManager</code></a> is the best place where to start.
</api>
</p>
<p>
<api group="java" name="GuardedSectionsSPI"type="export" category="official">
The module also allows to implement custom guarded section persistance in various content types like java, xml, ...
The easiest way is to subclass <a href="@org-netbeans-modules-editor-guards@/org/netbeans/spi/editor/guards/support/AbstractGuardedSectionsProvider.html">
<code>AbstractGuardedSectionsProvider</code></a>.<br/>In order to bind guarded sections to your editor see <a href="@org-netbeans-modules-editor-guards@/org/netbeans/spi/editor/guards/GuardedSectionsFactory.html">
<code>GuardedSectionsFactory</code></a>.
</api>
</p>
</answer>
<!-- <questionid="arch-quality"when="init"> Howwillthe<ahref="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a> ofyourcodebetestedand howarefutureregressionsgoingtobeprevented? <hint> Whatkindoftestingdo youwanttouse?Howmuchfunctionality,inwhichareas, shouldbecoveredbythetests?Howyoufindoutthatyour projectwassuccessful? </hint> </question>
-->
<answer id="arch-quality">
<p>
Code will be unit tested.
</p>
</answer>
<!-- <questionid="arch-usecases"when="init"> <hint> Contentofthisanswerwillbedisplayedaspartofpageat http://www.netbeans.org/download/dev/javadoc/usecases.html Youcanusetags<usecasename="name>regularhtmldescription</usecase> andifyouwanttouseanURLyoucanprefixifwith@TOP@tobegin attherootofyourjavadoc </hint> Describethemain<ahref="http://openide.netbeans.org/tutorial/api-design.html#usecase"> usecases</a>ofthenewAPI.Whowilluseitunder whatcircumstances?Whatkindofcodewouldtypicallyneedtobewritten tousethemodule? </question>
-->
<answer id="arch-usecases">
<usecase name="Add new section"id="AddingNewSection">
In order to add a new section after the existing section, which seems to be most frequent, use:
<pre>
String sectionName = ...;
StyledDocument doc = ...;
GuardedSectionManager guards = GuardedSectionManager.getInstance(doc);
GuardedSection g = guards.findSimpleSection(sectionName);
guards.createSimpleSection("new_name", doc.createPosition(g.getEndPosition().getOffset() + 1));
</pre>
</usecase>
<usecase name="Delete existing section"id="DeleteSection">
<pre>
StyledDocument doc = ...;
GuardedSectionManager guards = GuardedSectionManager.getInstance(doc);
GuardedSection g = guards.findSimpleSection("sectionName");
g.deleteSection();
</pre>
</usecase>
<usecase name="Plug guarded sections stuff into the editor"id="PlugSectionsProvider">
In case you want your <code>CloneableEditorSupport</code> to provide
guarded sections you should implement the <code>GuardedEditorSupport</code>
interface.
<pre>
private final class MyGuardedEditor implements GuardedEditorSupport {
...
}
</pre>
Further implement reading and writing of existing sections.
<pre>
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
if (guardedEditor == null) {
guardedEditor = new MyGuardedEditor();
// remember the provider
String mimeType = ((CloneableEditorSupport.Env) this.env).getMimeType();
guardedProvider = GuardedSectionsFactory.find(mimeType).create(guardedEditor);
}
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
if (guardedProvider != null) {
Charset cs = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
Writer writer = guardedProvider.createGuardedWriter(stream, cs);
try {
kit.write(writer, doc, 0, doc.getLength());
} finally {
writer.close();
}
} else {
kit.write(stream, doc, 0, doc.getLength());
}
}
</pre>
Your module should also require a proper implementation. In case of java
content add to your module manifest file:
<pre>
OpenIDE-Module-Requires: org.netbeans.api.editor.guards.Java
</pre>
</usecase>
</answer>
<!-- <questionid="arch-what"when="init"> Whatisthisprojectgoodfor? <hint> Pleaseprovidehereafewlinesdescribingtheproject, whatproblemitshouldsolve,providelinkstodocumentation, specifications,etc. </hint> </question>
-->
<answer id="arch-what">
<p>
Guarded Sections protects user from modifying document content. The main goal is
to simplify work with such a content to module writers and preserve created
sections.
</p>
</answer>
<!-- <questionid="compat-deprecation"when="init"> Howtheintroductionofyourprojectinfluencesfunctionality providedbypreviousversionoftheproduct? <hint> Ifyouareplanningtodeprecate/remove/changeanyexistingAPIs, listthemhereaccompaniedwiththereasonexplainingwhyyou aredoingso. </hint> </question>
-->
<answer id="compat-deprecation">
<p>
This API is intended to replace <code>JavaEditor</code> stuff of the java
module.
</p>
</answer>
<!-- <questionid="deploy-dependencies"when="final"> Whatdoothermodulesneedtodotodeclareadependencyonthisone, inadditiontoorinsteadofthenormalmoduledependencydeclaration (e.g.tokenstorequire)? <hint> Provideasampleoftheactuallinesyouwouldaddtoamodulemanifest todeclareadependency,forexampleOpenIDE-Module-Requires:some.token. Ifothermodulesshouldnotdependonthismodule,orshouldjustusea simpleregularmoduledependency,youcanjustanswer"nothing".Ifyou intentionallyexposeasemistableAPItoclientsusingimplementation dependencies,youshouldmentionthathere(butthereisnoneedtogive anexampleofusage). </hint> </question>
-->
<answer id="deploy-dependencies">
<p>
A module using the Guarded Sections API should also require a proper
implementation. Eg in case of java content add to your module manifest file:
</p>
<pre>
OpenIDE-Module-Requires: org.netbeans.api.editor.guards.Java
</pre>
<p>
A module implementing the Guarded Sections SPI should provide a token in
the manifest file. Eg in case of java content add:
</p>
<pre>
OpenIDE-Module-Provides: org.netbeans.api.editor.guards.Java
</pre>
</answer>
<!-- <questionid="deploy-packages"when="init"> Arepackagesofyourmodulemadeinaccessiblebynotdeclaringthem public? <hint> BydefaultNetBeansbuildharnesstreatsallpackagesareprivate. Ifyouexportsomeofthem-eitheraspublicorfriendpackages, youshouldhaveareason.Ifthereasonisdescribedelsewhere inthisdocument,youcanignorethisquestion. </hint> </question>
-->
<answer id="deploy-packages">
<p>
There are public api and spi packages. The implementation is private.
</p>
</answer>
<!-- <questionid="exec-component"when="impl"> Isexecutionofyourcodeinfluencedbyany(string)property ofanyofyourcomponents? <hint> Often<code>JComponent.getClientProperty</code>,<code>Action.getValue</code> or<code>PropertyDescriptor.getValue</code>,etc.areusedtoinfluence abehaviorofsomecode.Thisofcourseformsaninterfacethatshould bedocumented.Alsoifonedependsonsomeinterfacethatanobject implements(<code>componentinstanceofRunnable</code>)thatformsan APIaswell. </hint> </question>
-->
<answer id="exec-component">
<p>
<api name="org.netbeans.api.editor.guards.GuardedSectionManager" category="private"group="property"type="export">
The <code>GuardedSectionManager</code> instance is physically stored as a property of
the document with key <code>org.netbeans.api.editor.guards.GuardedSectionManager.class</code>. Modules should not depend on this.
</api>
</p>
</answer>
<!-- <questionid="lookup-lookup"when="init"> Doesyourmoduleuse<code>org.openide.util.Lookup</code> oranysimilartechnologytofindanycomponentstocommunicatewith?Whichones? <hint> NetBeansisbuildaroundagenericregistryofservicescalled lookup.Itispreferabletouseitforregistrationanddiscovery ifpossible.See <ahref="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html"> TheSolutiontoComunicationBetweenComponents </a>.Ifyoudonotplantouselookupandinsistusage ofothersolution,thenpleasedescribewhyitisnotworkingfor you. <br/> Whenfillingthefinalversionofyourarchdocument,please describetheinterfacesyouaresearchingfor,where aredefined,whetheryouaresearchingforjustoneormoreofthem, iftheorderisimportant,etc.Alsoclassifythestabilityofsuch APIcontract.Use<apigroup=&lookup&/>tag,so yourinformationgetslistedinthesummarypageofyourjavadoc. </hint> </question>
-->
<answer id="lookup-lookup">
<p>
<api category="official" group="lookup" name="GuardedSectionsFactory"type="export"url="@org-netbeans-modules-editor-guards@/org/netbeans/spi/editor/guards/GuardedSectionsFactory.html">
Factories of custom providers that implements reading and writing guarded sections
should be registered under <code>Editors/<mime path></code>
in the module layer file. The first one is chosen for the given mime path.
</api>
</p>
</answer>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.