sk.uniba.euromath.document
Class DocumentModifyHelper

java.lang.Object
  extended by sk.uniba.euromath.document.DocumentModifyHelper

public final class DocumentModifyHelper
extends Object

Provides basic editing features, document modification driven by schema.

Author:
Martin Vysny, Tomáš Studva

Constructor Summary
DocumentModifyHelper(XMLAccess xmlAccess)
          Constuctor.
 
Method Summary
 String canDecloseNodes(Element e)
          Test if element can be declosed.
 String canDeleteAttribute(Attr attr)
          Tests if given attribute can be deleted.
 String canDeleteElements(Set<Element> elements, Node parent)
          Tests if elements can bedelted
 String canEncloseNodes(DomPointer start, DomPointer end, INameList<NewElementRule> outElements)
          Tests if nodes can be enclosed.
 String canInsertComment(DomPointer pointer)
          Tests if comment can be inserted.
 String canInsertFragment(DomPointer ptr, DocumentFragment fragment)
          Tests if fragment can be inserted.
 String canInsertProcessingInstruction(DomPointer pointer)
          Tests if processing instruction can be inserted.
 String canInsertTextAt(DomPointer ptr, String string)
          Tests if text can be inserted.
 String checkInEntity(DomPointer ptr)
          Checks if given pointer points into entity.
 String checkInEntity(Node node)
          Checks if given node is in entity.
 boolean checkInEntity(Shell shell, DomPointer ptr)
          Checks if given pointer points into entity.
 boolean checkInEntity(Shell shell, Node node)
          Checks if given node is in entity.
 void decloseNodes(Shell parent, Element e)
          Manages the process of declosing the nodes - replaces given element with its contents.
 void deleteAttribute(Shell parent, Attr attr)
          Manages the process of deleting the attribute.
 void deleteElements(Shell shell, Set<Element> elements)
          Manages the process of deleting the elements.
 void deleteNode(Shell shell, Node node)
          Tries to delete a single node.
 void deleteReplaceText(Shell shell, DOMInterval cut, String replaceWith)
          Tries to delete text from specified location.
 void deleteTextNode(Shell shell, Node node)
          Deletes given text node by wizard.
 void encloseNodes(Shell parent, DomPointer start, DomPointer end)
          Manages the process of enclosing the nodes.
 List<QName> getDomQnames(DisplayableNameList dnl)
          Computes QNames of elements from DisplayableNameList.
 List<QName> getInsertableElementsQNames(DomPointer pointer)
          Computes list of names of elements, insertable at given pointer.
 List<String> getInsertableEntities(Shell parent, DomPointer ptr)
          Computes insertable entities.
 void insertComment(Shell shell, DomPointer pointer)
          Inserts processing instruction at pointer.
 void insertComment(String text, Shell shell, DomPointer pointer)
          Inserts comment with text text at pointer.
 void insertEntity(Shell parent, DomPointer ptr)
          Manages the process of inserting an entity into selected position by dialog.
 void insertEntity(String entityName, DomPointer ptr)
          Inserts entity to given position.
 void insertFragment(Shell shell, DomPointer ptr, DocumentFragment fragment)
          Tries to insert given document fragment into given position.
 void insertNewAttribute(Shell parent, Element e)
          Manages the process of inserting a new attribute into given element by wizard.
 void insertProcessingInstruction(Shell shell, DomPointer pointer)
          Inserts processing instruction at pointer.
 void insertTextAt(Shell shell, DomPointer ptr, String string, short type)
          Tries to insert text at specified location.
 void insertTextNode(Shell shell, DomPointer point, short nodeType)
          Inserts text to given point.
 void modifyAttribute(Shell parent, Attr attr)
          Manages the process of modifying the attribute value by wizard.
 void modifyComment(Shell shell, Comment comment)
          Modifies comment node by dialog.
 void modifyProcessingInstruction(Shell shell, ProcessingInstruction pi)
          Modifies processing instruction node by dialog.
 void modifyTextNode(Shell shell, Node node)
          Modifies text of node by dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentModifyHelper

public DocumentModifyHelper(XMLAccess xmlAccess)
Constuctor.

Parameters:
xmlAccess - the document instance.
Method Detail

insertNewAttribute

public void insertNewAttribute(Shell parent,
                               Element e)
                        throws ExportException
Manages the process of inserting a new attribute into given element by wizard.

Parameters:
parent - parent window. Should not be null.
e - the element where to insert new attribute.
Throws:
ExportException - when document modification finalization fails.

modifyAttribute

public void modifyAttribute(Shell parent,
                            Attr attr)
                     throws ExportException
Manages the process of modifying the attribute value by wizard.

Parameters:
parent - parent window. Should not be null.
attr - the attribute whose value has to be modified.
Throws:
ExportException - when document modification finalization fails.

