sk.uniba.euromath.document.schema
Class ElementRule

java.lang.Object
  extended by sk.uniba.euromath.document.schema.ElementRule

public class ElementRule
extends Object

Represents rule for one element, already present in the document. Document must NOT be modified (not even through DocumentModifier) while this instance is used.

Author:
Martin Vysny

Method Summary
 List<? extends Element> areElementsDeletable(Set<? extends Element> elements)
          Checks whether given elements are deletable.
 AttributeRule getAttributeRule(Attr attribute)
          Gets attribute rule for given attribute.
 INameList<NewElementRule> getEnclosingElements(sk.baka.ikslibs.ptr.DOMPoint start, sk.baka.ikslibs.ptr.DOMPoint end)
          Computes and returns an one-sized insertlist of elements, that can enclose given nodeset.
 INameList<AttributeRule> getInsertableAttributes()
           Computes all insertable attributes, that can be inserted into given element.
 List<InsertList> getInsertableElements(sk.baka.ikslibs.ptr.DOMPoint point)
          Computes insertable elements, with their positions between other nodes.
 IValueRule getValueRule()
          Gets text acceptor, that checks valid text values for given element.
 String isAcceptable(sk.baka.ikslibs.ptr.DomPointer ptr, boolean create, String newValue)
          Checks whether the new text value is acceptable.
 boolean isAnyStringInsertable(sk.baka.ikslibs.ptr.DOMPoint ip)
           Checks, if there can be any string inserted into given point.
 boolean isDeclosable(Element e)
          Checks if given element is declosable - if the contents of given element can replace the element.
 boolean isDeletable(sk.baka.ikslibs.ptr.DOMPoint start, sk.baka.ikslibs.ptr.DOMPoint end)
          Checks if given node interval is removable.
 boolean isDeletable(EntityReference entity)
          Checks if given entity node is removable.
 boolean isDeletableAttribute(Attr attribute)
          Checks, whether given attribute is deletable from its element.
 boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip, DocumentFragment frag)
          Checks if all nodes from the document fragment are insertable t the specified position.
 boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip, String entityName)
          Checks if the entity is insertable at the specified position.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getInsertableElements

public List<InsertList> getInsertableElements(sk.baka.ikslibs.ptr.DOMPoint point)
Computes insertable elements, with their positions between other nodes. User can choose, which sequence he wishes to create. Then simply call createElement() for each element.

Parameters:
point - insertion point, before which we want to insert element. If InsertPoint.FIRST, new element will be created before first node.
Returns:
array of element lists, each list represents one possibility, which elements can be inserted.

getInsertableAttributes

public INameList<AttributeRule> getInsertableAttributes()

Computes all insertable attributes, that can be inserted into given element. Returned NameList must NOT be used to create more than one attribute.

Warning: when creating attributes with same namespace as their owner element (local namespaces), their prefix AND namespace MUST be null.

Returns:
NameList of RulePool.AttributeRule objects.

isDeletableAttribute

public boolean isDeletableAttribute(Attr attribute)
Checks, whether given attribute is deletable from its element.

Parameters:
attribute - attribute to check.
Returns:
false if attribute is not deletable.

getAttributeRule

public AttributeRule getAttributeRule(Attr attribute)
Gets attribute rule for given attribute. It can be used to validate textual value of attribute.

Parameters:
attribute - return rule for this attribute.
Returns:
rule for this attribute.

isAnyStringInsertable

public boolean isAnyStringInsertable(sk.baka.ikslibs.ptr.DOMPoint ip)

Checks, if there can be any string inserted into given point. Must be used only for element, that contains some elements - if true, then any string can be inserted at selected position, if false, then no string can be inserted at all.

When element doesn't contain no child element, then getValueRule should be used: it returns more useful rule.

Parameters:
ip - insert point, where we want to insert some text. ip.pos must be equal to zero.
Returns:
true, if there can be inserted any string, false otherwise.

getValueRule

public IValueRule getValueRule()
Gets text acceptor, that checks valid text values for given element. Result applies only to textual content of element, that doesn't contain a child element(s). It applies to whole textual content - it may be multiple Text and CData nodes.

Returns:
text acceptor. If it was called on element with one or more child elements, returns null.

isAcceptable

public String isAcceptable(sk.baka.ikslibs.ptr.DomPointer ptr,
                           boolean create,
                           String newValue)
Checks whether the new text value is acceptable. This method can be used ONLY if the current element does not contain other elements. If new value is acceptable then null is returned, otherwise an error string is given.

Parameters:
ptr - points to text/cdata node whose text value has to be modified, or to a place where text/cdata node is about to be created.
create - if true then new text/cdata node is about to be created at specified pointer. If false then the node where ptr points will be modified.
newValue - the new text value.
Returns:
null if new element content will be accepted, or non- null error string if new value is rejected.

toString

public String toString()
Overrides:
toString in class Object

areElementsDeletable

public List<? extends Element> areElementsDeletable(Set<? extends Element> elements)
Checks whether given elements are deletable. These elements must be children of context element. If all these elements can be safely deleted then function returns non-null reference to a list of elements, that must be deleted aswell. If null is returned then given elements are not deletable.

Parameters:
elements - set of elements that are to be deleted.
Returns:
list of elements that must be deleted aswell. The list may be empty. None of the elements contained in result list are contained in the elements aswell. If null is returned then given elements cannot be deleted.

getEnclosingElements

public INameList<NewElementRule> getEnclosingElements(sk.baka.ikslibs.ptr.DOMPoint start,
                                                      sk.baka.ikslibs.ptr.DOMPoint end)
Computes and returns an one-sized insertlist of elements, that can enclose given nodeset.

Parameters:
start - the start of the nodeset. It must point before the end insertpoint.
end - the end of the nodeset.
Returns:
insertlist with one item. The item denotes an element, that can replace given content and contain this content as its children. If null is returned then no such element is suitable.

isDeclosable

public boolean isDeclosable(Element e)
Checks if given element is declosable - if the contents of given element can replace the element.

Parameters:
e - the element to declose
Returns:
true if e is declosable, false otherwise.

isInsertable

public boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip,
                            String entityName)
Checks if the entity is insertable at the specified position.

Parameters:
ip - the insertpoint where the entity should be inserted.
entityName - the name of the entity
Returns:
true if the entity is insertable, false otherwise.

isInsertable

public boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip,
                            DocumentFragment frag)
Checks if all nodes from the document fragment are insertable t the specified position.

Parameters:
ip - the insertpoint where the nodes should be inserted.
frag - the document fragment containing the nodes
Returns:
true if the entity is insertable, false otherwise.

isDeletable

public boolean isDeletable(EntityReference entity)
Checks if given entity node is removable.

Parameters:
entity - the entity node, it must be a descendant of this element.
Returns:
true if the entity is deletable, false otherwise.

isDeletable

public boolean isDeletable(sk.baka.ikslibs.ptr.DOMPoint start,
                           sk.baka.ikslibs.ptr.DOMPoint end)
Checks if given node interval is removable.

Parameters:
start - the start of the interval
end - the end of the interval
Returns:
true if the entity is deletable, false otherwise.


Copyright © 2003-2006 null. All Rights Reserved.