Build A XML TextEditorWord格式文档下载.docx

上传人:b****5 文档编号:20899649 上传时间:2023-01-26 格式:DOCX 页数:37 大小:356.09KB
下载 相关 举报
Build A XML TextEditorWord格式文档下载.docx_第1页
第1页 / 共37页
Build A XML TextEditorWord格式文档下载.docx_第2页
第2页 / 共37页
Build A XML TextEditorWord格式文档下载.docx_第3页
第3页 / 共37页
Build A XML TextEditorWord格式文档下载.docx_第4页
第4页 / 共37页
Build A XML TextEditorWord格式文档下载.docx_第5页
第5页 / 共37页
点击查看更多>>
下载资源
资源描述

Build A XML TextEditorWord格式文档下载.docx

《Build A XML TextEditorWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《Build A XML TextEditorWord格式文档下载.docx(37页珍藏版)》请在冰豆网上搜索。

Build A XML TextEditorWord格式文档下载.docx

Youcandothisasfollows:

1.File->

New->

Project...

2.SelectPlug-inProject

Thenfollowthewizardscreenuntilyougettothe 

Templates 

selectionasshownbelow:

Hereyouchecktheboxtocreatetheplug-inusingoneofthetemplates,andselectthetemplatePlug-inwithaneditor.EclipseverykindlygeneratesforyouaworkingXMLeditor,albeitonewhichdoesverylittle.

TheXMLeditorwhichEclipsegenerateslookslikethis:

Ofcourse,yougetallthesourcecode,andthegeneratedapplicationisquitenicelywritten,soitmakesanexcellentstartingpointforlearningthenewtechnology.TheXMLeditorisclearlymorethanjustatexteditor–ithassyntaxhighlighting.What'

smissingthough,aresomereallyusefulfeatures:

∙errormarking.Ifwemodifyourdocumentreplacingsomeofthemarkupwithrandomtext,wewantvisualcluesthatthedocumentisnotwell-formed.NormallyEclipsedoesthisbysquigglyredlinesundertheoffendingtext,anerroricononthelefthandruler,andanentryinthe'

Problems'

view

∙contentassist.We'

vegotaDTD,sowhycan'

tthetoolusethistofigurewhatbitsoftextyoucouldaddtoaparticularpartofthedocument?

∙acontentoutline.Eclipsetypicallyusesthe'

Outline'

viewtoprovideavisual(usuallytree-based)representationofourdocument,whichwecanusetonavigateeasilybetweendifferentpartsofthedocument.We'

dliketobeabletousethismechanism

∙formattingsupport.Wewantbeabletoformatsomeoneelse'

s(orourown)messyXMLintoanicelylaidoutdocument.Ideally,weevenwanttobeabletoformatpartofourdocumentinisolation

∙moresyntaxhighlightingoptions.Thebasictexteditoronlyprovidescolourdifferentiationforelementsandattributes.Whatifwewanttorepresentotherpartsofourdocumentinthisway?

Soyouwantallofthesefeaturesandmore,andwhatyouhaveisthebasictexteditorsource,wheredoyougofromhere?

That'

swhatthisarticleisallabout.Iamnoexpert.Hopefully,however,Ihavelearntenoughtoknowwhatiseasytoachieve,andgivesomehelpfulindicationsonhowtoaccomplishthemoredifficultbits.

Youcanuse 

thislinktodownloadthefullsourcecodeonwhichthisarticleisbased.

Part2:

GettingtoKnowJFaceText

TextEditors

TheJFaceTextframeworkisordinarilyusedwithanEclipsetexteditor,forwhichtheabstractbaseclassisa 

AbstractTextEditor 

(packageandpluginname).Normally,itwouldbemostconvenienttosubclassTextEditor,whichiswhattheprovidedXMLeditordoesinaclassnamed 

XMLEditor.

TheEclipseprovided 

XMLEditor 

classitselfdoesdoesnotdomuch–itsimplyusesthebaseclassfunctionality,anddelegatesthejobofaddingadditionalfeatures.

publicclassXMLEditorextendsTextEditor

{

privateColorManagercolorManager;

publicXMLEditor()

{

super();

colorManager=newColorManager();

setSourceViewerConfiguration(newXMLConfiguration(colorManager));

setDocumentProvider(newXMLDocumentProvider());

}

publicvoiddispose()

colorManager.dispose();

super.dispose();

}

Itsfirstdelegateisa 

SourceViewerConfiguration 

classinstance,whichisusedtoaddadditionalfeaturestotheeditor'

suserinterface.Thesecondisaninstanceofthe 

IDocumentProvider 

interface,whichencapsulatesthemechanismforcreatingaJFaceTextrepresentationofthedocumentbeingeditedfromitssource(suchasafileinthefilesystem).Understandinghowtousethe 

andtheDocumentProvider 

isnecessary,sowewillcoverbothlaterinthearticle.

WewillalsoseethatwhenaddingadditionalfeaturestotheXMLeditor,suchaserrormarkingandcontentoutlining,wewillalsoneedtoaddsomeenhancementstotheXMLeditorclass.

JFaceTextDocuments

WhenworkingwithJFaceText,thedocumentyouareeditingworkswithan 

IDocument 

instance.The 

containsthetextofyourdocument,andcanbeusedtoqueryitsstructure.The 

canalsobeusedtomarkforpositionsinthedocument,whichtheframeworkcanusetostoredocumentpartitioninformationandothermetadata,suchashighlightingranges.We'

lllearnmoreaboutdocumentpartitioninglaterinthearticle.Positionsarestoredindocumentsasinstancesofthe 

Position 

classorsubclasses.

Yourapplicationprobablywon'

toftenneedtouseanythingotherthanthedefaultprovided 

implementations.Alltheprovided 

implementationsarealsopartition-aware,thatis,canbedividedintonon-overlappingregionsoftext.PartitionsplayanimportantroleinJFacetext,sowewillbecoveringtheminsomedetaillaterinthearticle.

The 

interfaceisdesignedtoworkwithoutanyknowledgeofhowitisstored.Thatis,an 

instancehasnoknowledgeofwhetherithasbeenloadedfromthefilesystem,fromadatabaseorfromanyothersource.Thejobofcreatingthedocumentinstanceandinitiatingtheprocessthatsetsthedocumentsinitialstateisthejobofthe 

IDocumentProvider.Eclipseprovidesexcellentoutoftheboxsupportformloadingdocumentsfromthefilesystem,throughthe 

FileDocumentProvider 

class.

Wesawwhenintroductingthe 

classhowthe 

instanceismadeavailabletotheeditor.Wecannotsimplyusethe 

asis,becausethe 

FileDocumentProviderhasnoknowledgeofourplugin'

spartitioningscheme.

TheXMLeditor'

sdocumentproviderremediesthisbyoverridingonlyonemethod– 

createDocument() 

-withthefollowingcode:

protectedIDocumentcreateDocument(Objectelement)throwsCoreException

IDocumentdocument=super.createDocument(element);

...

returndocument;

UnlessyoualreadyknowJFaceText,therewouldbenopointatthisstagedescribingthecodethatgoesinthismethod,excepttosaythatinadditiontotheinheritedbehaviour,itconfiguresthedocument'

spartitioningmechanism.Atthisstage,youmaynotbeveryclearonwhatpartitioningis,orhowitworks.SincepartitioningissocentraltothewayJFaceTextworks,wewillnowtalkaboutitinabitmoredetail.

Partitioning

WhenyouopenadocumentwhichusesJFaceText,theframeworkdividesthedocumentintopartitions,thatis,aregionoftextwithinthedocument.Thesepartitionsarenon-overlapping.Thepartitionsarecategorised,sothateachpartitionisassociatedwithaparticular"

contenttype"

.

Theeasiestwaytounderstandpartitioningisbyviewinganexample.Ihaveaddedasimplemechanismtoeasilyprintthedocumentpartitioningtotheconsole,whichIwilldescribelater.Fornow,weareconcernedabouthowthedocumentispartitioned.

Below,wehaveanabridgedversionofthepartitioningforthedocumentshownabove.

Partitiontype:

__xml_pi,offset:

0,length:

21

Text:

<

?

xmlversion="

1.0"

>

---------------------------

__dftl_partition_content_type,offset:

21,length:

2

__xml_doctype,offset:

23,length:

36

!

DOCTYPEworldSYSTEM"

cities.dtd"

59,length:

__xml_start_tag,offset:

61,length:

7

world>

68,length:

5

73,length:

27

continentname="

Africa"

100,length:

4

--------------------------

104,length:

13

description>

...restofdocumentuntilend...

__xml_end_tag,offset:

1301,length:

8

/world>

Noticeafewthingsaboutthedocument'

spartitioning:

∙fromthedocumentoffsetsforeachpartition,wecanseethattheyarenon-overlapping

∙eachpartitionhasapartitiontype.Bydefault,thepartitiontypeis 

__dftl_partition_content_type.Here,thecontenttypehasnotbeenspecified

∙Ifwescanthroughthelisting,weseethatthereareonlytwootherpartitiontypes:

__xml_tag 

an

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1