本文整理汇总了Java中org.opensaml.xml.schema.XSString.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java XSString.getValue方法的具体用法?Java XSString.getValue怎么用?Java XSString.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensaml.xml.schema.XSString
的用法示例。
在下文中一共展示了XSString.getValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractAttributeValueValue
import org.opensaml.xml.schema.XSString; //导入方法依赖的package包/类
/**
* Extract the value of the first attributeValue within an SAML20 attribute
*
* @param attribute
* The attribute
* @return The text value of the attributeValue
*/
public static String extractAttributeValueValue(Attribute attribute) {
for (int i = 0; i < attribute.getAttributeValues().size(); i++) {
if (attribute.getAttributeValues().get(i) instanceof XSString) {
XSString str = (XSString) attribute.getAttributeValues().get(i);
if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(str.getElementQName().getLocalPart())
&& SAMLConstants.SAML20_NS.equals(str.getElementQName().getNamespaceURI())) {
return str.getValue();
}
} else {
XSAny ep = (XSAny) attribute.getAttributeValues().get(i);
if (AttributeValue.DEFAULT_ELEMENT_LOCAL_NAME.equals(ep.getElementQName().getLocalPart())
&& SAMLConstants.SAML20_NS.equals(ep.getElementQName().getNamespaceURI())) {
if (ep.getUnknownXMLObjects().size() > 0) {
StringBuilder res = new StringBuilder();
for (XMLObject obj : ep.getUnknownXMLObjects()) {
res.append(XMLHelper.nodeToString(SAMLUtil.marshallObject(obj)));
}
return res.toString();
}
return ep.getTextContent();
}
}
}
return null;
}
示例2: marshallElementContent
import org.opensaml.xml.schema.XSString; //导入方法依赖的package包/类
/**
* The element content of a {@code CurrentAddressType} is the Base64-encoding of the serialized value of the
* {@code CurrentAddressStructuredType}. So ... we have to get there by iterating over our child elements.
*/
@Override
protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
// Find out if the our namespace already has been defined, and if so, get the prefix.
//
final String namespace = CurrentAddressType.TYPE_NAME.getNamespaceURI();
String prefix = CurrentAddressType.TYPE_NAME.getPrefix();
for (Namespace ns : xmlObject.getNamespaceManager().getNamespaces()) {
if (namespace.equals(ns.getNamespaceURI())) {
prefix = ns.getNamespacePrefix();
break;
}
}
StringBuilder sb = new StringBuilder();
final List<XMLObject> childXMLObjects = xmlObject.getOrderedChildren();
if (childXMLObjects != null && childXMLObjects.size() > 0) {
for (final XMLObject childXMLObject : childXMLObjects) {
if (childXMLObject == null) {
continue;
}
if (!(childXMLObject instanceof XSString)) {
throw new MarshallingException("Unexpected type of child element - " + childXMLObject.getClass().getName());
}
XSString childString = (XSString) childXMLObject;
if (childString.getValue() == null) {
continue;
}
String localPart = childString.getElementQName().getLocalPart();
sb.append(String.format("<%s:%s>%s</%s:%s>", prefix, localPart, childString.getValue(), prefix, localPart));
}
}
if (sb.length() > 0) {
byte[] bytes;
try {
bytes = sb.toString().getBytes("UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new MarshallingException(e);
}
String base64String = Base64.encodeBytes(bytes, Base64.NO_OPTIONS);
XMLHelper.appendTextContent(domElement, base64String);
}
}