org.activemath.omdocjdom
Class OJUtilities

java.lang.Object
  extended by org.activemath.omdocjdom.OJUtilities
All Implemented Interfaces:
Serializable

public class OJUtilities
extends Object
implements Serializable

See Also:
Serialized Form

Nested Class Summary
static class OJUtilities.NameAndNamespace
          A simple class to contain a record of a name and a namespace.
 
Method Summary
static void addItemSeparator(org.jdom.Element element)
           
static org.jdom.Element duplicateElementWithoutKids(org.jdom.Element elt)
          Creates a clone of the element (with namespace, names, and attributes) without copying the kids.
static OJElement duplicateElementWithoutKids(OJElement elt)
          Creates a clone of the element (with namespace, names, and attributes) without copying the kids.
static OJElement findElementWithLangOrDefauit(Iterator eltsIt, String prefLang)
          A utility method to scan through the list and find the first element whose xml:lang attribute is the given language or that has no language.
static File getDocumentsFile(OJElement elt)
          Returns the file associated to the document of the elementif there is anything such (i.e there can be no document or no file for the document.
static Transformer getXmlOutputterTransformer()
           
static boolean hasText(org.jdom.Element elt, String s)
          Searches through all the descendent text-nodes of the element if the given string exists.
static boolean isConceptName(String s)
          Deprecated. Please use, in the future, the ActiveMathConstants class.
static boolean isItemName(String s)
          Deprecated. please use OJConstants.isItemName(java.lang.String)
static boolean isOneOfThese(String s, String[] list)
          Checks if the string s is String.equals(java.lang.Object) to this one.
static void printElementWithAtttributes(org.jdom.Element element, PrintStream out)
          Does the same thing as printElementWithAtttributes(org.jdom.Element, java.io.PrintWriter).
static void printElementWithAtttributes(org.jdom.Element element, PrintWriter out)
          Simply prints the "first line" of the element without the kids or closing tag (with namespaces omitted !)
static String relativizePath(String absolutePath, String basePath)
           
static void removeAttributes(OJElement elt, OJUtilities.NameAndNamespace[] nns)
          Walks through all the children of the given element and remove any existing "mid" attribute.
static void removeExtradataMetadataKids(OJElement elt, OJUtilities.NameAndNamespace[] nns)
          A recursive method to remove all the elements with given name from the metadata/extradata children of the given element or go down along the children of this element.
static OJElement replaceXrefs(OJElement elt, Map table)
          Walks around all the children of the element to check weather there is an OMOBJ xref attribute and replace it with the content it's pointing to.
static boolean stringEquals(String a, String b)
          A utility method to check the equality of two string variables including if they are both null.
static OJSAXBuilder.LocationInfo tryToGetLocationInfo(OJElement elt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

stringEquals

public static final boolean stringEquals(String a,
                                         String b)
A utility method to check the equality of two string variables including if they are both null.


findElementWithLangOrDefauit

public static final OJElement findElementWithLangOrDefauit(Iterator eltsIt,
                                                           String prefLang)
A utility method to scan through the list and find the first element whose xml:lang attribute is the given language or that has no language.

Parameters:
eltsIt - an iterator to be consumed by the search, all elements returned are supposed to be of type Element
prefLang - the preferred language
Returns:
the first element that matched or null if no suitable element found.s

isItemName

public static final boolean isItemName(String s)
Deprecated. please use OJConstants.isItemName(java.lang.String)

Checks if the string s is part of the OJConstants.ITEM_NAMES


isConceptName

public static final boolean isConceptName(String s)
Deprecated. Please use, in the future, the ActiveMathConstants class.


isOneOfThese

public static final boolean isOneOfThese(String s,
                                         String[] list)
Checks if the string s is String.equals(java.lang.Object) to this one.


printElementWithAtttributes

public static final void printElementWithAtttributes(org.jdom.Element element,
                                                     PrintWriter out)
Simply prints the "first line" of the element without the kids or closing tag (with namespaces omitted !)


printElementWithAtttributes

public static final void printElementWithAtttributes(org.jdom.Element element,
                                                     PrintStream out)
Does the same thing as printElementWithAtttributes(org.jdom.Element, java.io.PrintWriter).


getDocumentsFile

public static final File getDocumentsFile(OJElement elt)
Returns the file associated to the document of the elementif there is anything such (i.e there can be no document or no file for the document.


duplicateElementWithoutKids

public static final org.jdom.Element duplicateElementWithoutKids(org.jdom.Element elt)
Creates a clone of the element (with namespace, names, and attributes) without copying the kids. Used in OmdocJdomMBase.getChildren(org.activemath.abstractcontent.MBaseID, java.lang.String).


duplicateElementWithoutKids

public static final OJElement duplicateElementWithoutKids(OJElement elt)
Creates a clone of the element (with namespace, names, and attributes) without copying the kids. Used in OmdocJdomMBase.getChildren(org.activemath.abstractcontent.MBaseID, java.lang.String).


hasText

public static final boolean hasText(org.jdom.Element elt,
                                    String s)
Searches through all the descendent text-nodes of the element if the given string exists. This is a rather expensive method, a much better way would be to gather all text somewhere for one search. A way better even, would be an index...


replaceXrefs

public static OJElement replaceXrefs(OJElement elt,
                                     Map table)
Walks around all the children of the element to check weather there is an OMOBJ xref attribute and replace it with the content it's pointing to.

Parameters:
elt - the element that needs to be walked
table - the table to find the xref.
Returns:
a deep clone of the object, outside the strings

removeExtradataMetadataKids

public static void removeExtradataMetadataKids(OJElement elt,
                                               OJUtilities.NameAndNamespace[] nns)
A recursive method to remove all the elements with given name from the metadata/extradata children of the given element or go down along the children of this element. This search process stops at OJItem elements from where it makes the remove explict.

Parameters:
elt - the element to start from
nns - an array of OJUtilities.NameAndNamespace pairs to match and remove

removeAttributes

public static void removeAttributes(OJElement elt,
                                    OJUtilities.NameAndNamespace[] nns)
Walks through all the children of the given element and remove any existing "mid" attribute. This method is here to help authors whose OMdocs should never contain "mid" attributes.


addItemSeparator

public static void addItemSeparator(org.jdom.Element element)

relativizePath

public static String relativizePath(String absolutePath,
                                    String basePath)

tryToGetLocationInfo

public static OJSAXBuilder.LocationInfo tryToGetLocationInfo(OJElement elt)

getXmlOutputterTransformer

public static Transformer getXmlOutputterTransformer()