canDeleteAttribute

public String canDeleteAttribute(Attr attr)
Tests if given attribute can be deleted.

Parameters:
tested - attribute
Returns:
null if can be deleted, otherwise error message

deleteAttribute

public void deleteAttribute(Shell parent,
                            Attr attr)
                     throws ExportException
Manages the process of deleting the attribute.

Parameters:
parent - parent window. Should not be null.
attr - the attribute which has to be deleted.
Throws:
ExportException - when document modification finalization fails.

canDeleteElements

public String canDeleteElements(Set<Element> elements,
                                Node parent)
Tests if elements can bedelted

Parameters:
elements - to test
parent - - output argument, method computes common parent of elements and stores it in parent
Returns:
null if can be deleted, otherwise error message

deleteElements

public void deleteElements(Shell shell,
                           Set<Element> elements)
                    throws ExportException
Manages the process of deleting the elements. All elements must have the same parent.

Parameters:
shell - parent window. Should not be null.
elements - set of Element s that must be deleted.
Throws:
ExportException - when document modification finalization fails.

canEncloseNodes

public String canEncloseNodes(DomPointer start,
                              DomPointer end,
                              INameList<NewElementRule> outElements)
Tests if nodes can be enclosed.

Parameters:
start - start of the interval. Must point before the end parameter.
end - end of the interval.
outElements - - output argument, method computes elements that are allowed by schema to enclose interval
Returns:
null if can be enclosed, otherwise error message

encloseNodes

public void encloseNodes(Shell parent,
                         DomPointer start,
                         DomPointer end)
                  throws ExportException
Manages the process of enclosing the nodes. All nodes must have the same parent. Both pointers may point inside a text.

Parameters:
start - start of the interval. Must point before the end parameter.
end - end of the interval.
parent - parent window. Should not be null.
Throws:
ExportException - when document modification finalization fails.

canDecloseNodes

public String canDecloseNodes(Element e)
Test if element can be declosed.

Parameters:
e - element to declose
Returns:
null if can be declosed, otherwise error message

decloseNodes

public void decloseNodes(Shell parent,
                         Element e)
                  throws ExportException
Manages the process of declosing the nodes - replaces given element with its contents.

Parameters:
parent - parent window. Should not be null.
e - the element, that shall be replaced by its children if the declosing is allowed.
Throws:
ExportException - when document modification finalization fails.

canInsertProcessingInstruction

public String canInsertProcessingInstruction(DomPointer pointer)
Tests if processing instruction can be inserted.

Parameters:
pointer -
Returns:
null if can be inserted, otherwise error message

insertProcessingInstruction

public void insertProcessingInstruction(Shell shell,
                                        DomPointer pointer)
                                 throws ExportException
Inserts processing instruction at pointer.

Parameters:
shell - parent window. !!! Cannot be null.
pointer - dom pointer where to insert
Throws:
ExportException

modifyProcessingInstruction

public void modifyProcessingInstruction(Shell shell,
                                        ProcessingInstruction pi)
                                 throws ExportException
Modifies processing instruction node by dialog.

Parameters:
shell - parent window. !!! Cannot be null.
node - processing instruction node to modify
Throws:
ExportException

canInsertComment

public String canInsertComment(DomPointer pointer)
Tests if comment can be inserted.

Parameters:
pointer -
Returns:
null if can be inserted, otherwise error message

insertComment

public void insertComment(Shell shell,
                          DomPointer pointer)
                   throws ExportException
Inserts processing instruction at pointer.

Parameters:
shell - parent window. !!! Cannot be null.
pointer - dom pointer where to insert
Throws:
ExportException

insertComment

public void insertComment(String text,
                          Shell shell,
                          DomPointer pointer)
                   throws ExportException
Inserts comment with text text at pointer.

Parameters:
text - text of comment to insert
shell - parent window. !!! Cannot be null.
pointer - dom pointer where to insert
Throws:
ExportException

modifyComment

public void modifyComment(Shell shell,
                          Comment comment)
                   throws ExportException
Modifies comment node by dialog.

Parameters:
shell - parent window. !!! Cannot be null.
node - comment node to modify
Throws:
ExportException

insertEntity

public void insertEntity(Shell parent,
                         DomPointer ptr)
                  throws ExportException
Manages the process of inserting an entity into selected position by dialog.

Parameters:
ptr - the desired place.
parent - parent window. Should not be null.
Throws:
ExportException - when document modification finalization fails.

insertEntity

public void insertEntity(String entityName,
                         DomPointer ptr)
                  throws ExportException
Inserts entity to given position.

Parameters:
entityName - the entity name.
ptr - the insert point.
Throws:
ExportException - if document modification finalization fails.

getInsertableEntities

public List<String> getInsertableEntities(Shell parent,
                                          DomPointer ptr)
