Package org.eclipse.ui
Class XMLMemento
- java.lang.Object
-
- org.eclipse.ui.XMLMemento
-
-
Constructor Summary
Constructors Constructor Description XMLMemento(Document document, Element element)Creates a memento for the specified document and element.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IMementocopyChild(IMemento child)Create a copy of the child node and append it to this node.IMementocreateChild(String type)Creates a new child of this memento with the given type.IMementocreateChild(String type, String id)Creates a new child of this memento with the given type and id.static XMLMementocreateReadRoot(Reader reader)Creates aDocumentfrom theReaderand returns a memento on the firstElementfor reading the document.static XMLMementocreateReadRoot(Reader reader, String baseDir)Creates aDocumentfrom theReaderand returns a memento on the firstElementfor reading the document.static XMLMementocreateWriteRoot(String type)Returns a root memento for writing a document.String[]getAttributeKeys()Returns an array of all the attribute keys of the memento.BooleangetBoolean(String key)Returns the boolean value of the given key.IMementogetChild(String type)Returns the first child with the given type id.IMemento[]getChildren()Returns all children of this node.IMemento[]getChildren(String type)Returns all children with the given type id.FloatgetFloat(String key)Returns the floating point value of the given key.StringgetID()Returns the id for this memento.IntegergetInteger(String key)Returns the integer value of the given key.StringgetString(String key)Returns the string value of the given key.StringgetTextData()Returns the data of the Text node of the memento.StringgetType()Returns the type for this memento.voidputBoolean(String key, boolean value)Sets the value of the given key to the given boolean value.voidputFloat(String key, float f)Sets the value of the given key to the given floating point number.voidputInteger(String key, int n)Sets the value of the given key to the given integer.voidputMemento(IMemento memento)Copy the attributes and children frommementoto the receiver.voidputString(String key, String value)Sets the value of the given key to the given string.voidputTextData(String data)Sets the memento's Text node to contain the given data.voidsave(Writer writer)Saves this memento's document current values to the specified writer.StringtoString()
-
-
-
Constructor Detail
-
XMLMemento
public XMLMemento(Document document, Element element)
Creates a memento for the specified document and element.Clients should use
createReadRootandcreateWriteRootto create the initial memento on a document.- Parameters:
document- the document for the mementoelement- the element node for the memento
-
-
Method Detail
-
createReadRoot
public static XMLMemento createReadRoot(Reader reader) throws WorkbenchException
Creates aDocumentfrom theReaderand returns a memento on the firstElementfor reading the document.Same as calling createReadRoot(reader, null)
- Parameters:
reader- theReaderused to create the memento's document- Returns:
- a memento on the first
Elementfor reading the document - Throws:
WorkbenchException- if IO problems, invalid format, or no element.
-
createReadRoot
public static XMLMemento createReadRoot(Reader reader, String baseDir) throws WorkbenchException
Creates aDocumentfrom theReaderand returns a memento on the firstElementfor reading the document.- Parameters:
reader- theReaderused to create the memento's documentbaseDir- the directory used to resolve relative file names in the XML document. This directory must exist and include the trailing separator. The directory format, including the separators, must be valid for the platform. Can benullif not needed.- Returns:
- a memento on the first
Elementfor reading the document - Throws:
WorkbenchException- if IO problems, invalid format, or no element.
-
createWriteRoot
public static XMLMemento createWriteRoot(String type) throws DOMException
Returns a root memento for writing a document.- Parameters:
type- the element node type to create on the document- Returns:
- the root memento for writing a document
- Throws:
DOMException- when the element could not be created for the passed type
-
createChild
public IMemento createChild(String type) throws DOMException
Creates a new child of this memento with the given type.The
getChildandgetChildrenmethods are used to retrieve children of a given type.- Specified by:
createChildin interfaceIMemento- Parameters:
type- the type- Returns:
- a new child memento
- Throws:
DOMException- if the child cannot be created- See Also:
getChild(java.lang.String),getChildren()
-
createChild
public IMemento createChild(String type, String id) throws DOMException
Creates a new child of this memento with the given type and id. The id is stored in the child memento (using a special reserved key,TAG_ID) and can be retrieved usinggetId.The
getChildandgetChildrenmethods are used to retrieve children of a given type.- Specified by:
createChildin interfaceIMemento- Parameters:
type- the typeid- the child id- Returns:
- a new child memento with the given type and id
- Throws:
DOMException- if the child cannot be created- See Also:
getID()
-
copyChild
public IMemento copyChild(IMemento child) throws DOMException
Create a copy of the child node and append it to this node.- Parameters:
child- the child to copy- Returns:
- An IMenento for the new child node.
- Throws:
DOMException- if the child cannot be created
-
getChild
public IMemento getChild(String type)
Description copied from interface:IMementoReturns the first child with the given type id.
-
getChildren
public IMemento[] getChildren()
Description copied from interface:IMementoReturns all children of this node.- Specified by:
getChildrenin interfaceIMemento- Returns:
- an array of children of this node. This will not be
null. If there are no children, an array of length zero will be returned.
-
getChildren
public IMemento[] getChildren(String type)
Description copied from interface:IMementoReturns all children with the given type id.- Specified by:
getChildrenin interfaceIMemento- Parameters:
type- the type id- Returns:
- an array of children with the given type. This will not be
null. If there are no keys, an array of length zero will be returned.
-
getFloat
public Float getFloat(String key)
Description copied from interface:IMementoReturns the floating point value of the given key.
-
getType
public String getType()
Description copied from interface:IMementoReturns the type for this memento.- Specified by:
getTypein interfaceIMemento- Returns:
- the memento type
- Since:
- 3.4
- See Also:
IMemento.createChild(java.lang.String),IMemento.createChild(java.lang.String,java.lang.String)
-
getID
public String getID()
Description copied from interface:IMementoReturns the id for this memento.- Specified by:
getIDin interfaceIMemento- Returns:
- the memento id, or
nullif none - See Also:
IMemento.createChild(java.lang.String,java.lang.String)
-
getInteger
public Integer getInteger(String key)
Description copied from interface:IMementoReturns the integer value of the given key.- Specified by:
getIntegerin interfaceIMemento- Parameters:
key- the key- Returns:
- the value, or
nullif the key was not found or was found but was not an integer
-
getString
public String getString(String key)
Description copied from interface:IMementoReturns the string value of the given key.
-
getBoolean
public Boolean getBoolean(String key)
Description copied from interface:IMementoReturns the boolean value of the given key.- Specified by:
getBooleanin interfaceIMemento- Parameters:
key- the key- Returns:
- the value, or
nullif the key was not found - Since:
- 3.4
-
getTextData
public String getTextData() throws DOMException
Returns the data of the Text node of the memento. Each memento is allowed only one Text node.- Specified by:
getTextDatain interfaceIMemento- Returns:
- the data of the Text node of the memento, or
nullif the memento has no Text node. - Throws:
DOMException- if the text node is too big- Since:
- 2.0
-
getAttributeKeys
public String[] getAttributeKeys()
Description copied from interface:IMementoReturns an array of all the attribute keys of the memento. This will not benull. If there are no keys, an array of length zero will be returned.- Specified by:
getAttributeKeysin interfaceIMemento- Returns:
- an array with all the attribute keys of the memento
- Since:
- 3.4
-
putFloat
public void putFloat(String key, float f) throws DOMException
Sets the value of the given key to the given floating point number.- Specified by:
putFloatin interfaceIMemento- Parameters:
key- the keyf- the value- Throws:
DOMException- if the attribute cannot be set
-
putInteger
public void putInteger(String key, int n) throws DOMException
Sets the value of the given key to the given integer.- Specified by:
putIntegerin interfaceIMemento- Parameters:
key- the keyn- the value- Throws:
DOMException- if the attribute cannot be set
-
putMemento
public void putMemento(IMemento memento) throws DOMException
Copy the attributes and children frommementoto the receiver.- Specified by:
putMementoin interfaceIMemento- Parameters:
memento- the IMemento to be copied.- Throws:
DOMException- if the attributes or children cannot be copied to this node.
-
putString
public void putString(String key, String value) throws DOMException
Sets the value of the given key to the given string.- Specified by:
putStringin interfaceIMemento- Parameters:
key- the keyvalue- the value- Throws:
DOMException- if the attribute cannot be set
-
putBoolean
public void putBoolean(String key, boolean value) throws DOMException
Sets the value of the given key to the given boolean value.- Specified by:
putBooleanin interfaceIMemento- Parameters:
key- the keyvalue- the value- Throws:
DOMException- if the attribute cannot be set- Since:
- 3.4
-
putTextData
public void putTextData(String data) throws DOMException
Sets the memento's Text node to contain the given data. Creates the Text node if none exists. If a Text node does exist, it's current contents are replaced. Each memento is allowed only one text node.- Specified by:
putTextDatain interfaceIMemento- Parameters:
data- the data to be placed on the Text node- Throws:
DOMException- if the text node cannot be created under this node.- Since:
- 2.0
-
save
public void save(Writer writer) throws IOException
Saves this memento's document current values to the specified writer.- Parameters:
writer- the writer used to save the memento's document- Throws:
IOException- if there is a problem serializing the document to the stream.
-
-