本文整理汇总了Java中com.evolveum.midpoint.util.DOMUtil.setNamespaceDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java DOMUtil.setNamespaceDeclaration方法的具体用法?Java DOMUtil.setNamespaceDeclaration怎么用?Java DOMUtil.setNamespaceDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.evolveum.midpoint.util.DOMUtil
的用法示例。
在下文中一共展示了DOMUtil.setNamespaceDeclaration方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toElement
import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
public Element toElement(String elementNamespace, String localElementName, Document document) {
Element element = document.createElementNS(elementNamespace, localElementName);
if (!StringUtils.isBlank(elementNamespace)) {
String prefix = GlobalDynamicNamespacePrefixMapper.getPreferredPrefix(elementNamespace);
if (!StringUtils.isBlank(prefix)) {
try {
element.setPrefix(prefix);
} catch (DOMException e) {
throw new SystemException("Error setting XML prefix '"+prefix+"' to element {"+elementNamespace+"}"+localElementName+": "+e.getMessage(), e);
}
}
}
element.setTextContent(getXPathWithDeclarations());
Map<String, String> namespaceMap = getNamespaceMap();
if (namespaceMap != null) {
for (Entry<String, String> entry : namespaceMap.entrySet()) {
DOMUtil.setNamespaceDeclaration(element, entry.getKey(), entry.getValue());
}
}
return element;
}
示例2: addDefaultNamespaceDeclaration
import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
/**
* Adds xmlns='...common-3' if needed.
* In fact, this is VERY ugly hack to avoid putting common-3 declarations all over the elements in bulk actions response.
* e.getNamespaceURI returns something only if it was present during node creation.
* So, in fact, this code is more than fragile. Seems to work with the current XNode->DOM serialization, though.
*/
private void addDefaultNamespaceDeclaration(Element top) {
List<Element> prefixless = DOMUtil.getElementsWithoutNamespacePrefix(top);
if (prefixless.size() < 2) {
return; // nothing to do here
}
Set<String> namespaces = prefixless.stream().map(e -> emptyIfNull(e.getNamespaceURI())).collect(Collectors.toSet());
if (namespaces.size() != 1 || StringUtils.isEmpty(namespaces.iterator().next())) {
return;
}
DOMUtil.setNamespaceDeclaration(top, "", namespaces.iterator().next());
}
示例3: unfortifyNamespaceDeclarations
import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
private static void unfortifyNamespaceDeclarations(Element definitionElement, Element childElement,
Map<String, String> namespaces) {
for (Entry<String, String> entry: namespaces.entrySet()) {
String prefix = entry.getKey();
String namespace = entry.getValue();
String declaredNamespace = DOMUtil.getNamespaceDeclarationForPrefix(childElement, prefix);
if (declaredNamespace == null) {
DOMUtil.setNamespaceDeclaration(childElement, prefix, namespace);
} else if (!namespace.equals(declaredNamespace)) {
throw new IllegalStateException("Namespace declaration with prefix '"+prefix+"' that was used to declare "+
"namespace '"+namespace+"' is now used for namespace '"+declaredNamespace+"', cannot unfortify.");
}
}
}
示例4: init
import com.evolveum.midpoint.util.DOMUtil; //导入方法依赖的package包/类
/**
* Create schema XSD DOM document.
*/
private void init() throws ParserConfigurationException {
if (namespacePrefixMapper == null) {
// TODO: clone?
namespacePrefixMapper = ((SchemaRegistryImpl) prismContext.getSchemaRegistry()).getNamespacePrefixMapper();
}
// We don't want the "tns" prefix to be kept in the mapper
namespacePrefixMapper = namespacePrefixMapper.clone();
namespacePrefixMapper.registerPrefixLocal(getNamespace(), "tns");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Using namespace prefix mapper to serialize schema:\n{}",DebugUtil.dump(namespacePrefixMapper));
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
document = db.newDocument();
Element root = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "schema"));
document.appendChild(root);
rootXsdElement = document.getDocumentElement();
setAttribute(rootXsdElement, "targetNamespace", getNamespace());
setAttribute(rootXsdElement, "elementFormDefault", "qualified");
DOMUtil.setNamespaceDeclaration(rootXsdElement, "tns", getNamespace());
if (attributeQualified) {
setAttribute(rootXsdElement, "attributeFormDefault", "qualified");
}
}