[Primitives for XML support (continued).
cadmium@x9c.fr**20071022205945] {
adddir ./src/fr/x9c/cadmium/primitives/cadmiumxml
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/Documents.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/Documents.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.validation.Schema;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Entity;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Notation;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+import fr.x9c.cadmium.kernel.Block;
+import fr.x9c.cadmium.kernel.Channel;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for document manipulation.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class Documents {
+
+ /**
+ * No instance of this class.
+ */
+ private Documents() {
+ } // end empty constructor
+
+ /**
+ * Returns the root element of the document.
+ * @param ctxt context
+ * @param doc document
+ * @return the root element of the passed document
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document_element(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ return Cadmium.createObject(d.getDocumentElement());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document_element(CodeRunner, Value)'
+
+ /**
+ * Returns the document encoding.
+ * @param ctxt context
+ * @param doc document
+ * @return the encoding used for the passed document
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_xml_encoding(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ final String res = d.getXmlEncoding();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_xml_encoding(CodeRunner, Value)'
+
+ /**
+ * Sets the 'scrict-error-checking' property for passed document.
+ * @param ctxt context
+ * @param doc document
+ * @param value value for 'scrict-error-checking' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_strict_error_checking(final CodeRunner ctxt,
+ final Value doc,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ d.setStrictErrorChecking(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_strict_error_checking(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'scrict-error-checking' property for passed document.
+ * @param ctxt context
+ * @param doc document
+ * @return value for 'scrict-error-checking' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_is_strict_error_checking(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ return d.getStrictErrorChecking() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_is_strict_error_checking(CodeRunner, Value)'
+
+ /**
+ * Sets the 'xml-standlone' property for a document.
+ * @param ctxt context
+ * @param doc document
+ * @param value value for 'xml-standlone' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_xml_standalone(final CodeRunner ctxt,
+ final Value doc,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ d.setXmlStandalone(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_xml_standalone(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'xml-standlone' property for passed document.
+ * @param ctxt context
+ * @param doc document
+ * @return value for 'xml-standlone' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_is_xml_standalone(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ return d.getXmlStandalone() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_is_xml_standalone(CodeRunner, Value)'
+
+ /**
+ * Sets the 'xml-version' property for a document.
+ * @param ctxt context
+ * @param doc document
+ * @param value value for 'xml-version' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_xml_version(final CodeRunner ctxt,
+ final Value doc,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ d.setXmlVersion(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_xml_version(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'xml-version' property for passed document.
+ * @param ctxt context
+ * @param doc document
+ * @return value for 'xml-version' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_xml_version(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ final String res = d.getXmlVersion();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_xml_version(CodeRunner, Value)'
+
+ /**
+ * Normalizes a document.
+ * @param ctxt context
+ * @param doc document to normalize
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_normalize_document(final CodeRunner ctxt,
+ final Value doc)
+ throws Fail.Exception {
+ try {
+ final Document d = (Document) doc.asBlock().asCustom();
+ d.normalize();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_normalize_document(CodeRunner, Value)'
+
+ /**
+ * Returns the parent of the passed attribute.
+ * @param ctxt context
+ * @param attr attribute
+ * @return the parent of the passed attribute
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attr_parent(final CodeRunner ctxt,
+ final Value attr)
+ throws Fail.Exception {
+ try {
+ final Attr a = (Attr) attr.asBlock().asCustom();
+ return Cadmium.createObject(a.getOwnerElement());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attr_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the name of the passed attribute.
+ * @param ctxt context
+ * @param attr attribute
+ * @return the name of the passed attribute
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attr_name(final CodeRunner ctxt,
+ final Value attr)
+ throws Fail.Exception {
+ try {
+ final Attr a = (Attr) attr.asBlock().asCustom();
+ final String res = a.getName();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attr_name(CodeRunner, Value)'
+
+ /**
+ * Returns the value of the passed attribute.
+ * @param ctxt context
+ * @param attr attribute
+ * @return the value of the passed attribute
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attr_value(final CodeRunner ctxt,
+ final Value attr)
+ throws Fail.Exception {
+ try {
+ final Attr a = (Attr) attr.asBlock().asCustom();
+ final String res = a.getValue();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attr_value(CodeRunner, Value)'
+
+ /**
+ * Changes the value of the passed attribute.
+ * @param ctxt context
+ * @param attr attribute
+ * @param value new value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_attr_value(final CodeRunner ctxt,
+ final Value attr,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Attr a = (Attr) attr.asBlock().asCustom();
+ a.setValue(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_attr_value(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the parent of the passed cdata.
+ * @param ctxt context
+ * @param cdata cdata
+ * @return the parent of the passed cdata
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_cdata_parent(final CodeRunner ctxt,
+ final Value cdata)
+ throws Fail.Exception {
+ try {
+ final CDATASection c = (CDATASection) cdata.asBlock().asCustom();
+ return createNode(c.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_cdata_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the data of the passed cdata.
+ * @param ctxt context
+ * @param cdata cdata
+ * @return the data of the passed cdata
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_cdata(final CodeRunner ctxt,
+ final Value cdata)
+ throws Fail.Exception {
+ try {
+ final CDATASection c = (CDATASection) cdata.asBlock().asCustom();
+ final String res = c.getData();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_cdata(CodeRunner, Value)'
+
+ /**
+ * Changes the data of the passed cdata.
+ * @param ctxt context
+ * @param cdata cdata
+ * @param value new data
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_cdata(final CodeRunner ctxt,
+ final Value cdata,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final CDATASection c = (CDATASection) cdata.asBlock().asCustom();
+ c.setData(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_cdata(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the parent of the passed comment.
+ * @param ctxt context
+ * @param comment comment
+ * @return the parent of the passed comment
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_comment_parent(final CodeRunner ctxt,
+ final Value comment)
+ throws Fail.Exception {
+ try {
+ final Comment c = (Comment) comment.asBlock().asCustom();
+ return createNode(c.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_comment_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the data of the passed comment.
+ * @param ctxt context
+ * @param comment comment
+ * @return the data of the passed comment
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_comment(final CodeRunner ctxt,
+ final Value comment)
+ throws Fail.Exception {
+ try {
+ final Comment c = (Comment) comment.asBlock().asCustom();
+ final String res = c.getData();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_comment(CodeRunner, Value)'
+
+ /**
+ * Changes the data of the passed comment.
+ * @param ctxt context
+ * @param comment comment
+ * @param value new data
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_comment(final CodeRunner ctxt,
+ final Value comment,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Comment c = (Comment) comment.asBlock().asCustom();
+ c.setData(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_comment(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the parent of the passed document type.
+ * @param ctxt context
+ * @param doctype document type
+ * @return the parent of the passed document type
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document_type_parent(final CodeRunner ctxt,
+ final Value doctype)
+ throws Fail.Exception {
+ try {
+ final DocumentType dt = (DocumentType) doctype.asBlock().asCustom();
+ return createNode(dt.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document_type_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the name of the passed document type.
+ * @param ctxt context
+ * @param doctype document type
+ * @return the name of the passed document type
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document_type_name(final CodeRunner ctxt,
+ final Value doctype)
+ throws Fail.Exception {
+ try {
+ final DocumentType dt = (DocumentType) doctype.asBlock().asCustom();
+ final String res = dt.getName();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document_type_name(CodeRunner, Value)'
+
+ /**
+ * Returns the public ID of the passed document type.
+ * @param ctxt context
+ * @param doctype document type
+ * @return the public ID of the passed document type
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document_type_public_id(final CodeRunner ctxt,
+ final Value doctype)
+ throws Fail.Exception {
+ try {
+ final DocumentType dt = (DocumentType) doctype.asBlock().asCustom();
+ final String res = dt.getPublicId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document_type_public_id(CodeRunner, Value)'
+
+ /**
+ * Returns the system ID of the passed document type.
+ * @param ctxt context
+ * @param doctype document type
+ * @return the system ID of the passed document type
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document_type_system_id(final CodeRunner ctxt,
+ final Value doctype)
+ throws Fail.Exception {
+ try {
+ final DocumentType dt = (DocumentType) doctype.asBlock().asCustom();
+ final String res = dt.getSystemId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document_type_system_id(CodeRunner, Value)'
+
+ /**
+ * Returns the parent of the passed element.
+ * @param ctxt context
+ * @param element element
+ * @return the parent of the passed element
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_element_parent(final CodeRunner ctxt,
+ final Value element)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ return createNode(e.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_element_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the value of an attribute.
+ * @param ctxt context
+ * @param element to get attribute from
+ * @param name attribute
+ * @return value of given attribute for passed element
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attribute(final CodeRunner ctxt,
+ final Value element,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ final String res = e.getAttribute(name.asBlock().asString());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attribute(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the value of an attribute.
+ * @param ctxt context
+ * @param element to get attribute from
+ * @param ns namespace
+ * @param name attribute
+ * @return value of given attribute for passed element
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attribute_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ final String res = e.getAttributeNS(ns.asBlock().asString(),
+ name.asBlock().asString());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attribute_ns(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Returns the attribute.
+ * @param ctxt context
+ * @param element to get attribute from
+ * @param name attribute
+ * @return given attribute for passed element
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attribute_node(final CodeRunner ctxt,
+ final Value element,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ return Cadmium.createObject(e.getAttributeNode(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attribute_node(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the attribute.
+ * @param ctxt context
+ * @param element to get attribute from
+ * @param ns namespace
+ * @param name attribute
+ * @return given attribute for passed element
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_attribute_node_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ return Cadmium.createObject(e.getAttributeNodeNS(ns.asBlock().asString(),
+ name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_attribute_node_ns(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Returns child elements having a given tag.
+ * @param ctxt context
+ * @param element to get children from
+ * @param name tag name
+ * @return the child elements with given tag name
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_elements_by_tag_name(final CodeRunner ctxt,
+ final Value element,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ final NodeList l = e.getElementsByTagName(name.asBlock().asString());
+ Value res = Value.EMPTY_LIST;
+ for (int i = l.getLength() - 1; i >= 0; i--) {
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ Cadmium.createObject(l.item(i)),
+ res);
+ res = Value.createFromBlock(b);
+ } // end for
+ return res;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_elements_by_tag_name(CodeRunner, Value, Value)'
+
+ /**
+ * Returns child elements having a given tag.
+ * @param ctxt context
+ * @param element to get children from
+ * @param ns namespace
+ * @param name tag name
+ * @return the child elements with given tag name
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_elements_by_tag_name_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ final NodeList l = e.getElementsByTagNameNS(ns.asBlock().asString(),
+ name.asBlock().asString());
+ Value res = Value.EMPTY_LIST;
+ for (int i = l.getLength() - 1; i >= 0; i--) {
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ Cadmium.createObject(l.item(i)),
+ res);
+ res = Value.createFromBlock(b);
+ } // end for
+ return res;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_elements_by_tag_name_ns(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Returns the tag name of the passed element.
+ * @param ctxt context
+ * @param element element
+ * @return the tag name of the passed element.
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_tag_name(final CodeRunner ctxt,
+ final Value element)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ final String res = e.getTagName();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_tag_name(CodeRunner, Value)'
+
+ /**
+ * Tests if an element has a given attribute.
+ * @param ctxt context
+ * @param element element
+ * @param name attribute name
+ * @return true if the passed element has an attribute of given name,
+ * false otherwise
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_has_attribute(final CodeRunner ctxt,
+ final Value element,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ return e.hasAttribute(name.asBlock().asString()) ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_has_attribute(CodeRunner, Value, Value)'
+
+ /**
+ * Tests if an element has a given attribute.
+ * @param ctxt context
+ * @param element element
+ * @param ns namespace
+ * @param name attribute name
+ * @return true if the passed element has an attribute of given name,
+ * false otherwise
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_has_attribute_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ return e.hasAttributeNS(ns.asBlock().asString(), name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_has_attribute_ns(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Removes an attribute from an element.
+ * @param ctxt context
+ * @param element element
+ * @param name attribute name
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_remove_attribute(final CodeRunner ctxt,
+ final Value element,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ e.removeAttribute(name.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_remove_attribute(CodeRunner, Value, Value)'
+
+ /**
+ * Removes an attribute from an element.
+ * @param ctxt context
+ * @param element element
+ * @param ns namespace
+ * @param name attribute name
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_remove_attribute_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ e.removeAttributeNS(ns.asBlock().asString(), name.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_remove_attribute_ns(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Removes an attribute from an element.
+ * @param ctxt context
+ * @param element element
+ * @param attr attribute to remove
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_remove_attribute_node(final CodeRunner ctxt,
+ final Value element,
+ final Value attr)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ e.removeAttributeNode((Attr) attr.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_remove_attribute_node(CodeRunner, Value, Value)'
+
+ /**
+ * Changes the value of an attribute for the passed element.
+ * @param ctxt context
+ * @param element element
+ * @param name attribute name
+ * @param value new attribute value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_attribute(final CodeRunner ctxt,
+ final Value element,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ e.setAttribute(name.asBlock().asString(), value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_attribute(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Changes the value of an attribute for the passed element.
+ * @param ctxt context
+ * @param element element
+ * @param ns namespace
+ * @param name attribute name
+ * @param value new attribute value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_attribute_ns(final CodeRunner ctxt,
+ final Value element,
+ final Value ns,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Element e = (Element) element.asBlock().asCustom();
+ e.setAttributeNS(ns.asBlock().asString(),
+ name.asBlock().asString(),
+ value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_attribute_ns(CodeRunner, Value, Value, Value, Value)'
+
+ /**
+ * Returns the parent of the passed entity.
+ * @param ctxt context
+ * @param entity entity
+ * @return the parent of the passed entity
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_entity_parent(final CodeRunner ctxt,
+ final Value entity)
+ throws Fail.Exception {
+ try {
+ final Entity e = (Entity) entity.asBlock().asCustom();
+ return Cadmium.createObject(e.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_entity_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the notation name of the passed entity.
+ * @param ctxt context
+ * @param entity entity
+ * @return the notation name of the passed entity
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_entity_notation_name(final CodeRunner ctxt,
+ final Value entity)
+ throws Fail.Exception {
+ try {
+ final Entity e = (Entity) entity.asBlock().asCustom();
+ final String res = e.getNotationName();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_entity_notation_name(CodeRunner, Value)'
+
+ /**
+ * Returns the public ID of the passed entity.
+ * @param ctxt context
+ * @param entity entity
+ * @return the public ID of the passed entity
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_entity_public_id(final CodeRunner ctxt,
+ final Value entity)
+ throws Fail.Exception {
+ try {
+ final Entity e = (Entity) entity.asBlock().asCustom();
+ final String res = e.getPublicId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_entity_public_id(CodeRunner, Value)'
+
+ /**
+ * Returns the system ID of the passed entity.
+ * @param ctxt context
+ * @param entity entity
+ * @return the system ID of the passed entity
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_entity_system_id(final CodeRunner ctxt,
+ final Value entity)
+ throws Fail.Exception {
+ try {
+ final Entity e = (Entity) entity.asBlock().asCustom();
+ final String res = e.getSystemId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_entity_system_id(CodeRunner, Value)'
+
+ /**
+ * Returns the parent of the passed notation.
+ * @param ctxt context
+ * @param notation notation
+ * @return the parent of the passed notation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_notation_parent(final CodeRunner ctxt,
+ final Value notation)
+ throws Fail.Exception {
+ try {
+ final Notation n = (Notation) notation.asBlock().asCustom();
+ return Cadmium.createObject(n.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_notation_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the public ID of the passed notation.
+ * @param ctxt context
+ * @param notation notation
+ * @return the public ID of the passed notation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_notation_public_id(final CodeRunner ctxt,
+ final Value notation)
+ throws Fail.Exception {
+ try {
+ final Notation n = (Notation) notation.asBlock().asCustom();
+ final String res = n.getPublicId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_notation_public_id(CodeRunner, Value)'
+
+ /**
+ * Returns the system ID of the passed notation.
+ * @param ctxt context
+ * @param notation notation
+ * @return the system ID of the passed notation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_notation_system_id(final CodeRunner ctxt,
+ final Value notation)
+ throws Fail.Exception {
+ try {
+ final Notation n = (Notation) notation.asBlock().asCustom();
+ final String res = n.getSystemId();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_notation_system_id(CodeRunner, Value)'
+
+ /**
+ * Returns the parent of the passed processing instruction.
+ * @param ctxt context
+ * @param pi processing instruction
+ * @return the parent of the passed processing instruction
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_processing_instruction_parent(final CodeRunner ctxt,
+ final Value pi)
+ throws Fail.Exception {
+ try {
+ final ProcessingInstruction p =
+ (ProcessingInstruction) pi.asBlock().asCustom();
+ return Cadmium.createObject(p.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_processing_instruction_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the target of the passed processing instruction.
+ * @param ctxt context
+ * @param pi processing instruction
+ * @return the target of the passed processing instruction
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_processing_instruction_target(final CodeRunner ctxt,
+ final Value pi)
+ throws Fail.Exception {
+ try {
+ final ProcessingInstruction p =
+ (ProcessingInstruction) pi.asBlock().asCustom();
+ final String res = p.getTarget();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_processing_instruction_target(CodeRunner, Value)'
+
+ /**
+ * Returns the data of the passed processing instruction.
+ * @param ctxt context
+ * @param pi processing instruction
+ * @return the data of the passed processing instruction
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_processing_instruction_data(final CodeRunner ctxt,
+ final Value pi)
+ throws Fail.Exception {
+ try {
+ final ProcessingInstruction p =
+ (ProcessingInstruction) pi.asBlock().asCustom();
+ final String res = p.getData();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_processing_instruction_data(CodeRunner, Value)'
+
+ /**
+ * Changes the data of the passed processing instruction.
+ * @param ctxt context
+ * @param pi processing instruction
+ * @param value new data
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_processing_instruction_data(final CodeRunner ctxt,
+ final Value pi,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final ProcessingInstruction p =
+ (ProcessingInstruction) pi.asBlock().asCustom();
+ p.setData(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_processing_instruction_data(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the parent of the passed text.
+ * @param ctxt context
+ * @param text text
+ * @return the parent of the passed text
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_text_parent(final CodeRunner ctxt,
+ final Value text)
+ throws Fail.Exception {
+ try {
+ final Text t = (Text) text.asBlock().asCustom();
+ return Cadmium.createObject(t.getParentNode());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_text_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the data of the passed texte.
+ * @param ctxt context
+ * @param text text
+ * @return the data of the passed text
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_text(final CodeRunner ctxt,
+ final Value text)
+ throws Fail.Exception {
+ try {
+ final Text t = (Text) text.asBlock().asCustom();
+ final String res = t.getData();
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_text(CodeRunner, Value)'
+
+ /**
+ * Changes the data of the passed text.
+ * @param ctxt context
+ * @param text text
+ * @param value new data
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_set_text(final CodeRunner ctxt,
+ final Value text,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Text t = (Text) text.asBlock().asCustom();
+ t.setData(value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_set_text(CodeRunner, Value, Value)'
+
+ /**
+ * Returns the parent of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the parent of the passed node
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_parent(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node res = n.getParentNode();
+ if (res != null) {
+ return createNode(res);
+ } else {
+ Fail.raiseNotFound();
+ return Value.UNIT; // never reached
+ } // end if/else
+ } catch (final Fail.Exception fe) {
+ throw fe;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_parent(CodeRunner, Value)'
+
+ /**
+ * Returns the enclosing document of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the enclosing document of the passed node
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_document(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ return Cadmium.createObject(n.getOwnerDocument());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_document(CodeRunner, Value)'
+
+ /**
+ * Adds an attribute child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param value attribute name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_attr_child(final CodeRunner ctxt,
+ final Value node,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createAttribute(value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_attr_child(CodeRunner, Value, Value)'
+
+ /**
+ * Adds an attribute child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param ns namespace
+ * @param value attribute name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_attr_ns_child(final CodeRunner ctxt,
+ final Value node,
+ final Value ns,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createAttributeNS(ns.asBlock().asString(),
+ value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_attr_ns_child(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds a cdata child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param value data
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_cdata_child(final CodeRunner ctxt,
+ final Value node,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createCDATASection(value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_cdata_child(CodeRunner, Value, Value)'
+
+ /**
+ * Adds a comment child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param value data
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_comment_child(final CodeRunner ctxt,
+ final Value node,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createComment(value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_comment_child(CodeRunner, Value, Value)'
+
+ /**
+ * Adds an element child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param value element tag
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_element_child(final CodeRunner ctxt,
+ final Value node,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createElement(value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_element_child(CodeRunner, Value, Value)'
+
+ /**
+ * Adds an element child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param ns namespace
+ * @param value element tag
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_element_ns_child(final CodeRunner ctxt,
+ final Value node,
+ final Value ns,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createElementNS(ns.asBlock().asString(),
+ value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_element_ns_child(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds an entity reference child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param value reference name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_append_entity_reference_child(final CodeRunner ctxt,
+ final Value node,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createEntityReference(value.asBlock().asString());
+ n.appendChild(c);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_append_entity_reference_child(CodeRunner, Value, Value)'
+
+ /**
+ * Adds an attribute child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param value attribute name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_attr_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createAttribute(value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_attr_child_before(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds an attribute child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param ns namespace
+ * @param value attribute name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_attr_ns_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value ns,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createAttributeNS(ns.asBlock().asString(),
+ value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_attr_ns_child_before(CodeRunner, Value, Value, Value, Value)'
+
+ /**
+ * Adds a cdata child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param value data
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_cdata_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createCDATASection(value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_cdata_child_before(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds a comment child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param value data
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_comment_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createComment(value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_comment_child_before(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds an element child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param value element tag
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_element_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createElement(value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_element_child_before(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Adds an element child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param ns namespace
+ * @param value element tag
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_element_ns_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value ns,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createElementNS(ns.asBlock().asString(),
+ value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_element_ns_child_before(CodeRunner, Value, Value, Value, Value)'
+
+ /**
+ * Adds an entity reference child to the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param before child to insert before
+ * @param value reference name
+ * @return the added child
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_insert_entity_reference_child_before(final CodeRunner ctxt,
+ final Value node,
+ final Value before,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node b = (Node) before.asBlock().get(0).asBlock().asCustom();
+ final Document d = n.getOwnerDocument();
+ final Node c = d.createEntityReference(value.asBlock().asString());
+ n.insertBefore(c, b);
+ return Cadmium.createObject(c);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_insert_entity_reference_child_before(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Returns the child nodes of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the child nodes of the passed node
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_child_nodes(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final NodeList l = n.getChildNodes();
+ Value res = Value.EMPTY_LIST;
+ for (int i = l.getLength() - 1; i >= 0; i--) {
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ createNode(l.item(i)),
+ res);
+ res = Value.createFromBlock(b);
+ } // end for
+ return res;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_child_nodes(CodeRunner, Value)'
+
+ /**
+ * Returns the first child of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the first child of the passed node
+ * @throws Fail.Exception raise Not_found if such a node does not exit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_first_child(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node res = n.getFirstChild();
+ if (res != null) {
+ return createNode(res);
+ } else {
+ Fail.raiseNotFound();
+ return Value.UNIT; // never reached
+ } // end if/else
+ } catch (final Fail.Exception fe) {
+ throw fe;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_first_child(CodeRunner, Value)'
+
+ /**
+ * Returns the last child of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the last child of the passed node
+ * @throws Fail.Exception raise Not_found if such a node does not exit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_last_child(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node res = n.getLastChild();
+ if (res != null) {
+ return createNode(res);
+ } else {
+ Fail.raiseNotFound();
+ return Value.UNIT; // never reached
+ } // end if/else
+ } catch (final Fail.Exception fe) {
+ throw fe;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_last_child(CodeRunner, Value)'
+
+ /**
+ * Returns the previous sibling of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the previous sibling of the passed node
+ * @throws Fail.Exception raise Not_found if such a node does not exit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_previous_sibling(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node res = n.getPreviousSibling();
+ if (res != null) {
+ return createNode(res);
+ } else {
+ Fail.raiseNotFound();
+ return Value.UNIT; // never reached
+ } // end if/else
+ } catch (final Fail.Exception fe) {
+ throw fe;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_previous_sibling(CodeRunner, Value)'
+
+ /**
+ * Returns the next sibling of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @return the next sibling of the passed node
+ * @throws Fail.Exception raise Not_found if such a node does not exit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_get_next_sibling(final CodeRunner ctxt,
+ final Value node)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node res = n.getNextSibling();
+ if (res != null) {
+ return createNode(res);
+ } else {
+ Fail.raiseNotFound();
+ return Value.UNIT; // never reached
+ } // end if/else
+ } catch (final Fail.Exception fe) {
+ throw fe;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_get_next_sibling(CodeRunner, Value)'
+
+ /**
+ * Removes a child of the passed node.
+ * @param ctxt context
+ * @param node node
+ * @param child child to remove
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_remove_child(final CodeRunner ctxt,
+ final Value node,
+ final Value child)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node c = (Node) child.asBlock().get(0).asBlock().asCustom();
+ n.removeChild(c);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_remove_child(CodeRunner, Value, Value)'
+
+ /**
+ * Replaces a node by another one.
+ * @param ctxt context
+ * @param node node
+ * @param newChild new child
+ * @param oldChild old child
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_document_replace_child(final CodeRunner ctxt,
+ final Value node,
+ final Value newChild,
+ final Value oldChild)
+ throws Fail.Exception {
+ try {
+ final Node n = (Node) node.asBlock().get(0).asBlock().asCustom();
+ final Node nc = (Node) newChild.asBlock().get(0).asBlock().asCustom();
+ final Node oc = (Node) oldChild.asBlock().get(0).asBlock().asCustom();
+ n.replaceChild(nc, oc);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_document_replace_child(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Constructs a factory.
+ * @param ctxt context
+ * @param unit ignored
+ * @return a new factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_make(final CodeRunner ctxt,
+ final Value unit)
+ throws Fail.Exception {
+ try {
+ return Cadmium.createObject(DocumentBuilderFactory.newInstance());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of an attribute.
+ * @param ctxt context
+ * @param fact factory
+ * @param name attribute name
+ * @param value attribute value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_attribute(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setAttribute(name.asBlock().asString(), value.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_attribute(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of an attribute.
+ * @param ctxt context
+ * @param fact factory
+ * @param name attribute name
+ * @return value of passed attribute
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_get_attribute(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.getAttribute(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_get_attribute(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @param value feature value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setFeature(name.asBlock().asString(), value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_feature(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @return value of passed feature
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_get_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.getFeature(name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_get_feature(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the schema for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param schema schema to use
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_schema(final CodeRunner ctxt,
+ final Value fact,
+ final Value schema)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setSchema((Schema) schema.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_schema(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the schema for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return schema used by constructed parsers
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_get_schema(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.getSchema());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_get_schema(CodeRunner, Value)'
+
+ /**
+ * Sets the 'coalescing' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'coalescing' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_coalescing(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setCoalescing(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_coalescing(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'coalescing' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'coalesing' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_coalescing(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isCoalescing() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_coalescing(CodeRunner, Value)'
+
+ /**
+ * Sets the 'expand-entity-references' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'expand-entity-references' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_expand_entity_references(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setExpandEntityReferences(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_expand_entity_references(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'expand-entity-reference' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'expand-entity-references' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_expand_entity_references(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isExpandEntityReferences() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_expand_entity_references(CodeRunner, Value)'
+
+ /**
+ * Sets the 'ignoring-comments' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'ignoring-comments' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_ignoring_comments(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setIgnoringComments(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_ignoring_comments(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'ignoring-comments' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'ignoring-comments' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_ignoring_comments(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isIgnoringComments() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_ignoring_comments(CodeRunner, Value)'
+
+ /**
+ * Sets the 'ignoring-element-content-whitespace' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'ignoring-element-content-whitespace' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_ignoring_element_content_whitespace(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setIgnoringElementContentWhitespace(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_ignoring_element_content_whitespace(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'ignoring-element-conent-whitespace' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'ignoring-element-content-whitespace' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_ignoring_element_content_whitespace(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isIgnoringElementContentWhitespace() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_ignoring_element_content_whitespace(CodeRunner, Value)'
+
+ /**
+ * Sets the 'namespace-aware' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'namespace-aware' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_namespace_aware(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setNamespaceAware(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_namespace_aware(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'namespace-aware' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'namespace-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_namespace_aware(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isNamespaceAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_namespace_aware(CodeRunner, Value)'
+
+ /**
+ * Sets the 'validating' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'validating' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_validating(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setValidating(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_validating(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'validating' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'validating' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_validating(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isValidating() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_validating(CodeRunner, Value)'
+
+ /**
+ * Sets the 'xinclude-aware' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'xinclude-aware' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_set_xinclude_aware(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ f.setXIncludeAware(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_set_xinclude_aware(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'xinclude-aware' property for constructed DOM parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'xinclude-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentfactory_is_xinclude_aware(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return f.isXIncludeAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentfactory_is_xinclude_aware(CodeRunner, Value)'
+
+ /**
+ * Constructs a builder from a factory.
+ * @param ctxt context
+ * @param fact factory
+ * @return a new builder
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_make(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilderFactory f =
+ (DocumentBuilderFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.newDocumentBuilder());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_make(CodeRunner, Value)'
+
+ /**
+ * Gets the schema for passed builder
+ * @param ctxt context
+ * @param builder builder
+ * @return schema used by passed builder
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_get_schema(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return Cadmium.createObject(b.getSchema());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_get_schema(CodeRunner, Value)'
+
+ /**
+ * Gets the 'namespace-aware' property for passed builder.
+ * @param ctxt context
+ * @param builder builder
+ * @return value for 'namespace-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_is_namespace_aware(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return b.isNamespaceAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_is_namespace_aware(CodeRunner, Value)'
+
+ /**
+ * Gets the 'validating' property for passed builder.
+ * @param ctxt context
+ * @param builder builder
+ * @return value for 'validating' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_is_validating(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return b.isValidating() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_is_validating(CodeRunner, Value)'
+
+ /**
+ * Gets the 'xinclude-aware' property for passed builder.
+ * @param ctxt context
+ * @param builder builder
+ * @return value for 'xinclude-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_is_xinclude_aware(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return b.isXIncludeAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_is_xinclude_aware(CodeRunner, Value)'
+
+ /**
+ * Creates an empty document.
+ * @param ctxt context
+ * @param builder builder
+ * @return empty document
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_new_document(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return Cadmium.createObject(b.newDocument());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_new_document(CodeRunner, Value)'
+
+ /**
+ * Parses a file using a document builder.
+ * @param ctxt context
+ * @param builder builder
+ * @param file file to parse
+ * @return parsed document
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_parse_file(final CodeRunner ctxt,
+ final Value builder,
+ final Value file)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ return Cadmium.createObject(b.parse(ctxt.getContext().getFile(file)));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_parse_file(CodeRunner, Value, Value)'
+
+ /**
+ * Parses a channel using a document builder.
+ * @param ctxt context
+ * @param builder builder
+ * @param channel channel to parse
+ * @return parsed document
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_parse_channel(final CodeRunner ctxt,
+ final Value builder,
+ final Value channel)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ final Channel ch = (Channel) channel.asBlock().asCustom();
+ return Cadmium.createObject(b.parse(ch.asInputStream()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_parse_channel(CodeRunner, Value, Value)'
+
+ /**
+ * Resets the passed builder.
+ * @param ctxt context
+ * @param builder builder
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_documentbuilder_reset(final CodeRunner ctxt,
+ final Value builder)
+ throws Fail.Exception {
+ try {
+ final DocumentBuilder b = (DocumentBuilder) builder.asBlock().asCustom();
+ b.reset();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_documentbuilder_reset(CodeRunner, Value)'
+
+ /**
+ * Encodes an Objective Caml node instance from a Java node instance.
+ * @param n node to encode - should not be null
+ * @return encoded node
+ * @throws Fail.Exception if the passed node has an unknown type
+ */
+ private static Value createNode(final Node n) throws Fail.Exception {
+ assert n != null : "null n";
+ if (n instanceof Attr) {
+ return Value.createFromBlock(Block.createBlock(0, Cadmium.createObject(n)));
+ } else if (n instanceof CDATASection) {
+ return Value.createFromBlock(Block.createBlock(1, Cadmium.createObject(n)));
+ } else if (n instanceof Comment) {
+ return Value.createFromBlock(Block.createBlock(2, Cadmium.createObject(n)));
+ } else if (n instanceof Document) {
+ return Value.createFromBlock(Block.createBlock(3, Cadmium.createObject(n)));
+ } else if (n instanceof DocumentType) {
+ return Value.createFromBlock(Block.createBlock(4, Cadmium.createObject(n)));
+ } else if (n instanceof Element) {
+ return Value.createFromBlock(Block.createBlock(5, Cadmium.createObject(n)));
+ } else if (n instanceof Entity) {
+ return Value.createFromBlock(Block.createBlock(6, Cadmium.createObject(n)));
+ } else if (n instanceof EntityReference) {
+ return Value.createFromBlock(Block.createBlock(7, Cadmium.createObject(n)));
+ } else if (n instanceof Notation) {
+ return Value.createFromBlock(Block.createBlock(8, Cadmium.createObject(n)));
+ } else if (n instanceof ProcessingInstruction) {
+ return Value.createFromBlock(Block.createBlock(9, Cadmium.createObject(n)));
+ } else if (n instanceof Text) {
+ return Value.createFromBlock(Block.createBlock(10, Cadmium.createObject(n)));
+ } else {
+ Fail.failWith("unknown node type");
+ return Value.UNIT; // never reached
+ } // end if/elsif/else
+ } // end method 'createNode(Node)'
+
+} // end class 'Documents'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/SAX.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/SAX.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import java.io.File;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.validation.Schema;
+
+import fr.x9c.cadmium.kernel.Channel;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.FalseExit;
+import fr.x9c.cadmium.kernel.Fatal;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for SAX parsers manipulation.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class SAX {
+
+ /**
+ * No instance of this class.
+ */
+ private SAX() {
+ } // end empty constructor
+
+ /**
+ * Constructs a SAX parser factory.
+ * @param ctxt context
+ * @param unit ignored
+ * @return a new SAX parser factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_make(final CodeRunner ctxt,
+ final Value unit)
+ throws Fail.Exception {
+ try {
+ return Cadmium.createObject(SAXParserFactory.newInstance());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @param value feature value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_set_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ spf.setFeature(name.asBlock().asString(), value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_set_feature(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @return value of passed feature
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_get_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return spf.getFeature(name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_get_feature(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the schema for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param schema schema to use
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_set_schema(final CodeRunner ctxt,
+ final Value fact,
+ final Value schema)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ final Schema s = (Schema) schema.asBlock().asCustom();
+ spf.setSchema(s);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_set_schema(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the schema for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return schema used by constructed parsers
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_get_schema(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(spf.getSchema());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_get_schema(CodeRunner, Value)'
+
+ /**
+ * Sets the 'namespace-aware' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'namespace-aware' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_set_namespace_aware(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ spf.setNamespaceAware(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_set_namespace_aware(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'namespace-aware' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'namespace-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_is_namespace_aware(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return spf.isNamespaceAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_is_namespace_aware(CodeRunner, Value)'
+
+ /**
+ * Sets the 'validating' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'validating' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_set_validating(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ spf.setValidating(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_set_validating(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'validating' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'validating' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_is_validating(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return spf.isValidating() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_is_validating(CodeRunner, Value)'
+
+ /**
+ * Sets the 'xinclude-aware' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @param value value for 'xinclude-aware' property
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_set_xinclude_aware(final CodeRunner ctxt,
+ final Value fact,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ spf.setXIncludeAware(value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_set_xinclude_aware(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the 'xinclude-aware' property for constructed SAX parsers.
+ * @param ctxt context
+ * @param fact factory
+ * @return value for 'xinclude-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_saxfactory_is_xinclude_aware(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return spf.isXIncludeAware() ? Value.TRUE : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_saxfactory_is_xinclude_aware(CodeRunner, Value)'
+
+ /**
+ * Constructs a SAX parser.
+ * @param ctxt context
+ * @param fact factory
+ * @return a new SAX parser
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_make(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final SAXParserFactory spf = (SAXParserFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(spf.newSAXParser());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of a property.
+ * @param ctxt context
+ * @param parser parser
+ * @param name property name
+ * @param obj property value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_set_property(final CodeRunner ctxt,
+ final Value parser,
+ final Value name,
+ final Value obj)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ sp.setProperty(name.asBlock().asString(), obj.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_set_property(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a property.
+ * @param ctxt context
+ * @param parser parser
+ * @param name property name
+ * @return value of passed property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_get_property(final CodeRunner ctxt,
+ final Value parser,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ return Cadmium.createObject(sp.getProperty(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_get_property(CodeRunner, Value, Value)'
+
+ /**
+ * Gets the schema used by a parser.
+ * @param ctxt context
+ * @param parser parser
+ * @return schema used by passed parser
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_get_schema(final CodeRunner ctxt,
+ final Value parser)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ return Cadmium.createObject(sp.getSchema());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_get_schema(CodeRunner, Value)'
+
+ /**
+ * Gets the 'namespace-aware' property for passed parser.
+ * @param ctxt context
+ * @param parser parser
+ * @return value for 'namespace-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_is_namespace_aware(final CodeRunner ctxt,
+ final Value parser)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ return sp.isNamespaceAware()
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_is_namespace_aware(CodeRunner, Value)'
+
+ /**
+ * Gets the 'validating' property for passed parser.
+ * @param ctxt context
+ * @param parser parser
+ * @return value for 'validating' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_is_validating(final CodeRunner ctxt,
+ final Value parser)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ return sp.isValidating()
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_is_validating(CodeRunner, Value)'
+
+ /**
+ * Gets the 'xinclude-aware' property for passed parser.
+ * @param ctxt context
+ * @param parser parser
+ * @return value for 'xinclude-aware' property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_is_xinclude_aware(final CodeRunner ctxt,
+ final Value parser)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ return sp.isXIncludeAware()
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_is_xinclude_aware(CodeRunner, Value)'
+
+ /**
+ * Parses a file with a SAX parser/handler.
+ * @param ctxt context
+ * @param parser parser
+ * @param handler handler, as collection of Objective Caml functions (callbacks)
+ * @param filename name of file to parse
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_parse_file(final CodeRunner ctxt,
+ final Value parser,
+ final Value handler,
+ final Value filename)
+ throws Fail.Exception, Fatal.Exception, FalseExit {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ sp.parse(ctxt.getContext().getFile(filename),
+ new SAXHandler(ctxt, handler));
+ return Value.UNIT;
+ } catch (final WrappedException we) {
+ final Throwable cause = we.getCause();
+ if (cause instanceof Fail.Exception) {
+ throw ((Fail.Exception) cause);
+ } else if (cause instanceof Fatal.Exception) {
+ throw ((Fatal.Exception) cause);
+ } else if (cause instanceof FalseExit) {
+ throw ((FalseExit) cause);
+ } else {
+ Fail.failWith(cause.toString());
+ return Value.UNIT; // never reached
+ } // end if/elsif/else
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_parse_file(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Parses a channel with a SAX parser/handler.
+ * @param ctxt context
+ * @param parser parser
+ * @param handler handler, as collection of Objective Caml functions (callbacks)
+ * @param channel channel to parse
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_parse_channel(final CodeRunner ctxt,
+ final Value parser,
+ final Value handler,
+ final Value channel)
+ throws Fail.Exception, Fatal.Exception, FalseExit {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ sp.parse(((Channel) channel.asBlock().asCustom()).asInputStream(),
+ new SAXHandler(ctxt, handler));
+ return Value.UNIT;
+ } catch (final WrappedException we) {
+ final Throwable cause = we.getCause();
+ if (cause instanceof Fail.Exception) {
+ throw ((Fail.Exception) cause);
+ } else if (cause instanceof Fatal.Exception) {
+ throw ((Fatal.Exception) cause);
+ } else if (cause instanceof FalseExit) {
+ throw ((FalseExit) cause);
+ } else {
+ Fail.failWith(cause.toString());
+ return Value.UNIT; // never reached
+ } // end if/elsif/else
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_parse_channel(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Resets a SAX parser.
+ * @param ctxt context
+ * @param parser parser to reset
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_sax_reset(final CodeRunner ctxt,
+ final Value parser)
+ throws Fail.Exception {
+ try {
+ final SAXParser sp = (SAXParser) parser.asBlock().asCustom();
+ sp.reset();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_sax_reset(CodeRunner, Value)'
+
+} // end class 'SAX'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/SAXHandler.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/SAXHandler.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXParseException;
+
+import fr.x9c.cadmium.kernel.Block;
+import fr.x9c.cadmium.kernel.CadmiumException;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.FalseExit;
+import fr.x9c.cadmium.kernel.Fatal;
+import fr.x9c.cadmium.kernel.Value;
+
+/**
+ * This class is a wrapper around an Objective Caml SAX handler.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+final class SAXHandler extends org.xml.sax.helpers.DefaultHandler {
+
+ /** Runner used for callbacks. */
+ private final CodeRunner runner;
+
+ /** Objective Caml SAX handler. */
+ private final Block handler;
+
+ /**
+ * Constructs an handler from a code runner and an Objective Caml handler.
+ * @param runner runner for callbacks - should not be null
+ * @param handler actual SAX handler - should not be null
+ */
+ SAXHandler(final CodeRunner runner, final Value handler) {
+ assert runner != null : "null runner";
+ assert handler != null : "null handler";
+ this.runner = runner;
+ this.handler = handler.asBlock();
+ } // end constructor (CodeRunner, Value)
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void characters(final char[] ch, final int start, final int length) {
+ final String s = new String(ch, start, length);
+ try {
+ this.runner.callback(this.handler.get(0),
+ Value.createFromBlock(Block.createString(s)));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'characters(char[], int, int)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void ignorableWhitespace(final char[] ch, final int start, final int length) {
+ final String s = new String(ch, start, length);
+ try {
+ this.runner.callback(this.handler.get(1),
+ Value.createFromBlock(Block.createString(s)));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'ignorableWhitespace(char[], int, int)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startDocument() {
+ try {
+ this.runner.callback(this.handler.get(2), Value.UNIT);
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'startDocument()'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void endDocument() {
+ try {
+ this.runner.callback(this.handler.get(3), Value.UNIT);
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'endDocument() {'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startElement(final String uri, final String localName,
+ final String qName, final Attributes attributes) {
+ try {
+ this.runner.callback(this.handler.get(4),
+ Value.createFromBlock(Block.createString(uri)),
+ Value.createFromBlock(Block.createString(localName)),
+ Value.createFromBlock(Block.createString(qName)),
+ createAttributeList(attributes));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'startElement(String, String, String, Attributes)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void endElement(final String uri, final String localName, final String qName) {
+ try {
+ this.runner.callback(this.handler.get(5),
+ Value.createFromBlock(Block.createString(uri)),
+ Value.createFromBlock(Block.createString(localName)),
+ Value.createFromBlock(Block.createString(qName)));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'endElement(String, String, String)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void startPrefixMapping(final String prefix, final String uri) {
+ try {
+ this.runner.callback(this.handler.get(6),
+ Value.createFromBlock(Block.createString(prefix)),
+ Value.createFromBlock(Block.createString(uri)));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'startPrefixMapping(String, String)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void endPrefixMapping(final String prefix) {
+ try {
+ this.runner.callback(this.handler.get(7),
+ Value.createFromBlock(Block.createString(prefix)));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'endPrefixMapping(String)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void error(final SAXParseException e) {
+ try {
+ this.runner.callback(this.handler.get(8), wrapParseException(e));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'error(SAXParseException)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void fatalError(final SAXParseException e) {
+ try {
+ this.runner.callback(this.handler.get(9), wrapParseException(e));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'fatalError(SAXParseException)'
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void warning(final SAXParseException e) {
+ try {
+ this.runner.callback(this.handler.get(10), wrapParseException(e));
+ } catch (final Fail.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final Fatal.Exception fe) {
+ throw new WrappedException(fe);
+ } catch (final FalseExit fe) {
+ throw new WrappedException(fe);
+ } catch (final CadmiumException fe) {
+ throw new WrappedException(fe);
+ } // end try/catch
+ } // end method 'warning(SAXParseException)'
+
+ /**
+ * Creates an association list (of strings) from attributes.
+ * @param attrs attributes to convert - should not be null
+ * @return association list where each couple is of the form
+ * (attr_name, attr_value)
+ */
+ private static Value createAttributeList(final Attributes attrs) {
+ assert attrs != null : "null attrs";
+ Value res = Value.EMPTY_LIST;
+ for (int i = attrs.getLength() - 1; i >= 0; i--) {
+ final Block couple =
+ Block.createBlock(0,
+ Value.createFromBlock(Block.createString(attrs.getQName(i))),
+ Value.createFromBlock(Block.createString(attrs.getValue(i))));
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ Value.createFromBlock(couple),
+ res);
+ res = Value.createFromBlock(b);
+ } // end for
+ return res;
+ } // end method 'createAttributeList(Attributes)'
+
+ /**
+ * Wraps a SAXParseException into a parse_error.
+ * @param e exception to wrap - should not be null
+ * @return parse_error containing the informations of the passed exception
+ */
+ private static Value wrapParseException(final SAXParseException e) {
+ assert e != null : "null e";
+ final Block res =
+ Block.createBlock(0,
+ Value.createFromLong(e.getLineNumber()),
+ Value.createFromLong(e.getColumnNumber()),
+ Value.createFromBlock(Block.createString(e.getMessage())));
+ return Value.createFromBlock(res);
+ } // end method 'wrapParseException(SAXParseException)'
+
+} // end class 'SAXHandler'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/Schemas.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/Schemas.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import java.net.URL;
+
+import javax.xml.validation.SchemaFactory;
+
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for schema manipulation.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class Schemas {
+
+ /**
+ * No instance of this class.
+ */
+ private Schemas() {
+ } // end empty constructor
+
+ /**
+ * Constructs a schema factory.
+ * @param ctxt context
+ * @param lang schema language
+ * @return a new schema factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schemafactory_make(final CodeRunner ctxt,
+ final Value lang)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory res =
+ SchemaFactory.newInstance(lang.asBlock().asString());
+ return Cadmium.createObject(res);
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_schemafactory_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @param value feature value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schemafactory_set_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ sf.setFeature(name.asBlock().asString(), value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_schemafactory_set_feature(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @return value of passed feature
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schemafactory_get_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ return sf.getFeature(name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_schemafactory_get_feature(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the value of a property.
+ * @param ctxt context
+ * @param fact factory
+ * @param name property name
+ * @param obj property value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schemafactory_set_property(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value obj)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ sf.setProperty(name.asBlock().asString(), obj.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_schemafactory_set_property(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a property.
+ * @param ctxt context
+ * @param fact factory
+ * @param name property name
+ * @return value of passed property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schemafactory_get_property(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(sf.getProperty(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_schemafactory_get_property(CodeRunner, Value, Value)'
+
+ /**
+ * Constructs a schema from a file.
+ * @param ctxt context
+ * @param fact factory
+ * @param file filename
+ * @return schema constructed from file
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schema_from_file(final CodeRunner ctxt,
+ final Value fact,
+ final Value file)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(sf.newSchema(ctxt.getContext().getFile(file)));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'make_schema_from_file(CodeRunner, Value, Value)'
+
+ /**
+ * Constructs a schema from a URL.
+ * @param ctxt context
+ * @param fact factory
+ * @param url URL
+ * @return schema constructed from url
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_schema_from_url(final CodeRunner ctxt,
+ final Value fact,
+ final Value url)
+ throws Fail.Exception {
+ try {
+ final SchemaFactory sf = (SchemaFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(sf.newSchema(new URL(url.asBlock().asString())));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'make_schema_from_url(CodeRunner, Value, Value)'
+
+} // end class 'Schemas'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/Transformers.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/Transformers.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import fr.x9c.cadmium.kernel.Block;
+import fr.x9c.cadmium.kernel.Channel;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for Transformers.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class Transformers {
+
+ /**
+ * No instance of this class.
+ */
+ private Transformers() {
+ } // end empty constructor
+
+ /**
+ * Constructs a transformer factory.
+ * @param ctxt context
+ * @param unit ignored
+ * @return a new transformer factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformerfactory_make(final CodeRunner ctxt,
+ final Value unit)
+ throws Fail.Exception {
+ try {
+ return Cadmium.createObject(TransformerFactory.newInstance());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformerfactory_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of an attribute.
+ * @param ctxt context
+ * @param fact factory
+ * @param name attribute name
+ * @param value attribute value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformerfactory_set_attribute(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ f.setAttribute(name.asBlock().asString(), value.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformerfactory_set_attribute(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of an attribute.
+ * @param ctxt context
+ * @param fact factory
+ * @param name attribute name
+ * @return value of passed attribute
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformerfactory_get_attribute(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.getAttribute(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformerfactory_get_attribute(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @param value feature value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformerfactory_set_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ f.setFeature(name.asBlock().asString(), value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformerfactory_set_feature(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @return value of passed feature
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformerfactory_get_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ return f.getFeature(name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformerfactory_get_feature(CodeRunner, Value, Value)'
+
+ /**
+ * Constructs an identity transformer.
+ * @param ctxt context
+ * @param fact factory
+ * @return identity transformer
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_make_id(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.newTransformer());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_make_id(CodeRunner, Value)'
+
+ /**
+ * Constructs a transformer from a file.
+ * @param ctxt context
+ * @param fact factory
+ * @param filename filename
+ * @return transformer described by passed file
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_make_from_file(final CodeRunner ctxt,
+ final Value fact,
+ final Value filename)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.newTransformer(new StreamSource(ctxt.getContext().getFile(filename))));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_make_from_file(CodeRunner, Value, Value)'
+
+ /**
+ * Constructs a transformer from a channel.
+ * @param ctxt context
+ * @param fact factory
+ * @param channel channel
+ * @return transformer described by passed channel
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_make_from_channel(final CodeRunner ctxt,
+ final Value fact,
+ final Value channel)
+ throws Fail.Exception {
+ try {
+ final TransformerFactory f = (TransformerFactory) fact.asBlock().asCustom();
+ final Channel ch = (Channel) channel.asBlock().asCustom();
+ return Cadmium.createObject(f.newTransformer(new StreamSource(ch.asInputStream())));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_make_from_channel(CodeRunner, Value, Value)'
+
+ /**
+ * Clear the parameters of the passed transformer instance.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_clear_parameters(final CodeRunner ctxt,
+ final Value trans)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ t.clearParameters();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_clear_parameters(CodeRunner, Value)'
+
+ /**
+ * Sets the value of a parameter.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @param name parameter name
+ * @param obj parameter value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_set_parameter(final CodeRunner ctxt,
+ final Value trans,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ t.setParameter(name.asBlock().asString(), value.asBlock().asCustom());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_set_parameter(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a parameter.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @param name parameter name
+ * @return value of passed parameter
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_get_parameter(final CodeRunner ctxt,
+ final Value trans,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ return Cadmium.createObject(t.getParameter(name.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_get_parameter(CodeRunner, Value, Value)'
+
+ /**
+ * Sets the value of a property.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @param name property name
+ * @param obj property value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_set_output_property(final CodeRunner ctxt,
+ final Value trans,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ t.setOutputProperty(name.asBlock().asString(), value.asBlock().asString());
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_set_output_property(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a property.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @param name property name
+ * @return value of passed property
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_get_output_property(final CodeRunner ctxt,
+ final Value trans,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ final String s = t.getOutputProperty(name.asBlock().asString());
+ return Value.createFromBlock(Block.createString(s));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_get_output_property(CodeRunner, Value, Value)'
+
+ /**
+ * Applies a transformer.
+ * @param ctxt context
+ * @param trans transformer instance to apply
+ * @param src source document (file)
+ * @param dst destination document (file)
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_transform_file_to_file(final CodeRunner ctxt,
+ final Value trans,
+ final Value src,
+ final Value dst)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ t.transform(new StreamSource(ctxt.getContext().getFile(src)),
+ new StreamResult(ctxt.getContext().getFile(dst)));
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_transform_file_to_file(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Applies a transformer.
+ * @param ctxt context
+ * @param trans transformer instance to apply
+ * @param src source document (file)
+ * @param dst destination document (channel)
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_transform_file_to_channel(final CodeRunner ctxt,
+ final Value trans,
+ final Value src,
+ final Value dst)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ final Channel ch = (Channel) dst.asBlock().asCustom();
+ t.transform(new StreamSource(ctxt.getContext().getFile(src)),
+ new StreamResult(ch.asOutputStream()));
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_transform_file_to_channel(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Applies a transformer.
+ * @param ctxt context
+ * @param trans transformer instance to apply
+ * @param src source document (channel)
+ * @param dst destination document (file)
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_transform_channel_to_file(final CodeRunner ctxt,
+ final Value trans,
+ final Value src,
+ final Value dst)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ final Channel ch = (Channel) src.asBlock().asCustom();
+ t.transform(new StreamSource(ch.asInputStream()),
+ new StreamResult(ctxt.getContext().getFile(dst)));
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_transform_channel_to_file(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Applies a transformer.
+ * @param ctxt context
+ * @param trans transformer instance to apply
+ * @param src source document (channel)
+ * @param dst destination document (channel)
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_transform_channel_to_channel(final CodeRunner ctxt,
+ final Value trans,
+ final Value src,
+ final Value dst)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ final Channel ch1 = (Channel) src.asBlock().asCustom();
+ final Channel ch2 = (Channel) dst.asBlock().asCustom();
+ t.transform(new StreamSource(ch1.asInputStream()),
+ new StreamResult(ch2.asOutputStream()));
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_transform_channel_to_channel(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Resets the passed transformer instance.
+ * @param ctxt context
+ * @param trans transformer instance
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_transformer_reset(final CodeRunner ctxt,
+ final Value trans)
+ throws Fail.Exception {
+ try {
+ final Transformer t = (Transformer) trans.asBlock().asCustom();
+ t.reset();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_transformer_reset(CodeRunner, Value)'
+
+} // end class 'Transformers'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/Trees.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/Trees.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+import fr.x9c.cadmium.kernel.Block;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for tree conversion.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class Trees {
+
+ /**
+ * No instance of this class.
+ */
+ private Trees() {
+ } // end empty constructor
+
+ /**
+ * Converts a document into a simplified representation.
+ * @param ctxt context
+ * @param document document to convert
+ * @return passed document as a CadmiumXML.Tree.t instance
+ * @throws Fail.Exception if an error occurs during conversion
+ */
+ @Primitive
+ public static Value cadmiumxml_tree_of_document(final CodeRunner ctxt,
+ final Value document)
+ throws Fail.Exception {
+ try {
+ final Document doc = (Document) document.asBlock().asCustom();
+ return encodeNode(doc.getDocumentElement());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_tree_of_document(CodeRunner, Value)'
+
+ /**
+ * Encodes a node.
+ * @param n node to encode - should not be null
+ * @return passed node as a CadmiumXML.Tree.t instance
+ * @throws Fail.Exception if an error occurs during encoding
+ */
+ private static Value encodeNode(final Node n) throws Fail.Exception {
+ assert n != null : "null n";
+ if (n instanceof Element) {
+ final Element e = (Element) n;
+ final Value tag = Value.createFromBlock(Block.createString(e.getTagName()));
+ Value attributes = Value.EMPTY_LIST;
+ final NamedNodeMap al = e.getAttributes();
+ for (int i = al.getLength() - 1; i >= 0; i--) {
+ final Attr a = (Attr) al.item(i);
+ final Block couple = Block.createBlock(0,
+ Value.createFromBlock(Block.createString(a.getName())),
+ Value.createFromBlock(Block.createString(a.getValue())));
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ Value.createFromBlock(couple),
+ attributes);
+ attributes = Value.createFromBlock(b);
+ } // end for
+ Value children = Value.EMPTY_LIST;
+ final NodeList cl = e.getChildNodes();
+ for (int i = cl.getLength(); i >= 0; i--) {
+ final Node c = cl.item(i);
+ if ((c instanceof Element)
+ || (c instanceof CDATASection)
+ || (c instanceof Text)) {
+ final Block b = Block.createBlock(Block.TAG_CONS,
+ encodeNode(c),
+ children);
+ children = Value.createFromBlock(b);
+ } // end if
+ } // end for
+ final Block res = Block.createBlock(0, tag, attributes, children);
+ return Value.createFromBlock(Block.createBlock(0,
+ Value.createFromBlock(res)));
+ } else if (n instanceof CDATASection) {
+ final String d = ((CDATASection) n).getData();
+ final Value res = Value.createFromBlock(Block.createString(d));
+ return Value.createFromBlock(Block.createBlock(1, res));
+ } else if (n instanceof Text) {
+ final String d = ((Text) n).getData();
+ final Value res = Value.createFromBlock(Block.createString(d));
+ return Value.createFromBlock(Block.createBlock(2, res));
+ } else {
+ Fail.failWith("unknown node type");
+ return Value.UNIT; // never reached
+ } // end if/elsif/else
+ } // end method 'encodeNode(Node)'
+
+} // end class 'Trees'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/WrappedException.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/WrappedException.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+/**
+ * This class provides a bare exception wrapper.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+final class WrappedException extends RuntimeException {
+
+ /** Serialization UID. */
+ static final long serialVersionUID = -8571619121173746726L;
+
+ /**
+ * Wraps the passed exception.
+ * @param t exception to wrap
+ */
+ WrappedException(final Throwable t) {
+ super(t);
+ } // end constructor (Throwable)
+
+} // end class 'WrappedException'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/XPath.java
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/XPath.java 1
+/*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package fr.x9c.cadmium.primitives.cadmiumxml;
+
+import java.io.FileInputStream;
+
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+
+import fr.x9c.cadmium.kernel.Block;
+import fr.x9c.cadmium.kernel.Channel;
+import fr.x9c.cadmium.kernel.CodeRunner;
+import fr.x9c.cadmium.kernel.Fail;
+import fr.x9c.cadmium.kernel.Primitive;
+import fr.x9c.cadmium.kernel.PrimitiveProvider;
+import fr.x9c.cadmium.kernel.Value;
+import fr.x9c.cadmium.primitives.cadmium.Cadmium;
+
+/**
+ * This class provides the primitives for XPath queries.
+ *
+ * @author Xavier Clerc
+ * @version 1.0
+ * @since 1.0
+ */
+@PrimitiveProvider
+public final class XPath {
+
+ /**
+ * No instance of this class.
+ */
+ private XPath() {
+ } // end empty constructor
+
+ /**
+ * Constructs an xpath factory.
+ * @param ctxt context
+ * @param unit ignored
+ * @return a new xpath factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpathfactory_make(final CodeRunner ctxt,
+ final Value unit)
+ throws Fail.Exception {
+ try {
+ return Cadmium.createObject(XPathFactory.newInstance());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpathfactory_make(CodeRunner, Value)'
+
+ /**
+ * Sets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @param value feature value
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpathfactory_set_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name,
+ final Value value)
+ throws Fail.Exception {
+ try {
+ final XPathFactory f = (XPathFactory) fact.asBlock().asCustom();
+ f.setFeature(name.asBlock().asString(), value == Value.TRUE);
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpathfactory_set_feature(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Gets the value of a feature flag.
+ * @param ctxt context
+ * @param fact factory
+ * @param name feature name
+ * @return value of passed feature
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpathfactory_get_feature(final CodeRunner ctxt,
+ final Value fact,
+ final Value name)
+ throws Fail.Exception {
+ try {
+ final XPathFactory f = (XPathFactory) fact.asBlock().asCustom();
+ return f.getFeature(name.asBlock().asString())
+ ? Value.TRUE
+ : Value.FALSE;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpathfactory_get_feature(CodeRunner, Value, Value)'
+
+ /**
+ * Constructs an xpath instance.
+ * @param ctxt context
+ * @param fact factory
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_make(final CodeRunner ctxt,
+ final Value fact)
+ throws Fail.Exception {
+ try {
+ final XPathFactory f = (XPathFactory) fact.asBlock().asCustom();
+ return Cadmium.createObject(f.newXPath());
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_make(CodeRunner, Value)'
+
+ /**
+ * Compiles an xpath expression.
+ * @param ctxt context
+ * @param xpath xpath instance
+ * @param expr expression to compile
+ * @return compiled expression
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_compile(final CodeRunner ctxt,
+ final Value xpath,
+ final Value expr)
+ throws Fail.Exception {
+ try {
+ final javax.xml.xpath.XPath x =
+ (javax.xml.xpath.XPath) xpath.asBlock().asCustom();
+ return Cadmium.createObject(x.compile(expr.asBlock().asString()));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_compile(CodeRunner, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param xpath xpath instance
+ * @param expr expression to evaluate
+ * @param file evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_evaluate_file(final CodeRunner ctxt,
+ final Value xpath,
+ final Value expr,
+ final Value file)
+ throws Fail.Exception {
+ try {
+ final javax.xml.xpath.XPath x =
+ (javax.xml.xpath.XPath) xpath.asBlock().asCustom();
+ final String res =
+ x.evaluate(expr.asBlock().asString(),
+ new FileInputStream(ctxt.getContext().getFile(file)));
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ t.printStackTrace();
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_evaluate_file(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param xpath xpath instance
+ * @param expr expression to evaluate
+ * @param channel evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_evaluate_channel(final CodeRunner ctxt,
+ final Value xpath,
+ final Value expr,
+ final Value channel)
+ throws Fail.Exception {
+ try {
+ final javax.xml.xpath.XPath x =
+ (javax.xml.xpath.XPath) xpath.asBlock().asCustom();
+ final Channel ch = (Channel) channel.asBlock().asCustom();
+ final String res = x.evaluate(expr.asBlock().asString(), ch.asInputStream());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_evaluate_channel(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param xpath xpath instance
+ * @param expr expression to evaluate
+ * @param document evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_evaluate_document(final CodeRunner ctxt,
+ final Value xpath,
+ final Value expr,
+ final Value document)
+ throws Fail.Exception {
+ try {
+ final javax.xml.xpath.XPath x =
+ (javax.xml.xpath.XPath) xpath.asBlock().asCustom();
+ final String res = x.evaluate(expr.asBlock().asString(),
+ document.asBlock().asCustom());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_evaluate_document(CodeRunner, Value, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param expr xpath expression
+ * @param file evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_expr_evaluate_file(final CodeRunner ctxt,
+ final Value expr,
+ final Value file)
+ throws Fail.Exception {
+ try {
+ final XPathExpression e = (XPathExpression) expr.asBlock().asCustom();
+ final String res =
+ e.evaluate(new FileInputStream(ctxt.getContext().getFile(file)));
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_expr_evaluate_file(CodeRunner, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param expr xpath expression
+ * @param channel evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_expr_evaluate_channel(final CodeRunner ctxt,
+ final Value expr,
+ final Value channel)
+ throws Fail.Exception {
+ try {
+ final XPathExpression e = (XPathExpression) expr.asBlock().asCustom();
+ final Channel ch = (Channel) channel.asBlock().asCustom();
+ final String res = e.evaluate(ch.asInputStream());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_expr_evaluate_channel(CodeRunner, Value, Value)'
+
+ /**
+ * Evaluates an xpath expression.
+ * @param ctxt context
+ * @param expr xpath expression
+ * @param document evaluation context
+ * @return result of evaluation
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_expr_evaluate_document(final CodeRunner ctxt,
+ final Value expr,
+ final Value document)
+ throws Fail.Exception {
+ try {
+ final XPathExpression e = (XPathExpression) expr.asBlock().asCustom();
+ final String res = e.evaluate(document.asBlock().asCustom());
+ return Value.createFromBlock(Block.createString(res));
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_expr_evaluate_document(CodeRunner, Value, Value)'
+
+ /**
+ * Resets an xpath instance.
+ * @param ctxt context
+ * @param xpath xpath instance
+ * @return unit
+ * @throws Fail.Exception if any error occurs
+ */
+ @Primitive
+ public static Value cadmiumxml_xpath_reset(final CodeRunner ctxt,
+ final Value xpath)
+ throws Fail.Exception {
+ try {
+ final javax.xml.xpath.XPath x =
+ (javax.xml.xpath.XPath) xpath.asBlock().asCustom();
+ x.reset();
+ return Value.UNIT;
+ } catch (final Throwable t) {
+ Cadmium.fail(ctxt, t);
+ return Value.UNIT; // never reached
+ } // end try/catch
+ } // end method 'cadmiumxml_xpath_reset(CodeRunner, Value)'
+
+} // end class 'XPath'
addfile ./src/fr/x9c/cadmium/primitives/cadmiumxml/package.html
hunk ./src/fr/x9c/cadmium/primitives/cadmiumxml/package.html 1
+
+This package contains the classes providing implementation for XML support
+(CadmiumXML module).
+
addfile ./src/ocaml/cadmiumXML.ml
hunk ./src/ocaml/cadmiumXML.ml 1
+(*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *)
+
+module SchemaFactory =
+ struct
+ type t
+
+ external make : string -> t =
+ "cadmiumxml_schemafactory_make"
+
+ external set_feature : t -> string -> bool -> unit =
+ "cadmiumxml_schemafactory_set_feature"
+
+ external get_feature : t -> string -> bool =
+ "cadmiumxml_schemafactory_get_feature"
+
+ external set_property : t -> string -> Cadmium.java_object -> unit =
+ "cadmiumxml_schemafactory_set_property"
+
+ let set_property_obj x s o = set_property x s o#cd'this
+
+ external get_property : t -> string -> Cadmium.java_object =
+ "cadmiumxml_schemafactory_get_property"
+
+ let get_property_obj x s = new CadmiumObj.jObject (`Cd'init (get_property x s ))
+ end
+
+
+module Schema =
+ struct
+ type t
+
+ external make_schema_from_file : SchemaFactory.t -> string -> t =
+ "cadmiumxml_schema_from_file"
+
+ external make_schema_from_url : SchemaFactory.t -> string -> t =
+ "cadmiumxml_schema_from_url"
+ end
+
+
+module SAXFactory =
+ struct
+ type t
+
+ external make : unit -> t =
+ "cadmiumxml_saxfactory_make"
+
+ external set_feature : t -> string -> bool -> unit =
+ "cadmiumxml_saxfactory_set_feature"
+
+ external get_feature : t -> string -> bool =
+ "cadmiumxml_saxfactory_get_feature"
+
+ external set_schema : t -> Schema.t -> unit =
+ "cadmiumxml_saxfactory_set_schema"
+
+ external get_schema : t -> Schema.t =
+ "cadmiumxml_saxfactory_get_schema"
+
+ external set_namespace_aware : t -> bool -> unit =
+ "cadmiumxml_saxfactory_set_namespace_aware"
+
+ external is_namespace_aware : t -> bool =
+ "cadmiumxml_saxfactory_is_namespace_aware"
+
+ external set_validating : t -> bool -> unit =
+ "cadmiumxml_saxfactory_set_validating"
+
+ external is_validating : t -> bool =
+ "cadmiumxml_saxfactory_is_validating"
+
+ external set_xinclude_aware : t -> bool -> unit =
+ "cadmiumxml_saxfactory_set_xinclude_aware"
+
+ external is_xinclude_aware : t -> bool =
+ "cadmiumxml_saxfactory_is_xinclude_aware"
+ end
+
+
+module SAXParser =
+ struct
+ type t
+
+ type parse_error = int * int * string
+
+ type handler = {
+ characters : string -> unit;
+ ignorable_whitespace : string -> unit;
+ start_document : unit -> unit;
+ end_document : unit -> unit;
+ start_element : string -> string -> string -> ((string * string) list) -> unit;
+ end_element : string -> string -> string -> unit;
+ start_prefix_mapping : string -> string -> unit;
+ end_prefix_mapping : string -> unit;
+ error : parse_error -> unit;
+ fatal_error : parse_error -> unit;
+ warning : parse_error -> unit;
+ }
+
+ let default_handler = {
+ characters = (fun _ -> ());
+ ignorable_whitespace = (fun _ -> ());
+ start_document = (fun _ -> ());
+ end_document = (fun _ -> ());
+ start_element = (fun _ _ _ _ -> ());
+ end_element = (fun _ _ _ -> ());
+ start_prefix_mapping = (fun _ _ -> ());
+ end_prefix_mapping = (fun _ -> ());
+ error = (fun _ -> ());
+ fatal_error = (fun _ -> ());
+ warning = (fun _ -> ());
+ }
+
+ external make : SAXFactory.t -> t =
+ "cadmiumxml_sax_make"
+
+ external set_property : t -> string -> Cadmium.java_object -> unit =
+ "cadmiumxml_sax_set_property"
+
+ let set_property_obj x s o = set_property x s o#cd'this
+
+ external get_property : t -> string -> Cadmium.java_object =
+ "cadmiumxml_sax_get_property"
+
+ let get_property_obj x s = new CadmiumObj.jObject (`Cd'init (get_property x s ))
+
+ external get_schema : t -> Schema.t =
+ "cadmiumxml_sax_get_schema"
+
+ external is_namespace_aware : t -> bool =
+ "cadmiumxml_sax_is_namespace_aware"
+
+ external is_validating : t -> bool =
+ "cadmiumxml_sax_is_validating"
+
+ external is_xinclude_aware : t -> bool =
+ "cadmiumxml_sax_is_xinclude_aware"
+
+ external parse_file : t -> handler -> string -> unit =
+ "cadmiumxml_sax_parse_file"
+
+ external parse_channel : t -> handler -> in_channel -> unit =
+ "cadmiumxml_sax_parse_channel"
+
+ external reset : t -> unit =
+ "cadmiumxml_sax_reset"
+ end
+
+
+module Document =
+ struct
+ (* Types *)
+
+ type attr
+
+ type cdata
+
+ type comment
+
+ type document
+
+ type document_type
+
+ type element
+
+ type entity
+
+ type entity_reference
+
+ type notation
+
+ type processing_instruction
+
+ type text
+
+ type node =
+ | Attr of attr
+ | Cdata of cdata
+ | Comment of comment
+ | Document of document
+ | Document_type of document_type
+ | Element of element
+ | Entity of entity
+ | Entity_reference of entity_reference
+ | Notation of notation
+ | Processing_instruction of processing_instruction
+ | Text of text
+
+
+ (* Document functions *)
+
+ external get_document_element : document -> element =
+ "cadmiumxml_document_get_document_element"
+
+ external get_xml_encoding : document -> string =
+ "cadmiumxml_document_get_xml_encoding"
+
+ external set_strict_error_checking : document -> bool -> unit =
+ "cadmiumxml_document_set_strict_error_checking"
+
+ external is_strict_error_checking : document -> bool =
+ "cadmiumxml_document_is_strict_error_checking"
+
+ external set_xml_standalone : document -> bool -> unit =
+ "cadmiumxml_document_set_xml_standalone"
+
+ external is_xml_standalone : document -> bool =
+ "cadmiumxml_document_is_xml_standalone"
+
+ external set_xml_version : document -> bool -> unit =
+ "cadmiumxml_document_set_xml_version"
+
+ external get_xml_version : document -> string =
+ "cadmiumxml_document_get_xml_version"
+
+ external normalize_document : document -> unit =
+ "cadmiumxml_document_normalize_document"
+
+ let node_of_document d = Document d
+
+
+ (* Attribute functions *)
+
+ external get_attr_parent : attr -> element =
+ "cadmiumxml_document_get_attr_parent"
+
+ external get_attr_name : attr -> string =
+ "cadmiumxml_document_get_attr_name"
+
+ external get_attr_value : attr -> string =
+ "cadmiumxml_document_get_attr_value"
+
+ external set_attr_value : attr -> string -> unit =
+ "cadmiumxml_document_set_attr_value"
+
+ let node_of_attr a = Attr a
+
+
+ (* CData functions *)
+
+ external get_cdata_parent : cdata -> node =
+ "cadmiumxml_document_get_cdata_parent"
+
+ external get_cdata : cdata -> string =
+ "cadmiumxml_document_get_cdata"
+
+ external set_cdata : cdata -> string -> unit =
+ "cadmiumxml_document_set_cdata"
+
+ let node_of_cdata c = Cdata c
+
+
+ (* Comment functions *)
+
+ external get_comment_parent : comment -> node =
+ "cadmiumxml_document_get_comment_parent"
+
+ external get_comment : comment -> string =
+ "cadmiumxml_document_get_comment"
+
+ external set_comment : comment -> string -> unit =
+ "cadmiumxml_document_set_comment"
+
+ let node_of_comment c = Comment c
+
+
+ (* Document type functions *)
+
+ external get_document_type_parent : document_type -> node =
+ "cadmiumxml_document_get_document_type_parent"
+
+ external get_document_type_name : document_type -> string =
+ "cadmiumxml_document_get_document_type_name"
+
+ external get_document_type_public_id : document_type -> string =
+ "cadmiumxml_document_get_document_type_public_id"
+
+ external get_document_type_system_id : document_type -> string =
+ "cadmiumxml_document_get_document_type_system_id"
+
+ let node_of_document_type d = Document_type d
+
+
+ (* Element functions *)
+
+ external get_element_parent : element -> node =
+ "cadmiumxml_document_get_element_parent"
+
+ external get_attribute : element -> string -> string =
+ "cadmiumxml_document_get_attribute"
+
+ external get_attribute_ns : element -> string -> string -> string =
+ "cadmiumxml_document_get_attribute_ns"
+
+ external get_attribute_node : element -> string -> attr =
+ "cadmiumxml_document_get_attribute_node"
+
+ external get_attribute_node_ns : element -> string -> string -> attr =
+ "cadmiumxml_document_get_attribute_node_ns"
+
+ external get_elements_by_tag_name : element -> string -> element list =
+ "cadmiumxml_document_get_elements_by_tag_name"
+
+ external get_elements_by_tag_name_ns : element -> string -> string -> element list =
+ "cadmiumxml_document_get_elements_by_tag_name_ns"
+
+ external get_tag_name : element -> string =
+ "cadmiumxml_document_get_tag_name"
+
+ external has_attribute : element -> string -> bool =
+ "cadmiumxml_document_has_attribute"
+
+ external has_attribute_ns : element -> string -> string -> bool =
+ "cadmiumxml_document_has_attribute_ns"
+
+ external remove_attribute : element -> string -> unit =
+ "cadmiumxml_document_remove_attribute"
+
+ external remove_attribute_ns : element -> string -> string -> unit =
+ "cadmiumxml_document_remove_attribute_ns"
+
+ external remove_attribute_node : element -> attr -> unit =
+ "cadmiumxml_document_remove_attribute_node"
+
+ external set_attribute : element -> string -> string -> unit =
+ "cadmiumxml_document_set_attribute"
+
+ external set_attribute_ns : element -> string -> string -> string -> unit =
+ "cadmiumxml_document_set_attribute_ns"
+
+ let node_of_element e = Element e
+
+
+ (* Entity functions *)
+
+ external get_entity_parent : entity -> node =
+ "cadmiumxml_document_get_entity_parent"
+
+ external get_entity_notation_name : entity -> string =
+ "cadmiumxml_document_get_entity_notation_name"
+
+ external get_entity_public_id : entity -> string =
+ "cadmiumxml_document_get_entity_public_id"
+
+ external get_entity_system_id : entity -> string =
+ "cadmiumxml_document_get_entity_system_id"
+
+ let node_of_entity e = Entity e
+
+
+ (* Notation functions *)
+
+ external get_notation_parent : notation -> node =
+ "cadmiumxml_document_get_notation_parent"
+
+ external get_notation_public_id : notation -> string =
+ "cadmiumxml_document_get_notation_public_id"
+
+ external get_notation_system_id : notation -> string =
+ "cadmiumxml_document_get_notation_system_id"
+
+ let node_of_notation n = Notation n
+
+
+ (* Processing instruction functions *)
+
+ external get_processing_instruction_parent : processing_instruction -> node =
+ "cadmiumxml_document_get_processing_instruction_parent"
+
+ external get_processing_instruction_target : processing_instruction -> string =
+ "cadmiumxml_document_get_processing_instruction_target"
+
+ external get_processing_instruction_data : processing_instruction -> string =
+ "cadmiumxml_document_get_processing_instruction_data"
+
+ external set_processing_instruction_data : processing_instruction -> string -> unit =
+ "cadmiumxml_document_set_processing_instruction_data"
+
+ let node_of_processing_instruction pi = Processing_instruction pi
+
+
+ (* Text functions *)
+
+ external get_text_parent : text -> node =
+ "cadmiumxml_document_get_text_parent"
+
+ external get_text : text -> string =
+ "cadmiumxml_document_get_text"
+
+ external set_text : text -> string -> unit =
+ "cadmiumxml_document_set_text"
+
+ let node_of_text t = Text t
+
+
+ (* Node functions *)
+
+ external get_parent : node -> node =
+ "cadmiumxml_document_get_parent"
+
+ external get_document : node -> document =
+ "cadmiumxml_document_get_document"
+
+ external append_attr_child : node -> string -> attr =
+ "cadmiumxml_document_append_attr_child"
+
+ external append_attr_ns_child : node -> string -> string -> attr =
+ "cadmiumxml_document_append_attr_ns_child"
+
+ external append_cdata_child : node -> string -> cdata =
+ "cadmiumxml_document_append_cdata_child"
+
+ external append_comment_child : node -> string -> comment =
+ "cadmiumxml_document_append_comment_child"
+
+ external append_element_child : node -> string -> element =
+ "cadmiumxml_document_append_element_child"
+
+ external append_element_ns_child : node -> string -> string -> element =
+ "cadmiumxml_document_append_element_ns_child"
+
+ external append_entity_reference_child : node -> string -> entity_reference =
+ "cadmiumxml_document_append_entity_reference_child"
+
+ external insert_attr_child_before : node -> node -> string -> attr =
+ "cadmiumxml_document_insert_attr_child_before"
+
+ external insert_attr_ns_child_before : node -> node -> string -> string -> attr =
+ "cadmiumxml_document_insert_attr_ns_child_before"
+
+ external insert_cdata_child_before : node -> node -> string -> cdata =
+ "cadmiumxml_document_insert_cdata_child_before"
+
+ external insert_comment_child_before : node -> node -> string -> comment =
+ "cadmiumxml_document_insert_comment_child_before"
+
+ external insert_element_child_before : node -> node -> string -> element =
+ "cadmiumxml_document_insert_element_child_before"
+
+ external insert_element_ns_child_before : node -> node -> string -> string -> element =
+ "cadmiumxml_document_insert_element_ns_child_before"
+
+ external insert_entity_reference_child_before : node -> node -> string -> entity_reference =
+ "cadmiumxml_document_insert_entity_reference_child_before"
+
+ external get_child_nodes : node -> node list =
+ "cadmiumxml_document_get_child_nodes"
+
+ external get_first_child : node -> node =
+ "cadmiumxml_document_get_first_child"
+
+ external get_last_child : node -> node =
+ "cadmiumxml_document_get_last_child"
+
+ external get_previous_sibling : node -> node =
+ "cadmiumxml_document_get_previous_sibling"
+
+ external get_next_sibling : node -> node =
+ "cadmiumxml_document_get_next_sibling"
+
+ external remove_child : node -> node -> unit =
+ "cadmiumxml_document_remove_child"
+
+ external replace_child : node -> node -> node -> unit =
+ "cadmiumxml_document_replace_child"
+ end
+
+
+module DocumentFactory =
+ struct
+ type t
+
+ external make : unit -> t =
+ "cadmiumxml_documentfactory_make"
+
+ external set_attribute : t -> string -> Cadmium.java_object -> unit =
+ "cadmiumxml_documentfactory_set_attribute"
+
+ let set_attribute_obj x s o = set_attribute x s o#cd'this
+
+ external get_attribute : t -> string -> Cadmium.java_object =
+ "cadmiumxml_documentfactory_get_attribute"
+
+ let get_attribute_obj x s = new CadmiumObj.jObject (`Cd'init (get_attribute x s ))
+
+ external set_feature : t -> string -> bool -> unit =
+ "cadmiumxml_documentfactory_set_feature"
+
+ external get_feature : t -> string -> bool =
+ "cadmiumxml_documentfactory_get_feature"
+
+ external set_schema : t -> Schema.t -> unit =
+ "cadmiumxml_documentfactory_set_schema"
+
+ external get_schema : t -> Schema.t =
+ "cadmiumxml_documentfactory_get_schema"
+
+ external set_coalescing : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_coalescing"
+
+ external is_coalescing : t -> bool =
+ "cadmiumxml_documentfactory_is_coalescing"
+
+ external set_expand_entity_references : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_expand_entity_references"
+
+ external is_expand_entity_references : t -> bool =
+ "cadmiumxml_documentfactory_is_expand_entity_references"
+
+ external set_ignoring_comments : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_ignoring_comments"
+
+ external is_ignoring_comments : t -> bool =
+ "cadmiumxml_documentfactory_is_ignoring_comments"
+
+ external set_ignoring_element_content_whitespace : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_ignoring_element_content_whitespace"
+
+ external is_ignoring_element_content_whitespace : t -> bool =
+ "cadmiumxml_documentfactory_is_ignoring_element_content_whitespace"
+
+ external set_namespace_aware : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_namespace_aware"
+
+ external is_namespace_aware : t -> bool =
+ "cadmiumxml_documentfactory_is_namespace_aware"
+
+ external set_validating : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_validating"
+
+ external is_validating : t -> bool =
+ "cadmiumxml_documentfactory_is_validating"
+
+ external set_xinclude_aware : t -> bool -> unit =
+ "cadmiumxml_documentfactory_set_xinclude_aware"
+
+ external is_xinclude_aware : t -> bool =
+ "cadmiumxml_documentfactory_is_xinclude_aware"
+ end
+
+
+module DocumentBuilder =
+ struct
+ type t
+
+ external make : DocumentFactory.t -> t =
+ "cadmiumxml_documentbuilder_make"
+
+ external get_schema : t -> Schema.t =
+ "cadmiumxml_documentbuilder_get_schema"
+
+ external is_namespace_aware : t -> bool =
+ "cadmiumxml_documentbuilder_is_namespace_aware"
+
+ external is_validating : t -> bool =
+ "cadmiumxml_documentbuilder_is_validating"
+
+ external is_xinclude_aware : t -> bool =
+ "cadmiumxml_documentbuilder_is_xinclude_aware"
+
+ external new_document : t -> Document.document =
+ "cadmiumxml_documentbuilder_new_document"
+
+ external parse_file : t -> string -> Document.document =
+ "cadmiumxml_documentbuilder_parse_file"
+
+ external parse_channel : t -> in_channel -> Document.document =
+ "cadmiumxml_documentbuilder_parse_channel"
+
+ external reset : t -> unit =
+ "cadmiumxml_documentbuilder_reset"
+ end
+
+
+module Tree =
+ struct
+ type t = Element of element | Cdata of string | Text of string
+ and element = { tag : string; attributes : (string * string) list; children : t list; }
+
+ external of_document : Document.document -> t =
+ "cadmiumxml_tree_of_document"
+ end
+
+
+module TransformerFactory =
+ struct
+ type t
+
+ external make : unit -> t =
+ "cadmiumxml_transformerfactory_make"
+
+ external set_attribute : t -> string -> Cadmium.java_object -> unit =
+ "cadmiumxml_transformerfactory_set_attribute"
+
+ let set_attribute_obj x s o = set_attribute x s o#cd'this
+
+ external get_attribute : t -> string -> Cadmium.java_object =
+ "cadmiumxml_transformerfactory_get_attribute"
+
+ let get_attribute_obj x s = new CadmiumObj.jObject (`Cd'init (get_attribute x s ))
+
+ external set_feature : t -> string -> bool -> unit =
+ "cadmiumxml_transformerfactory_set_feature"
+
+ external get_feature : t -> string -> bool =
+ "cadmiumxml_transformerfactory_get_feature"
+ end
+
+
+module Transformer =
+ struct
+ type t
+
+ external make_id : TransformerFactory.t -> t =
+ "cadmiumxml_transformer_make_id"
+
+ external make_from_file : TransformerFactory.t -> string -> t =
+ "cadmiumxml_transformer_make_from_file"
+
+ external make_from_channel : TransformerFactory.t -> in_channel -> t =
+ "cadmiumxml_transformer_make_from_channel"
+
+ external clear_parameters : t -> unit =
+ "cadmiumxml_transformer_clear_parameters"
+
+ external set_parameter : t -> string -> Cadmium.java_object -> unit =
+ "cadmiumxml_transformer_set_parameter"
+
+ let set_parameter_obj x s o = set_parameter x s o#cd'this
+
+ external get_parameter : t -> string -> Cadmium.java_object =
+ "cadmiumxml_transformer_get_parameter"
+
+ let get_parameter_obj x s = new CadmiumObj.jObject (`Cd'init (get_parameter x s ))
+
+ external set_output_property : t -> string -> string -> unit =
+ "cadmiumxml_transformer_set_output_property"
+
+ external get_output_property : t -> string -> string =
+ "cadmiumxml_transformer_get_output_property"
+
+ external transform_file_to_file : t -> string -> string -> unit =
+ "cadmiumxml_transformer_transform_file_to_file"
+
+ external transform_file_to_channel : t -> string -> out_channel -> unit =
+ "cadmiumxml_transformer_transform_file_to_channel"
+
+ external transform_channel_to_file : t -> in_channel -> string -> unit =
+ "cadmiumxml_transformer_transform_channel_to_file"
+
+ external transform_channel_to_channel : t -> in_channel -> out_channel -> unit =
+ "cadmiumxml_transformer_transform_channel_to_channel"
+
+ external reset : t -> unit =
+ "cadmiumxml_transformer_reset"
+ end
+
+
+module XPathFactory =
+ struct
+ type t
+
+ external make : unit -> t =
+ "cadmiumxml_xpathfactory_make"
+
+ external set_feature : t -> string -> bool -> unit =
+ "cadmiumxml_xpathfactory_set_feature"
+
+ external get_feature : t -> string -> bool =
+ "cadmiumxml_xpathfactory_get_feature"
+ end
+
+
+module XPath =
+ struct
+ type t
+
+ type expr
+
+ external make : XPathFactory.t -> t =
+ "cadmiumxml_xpath_make"
+
+ external compile : t -> string -> expr =
+ "cadmiumxml_xpath_compile"
+
+ external evaluate_file : t -> string -> string -> string =
+ "cadmiumxml_xpath_evaluate_file"
+
+ external evaluate_channel : t -> string -> in_channel -> string =
+ "cadmiumxml_xpath_evaluate_channel"
+
+ external evaluate_document : t -> string -> Document.document -> string =
+ "cadmiumxml_xpath_evaluate_document"
+
+ external expr_evaluate_file : expr -> string -> string =
+ "cadmiumxml_xpath_expr_evaluate_file"
+
+ external expr_evaluate_channel : expr -> in_channel -> string =
+ "cadmiumxml_xpath_expr_evaluate_channel"
+
+ external expr_evaluate_document : expr -> Document.document -> string =
+ "cadmiumxml_xpath_expr_evaluate_document"
+
+ external reset : t -> unit =
+ "cadmiumxml_xpath_reset"
+ end
+
+
+let () = (* to ensure that the Cadmium library is initialized *)
+ ignore (Cadmium.is_available ())
addfile ./src/ocaml/cadmiumXML.mli
hunk ./src/ocaml/cadmiumXML.mli 1
+(*
+ * This file is part of Cadmium.
+ * Copyright (C) 2007 Xavier Clerc.
+ *
+ * Cadmium is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cadmium is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *)
+
+(** Access to XML parsers and transformers. *)
+
+(** The following modules (except {i Tree}) are "translations" of the Java classes
+ having the same name in packages {i javax.xml.parsers}, {i javax.xml.transform},
+ {i javax.xml.validation}, {i javax.xml.xpath}, as well as {i org.w3c.dom},
+ and {i org.xml.sax}. Detailed information about the various functions can hence be
+ found in the Javadoc of these packages and classes.
+
+ The {i Tree} module is not the "translation" of a Java class, only providing a
+ simplified representation of XML documents. *)
+
+
+module SchemaFactory :
+ sig
+ type t
+ (** Type of schema factories. *)
+
+ val make : string -> t
+ (** Constructs a schema factory, passed argument being the schema language. *)
+
+ val set_feature : t -> string -> bool -> unit
+ (** [set_feature f n v] sets value [v] to feature named [n] for factory [f]. *)
+
+ val get_feature : t -> string -> bool
+ (** [get_feature f n] gets value of feature named [n] for factory [f]. *)
+
+ val set_property : t -> string -> Cadmium.java_object -> unit
+ (** [set_property f n v] sets value [v] to property named [n] for factory [f]. *)
+
+ val set_property_obj : t -> string -> CadmiumObj.jObject -> unit
+ (** [set_property f n v] sets value [v] to property named [n] for factory [f]. *)
+
+ val get_property : t -> string -> Cadmium.java_object
+ (** [get_property f n] gets value of property named [n] for factory [f]. *)
+
+ val get_property_obj : t -> string -> CadmiumObj.jObject
+ (** [get_property f n] gets value of property named [n] for factory [f]. *)
+ end
+(** Schema factories. *)
+
+
+module Schema :
+ sig
+ type t
+ (** Type of schemas. *)
+
+ val make_schema_from_file : SchemaFactory.t -> string -> t
+ (** [make_schema_from_file f x] constructs a schema from file [x]
+ using factory [f]. *)
+
+ val make_schema_from_url : SchemaFactory.t -> string -> t
+ (** [make_schema_from_url f x] constructs a schema from url [x]
+ using factory [f]. *)
+ end
+(** Schema builders. *)
+
+
+module SAXFactory :
+ sig
+ type t
+ (** Type of SAX parser factories. *)
+
+ val make : unit -> t
+ (** Constructs a SAX parser factory. *)
+
+ val set_feature : t -> string -> bool -> unit
+ (** [set_feature f n v] sets value [v] to feature named [n] for factory [f]. *)
+
+ val get_feature : t -> string -> bool
+ (** [get_feature f n] gets value of feature named [n] for factory [f]. *)
+
+ val set_schema : t -> Schema.t -> unit
+ (** [set_schema f s] sets the schema for constructed parsers to [s]
+ for factory [f]. *)
+
+ val get_schema : t -> Schema.t
+ (** [get_schema f] gets the schema for constructed parsers for factory [f]. *)
+
+ val set_namespace_aware : t -> bool -> unit
+ (** Sets the 'namespace-aware' property for constructed parsers. *)
+
+ val is_namespace_aware : t -> bool
+ (** Gets the 'namespace-aware' property for constructed parsers. *)
+
+ val set_validating : t -> bool -> unit
+ (** Sets the 'validating' property for constructed parsers. *)
+
+ val is_validating : t -> bool
+ (** Gets the 'validating' property for constructed parsers. *)
+
+ val set_xinclude_aware : t -> bool -> unit
+ (** Sets the 'xinclude-aware' property for constructed parsers. *)
+
+ val is_xinclude_aware : t -> bool
+ (** Gets the 'xinclude-aware' property for constructed parsers. *)
+ end
+(** SAX parser factories. *)
+
+
+module SAXParser :
+ sig
+ type t
+ (** Type of SAX parsers. *)
+
+ type parse_error = int * int * string
+ (** Type of parse error. First component is line number, while second one is
+ column number. The last component is the exception message associated with
+ the parse error. *)
+
+ type handler = {
+ characters : string -> unit;
+ (** Called for notification of characters inside an element. *)
+ ignorable_whitespace : string -> unit;
+ (** Called for notification of ignorable whitespace inside an element. *)
+ start_document : unit -> unit;
+ (** Called for notification of document begin. *)
+ end_document : unit -> unit;
+ (** Called for notification of document end. *)
+ start_element : string -> string -> string -> ((string * string) list) -> unit;
+ (** Called for notification of element start. Parameters are:
+ - URI;
+ - local name for tag;
+ - qualified name for tag;
+ - association list from attribute names to attribute values. *)
+ end_element : string -> string -> string -> unit;
+ (** Called for notification of element end. Parameters are:
+ - URI;
+ - local name for tag;
+ - qualified name for tag. *)
+ start_prefix_mapping : string -> string -> unit;
+ (** Called for notification of prefix mapping.
+ Parameters are prefix and URI.*)
+ end_prefix_mapping : string -> unit;
+ (** Called for notification of prefix mapping. Parameter is prefix. *)
+ error : parse_error -> unit;
+ (** Called for notification of recoverable parse error. *)
+ fatal_error : parse_error -> unit;
+ (** Called for notification of fatal parse error. *)
+ warning : parse_error -> unit;
+ (** Called for notification of parse warning. *)
+ }
+ (** Type of SAX handlers, collection of callback functions. *)
+
+ val default_handler : handler
+ (** Default handler, all callbacks do nothing. To be used to construct handler
+ using the {i with} notation:
+ [{ default_handler with characters = print_endline }]. *)
+
+ val make : SAXFactory.t -> t
+ (** Constructs a new SAX parser. *)
+
+ val set_property : t -> string -> Cadmium.java_object -> unit
+ (** [set_property p n v] sets value [v] to property named [n] for parser [p]. *)
+
+ val set_property_obj : t -> string -> CadmiumObj.jObject -> unit
+ (** [set_property p n v] sets value [v] to property named [n] for parser [p]. *)
+
+ val get_property : t -> string -> Cadmium.java_object
+ (** [get_property p n] gets value of property named [n] for parser [p]. *)
+
+ val get_property_obj : t -> string -> CadmiumObj.jObject
+ (** [get_property p n] gets value of property named [n] for parser [p]. *)
+
+ val get_schema : t -> Schema.t
+ (** Gets the schema for the passed parser. *)
+
+ val is_namespace_aware : t -> bool
+ (** Gets the 'namespace-aware' property for the passed parser. *)
+
+ val is_validating : t -> bool
+ (** Gets the 'validating' property for the passed parser. *)
+
+ val is_xinclude_aware : t -> bool
+ (** Gets the 'xinclude-aware' property for the passed parser. *)
+
+ val parse_file : t -> handler -> string -> unit
+ (** [parse_file p h f] parses file [f] using parser [p] and handler [h]. *)
+
+ val parse_channel : t -> handler -> in_channel -> unit
+ (** [parse_channel p h ch] parses channel [ch] using parser [p] and handler [h]. *)
+
+ val reset : t -> unit
+ (** Resets the passed SAX parser. *)
+ end
+(** SAX parsers. *)
+
+
+module Document :
+ sig
+ (** {6 Types} *)
+
+ type attr
+ (** Type of attribute nodes. *)
+
+ type cdata
+ (** Type of cdata nodes. *)
+
+ type comment
+ (** Type of comment nodes. *)
+
+ type document
+ (** Type of document nodes. *)
+
+ type document_type
+ (** Type of document type nodes. *)
+
+ type element
+ (** Type of element nodes. *)
+
+ type entity
+ (** Type of entity nodes. *)
+
+ type entity_reference
+ (** Type of entity reference nodes. *)
+
+ type notation
+ (** Type of notation nodes. *)
+
+ type processing_instruction
+ (** Type of processing instruction nodes. *)
+
+ type text
+ (** Type of text nodes. *)
+
+ type node =
+ | Attr of attr (** attribute as bare node *)
+ | Cdata of cdata (** cdata as bare node *)
+ | Comment of comment (** comment as bare node *)
+ | Document of document (** document as bare node *)
+ | Document_type of document_type (** document type as bare node *)
+ | Element of element (** element as bare node *)
+ | Entity of entity (** entity as bare node *)
+ | Entity_reference of entity_reference (** entity reference as bare node *)
+ | Notation of notation (** notation as bare node *)
+ | Processing_instruction of processing_instruction (** processing instruction as bare node *)
+ | Text of text (** text as bare node *)
+ (** Type of nodes. *)
+
+
+ (** {6 Document functions} *)
+
+ val get_document_element : document -> element
+ (** Returns the root element of the document. *)
+
+ val get_xml_encoding : document -> string
+ (** Returns the document encoding. *)
+
+ val set_strict_error_checking : document -> bool -> unit
+ (** Sets the 'strict-error-checking' property for passed document. *)
+
+ val is_strict_error_checking : document -> bool
+ (** Gets the 'strict-error-checking' property for passed document. *)
+
+ val set_xml_standalone : document -> bool -> unit
+ (** Sets the 'stand-alone' property for passed document. *)
+
+ val is_xml_standalone : document -> bool
+ (** Gets the 'stand-alone' property for passed document. *)
+
+ val set_xml_version : document -> bool -> unit
+ (** Sets the 'xml-version' property for passed document. *)
+
+ val get_xml_version : document -> string
+ (** Gets the 'xml-version' property for passed document. *)
+
+ val normalize_document : document -> unit
+ (** Normalizes the passed document. *)
+
+ val node_of_document : document -> node
+ (** Converts the passed document into a bare node. *)
+
+
+ (** {6 Attribute functions} *)
+
+ val get_attr_parent : attr -> element
+ (** Returns the parent of the passed attribute. *)
+
+ val get_attr_name : attr -> string
+ (** Returns the name of the passed attribute. *)
+
+ val get_attr_value : attr -> string
+ (** Returns the value of the passed attribute. *)
+
+ val set_attr_value : attr -> string -> unit
+ (** Changes the value of the passed attribute. *)
+
+ val node_of_attr : attr -> node
+ (** Converts the passed attribute into a bare node. *)
+
+
+ (** {6 CData functions} *)
+
+ val get_cdata_parent : cdata -> node
+ (** Returns the parent of the passed cdata. *)
+
+ val get_cdata : cdata -> string
+ (** Returns the data of the passed cdata. *)
+
+ val set_cdata : cdata -> string -> unit
+ (** Changes the data of the passed cdata. *)
+
+ val node_of_cdata : cdata -> node
+ (** Converts the passed cdata into a bare node. *)
+
+
+ (** {6 Comment functions} *)
+
+ val get_comment_parent : comment -> node
+ (** Returns the parent of the passed comment. *)
+
+ val get_comment : comment -> string
+ (** Returns the data of the passed comment. *)
+
+ val set_comment : comment -> string -> unit
+ (** Changes the data of the passed comment. *)
+
+ val node_of_comment : comment -> node
+ (** Converts the passed comment into a bare node. *)
+
+
+ (** {6 Document type functions} *)
+
+ val get_document_type_parent : document_type -> node
+ (** Returns the parent of the passed document type. *)
+
+ val get_document_type_name : document_type -> string
+ (** Returns the name of the passed document type. *)
+
+ val get_document_type_public_id : document_type -> string
+ (** Returns the public ID of the passed document type. *)
+
+ val get_document_type_system_id : document_type -> string
+ (** Returns the system ID of the passed document type. *)
+
+ val node_of_document_type : document_type -> node
+ (** Converts the passed document type into a bare node. *)
+
+
+ (** {6 Element functions} *)
+
+ val get_element_parent : element -> node
+ (** Returns the parent of the passed element. *)
+
+ val get_attribute : element -> string -> string
+ (** [get_attribute e n] returns the value for the attribute of element [e]
+ named [n]. *)
+
+ val get_attribute_ns : element -> string -> string -> string
+ (** [get_attribute_ns e ns n] returns the value for the attribute of element [e]
+ named [n] in namespace [ns]. *)
+
+ val get_attribute_node : element -> string -> attr
+ (** [get_attribute_node e n] returns the attribute of element [e] named [n]. *)
+
+ val get_attribute_node_ns : element -> string -> string -> attr
+ (** [get_attribute_node_ns e ns n] returns the attribute of element [e] named [n]
+ in namespace [ns]. *)
+
+ val get_elements_by_tag_name : element -> string -> element list
+ (** [get_elements_by_tag_name e t] returns the child elements of [e] whose tag
+ is [t]. *)
+
+ val get_elements_by_tag_name_ns : element -> string -> string -> element list
+ (** [get_elements_by_tag_name_ns e ns t] returns the child elements of [e] whose
+ tag is [t], using namespace ns. *)
+
+ val get_tag_name : element -> string
+ (** Returns the tag name of the passed element. *)
+
+ val has_attribute : element -> string -> bool
+ (** [has_attribute e n] tests if element [e] has an attribute named [n]. *)
+
+ val has_attribute_ns : element -> string -> string -> bool
+ (** [has_attribute_ns e ns n] tests if element [e] has an attribute named [n]
+ in namespace [ns]. *)
+
+ val remove_attribute : element -> string -> unit
+ (** [remove_attribute e n] removes the attribute named [n] from element [e]. *)
+
+ val remove_attribute_ns : element -> string -> string -> unit
+ (** [remove_attribute_ns e ns n] removes the attribute named [n] from element [e]
+ in namespace [ns]. *)
+
+ val remove_attribute_node : element -> attr -> unit
+ (** [remove_attribute_node e n] removes attribute [n] from element [e]. *)
+
+ val set_attribute : element -> string -> string -> unit
+ (** [set_attribute e n v] sets the value of the attribute named [n] to the value
+ [v] for element [e]. *)
+
+ val set_attribute_ns : element -> string -> string -> string -> unit
+ (** [set_attribute e n v] sets the value of the attribute named [n] to the value
+ [v] for element [e] in namespace [ns]. *)
+
+ val node_of_element : element -> node
+ (** Converts the passed element into a bare node. *)
+
+
+ (** {6 Entity functions} *)
+
+ val get_entity_parent : entity -> node
+ (** Returns the parent of the passed entity. *)
+
+ val get_entity_notation_name : entity -> string
+ (** Returns the notation name of the passed entity. *)
+
+ val get_entity_public_id : entity -> string
+ (** Returns the public ID of the passed entity. *)
+
+ val get_entity_system_id : entity -> string
+ (** Returns the system ID of the passed entity. *)
+
+ val node_of_entity : entity -> node
+ (** Converts the passed entity into a bare node. *)
+
+
+ (** {6 Notation functions} *)
+
+ val get_notation_parent : notation -> node
+ (** Returns the parent of the passed notation. *)
+
+ val get_notation_public_id : notation -> string
+ (** Returns the public ID of the passed notation. *)
+
+ val get_notation_system_id : notation -> string
+ (** Returns the system ID of the passed notation. *)
+
+ val node_of_notation : notation -> node
+ (** Converts the passed notation into a bare node. *)
+
+
+ (** {6 Processing instruction functions} *)
+
+ val get_processing_instruction_parent : processing_instruction -> node
+ (** Returns the parent of the passed processing instruction. *)
+
+ val get_processing_instruction_target : processing_instruction -> string
+ (** Returns the target of the passed processing instruction. *)
+
+ val get_processing_instruction_data : processing_instruction -> string
+ (** Returns the data of the passed processing instruction. *)
+
+ val set_processing_instruction_data : processing_instruction -> string -> unit
+ (** Changes the data of the passed processing instruction. *)
+
+ val node_of_processing_instruction : processing_instruction -> node
+ (** Converts the passed processing instruction into a bare node. *)
+
+
+ (** {6 Text functions} *)
+
+ val get_text_parent : text -> node
+ (** Returns the parent of the passed text. *)
+
+ val get_text : text -> string
+ (** Returns the data of the passed text. *)
+
+ val set_text : text -> string -> unit
+ (** Changes the data of the passed text. *)
+
+ val node_of_text : text -> node
+ (** Converts the passed text into a bare node. *)
+
+
+ (** {6 Node functions} *)
+
+ val get_parent : node -> node
+ (** Returns the parent of the passed node.
+ Raises [Not_found] if such a node does not exist. *)
+
+ val get_document : node -> document
+ (** Returns the enclosing document of the passed node. *)
+
+ val append_attr_child : node -> string -> attr
+ (** [append_attr_child n a] adds an attribute child with name [a] to node [n].
+ Returns the added child. *)
+
+ val append_attr_ns_child : node -> string -> string -> attr
+ (** [append_attr_ns_child n ns a] adds an attribute child with name [a] to node
+ [n], using namespace [ns].
+ Returns the added child. *)
+
+ val append_cdata_child : node -> string -> cdata
+ (** [append_cdata_child n d] adds a cdata child with data [d] to node [n].
+ Returns the added child. *)
+
+ val append_comment_child : node -> string -> comment
+ (** [append_comment_child n d] adds a comment child with data [d] to node [n].
+ Returns the added child. *)
+
+ val append_element_child : node -> string -> element
+ (** [append_element_child n t] adds an element child with tag [t] to node [n].
+ Returns the added child. *)
+
+ val append_element_ns_child : node -> string -> string -> element
+ (** [append_element_ns_child n t] adds an element child with tag [t] to node [n]
+ in namespace [ns].
+ Returns the added child. *)
+
+ val append_entity_reference_child : node -> string -> entity_reference
+ (** [append_entity_reference_child n e] adds an entity reference child for
+ reference named [e] to node [n].
+ Returns the added child. *)
+
+ val insert_attr_child_before : node -> node -> string -> attr
+ (** [insert_attr_child n b a] adds an attribute child with name [a] to node [n]
+ before child [b].
+ Returns the added child. *)
+
+ val insert_attr_ns_child_before : node -> node -> string -> string -> attr
+ (** [insert_attr_ns_child n b ns a] adds an attribute child with name [a] to node
+ [n] before child [b], using namespace [ns].
+ Returns the added child. *)
+
+ val insert_cdata_child_before : node -> node -> string -> cdata
+ (** [insert_cdata_child n b d] adds a cdata child with data [d] to node [n]
+ before child [b].
+ Returns the added child. *)
+
+ val insert_comment_child_before : node -> node -> string -> comment
+ (** [insert_comment_child n b d] adds a comment child with data [d] to node [n]
+ before child [b].
+ Returns the added child. *)
+
+ val insert_element_child_before : node -> node -> string -> element
+ (** [insert_element_child n b t] adds an element child with tag [t] to node [n]
+ before child [b].
+ Returns the added child. *)
+
+ val insert_element_ns_child_before : node -> node -> string -> string -> element
+ (** [insert_element_ns_child n b t] adds an element child with tag [t]
+ to node [n] before child [b] in namespace [ns].
+ Returns the added child. *)
+
+ val insert_entity_reference_child_before : node -> node -> string -> entity_reference
+ (** [insert_entity_reference_child n b e] adds an entity reference child for
+ reference named [e] to node [n] before child [b].
+ Returns the added child. *)
+
+ val get_child_nodes : node -> node list
+ (** Returns the child nodes of the passed node. *)
+
+ val get_first_child : node -> node
+ (** Returns the first child of the passed node.
+ Raises [Not_found] if such a node does not exist. *)
+
+ val get_last_child : node -> node
+ (** Returns the last child of the passed node.
+ Raises [Not_found] if such a node does not exist. *)
+
+ val get_previous_sibling : node -> node
+ (** Returns the previous sibling of the passed node.
+ Raises [Not_found] if such a node does not exist. *)
+
+ val get_next_sibling : node -> node
+ (** Returns the next sibling of the passed node.
+ Raises [Not_found] if such a node does not exist. *)
+
+ val remove_child : node -> node -> unit
+ (** [remove_child n c] removes child [c] from node [n]. *)
+
+ val replace_child : node -> node -> node -> unit
+ (** [replace_child n nw od] replaces child [od] with [nw] for node [n]. *)
+ end
+(** Document manipulation. *)
+
+
+module DocumentFactory :
+ sig
+ type t
+ (** Type of document factories. *)
+
+ val make : unit -> t
+ (** Constructs a new factory. *)
+
+ val set_attribute : t -> string -> Cadmium.java_object -> unit
+ (** [set_attribute f n v] sets value [v] to attribute named [n] for factory [f]. *)
+
+ val set_attribute_obj : t -> string -> CadmiumObj.jObject -> unit
+ (** [set_attribute f n v] sets value [v] to attribute named [n] for factory [f]. *)
+
+ val get_attribute : t -> string -> Cadmium.java_object
+ (** [get_attribute f n] gets value of attribute named [n] for factory [f]. *)
+
+ val get_attribute_obj : t -> string -> CadmiumObj.jObject
+ (** [get_attribute f n] gets value of attribute named [n] for factory [f]. *)
+
+ val set_feature : t -> string -> bool -> unit
+ (** [set_feature f n v] sets value [v] to feature named [n] for factory [f]. *)
+
+ val get_feature : t -> string -> bool
+ (** [get_feature f n] gets value of feature named [n] for factory [f]. *)
+
+ val set_schema : t -> Schema.t -> unit
+ (** [set_schema f s] sets the schema for constructed parsers to [s]
+ for factory [f]. *)
+
+ val get_schema : t -> Schema.t
+ (** [get_schema f] gets the schema for constructed parsers for factory [f]. *)
+
+ val set_coalescing : t -> bool -> unit
+ (** Sets the 'coalescing' property for constructed parsers. *)
+
+ val is_coalescing : t -> bool
+ (** Gets the 'coalescing' property for constructed parsers. *)
+
+ val set_expand_entity_references : t -> bool -> unit
+ (** Sets the 'expand-entity' property for constructed parsers. *)
+
+ val is_expand_entity_references : t -> bool
+ (** Gets the 'expand-entity' property for constructed parsers. *)
+
+ val set_ignoring_comments : t -> bool -> unit
+ (** Sets the 'ignoring-comments' property for constructed parsers. *)
+
+ val is_ignoring_comments : t -> bool
+ (** Gets the 'ignoring-comments' property for constructed parsers. *)
+
+ val set_ignoring_element_content_whitespace : t -> bool -> unit
+ (** Sets the 'ignoring-element-content-whitespace' property for constructed parsers. *)
+
+ val is_ignoring_element_content_whitespace : t -> bool
+ (** Gets the 'ignoring-element-content-whitespace' property for constructed parsers. *)
+
+ val set_namespace_aware : t -> bool -> unit
+ (** Sets the 'namespace-aware' property for constructed parsers. *)
+
+ val is_namespace_aware : t -> bool
+ (** Gets the 'namespace-aware' property for constructed parsers. *)
+
+ val set_validating : t -> bool -> unit
+ (** Sets the 'validating' property for constructed parsers. *)
+
+ val is_validating : t -> bool
+ (** Gets the 'validating' property for constructed parsers. *)
+
+ val set_xinclude_aware : t -> bool -> unit
+ (** Sets the 'xinclude-aware' property for constructed parsers. *)
+
+ val is_xinclude_aware : t -> bool
+ (** Gets the 'xinclude-aware' property for constructed parsers. *)
+ end
+(** Document builder factories. *)
+
+
+module DocumentBuilder :
+ sig
+ type t
+ (** Type of transformer builders. *)
+
+ val make : DocumentFactory.t -> t
+ (** Constructs a new builder from passed factory. *)
+
+ val get_schema : t -> Schema.t
+ (** [get_schema b] gets the schema for builder [b]. *)
+
+ val is_namespace_aware : t -> bool
+ (** Gets the 'namespace-aware' property for passed builder. *)
+
+ val is_validating : t -> bool
+ (** Gets the 'validating' property for passed builder. *)
+
+ val is_xinclude_aware : t -> bool
+ (** Gets the 'xinclude-aware' property for passed builder. *)
+
+ val new_document : t -> Document.document
+ (** Creates an empty document. *)
+
+ val parse_file : t -> string -> Document.document
+ (** [parse_file b f] parses file [f] using builder [b]. *)
+
+ val parse_channel : t -> in_channel -> Document.document
+ (** [parse_channel b ch] parses channel [ch] using builder [b]. *)
+
+ val reset : t -> unit
+ (** Resets the passed builder. *)
+ end
+(** Document builders. *)
+
+
+module Tree :
+ sig
+ type t = Element of element | Cdata of string | Text of string
+ and element = { tag : string; attributes : (string * string) list; children : t list; }
+
+ val of_document : Document.document -> t
+ (** Converts the passed document into its simplified representation. *)
+ end
+(** Simplified representation of XML documents. *)
+
+
+module TransformerFactory :
+ sig
+ type t
+ (** Type of transformer factories. *)
+
+ val make : unit -> t
+ (** Constructs a transformer factory. *)
+
+ val set_attribute : t -> string -> Cadmium.java_object -> unit
+ (** [set_attribute f n v] sets value [v] to attribute named [n] for factory [f]. *)
+
+ val set_attribute_obj : t -> string -> CadmiumObj.jObject -> unit
+ (** [set_attribute f n v] sets value [v] to attribute named [n] for factory [f]. *)
+
+ val get_attribute : t -> string -> Cadmium.java_object
+ (** [get_attribute f n] gets value of attribute named [n] for factory [f]. *)
+
+ val get_attribute_obj : t -> string -> CadmiumObj.jObject
+ (** [get_attribute f n] gets value of attribute named [n] for factory [f]. *)
+
+ val set_feature : t -> string -> bool -> unit
+ (** [set_feature f n v] sets value [v] to feature named [n] for factory [f]. *)
+
+ val get_feature : t -> string -> bool
+ (** [get_feature f n] gets value of feature named [n] for factory [f]. *)
+ end
+(** Transformer factories. *)
+
+
+module Transformer :
+ sig
+ type t
+ (** Type of transformers. *)
+
+ val make_id : TransformerFactory.t -> t
+ (** Constructs an identity transformer. *)
+
+ val make_from_file : TransformerFactory.t -> string -> t
+ (** [make_from_file f fn] constructs a transformer from file [fn],
+ using factory [f]. *)
+
+ val make_from_channel : TransformerFactory.t -> in_channel -> t
+ (** [make_from_channel f ch] constructs a transformer from channel [ch],
+ using factory [f]. *)
+
+ val clear_parameters : t -> unit
+ (** Clears transformer parameters. *)
+
+ val set_parameter : t -> string -> Cadmium.java_object -> unit
+ (** [set_parameter t n v] sets value [v] to parameter named [n]
+ for transformer [t]. *)
+
+ val set_parameter_obj : t -> string -> CadmiumObj.jObject -> unit
+ (** [set_parameter t n v] sets value [v] to parameter named [n]
+ for transformer [t]. *)
+
+ val get_parameter : t -> string -> Cadmium.java_object
+ (** [get_parameter t n] gets value of parameter named [n] for transformer [t]. *)
+
+ val get_parameter_obj : t -> string -> CadmiumObj.jObject
+ (** [get_parameter t n] gets value of parameter named [n] for transformer [t]. *)
+
+ val set_output_property : t -> string -> string -> unit
+ (** [set_output_property t n v] sets value [v] to property named [n]
+ for transformer [t]. *)
+
+ val get_output_property : t -> string -> string
+ (** [get_output_property t n] gets value of property named [n]
+ for transformer [t]. *)
+
+ val transform_file_to_file : t -> string -> string -> unit
+ (** [transform_file_to_file t src dst] applies transformer [t]
+ to [src], producing [dst]. *)
+
+ val transform_file_to_channel : t -> string -> out_channel -> unit
+ (** [transform_file_to_channel t src dst] applies transformer [t]
+ to [src], producing [dst]. *)
+
+ val transform_channel_to_file : t -> in_channel -> string -> unit
+ (** [transform_channel_to_file t src dst] applies transformer [t]
+ to [src], producing [dst]. *)
+
+ val transform_channel_to_channel : t -> in_channel -> out_channel -> unit
+ (** [transform_channel_to_channel t src dst] applies transformer [t]
+ to [src], producing [dst]. *)
+
+ val reset : t -> unit
+ (** Resets the passed transformer. *)
+ end
+(** Transformers. *)
+
+
+module XPathFactory :
+ sig
+ type t
+ (** Type of xpath factories. *)
+
+ val make : unit -> t
+ (** Constructs an xpath factory. *)
+
+ val set_feature : t -> string -> bool -> unit
+ (** [set_feature f n v] sets value [v] to feature named [n] for factory [f]. *)
+
+ val get_feature : t -> string -> bool
+ (** [get_feature f n] gets value of feature named [n] for factory [f]. *)
+ end
+(** XPath factories. *)
+
+
+module XPath :
+ sig
+ type t
+ (** Type of xpath instances. *)
+
+ type expr
+ (** Type of xpath expressions. *)
+
+ val make : XPathFactory.t -> t
+ (** Constructs an xpath instance. *)
+
+ val compile : t -> string -> expr
+ (** Compiles the passed xpath expression. *)
+
+ val evaluate_file : t -> string -> string -> string
+ (** [evaluate_file x e f] evaluate expression [e] in file [f] using [x]. *)
+
+ val evaluate_channel : t -> string -> in_channel -> string
+ (** [evaluate_channel x e c] evaluate expression [e] in channel [c] using [x]. *)
+
+ val evaluate_document : t -> string -> Document.document -> string
+ (** [evaluate_document x e d] evaluate expression [e] in document [d]
+ using [x]. *)
+
+ val expr_evaluate_file : expr -> string -> string
+ (** [expr_evaluate_file e f] evaluate expression [e] in file [f]. *)
+
+ val expr_evaluate_channel : expr -> in_channel -> string
+ (** [expr_evaluate_channel e c] evaluate expression [e] in channel [c]. *)
+
+ val expr_evaluate_document : expr -> Document.document -> string
+ (** [expr_evaluate_document e d] evaluate expression [e] in document [d]. *)
+
+ val reset : t -> unit
+ (** Resets the passed xpath instance. *)
+ end
+(** XPath queries. *)
}