Computes insertable entities. Shows various warning dialogs if no entities can be found etc.

Parameters:
ptr - the desired place.
parent - parent window. Can be null.
Returns:
entity names that are insertable at given pointer. May return null if no entities are suitable.

getInsertableElementsQNames

public List<QName> getInsertableElementsQNames(DomPointer pointer)
Computes list of names of elements, insertable at given pointer.

Parameters:
pointer -
Returns:
ordered list of qnames.

getDomQnames

public List<QName> getDomQnames(DisplayableNameList dnl)
Computes QNames of elements from DisplayableNameList.

Parameters:
dnl - the list. If null then empty list is returned.
Returns:
list of qnames with best prefixes.

insertTextNode

public void insertTextNode(Shell shell,
                           DomPointer point,
                           short nodeType)
                    throws ExportException
Inserts text to given point. Displays a dialog allowing user to enter text being inserted. Only valid text is allowed.

Parameters:
point - insert the text here.
shell - parent window. !!! Cannot be null.
nodeType - the type of node to insert. May be Node.CDATA_SECTION_NODE or Node.TEXT_NODE only.
Throws:
ExportException

modifyTextNode

public void modifyTextNode(Shell shell,
                           Node node)
                    throws ExportException
Modifies text of node by dialog.

Parameters:
node - must be text node
shell - parent window. !!!Cannot be null.
Throws:
ExportException - if document fails to transform.

checkInEntity

public boolean checkInEntity(Shell shell,
                             Node node)
Checks if given node is in entity. If yes then error dialog is shown.

Parameters:
shell - parent, should not be null.
node - node to check
Returns:
true if node is in entity, false otherwise.

checkInEntity

public boolean checkInEntity(Shell shell,
                             DomPointer ptr)
Checks if given pointer points into entity. If yes then error dialog is shown.

Parameters:
shell - parent, should not be null.
ptr - the pointer to check
Returns:
true if the pointer points into an entity, false otherwise.

checkInEntity

public String checkInEntity(Node node)
Checks if given node is in entity. If yes then error message is returned.

Parameters:
node - node to check
Returns:
not null if node is in entity, null otherwise.

checkInEntity

public String checkInEntity(DomPointer ptr)
Checks if given pointer points into entity. If yes then error message is returned.

Parameters:
ptr - the pointer to check
Returns:
not null if node is in entity, null otherwise.

deleteTextNode

public void deleteTextNode(Shell shell,
                           Node node)
                    throws ExportException
Deletes given text node by wizard.

Parameters:
shell - parent window, should not be null.
node - node to delete, must not be null. May be text, cdata or pure-text entity only.
Throws:
ExportException - if shit happens.

deleteNode

public void deleteNode(Shell shell,
                       Node node)
                throws ExportException
Tries to delete a single node.

Parameters:
shell - parent shell, should not be null.
node - node to delete.
Throws:
ExportException - if shit happens.

canInsertFragment

public String canInsertFragment(DomPointer ptr,
                                DocumentFragment fragment)
Tests if fragment can be inserted.

Parameters:
ptr - place of insertion
fragment - to insert
Returns:
null if can be inserted, otherwise error message

insertFragment

public void insertFragment(Shell shell,
                           DomPointer ptr,
                           DocumentFragment fragment)
                    throws ExportException
Tries to insert given document fragment into given position.

Parameters:
shell - parent shell, should not be null.
ptr - the pointer where the fragment will be inserted. Must not be null.
fragment - the fragment to insert. A clone of this fragment is inserted hence the fragment is not modified by this method. Must not be null.
Throws:
ExportException

canInsertTextAt

public String canInsertTextAt(DomPointer ptr,
                              String string)
Tests if text can be inserted.

Parameters:
ptr - place of insertion
string - to insert
Returns:
null if can be inserted, otherwise error message

insertTextAt

public void insertTextAt(Shell shell,
                         DomPointer ptr,
                         String string,
                         short type)
                  throws ExportException
Tries to insert text at specified location.

Parameters:
shell - parent shell, should not be null.
ptr - the pointer where the fragment will be inserted. Must not be null.
string - a string to insert.
type - the type of node, Node.TEXT_NODE or Node.CDATA_SECTION_NODE.
Throws:
ExportException

deleteReplaceText

public void deleteReplaceText(Shell shell,
                              DOMInterval cut,
                              String replaceWith)
                       throws ExportException
Tries to delete text from specified location.

Parameters:
shell - parent shell, should not be null.
cut - the interval denoting text being deleted or replaced. Must not be null. Caller must ensure that there are no elements covered by this interval. between the two pointers.
replaceWith - a string that will replace given interval, may be null.
Throws:
ExportException


Copyright © 2003-2006 null. All Rights Reserved.