|
Java example source code file (DOMXMLObject.java)
The DOMXMLObject.java Java example source code/* * reserved comment block * DO NOT REMOVE OR ALTER! */ /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. */ /* * $Id: DOMXMLObject.java 1333415 2012-05-03 12:03:51Z coheigea $ */ package org.jcp.xml.dsig.internal.dom; import javax.xml.crypto.*; import javax.xml.crypto.dom.DOMCryptoContext; import javax.xml.crypto.dsig.*; import java.security.Provider; import java.util.*; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * DOM-based implementation of XMLObject. * * @author Sean Mullan */ public final class DOMXMLObject extends DOMStructure implements XMLObject { private final String id; private final String mimeType; private final String encoding; private final List<XMLStructure> content; private Element objectElem; /** * Creates an <code>XMLObject from the specified parameters. * * @param content a list of {@link XMLStructure}s. The list * is defensively copied to protect against subsequent modification. * May be <code>null or empty. * @param id the Id (may be <code>null) * @param mimeType the mime type (may be <code>null) * @param encoding the encoding (may be <code>null) * @return an <code>XMLObject * @throws ClassCastException if <code>content contains any * entries that are not of type {@link XMLStructure} */ public DOMXMLObject(List<? extends XMLStructure> content, String id, String mimeType, String encoding) { if (content == null || content.isEmpty()) { this.content = Collections.emptyList(); } else { this.content = Collections.unmodifiableList( new ArrayList<XMLStructure>(content)); for (int i = 0, size = this.content.size(); i < size; i++) { if (!(this.content.get(i) instanceof XMLStructure)) { throw new ClassCastException ("content["+i+"] is not a valid type"); } } } this.id = id; this.mimeType = mimeType; this.encoding = encoding; } /** * Creates an <code>XMLObject from an element. * * @param objElem an Object element * @throws MarshalException if there is an error when unmarshalling */ public DOMXMLObject(Element objElem, XMLCryptoContext context, Provider provider) throws MarshalException { // unmarshal attributes this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding"); Attr attr = objElem.getAttributeNodeNS(null, "Id"); if (attr != null) { this.id = attr.getValue(); objElem.setIdAttributeNode(attr, true); } else { this.id = null; } this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType"); NodeList nodes = objElem.getChildNodes(); int length = nodes.getLength(); List<XMLStructure> content = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java DOMXMLObject.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.