Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

In this page you can find the example usage for org.dom4j QName QName.

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:to.networld.security.common.data.AuthnResponse.java

License:Open Source License

public AuthnResponse(XMLSecurity _xmlsec, String _nameID, String _issuer, String _requestID,
        String _destinationIRI, String _audience, ID_FORMAT _format, AUTH_METHOD _classes) {
    ConstantHandler constHandler = ConstantHandler.getInstance();
    String currentDate = DateHelper.getCurrentDate();
    String futureDate = DateHelper.getFutureDate(10);

    Element authnResponse = this.xmlDocument.addElement(new QName("Response", SAMLP_NS));
    authnResponse.add(SAML_NS);/* www .  j  av a2 s. c  o  m*/

    authnResponse.addAttribute("Destination", _destinationIRI);
    String id = UUID.randomUUID().toString();
    authnResponse.addAttribute("ID", id);
    authnResponse.addAttribute("InResponseTo", _requestID);
    authnResponse.addAttribute("IssueInstant", currentDate);
    authnResponse.addAttribute("Version", "2.0");

    Element issuer = authnResponse.addElement(new QName("Issuer", SAML_NS));
    issuer.setText(_issuer);

    Element status = authnResponse.addElement(new QName("Status", SAMLP_NS));
    Element statusCode = status.addElement(new QName("StatusCode", SAMLP_NS));
    statusCode.addAttribute("Value", "urn:oasis:names:tc:SAML:2.0:status:Success");

    Element assertion = authnResponse.addElement(new QName("Assertion", SAML_NS));
    String assertionID = UUID.randomUUID().toString();
    assertion.addAttribute("ID", assertionID);
    assertion.addAttribute("Version", "2.0");
    assertion.addAttribute("IssueInstant", currentDate);

    Element assertionIssuer = assertion.addElement(new QName("Issuer", SAML_NS));
    assertionIssuer.setText(_issuer);

    Element assertionSubject = assertion.addElement(new QName("Subject", SAML_NS));

    Element assertionNameID = assertionSubject.addElement(new QName("NameID", SAML_NS));
    assertionNameID.addAttribute("Format", constHandler.getNameIDFormat(_format));
    assertionNameID.setText(_nameID);

    Element assertionSubjectConfirmation = assertionSubject
            .addElement(new QName("SubjectConfirmation", SAML_NS));
    assertionSubjectConfirmation.addAttribute("Method", "urn:oasis:names:tc:SAML:2.0:cm:bearer");

    Element assertionSubjectConfirmationData = assertionSubjectConfirmation
            .addElement(new QName("SubjectConfirmationData", SAML_NS));
    assertionSubjectConfirmationData.addAttribute("InResponseTo", _requestID);
    assertionSubjectConfirmationData.addAttribute("NotOnOrAfter", futureDate);
    assertionSubjectConfirmationData.addAttribute("Recipient", _destinationIRI);

    Element assertionConditions = assertion.addElement(new QName("Conditions", SAML_NS));
    assertionConditions.addAttribute("NotBefore", currentDate);
    assertionConditions.addAttribute("NotOnOrAfter", futureDate);

    Element assertionAudienceRestriction = assertionConditions
            .addElement(new QName("AudienceRestriction", SAML_NS));

    Element assertionAudience = assertionAudienceRestriction.addElement(new QName("Audience", SAML_NS));
    assertionAudience.setText(_audience);

    Element assertionAuthnStatement = assertion.addElement(new QName("AuthnStatement", SAML_NS));
    assertionAuthnStatement.addAttribute("AuthnInstant", currentDate);
    assertionAuthnStatement.addAttribute("SessionIndex", UUID.randomUUID().toString());

    Element assertionAuthnContext = assertionAuthnStatement.addElement(new QName("AuthnContext", SAML_NS));

    Element assertionAuthnContextClassRef = assertionAuthnContext
            .addElement(new QName("AuthnContextClassRef", SAML_NS));
    assertionAuthnContextClassRef.setText(constHandler.getAuthnContextClasses(_classes));

    this.signMessage(assertionID, _xmlsec);
}

From source file:to.networld.security.common.data.AuthnResponseError.java

License:Open Source License

public AuthnResponseError(CODE _code, String _issuer, String _destinationIRI, String _requestID) {
    this.initStatusVector();
    Element authnResponse = this.xmlDocument.addElement(new QName("Response", SAMLP_NS));
    authnResponse.add(SAML_NS);/*from w ww.  j a va  2s . c  o  m*/

    authnResponse.addAttribute("Destination", _destinationIRI);
    String id = UUID.randomUUID().toString();
    authnResponse.addAttribute("ID", id);
    authnResponse.addAttribute("InResponseTo", _requestID);
    authnResponse.addAttribute("IssueInstant", DateHelper.getCurrentDate());
    authnResponse.addAttribute("Version", "2.0");

    Element issuer = authnResponse.addElement(new QName("Issuer", SAML_NS));
    issuer.setText(_issuer);

    Element status = authnResponse.addElement(new QName("Status", SAMLP_NS));
    Element statusCode = status.addElement(new QName("StatusCode", SAMLP_NS));
    statusCode.addAttribute("Value", this.statusVector.get(_code.ordinal()));
}

