📄 informationcard.java
字号:
/* * Copyright 2005-2007 WSO2, Inc. (http://wso2.com) * * Licensed 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. */package org.wso2.solutions.identity.cards.model;import org.apache.axiom.om.OMAbstractFactory;import org.apache.axiom.om.OMConstants;import org.apache.axiom.om.OMElement;import org.apache.axiom.om.OMFactory;import org.wso2.solutions.identity.IdentityConstants;import javax.xml.namespace.QName;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.TimeZone;public class InformationCard implements CardElement { public final static QName NAME = new QName(IdentityConstants.NS, "InformationCard", IdentityConstants.PREFIX); private final static QName ISSUER = new QName(IdentityConstants.NS, "Issuer", IdentityConstants.PREFIX); private final static QName TIME_ISSUED = new QName(IdentityConstants.NS, "TimeIssued", IdentityConstants.PREFIX); private final static QName TIME_EXPIRES = new QName(IdentityConstants.NS, "TimeExpires", IdentityConstants.PREFIX); private final static QName CARD_NAME = new QName(IdentityConstants.NS, "CardName", IdentityConstants.PREFIX); private final static QName ATTR_LANG = new QName(OMConstants.XMLNS_URI, "lang", OMConstants.XMLNS_PREFIX); private InformationCardReference informationCardReference; private String cardName; private CardImage cardImage; private String issuer; private Date timeIssued; private Date timeExpires; private TokenServiceList tokenServiceList; private SupportedTokenTypeList supportedTokenTypeList; private SupportedClaimTypeList supportedClaimTypeList; private RequireAppliesTo requireAppliesTo; private PrivacyNotice privacyNotice; private String lang = "en-us"; public OMElement serialize() throws CardModelException { // check required elements if (this.informationCardReference == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { InformationCardReference.NAME.toString() }); } if (this.issuer == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { ISSUER.toString() }); } if (this.timeIssued == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { TIME_ISSUED.toString() }); } if (this.tokenServiceList == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { TokenServiceList.NAME.toString() }); } if (this.supportedTokenTypeList == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { SupportedTokenTypeList.NAME.toString() }); } if (this.supportedClaimTypeList == null) { throw new CardModelException( CardModelException.REQUIRED_ELEMENT_MISSING, new String[] { SupportedClaimTypeList.NAME.toString() }); } OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement elem = fac.createOMElement(NAME); elem.addAttribute(fac.createOMAttribute(ATTR_LANG.getLocalPart(), fac .createOMNamespace(ATTR_LANG.getNamespaceURI(), ATTR_LANG .getPrefix()), this.lang)); elem.addChild(this.informationCardReference.serialize()); if (this.cardName != null) { OMElement cardNameElem = fac.createOMElement(CARD_NAME, elem); cardNameElem.setText(this.cardName); } if (this.cardImage != null) { elem.addChild(this.cardImage.serialize()); } OMElement issuerElem = fac.createOMElement(ISSUER, elem); issuerElem.setText(this.issuer); DateFormat zulu = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); zulu.setTimeZone(TimeZone.getTimeZone("UTC")); OMElement timeIssuedElem = fac.createOMElement(TIME_ISSUED, elem); timeIssuedElem.setText(zulu.format(this.timeIssued)); if (this.timeExpires != null) { OMElement timeExpiresElem = fac.createOMElement(TIME_EXPIRES, elem); timeExpiresElem.setText(zulu.format(this.timeExpires)); } elem.addChild(this.tokenServiceList.serialize()); elem.addChild(this.supportedTokenTypeList.serialize()); elem.addChild(this.supportedClaimTypeList.serialize()); if (this.requireAppliesTo != null) { elem.addChild(this.requireAppliesTo.serialize()); } if (this.privacyNotice != null) { elem.addChild(this.privacyNotice.serialize()); } return elem; } public CardImage getCardImage() { return cardImage; } public void setCardImage(CardImage cardImage) { this.cardImage = cardImage; } public String getCardName() { return cardName; } public void setCardName(String cardName) { this.cardName = cardName; } public InformationCardReference getInformationCardReference() { return informationCardReference; } public void setInformationCardReference( InformationCardReference informationCardReference) { this.informationCardReference = informationCardReference; } public String getIssuer() { return issuer; } public void setIssuer(String issuer) { this.issuer = issuer; } public RequireAppliesTo getRequireAppliesTo() { return requireAppliesTo; } public void setRequireAppliesTo(RequireAppliesTo requireAppliesTo) { this.requireAppliesTo = requireAppliesTo; } public SupportedTokenTypeList getSupportedTokenTypeList() { return supportedTokenTypeList; } public void setSupportedTokenTypeList( SupportedTokenTypeList supportedTokenTypeList) { this.supportedTokenTypeList = supportedTokenTypeList; } public Date getTimeExpires() { return timeExpires; } public void setTimeExpires(Date timeExpires) { this.timeExpires = timeExpires; } public Date getTimeIssued() { return timeIssued; } public void setTimeIssued(Date timeIssued) { this.timeIssued = timeIssued; } public TokenServiceList getTokenServiceList() { return tokenServiceList; } public void setTokenServiceList(TokenServiceList tokenServiceList) { this.tokenServiceList = tokenServiceList; } public SupportedClaimTypeList getSupportedClaimTypeList() { return supportedClaimTypeList; } public void setSupportedClaimTypeList( SupportedClaimTypeList supportedClaimTypeList) { this.supportedClaimTypeList = supportedClaimTypeList; } public PrivacyNotice getPrivacyNotice() { return privacyNotice; } public void setPrivacyNotice(PrivacyNotice privacyNotice) { this.privacyNotice = privacyNotice; } public String getLang() { return lang; } public void setLang(String lang) { this.lang = lang; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -