use of org.w3c.dom.DOMException in project XobotOS by xamarin.
the class NodeImpl method setName.
/**
* Sets {@code node} to be not namespace-aware and assigns its name.
*
* @param node an element or attribute node.
*/
static void setName(NodeImpl node, String name) {
int prefixSeparator = name.lastIndexOf(":");
if (prefixSeparator != -1) {
String prefix = name.substring(0, prefixSeparator);
String localName = name.substring(prefixSeparator + 1);
if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
}
} else if (!DocumentImpl.isXMLIdentifier(name)) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
}
switch(node.getNodeType()) {
case ATTRIBUTE_NODE:
AttrImpl attr = (AttrImpl) node;
attr.namespaceAware = false;
attr.localName = name;
break;
case ELEMENT_NODE:
ElementImpl element = (ElementImpl) node;
element.namespaceAware = false;
element.localName = name;
break;
default:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot rename nodes of type " + node.getNodeType());
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class DOMConfigurationImpl method normalize.
public void normalize(Node node) {
switch(node.getNodeType()) {
case Node.CDATA_SECTION_NODE:
CDATASectionImpl cdata = (CDATASectionImpl) node;
if (cdataSections) {
if (cdata.needsSplitting()) {
if (splitCdataSections) {
cdata.split();
report(DOMError.SEVERITY_WARNING, "cdata-sections-splitted");
} else {
report(DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
checkTextValidity(cdata.buffer);
break;
}
node = cdata.replaceWithText();
case Node.TEXT_NODE:
TextImpl text = (TextImpl) node;
text = text.minimize();
if (text != null) {
checkTextValidity(text.buffer);
}
break;
case Node.COMMENT_NODE:
CommentImpl comment = (CommentImpl) node;
if (!comments) {
comment.getParentNode().removeChild(comment);
break;
}
if (comment.containsDashDash()) {
report(DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
checkTextValidity(comment.buffer);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
checkTextValidity(((ProcessingInstructionImpl) node).getData());
break;
case Node.ATTRIBUTE_NODE:
checkTextValidity(((AttrImpl) node).getValue());
break;
case Node.ELEMENT_NODE:
ElementImpl element = (ElementImpl) node;
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
normalize(attributes.item(i));
}
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
Node next;
for (Node child = node.getFirstChild(); child != null; child = next) {
// lookup next eagerly because normalize() may remove its subject
next = child.getNextSibling();
normalize(child);
}
break;
case Node.NOTATION_NODE:
case Node.DOCUMENT_TYPE_NODE:
case Node.ENTITY_NODE:
case Node.ENTITY_REFERENCE_NODE:
break;
default:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unsupported node type " + node.getNodeType());
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class LSSerializerImpl method writeToString.
/**
* Serializes the specified node and returns a String with the serialized
* data to the caller.
*
* @see org.w3c.dom.ls.LSSerializer#writeToString(org.w3c.dom.Node)
* @since DOM Level 3
* @param nodeArg The Node to serialize.
* @throws org.w3c.dom.ls.LSException SERIALIZE_ERR: Raised if the
* LSSerializer was unable to serialize the node.
*
*/
public String writeToString(Node nodeArg) throws DOMException, LSException {
// return null is nodeArg is null. Should an Exception be thrown instead?
if (nodeArg == null) {
return null;
}
// Should we reset the serializer configuration before each write operation?
// Obtain a reference to the serializer to use
Serializer serializer = fXMLSerializer;
serializer.reset();
if (nodeArg != fVisitedNode) {
// Determine the XML Document version of the Node
String xmlVersion = getXMLVersion(nodeArg);
serializer.getOutputFormat().setProperty("version", xmlVersion);
// Set the output encoding and xml version properties
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.S_XML_VERSION, xmlVersion);
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_ENCODING, "UTF-16");
// serialized.
if ((nodeArg.getNodeType() != Node.DOCUMENT_NODE || nodeArg.getNodeType() != Node.ELEMENT_NODE || nodeArg.getNodeType() != Node.ENTITY_NODE) && ((fFeatures & XMLDECL) != 0)) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, DOMConstants.DOM3_DEFAULT_FALSE);
}
fVisitedNode = nodeArg;
}
// Update the serializer properties
fXMLSerializer.setOutputFormat(fDOMConfigProperties);
// StringWriter to Output to
StringWriter output = new StringWriter();
//
try {
// Set the Serializer's Writer to a StringWriter
serializer.setWriter(output);
// Use this hack till Xalan support JAXP1.3
if (fDOMSerializer == null) {
fDOMSerializer = (DOM3Serializer) serializer.asDOM3Serializer();
}
// Set the error handler on the DOM3Serializer interface implementation
if (fDOMErrorHandler != null) {
fDOMSerializer.setErrorHandler(fDOMErrorHandler);
}
// Set the filter on the DOM3Serializer interface implementation
if (fSerializerFilter != null) {
fDOMSerializer.setNodeFilter(fSerializerFilter);
}
// Set the NewLine character to be used
fDOMSerializer.setNewLine(fEndOfLine.toCharArray());
// Serializer your DOM, where node is an org.w3c.dom.Node
fDOMSerializer.serializeDOM3(nodeArg);
} catch (LSException lse) {
// Rethrow LSException.
throw lse;
} catch (RuntimeException e) {
throw (LSException) createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
} catch (Exception e) {
if (fDOMErrorHandler != null) {
fDOMErrorHandler.handleError(new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, e.getMessage(), null, e));
}
throw (LSException) createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace();
}
// return the serialized string
return output.toString();
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class LSSerializerImpl method setParameter.
/**
* This method sets the value of the named parameter.
*
* @see org.w3c.dom.DOMConfiguration#setParameter(java.lang.String, java.lang.Object)
*
* @param name A String containing the DOMConfiguration parameter name.
* @param value An Object contaiing the parameters value to set.
*/
public void setParameter(String name, Object value) throws DOMException {
// If the value is a boolean
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS)) {
fFeatures = state ? fFeatures | COMMENTS : fFeatures & ~COMMENTS;
// comments
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS)) {
fFeatures = state ? fFeatures | CDATA : fFeatures & ~CDATA;
// cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES)) {
fFeatures = state ? fFeatures | ENTITIES : fFeatures & ~ENTITIES;
// entities
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES)) {
fFeatures = state ? fFeatures | NAMESPACES : fFeatures & ~NAMESPACES;
// namespaces
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS)) {
fFeatures = state ? fFeatures | NAMESPACEDECLS : fFeatures & ~NAMESPACEDECLS;
// namespace-declarations
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA)) {
fFeatures = state ? fFeatures | SPLITCDATA : fFeatures & ~SPLITCDATA;
// split-cdata-sections
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_SPLIT_CDATA, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED)) {
fFeatures = state ? fFeatures | WELLFORMED : fFeatures & ~WELLFORMED;
// well-formed
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT)) {
fFeatures = state ? fFeatures | DISCARDDEFAULT : fFeatures & ~DISCARDDEFAULT;
// discard-default-content
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DISCARD_DEFAULT_CONTENT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT)) {
fFeatures = state ? fFeatures | PRETTY_PRINT : fFeatures & ~PRETTY_PRINT;
// format-pretty-print
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_FORMAT_PRETTY_PRINT, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL)) {
fFeatures = state ? fFeatures | XMLDECL : fFeatures & ~XMLDECL;
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "no");
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_XSL_OUTPUT_OMIT_XML_DECL, "yes");
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fFeatures = state ? fFeatures | ELEM_CONTENT_WHITESPACE : fFeatures & ~ELEM_CONTENT_WHITESPACE;
// element-content-whitespace
if (state) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
// false is not supported
if (!state) {
// Here we have to add the Xalan specific DOM Message Formatter
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) // || name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)
{
// true is not supported
if (state) {
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
} else {
if (name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CANONICAL_FORM, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA)) {
fDOMConfigProperties.setProperty(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION + DOMConstants.DOM_CHECK_CHAR_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
} else if (name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
/* else if (name.equalsIgnoreCase(DOMConstants.DOM_NORMALIZE_CHARACTERS)) {
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS
+ DOMConstants.DOM_NORMALIZE_CHARACTERS, DOMConstants.DOM3_EXPLICIT_FALSE);
} */
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
// infoset
if (state) {
fFeatures &= ~ENTITIES;
fFeatures &= ~CDATA;
fFeatures &= ~SCHEMAVALIDATE;
fFeatures &= ~DTNORMALIZE;
fFeatures |= NAMESPACES;
fFeatures |= NAMESPACEDECLS;
fFeatures |= WELLFORMED;
fFeatures |= ELEM_CONTENT_WHITESPACE;
fFeatures |= COMMENTS;
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACES, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_NAMESPACE_DECLARATIONS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_COMMENTS, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_WELLFORMED, DOMConstants.DOM3_EXPLICIT_TRUE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_XERCES_PROPERTIES_NS + DOMConstants.DOM_ENTITIES, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_CDATA_SECTIONS, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_VALIDATE_IF_SCHEMA, DOMConstants.DOM3_EXPLICIT_FALSE);
fDOMConfigProperties.setProperty(DOMConstants.S_DOM3_PROPERTIES_NS + DOMConstants.DOM_DATATYPE_NORMALIZATION, DOMConstants.DOM3_EXPLICIT_FALSE);
}
} else {
// If this is a non-boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else // If the parameter value is not a boolean
if (name.equalsIgnoreCase(DOMConstants.DOM_ERROR_HANDLER)) {
if (value == null || value instanceof DOMErrorHandler) {
fDOMErrorHandler = (DOMErrorHandler) value;
} else {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_LOCATION) || name.equalsIgnoreCase(DOMConstants.DOM_SCHEMA_TYPE)) {
if (value != null) {
if (!(value instanceof String)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_SUPPORTED, new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
} else {
// If this is a boolean parameter a type mismatch should be thrown.
if (name.equalsIgnoreCase(DOMConstants.DOM_COMMENTS) || name.equalsIgnoreCase(DOMConstants.DOM_CDATA_SECTIONS) || name.equalsIgnoreCase(DOMConstants.DOM_ENTITIES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACES) || name.equalsIgnoreCase(DOMConstants.DOM_NAMESPACE_DECLARATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_SPLIT_CDATA) || name.equalsIgnoreCase(DOMConstants.DOM_WELLFORMED) || name.equalsIgnoreCase(DOMConstants.DOM_DISCARD_DEFAULT_CONTENT) || name.equalsIgnoreCase(DOMConstants.DOM_FORMAT_PRETTY_PRINT) || name.equalsIgnoreCase(DOMConstants.DOM_XMLDECL) || name.equalsIgnoreCase(DOMConstants.DOM_ELEMENT_CONTENT_WHITESPACE) || name.equalsIgnoreCase(DOMConstants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS) || name.equalsIgnoreCase(DOMConstants.DOM_CANONICAL_FORM) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE_IF_SCHEMA) || name.equalsIgnoreCase(DOMConstants.DOM_VALIDATE) || name.equalsIgnoreCase(DOMConstants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_DATATYPE_NORMALIZATION) || name.equalsIgnoreCase(DOMConstants.DOM_INFOSET)) {
String msg = Utils.messages.createMessage(MsgKey.ER_TYPE_MISMATCH_ERR, new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
// Parameter is not recognized
String msg = Utils.messages.createMessage(MsgKey.ER_FEATURE_NOT_FOUND, new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
use of org.w3c.dom.DOMException in project nifi by apache.
the class StandardFlowSerializer method serialize.
@Override
public void serialize(final FlowController controller, final OutputStream os, final ScheduledStateLookup scheduledStateLookup) throws FlowSerializationException {
try {
// create a new, empty document
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
final Document doc = docBuilder.newDocument();
// populate document with controller state
final Element rootNode = doc.createElement("flowController");
rootNode.setAttribute("encoding-version", MAX_ENCODING_VERSION);
doc.appendChild(rootNode);
addTextElement(rootNode, "maxTimerDrivenThreadCount", controller.getMaxTimerDrivenThreadCount());
addTextElement(rootNode, "maxEventDrivenThreadCount", controller.getMaxEventDrivenThreadCount());
final Element registriesElement = doc.createElement("registries");
rootNode.appendChild(registriesElement);
addFlowRegistries(registriesElement, controller.getFlowRegistryClient());
addProcessGroup(rootNode, controller.getGroup(controller.getRootGroupId()), "rootGroup", scheduledStateLookup);
// Add root-level controller services
final Element controllerServicesNode = doc.createElement("controllerServices");
rootNode.appendChild(controllerServicesNode);
for (final ControllerServiceNode serviceNode : controller.getRootControllerServices()) {
addControllerService(controllerServicesNode, serviceNode);
}
final Element reportingTasksNode = doc.createElement("reportingTasks");
rootNode.appendChild(reportingTasksNode);
for (final ReportingTaskNode taskNode : controller.getAllReportingTasks()) {
addReportingTask(reportingTasksNode, taskNode, encryptor);
}
final DOMSource domSource = new DOMSource(doc);
final StreamResult streamResult = new StreamResult(new BufferedOutputStream(os));
// configure the transformer and convert the DOM
final TransformerFactory transformFactory = TransformerFactory.newInstance();
final Transformer transformer = transformFactory.newTransformer();
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transform the document to byte stream
transformer.transform(domSource, streamResult);
} catch (final ParserConfigurationException | DOMException | TransformerFactoryConfigurationError | IllegalArgumentException | TransformerException e) {
throw new FlowSerializationException(e);
}
}
Aggregations