From source file:to.networld.semantic.contexthandler.data.ContextCloud.java

License:Open Source License

public ContextCloud(String _contextCloudID) throws DocumentException {
    super();//from w ww  .  ja  va  2  s . c o  m
    this.contextCloudID = _contextCloudID;

    Element rdfRootNode = this.document.addElement(new QName("RDF", Ontologies.RDF));
    rdfRootNode.add(Ontologies.RDF);
    rdfRootNode.add(Ontologies.RDFS);
    rdfRootNode.add(Ontologies.SCOT);
    rdfRootNode.add(Ontologies.SKOS);
    rdfRootNode.add(Ontologies.LIST);

    this.contextTagRootNode = rdfRootNode.addElement(new QName("TagCloud", Ontologies.SCOT));
    this.contextTagRootNode.addAttribute(new QName("about", Ontologies.RDF), _contextCloudID);
}

From source file:to.networld.semantic.contexthandler.data.ContextCloud.java

License:Open Source License

/**
 * @see to.networld.semantic.contexthandler.interfaces.IContextCloud#flush()
 *///ww w  . ja v a2 s  .com
@Override
public void flush() {
    Collection<ContextTag> tags = this.internalContextCloud.values();
    for (ContextTag entry : tags) {
        Element tag = entry.getTagNode();
        tag.detach();

        Element cooccureElement = this.contextTagRootNode.addElement(new QName("contains", Ontologies.SCOT));
        cooccureElement.add(tag);

        tag.addElement(new QName("own_afrequency", Ontologies.SCOT)).addText(entry.getAbsoluteFrequency() + "");
        tag.addElement(new QName("priority", Ontologies.LIST)).addText(entry.getPriority() + "");
    }
}

From source file:to.networld.semantic.contexthandler.data.ContextTag.java

License:Open Source License

/**
 * @throws DocumentException/*from   w  w  w.j a v  a 2  s. com*/
 */
public ContextTag(String _normalizedTag) throws DocumentException {
    super();
    this.normalizedTag = _normalizedTag;

    this.tagNode = this.document.addElement(new QName("Tag", Ontologies.SCOT));
    Config config;
    try {
        config = Config.getInstance();
        tagNode.addAttribute(new QName("about", Ontologies.RDF),
                config.getContextTagPrefix() + this.normalizedTag);
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.tagNode.addElement(new QName("name", Ontologies.SCOT)).addText(this.normalizedTag);

    this.setAbsoluteFrequency(1);
}

From source file:to.networld.semantic.contexthandler.data.ContextTag.java

License:Open Source License

/**
 * @see to.networld.semantic.contexthandler.interfaces.IContextTag#setOrgSpelling(java.lang.String)
 *//*from  w w  w . j av a  2  s .  c  o  m*/
@Override
public void setOrgSpelling(String _tagOrgName) {
    if (!this.orginalSpellingVector.contains(_tagOrgName)) {
        this.orginalSpellingVector.add(_tagOrgName);
        this.tagNode.addElement(new QName("spelling_variant", Ontologies.SCOT)).addText(_tagOrgName);
    }
}

From source file:to.networld.semantic.contexthandler.data.ContextTag.java

License:Open Source License

/**
 * @see to.networld.semantic.contexthandler.interfaces.IContextTag#setClassification(java.lang.String)
 *///w w  w  .  j  av a2 s.c  o m
@Override
public void setClassification(String _classificationURIorString) {
    if (!this.classificationVector.contains(_classificationURIorString)) {
        this.classificationVector.add(_classificationURIorString);
        Element hasTopConcept = this.tagNode.addElement(new QName("broader", Ontologies.SKOS));
        hasTopConcept.addAttribute(new QName("resource", Ontologies.RDF), _classificationURIorString);
    }
}

From source file:to.networld.semantic.contexthandler.data.ContextTag.java

License:Open Source License

/**
 * @see to.networld.semantic.contexthandler.interfaces.IContextTag#setCooccurURI(java.lang.String)
 *//*from   w  ww .j a  v a 2s.  com*/
@Override
public void setCooccurURI(String _uri) {
    if (!this.cooccurVector.contains(_uri)) {
        this.cooccurVector.add(_uri);
        Element element = this.tagNode.addElement(new QName("cooccurs_in", Ontologies.SCOT));
        element.addAttribute(new QName("resource", Ontologies.RDF), _uri);
    }
}