下面列出了javax.imageio.metadata.IIOInvalidTreeException 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void mergeTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException(I18N.getString("J2KMetadata0"));
}
if (root == null) {
throw new IllegalArgumentException(I18N.getString("J2KMetadata2"));
}
if (formatName.equals(nativeMetadataFormatName) &&
root.getNodeName().equals(nativeMetadataFormatName)) {
mergeNativeTree(root);
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
mergeStandardTree(root);
} else {
throw new IllegalArgumentException(I18N.getString("J2KMetadata1")
+ " " + formatName);
}
}
protected static boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException("null formatName!");
}
if (root == null) {
throw new IllegalArgumentException("null root!");
}
if (isStream &&
(formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals(JPEG.nativeImageMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName))) {
// In this case a reset followed by a merge is correct
super.setFromTree(formatName, root);
} else {
throw new IllegalArgumentException("Unsupported format name: "
+ formatName);
}
}
private void mergeStandardTextNode(Node node)
throws IIOInvalidTreeException {
// Convert to comments. For the moment ignore the encoding issue.
// Ignore keywords, language, and encoding (for the moment).
// If compression tag is present, use only entries with "none".
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
NamedNodeMap attrs = child.getAttributes();
Node comp = attrs.getNamedItem("compression");
boolean copyIt = true;
if (comp != null) {
String compString = comp.getNodeValue();
if (!compString.equals("none")) {
copyIt = false;
}
}
if (copyIt) {
String value = attrs.getNamedItem("value").getNodeValue();
COMMarkerSegment com = new COMMarkerSegment(value);
insertCOMMarkerSegment(com);
}
}
}
private boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
void updateFromNativeNode(Node node, boolean fromScratch)
throws IIOInvalidTreeException {
NamedNodeMap attrs = node.getAttributes();
int value = getAttributeValue(node, attrs, "process", 0, 2, false);
tag = (value != -1) ? value+JPEG.SOF0 : tag;
// If samplePrecision is present, it must be 8.
// This just checks. We don't bother to assign the value.
value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
numLines = (value != -1) ? value : numLines;
value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
samplesPerLine = (value != -1) ? value : samplesPerLine;
int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
1, 4, false);
NodeList children = node.getChildNodes();
if (children.getLength() != numComponents) {
throw new IIOInvalidTreeException
("numFrameComponents must match number of children", node);
}
componentSpecs = new ComponentSpec [numComponents];
for (int i = 0; i < numComponents; i++) {
componentSpecs[i] = new ComponentSpec(children.item(i));
}
}
public void mergeTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName.equals(nativeMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeNativeTree(root);
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeStandardTree(root);
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
void updateFromNativeNode(Node node, boolean fromScratch)
throws IIOInvalidTreeException {
NamedNodeMap attrs = node.getAttributes();
int value = getAttributeValue(node, attrs, "process", 0, 2, false);
tag = (value != -1) ? value+JPEG.SOF0 : tag;
// If samplePrecision is present, it must be 8.
// This just checks. We don't bother to assign the value.
value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
numLines = (value != -1) ? value : numLines;
value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
samplesPerLine = (value != -1) ? value : samplesPerLine;
int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
1, 4, false);
NodeList children = node.getChildNodes();
if (children.getLength() != numComponents) {
throw new IIOInvalidTreeException
("numFrameComponents must match number of children", node);
}
componentSpecs = new ComponentSpec [numComponents];
for (int i = 0; i < numComponents; i++) {
componentSpecs[i] = new ComponentSpec(children.item(i));
}
}
/**
* Merge a JFIF subtree into the marker sequence, if the subtree
* is non-empty.
* If a JFIF marker exists, update it from the subtree.
* If none exists, create one from the subtree and insert it at the
* beginning of the marker sequence.
*/
private void mergeJFIFsubtree(Node JPEGvariety)
throws IIOInvalidTreeException {
if (JPEGvariety.getChildNodes().getLength() != 0) {
Node jfifNode = JPEGvariety.getFirstChild();
// is there already a jfif marker segment?
JFIFMarkerSegment jfifSeg =
(JFIFMarkerSegment) findMarkerSegment(JFIFMarkerSegment.class, true);
if (jfifSeg != null) {
jfifSeg.updateFromNativeNode(jfifNode, false);
} else {
// Add it as the first element in the list.
markerSequence.add(0, new JFIFMarkerSegment(jfifNode));
}
}
}
protected static int getEnumeratedAttribute(Node node,
String name,
String[] legalNames,
int defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
for (int i = 0; i < legalNames.length; i++) {
if(value.equals(legalNames[i])) {
return i;
}
}
fatal(node, "Illegal value for attribute " + name + "!");
return -1;
}
void updateFromNativeNode(Node node, boolean fromScratch)
throws IIOInvalidTreeException {
NamedNodeMap attrs = node.getAttributes();
int value = getAttributeValue(node, attrs, "process", 0, 2, false);
tag = (value != -1) ? value+JPEG.SOF0 : tag;
// If samplePrecision is present, it must be 8.
// This just checks. We don't bother to assign the value.
value = getAttributeValue(node, attrs, "samplePrecision", 8, 8, false);
value = getAttributeValue(node, attrs, "numLines", 0, 65535, false);
numLines = (value != -1) ? value : numLines;
value = getAttributeValue(node, attrs, "samplesPerLine", 0, 65535, false);
samplesPerLine = (value != -1) ? value : samplesPerLine;
int numComponents = getAttributeValue(node, attrs, "numFrameComponents",
1, 4, false);
NodeList children = node.getChildNodes();
if (children.getLength() != numComponents) {
throw new IIOInvalidTreeException
("numFrameComponents must match number of children", node);
}
componentSpecs = new ComponentSpec [numComponents];
for (int i = 0; i < numComponents; i++) {
componentSpecs[i] = new ComponentSpec(children.item(i));
}
}
protected static boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
protected static boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException("null formatName!");
}
if (root == null) {
throw new IllegalArgumentException("null root!");
}
if (isStream &&
(formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals(JPEG.nativeImageMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName))) {
// In this case a reset followed by a merge is correct
super.setFromTree(formatName, root);
} else {
throw new IllegalArgumentException("Unsupported format name: "
+ formatName);
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException("null formatName!");
}
if (root == null) {
throw new IllegalArgumentException("null root!");
}
if (isStream &&
(formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals(JPEG.nativeImageMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName))) {
// In this case a reset followed by a merge is correct
super.setFromTree(formatName, root);
} else {
throw new IllegalArgumentException("Unsupported format name: "
+ formatName);
}
}
private void mergeNativeTree(Node root) throws IIOInvalidTreeException {
Node node = root;
if (!node.getNodeName().equals(nativeMetadataFormatName)) {
fatal(node, "Root must be " + nativeMetadataFormatName);
}
node = node.getFirstChild();
if (node == null || !node.getNodeName().equals("ByteOrder")) {
fatal(node, "Root must have \"ByteOrder\" child");
}
NamedNodeMap attrs = node.getAttributes();
String order = attrs.getNamedItem("value").getNodeValue();
if (order == null) {
fatal(node, "ByteOrder node must have a \"value\" attribute");
}
if (order.equals(bigEndianString)) {
this.byteOrder = ByteOrder.BIG_ENDIAN;
} else if (order.equals(littleEndianString)) {
this.byteOrder = ByteOrder.LITTLE_ENDIAN;
} else {
fatal(node, "Incorrect value for ByteOrder \"value\" attribute");
}
}
/**
* Constructs a marker segment from a native tree node. If the node
* is an <code>IIOMetadataNode</code> and contains a user object,
* that object is used rather than the string attribute. If the
* string attribute is used, the default encoding is used.
*/
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
super(JPEG.COM);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
data = (byte []) ourNode.getUserObject();
}
if (data == null) {
String comment =
node.getAttributes().getNamedItem("comment").getNodeValue();
if (comment != null) {
data = comment.getBytes(); // Default encoding
} else {
throw new IIOInvalidTreeException("Empty comment node!", node);
}
}
}
private boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
/**
* Constructs a marker segment from a native tree node. If the node
* is an <code>IIOMetadataNode</code> and contains a user object,
* that object is used rather than the string attribute. If the
* string attribute is used, the default encoding is used.
*/
COMMarkerSegment(Node node) throws IIOInvalidTreeException{
super(JPEG.COM);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
data = (byte []) ourNode.getUserObject();
}
if (data == null) {
String comment =
node.getAttributes().getNamedItem("comment").getNodeValue();
if (comment != null) {
data = comment.getBytes(); // Default encoding
} else {
throw new IIOInvalidTreeException("Empty comment node!", node);
}
}
}
public void setFromTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName == null) {
throw new IllegalArgumentException("null formatName!");
}
if (root == null) {
throw new IllegalArgumentException("null root!");
}
if (isStream &&
(formatName.equals(JPEG.nativeStreamMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals(JPEG.nativeImageMetadataFormatName))) {
setFromNativeTree(root);
} else if (!isStream &&
(formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName))) {
// In this case a reset followed by a merge is correct
super.setFromTree(formatName, root);
} else {
throw new IllegalArgumentException("Unsupported format name: "
+ formatName);
}
}
private void mergeStandardTree(Node root) throws IIOInvalidTreeException {
transparencyDone = false;
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
String name = node.getNodeName();
if (name.equals("Chroma")) {
mergeStandardChromaNode(node, children);
} else if (name.equals("Compression")) {
mergeStandardCompressionNode(node);
} else if (name.equals("Data")) {
mergeStandardDataNode(node);
} else if (name.equals("Dimension")) {
mergeStandardDimensionNode(node);
} else if (name.equals("Document")) {
mergeStandardDocumentNode(node);
} else if (name.equals("Text")) {
mergeStandardTextNode(node);
} else if (name.equals("Transparency")) {
mergeStandardTransparencyNode(node);
} else {
throw new IIOInvalidTreeException("Invalid node: " + name, node);
}
}
}
/**
* Merge the given Unknown node into the marker sequence.
* A new Unknown marker segment is created and added to the sequence as
* follows:
* If there already exist Unknown marker segments, the new one is inserted
* after the last one.
* If there are no Unknown marker segments, the new Unknown marker segment
* is inserted after the JFIF segment, if there is one.
* If there is no JFIF segment, the new Unknown segment is inserted before
* the Adobe marker segment, if there is one.
* If there is no Adobe segment, the new Unknown segment is inserted
* at the beginning of the sequence.
*/
private void mergeUnknownNode(Node node) throws IIOInvalidTreeException {
MarkerSegment newGuy = new MarkerSegment(node);
int lastUnknown = findLastUnknownMarkerSegmentPosition();
boolean hasJFIF = (findMarkerSegment(JFIFMarkerSegment.class, true) != null);
int firstAdobe = findMarkerSegmentPosition(AdobeMarkerSegment.class, true);
if (lastUnknown != -1) {
markerSequence.add(lastUnknown+1, newGuy);
} else if (hasJFIF) {
markerSequence.add(1, newGuy); // JFIF is always 0
} if (firstAdobe != -1) {
markerSequence.add(firstAdobe, newGuy);
} else {
markerSequence.add(0, newGuy);
}
}
protected static boolean getBooleanAttribute(Node node, String name,
boolean defaultValue,
boolean required)
throws IIOInvalidTreeException {
Node attr = node.getAttributes().getNamedItem(name);
if (attr == null) {
if (!required) {
return defaultValue;
} else {
fatal(node, "Required attribute " + name + " not present!");
}
}
String value = attr.getNodeValue();
// Allow lower case booleans for backward compatibility, #5082756
if (value.equals("TRUE") || value.equals("true")) {
return true;
} else if (value.equals("FALSE") || value.equals("false")) {
return false;
} else {
fatal(node, "Attribute " + name + " must be 'TRUE' or 'FALSE'!");
return false;
}
}
/** Constructs a <code>UUIDListBox</code> based on the provided
* <code>org.w3c.dom.Node</code>.
*/
public XMLBox(Node node) throws IIOInvalidTreeException {
super(node);
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
String name = child.getNodeName();
if ("Content".equals(name)) {
String value = child.getNodeValue();
if (value != null)
data = value.getBytes();
else if (child instanceof IIOMetadataNode) {
value = (String)((IIOMetadataNode)child).getUserObject();
if (value != null)
data = value.getBytes();
}
}
}
}
public void mergeTree(String formatName, Node root)
throws IIOInvalidTreeException {
if (formatName.equals(nativeMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeNativeTree(root);
} else if (formatName.equals
(IIOMetadataFormatImpl.standardMetadataFormatName)) {
if (root == null) {
throw new IllegalArgumentException("root == null!");
}
mergeStandardTree(root);
} else {
throw new IllegalArgumentException("Not a recognized format!");
}
}
/**
* Merges <code>inData</code> into <code>outData</code>. The supplied
* metadata format name is attempted first and failing that the standard
* metadata format name is attempted.
*/
private void convertMetadata(String metadataFormatName,
IIOMetadata inData,
IIOMetadata outData) {
String formatName = null;
String nativeFormatName = inData.getNativeMetadataFormatName();
if (nativeFormatName != null &&
nativeFormatName.equals(metadataFormatName)) {
formatName = metadataFormatName;
} else {
String[] extraFormatNames = inData.getExtraMetadataFormatNames();
if (extraFormatNames != null) {
for (int i = 0; i < extraFormatNames.length; i++) {
if (extraFormatNames[i].equals(metadataFormatName)) {
formatName = metadataFormatName;
break;
}
}
}
}
if (formatName == null &&
inData.isStandardMetadataFormatSupported()) {
formatName = STANDARD_METADATA_NAME;
}
if (formatName != null) {
try {
Node root = inData.getAsTree(formatName);
outData.mergeTree(formatName, root);
} catch(IIOInvalidTreeException e) {
// ignore
}
}
}
SOSMarkerSegment(Node node) throws IIOInvalidTreeException {
super(JPEG.SOS);
startSpectralSelection = 0;
endSpectralSelection = 63;
approxHigh = 0;
approxLow = 0;
updateFromNativeNode(node, true);
}
Qtable(Node node) throws IIOInvalidTreeException {
if (node.getNodeName().equals("dqtable")) {
NamedNodeMap attrs = node.getAttributes();
int count = attrs.getLength();
if ((count < 1) || (count > 2)) {
throw new IIOInvalidTreeException
("dqtable node must have 1 or 2 attributes", node);
}
elementPrecision = 0;
tableID = getAttributeValue(node, attrs, "qtableId", 0, 3, true);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
JPEGQTable table = (JPEGQTable) ourNode.getUserObject();
if (table == null) {
throw new IIOInvalidTreeException
("dqtable node must have user object", node);
}
data = table.getTable();
} else {
throw new IIOInvalidTreeException
("dqtable node must have user object", node);
}
} else {
throw new IIOInvalidTreeException
("Invalid node, expected dqtable", node);
}
}
/**
* Constructs a Box from an "unknown" Node. This node has at
* least the attribute "Type", and may have the attribute "Length",
* "ExtraLength" and a child "Content". The child node content is a
* IIOMetaDataNode with a byte[] user object.
*/
public Box(Node node) throws IIOInvalidTreeException {
NodeList children = node.getChildNodes();
String value = (String)Box.getAttribute(node, "Type");
type = getTypeInt(value);
if (value == null || names.get(new Integer(type)) == null)
throw new IIOInvalidTreeException("Type is not defined", node);
value = (String)Box.getAttribute(node, "Length");
if (value != null)
length = new Integer(value).intValue();
value = (String)Box.getAttribute(node, "ExtraLength");
if (value != null)
extraLength = new Long(value).longValue();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if ("Content".equals(child.getNodeName())) {
if (child instanceof IIOMetadataNode) {
IIOMetadataNode cnode = (IIOMetadataNode)child;
try {
data = (byte[])cnode.getUserObject();
} catch (Exception e) {
}
}else {
data = getByteArrayElementValue(child);
}
if (data == null) {
value = node.getNodeValue();
if (value != null)
data = value.getBytes();
}
}
}
}
SOSMarkerSegment(Node node) throws IIOInvalidTreeException {
super(JPEG.SOS);
startSpectralSelection = 0;
endSpectralSelection = 63;
approxHigh = 0;
approxLow = 0;
updateFromNativeNode(node, true);
}