org.dom4j.Namespace Java Examples

The following examples show how to use org.dom4j.Namespace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedRequestDsml.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    // Request Name
    if ( getDecorated().getRequestName() != null )
    {
        element.addElement( "requestName" ).setText(
            getDecorated().getRequestName() );
    }

    // Request Value        
    Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
    Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
    element.getDocument().getRootElement().add( xsdNamespace );
    element.getDocument().getRootElement().add( xsiNamespace );

    Element valueElement = element.addElement( "requestValue" ).addText(
        ParserUtils.base64Encode( getRequestValue() ) );
    valueElement.addAttribute( new QName( "type", xsiNamespace ),
        "xsd:" + ParserUtils.BASE64BINARY );

    return element;
}
 
Example #2
Source File: XmppControllerImplTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding, removing IQ listeners and handling IQ stanzas.
 */
@Test
public void handlePackets() {
    // IQ packets
    IQ iq = new IQ();
    Element element = new DefaultElement("pubsub", Namespace.get(testNamespace));
    iq.setChildElement(element);
    agent.processUpstreamEvent(jid1, iq);
    assertThat(testXmppIqListener.handledIqs, hasSize(1));
    agent.processUpstreamEvent(jid2, iq);
    assertThat(testXmppIqListener.handledIqs, hasSize(2));
    // Message packets
    Packet message = new Message();
    agent.processUpstreamEvent(jid1, message);
    assertThat(testXmppMessageListener.handledMessages, hasSize(1));
    agent.processUpstreamEvent(jid2, message);
    assertThat(testXmppMessageListener.handledMessages, hasSize(2));
    Packet presence = new Presence();
    agent.processUpstreamEvent(jid1, presence);
    assertThat(testXmppPresenceListener.handledPresenceStanzas, hasSize(1));
    agent.processUpstreamEvent(jid2, presence);
    assertThat(testXmppPresenceListener.handledPresenceStanzas, hasSize(2));
}
 
Example #3
Source File: XmppStreamOpen.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public String toXml() {
    StringWriter out = new StringWriter();
    XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat());
    try {
        out.write("<");
        writer.write(element.getQualifiedName());
        for (Attribute attr : (List<Attribute>) element.attributes()) {
            writer.write(attr);
        }
        writer.write(Namespace.get(this.element.getNamespacePrefix(), this.element.getNamespaceURI()));
        writer.write(Namespace.get("jabber:client"));
        out.write(">");
    } catch (IOException ex) {
        log.info("Error writing XML", ex);
    }
    return out.toString();
}
 
Example #4
Source File: WebSocketConnection.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void deliver(Packet packet) throws UnauthorizedException
{
    final String xml;
    if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) {
        // use string-based operation here to avoid cascading xmlns wonkery
        StringBuilder packetXml = new StringBuilder(packet.toXML());
        packetXml.insert(packetXml.indexOf(" "), " xmlns=\"jabber:client\"");
        xml = packetXml.toString();
    } else {
        xml = packet.toXML();
    }
    if (validate()) {
        deliverRawText(xml);
    } else {
        // use fallback delivery mechanism (offline)
        getPacketDeliverer().deliver(packet);
    }
}
 
Example #5
Source File: HttpSession.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the stream features which are available for this session.
 *
 * @return the stream features which are available for this session.
 */
public Collection<Element> getAvailableStreamFeaturesElements() {
    List<Element> elements = new ArrayList<>();

    if (getAuthToken() == null) {
        Element sasl = SASLAuthentication.getSASLMechanismsElement(this);
        if (sasl != null) {
            elements.add(sasl);
        }
    }

    if (XMPPServer.getInstance().getIQRegisterHandler().isInbandRegEnabled()) {
        elements.add(DocumentHelper.createElement(new QName("register",
                new Namespace("", "http://jabber.org/features/iq-register"))));
    }
    Element bind = DocumentHelper.createElement(new QName("bind",
            new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
    elements.add(bind);

    Element session = DocumentHelper.createElement(new QName("session",
            new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
    session.addElement("optional");
    elements.add(session);
    return elements;
}
 
Example #6
Source File: HttpSession.java    From Openfire with Apache License 2.0 6 votes vote down vote up
public Deliverable(Collection<Packet> elements) {
    this.text = null;
    this.packets = new ArrayList<>();
    for (Packet packet : elements) {
        // Append packet namespace according XEP-0206 if needed
        if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) {
            // use string-based operation here to avoid cascading xmlns wonkery
            StringBuilder packetXml = new StringBuilder(packet.toXML());
            final int noslash = packetXml.indexOf( ">" );
            final int slash = packetXml.indexOf( "/>" );
            final int insertAt = ( noslash - 1 == slash ? slash : noslash );
            packetXml.insert( insertAt, " xmlns=\"jabber:client\"");
            this.packets.add(packetXml.toString());
        } else {
            this.packets.add(packet.toXML());
        }
    }
}
 
Example #7
Source File: SASLAuthentication.java    From Openfire with Apache License 2.0 6 votes vote down vote up
public static Element getSASLMechanismsElement( ClientSession session )
{
    final Element result = DocumentHelper.createElement( new QName( "mechanisms", new Namespace( "", SASL_NAMESPACE ) ) );
    for (String mech : getSupportedMechanisms()) {
        if (mech.equals("EXTERNAL")) {
            boolean trustedCert = false;
            if (session.isSecure()) {
                final Connection connection = ( (LocalClientSession) session ).getConnection();
                if ( SKIP_PEER_CERT_REVALIDATION_CLIENT.getValue() ) {
                    // Trust that the peer certificate has been validated when TLS got established.
                    trustedCert = connection.getPeerCertificates() != null && connection.getPeerCertificates().length > 0;
                } else {
                    // Re-evaluate the validity of the peer certificate.
                    final TrustStore trustStore = connection.getConfiguration().getTrustStore();
                    trustedCert = trustStore.isTrusted( connection.getPeerCertificates() );
                }
            }
            if ( !trustedCert ) {
                continue; // Do not offer EXTERNAL.
            }
        }
        final Element mechanism = result.addElement("mechanism");
        mechanism.setText(mech);
    }
    return result;
}
 
Example #8
Source File: SASLAuthentication.java    From Openfire with Apache License 2.0 6 votes vote down vote up
public static Element getSASLMechanismsElement( LocalIncomingServerSession session )
{
    final Element result = DocumentHelper.createElement( new QName( "mechanisms", new Namespace( "", SASL_NAMESPACE ) ) );
    if (session.isSecure()) {
        final Connection connection   = session.getConnection();
        final TrustStore trustStore   = connection.getConfiguration().getTrustStore();
        final X509Certificate trusted = trustStore.getEndEntityCertificate( session.getConnection().getPeerCertificates() );

        boolean haveTrustedCertificate = trusted != null;
        if (trusted != null && session.getDefaultIdentity() != null) {
            haveTrustedCertificate = verifyCertificate(trusted, session.getDefaultIdentity());
        }
        if (haveTrustedCertificate) {
            // Offer SASL EXTERNAL only if TLS has already been negotiated and the peer has a trusted cert.
            final Element mechanism = result.addElement("mechanism");
            mechanism.setText("EXTERNAL");
        }
    }
    return result;
}
 
Example #9
Source File: XmppPubSubControllerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private XmppSubscribe buildXmppSubscribe() {
    IQ iq = new IQ(IQ.Type.set);
    iq.setTo(toJid);
    iq.setFrom(fromJid);
    Element element = new DefaultElement(pubSub, Namespace.get(XmppPubSubConstants.PUBSUB_NAMESPACE));
    Element childElement = new DefaultElement(subscribe);
    childElement.addAttribute(node, nodeAttribute);
    element.add(childElement);
    iq.setChildElement(element);
    XmppSubscribe xmppSubscribe = new XmppSubscribe(iq);
    return xmppSubscribe;
}
 
Example #10
Source File: GetXmlData.java    From hop with Apache License 2.0 5 votes vote down vote up
public void prepareNSMap( Element l ) {
  @SuppressWarnings( "unchecked" )
  List<Namespace> namespacesList = l.declaredNamespaces();
  for ( Namespace ns : namespacesList ) {
    if ( ns.getPrefix().trim().length() == 0 ) {
      data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() );
      String path = "";
      Element element = l;
      while ( element != null ) {
        if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) {
          path = GetXmlDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path;
        } else {
          path = GetXmlDataMeta.N0DE_SEPARATOR + element.getName() + path;
        }
        element = element.getParent();
      }
      data.NSPath.add( path );
    } else {
      data.NAMESPACE.put( ns.getPrefix(), ns.getURI() );
    }
  }

  @SuppressWarnings( "unchecked" )
  List<Element> elementsList = l.elements();
  for ( Element e : elementsList ) {
    prepareNSMap( e );
  }
}
 
Example #11
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespaceInChildren(Element treeRoot, Namespace oldNsp, Namespace newNsp) {
    for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) {
        Element e = (Element) i.next();
        if (e.getNamespace().equals(oldNsp)) {
            e.setQName(QName.get(e.getName(), newNsp));
            e.remove(oldNsp);
        }
        moveNamespaceInChildren(e, oldNsp, newNsp);
    }
}
 
Example #12
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespace(Element treeRoot, String oldNspURI, String newNspURI) {
    Namespace oldNsp = treeRoot.getNamespace();
    if (oldNspURI.equals(oldNsp.getURI())) {
        Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI);
        treeRoot.setQName(QName.get(treeRoot.getName(), newNsp));
        treeRoot.remove(oldNsp);
    }
    moveNamespaceInChildren(treeRoot, oldNspURI, newNspURI);
}
 
Example #13
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespaceInChildren(Element treeRoot, String oldNspURI, String newNspURI) {
    for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) {
        Element e = (Element) i.next();
        Namespace oldNsp = e.getNamespace();
        if (oldNspURI.equals(oldNsp.getURI())) {
            Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI);
            e.setQName(QName.get(e.getName(), newNsp));
            e.remove(oldNsp);
        }
        moveNamespaceInChildren(e, oldNspURI, newNspURI);
    }
}
 
Example #14
Source File: PdmParser.java    From hermes with Apache License 2.0 5 votes vote down vote up
/**
 * @return
 */
public static Map<String, Namespace> namespaces() {
	if (namespaces == null) {
		namespaces = new HashMap<String, Namespace>();
		namespaces.put("a", new Namespace("a", "attribute"));
		namespaces.put("c", new Namespace("c", "collection"));
		namespaces.put("o", new Namespace("o", "object"));
	}
	return namespaces;
}
 
Example #15
Source File: RouteJavaScriptOSGIForESBManager.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private static void moveNamespace(Element treeRoot, Namespace oldNsp, Namespace newNsp) {
    if (treeRoot.getNamespace().equals(oldNsp)) {
        treeRoot.setQName(QName.get(treeRoot.getName(), newNsp));
        treeRoot.remove(oldNsp);
    }
    moveNamespaceInChildren(treeRoot, oldNsp, newNsp);
}
 
Example #16
Source File: XmppPubSubControllerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private XmppUnsubscribe buildXmppUnsubscribe() {
    IQ iq = new IQ(IQ.Type.set);
    iq.setTo(toJid);
    iq.setFrom(fromJid);
    Element element = new DefaultElement(pubSub, Namespace.get(XmppPubSubConstants.PUBSUB_NAMESPACE));
    Element childElement = new DefaultElement(unsubscribe);
    childElement.addAttribute(node, nodeAttribute);
    element.add(childElement);
    iq.setChildElement(element);
    XmppUnsubscribe xmppUnsubscribe = new XmppUnsubscribe(iq);
    return xmppUnsubscribe;
}
 
Example #17
Source File: XmppPubSubControllerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private XmppPublish buildXmppPublish() {
    IQ iq = new IQ(IQ.Type.set);
    iq.setTo(toJid);
    iq.setFrom(fromJid);
    Element element = new DefaultElement(pubSub, Namespace.get(XmppPubSubConstants.PUBSUB_NAMESPACE));
    Element publishElement = new DefaultElement(publish).addAttribute(node, nodeAttribute);
    Element itemElement = new DefaultElement(item).addAttribute(id, itemId);
    Element entryElement = new DefaultElement(entry, Namespace.get(testNamespace));
    itemElement.add(entryElement);
    publishElement.add(itemElement);
    element.add(publishElement);
    iq.setChildElement(element);
    XmppPublish xmppPublish = new XmppPublish(iq);
    return xmppPublish;
}
 
Example #18
Source File: XmppPubSubControllerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private XmppRetract buildXmppRetract() {
    IQ iq = new IQ(IQ.Type.set);
    iq.setTo(toJid);
    iq.setFrom(fromJid);
    Element element = new DefaultElement(pubSub, Namespace.get(XmppPubSubConstants.PUBSUB_NAMESPACE));
    Element retractElement = new DefaultElement(retract).addAttribute(node, nodeAttribute);
    Element itemElement = new DefaultElement(item).addAttribute(id, itemId);
    retractElement.add(itemElement);
    element.add(retractElement);
    iq.setChildElement(element);
    XmppRetract xmppRetract = new XmppRetract(iq);
    return xmppRetract;
}
 
Example #19
Source File: DefaultXmlCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the xml string from YDT.
 *
 * @param ydtBuilder YDT builder
 * @return the xml string from YDT
 */
private String buildXmlForYdt(YdtBuilder ydtBuilder) {

    YdtExtendedBuilder extBuilder = (YdtExtendedBuilder) ydtBuilder;
    YdtExtendedContext rootNode = extBuilder.getRootNode();

    if (rootNode == null) {
        throw new YchException(E_YDT_ROOT_NODE);
    }

    // Creating the root element for xml.
    Element rootElement =
            DocumentHelper.createDocument().addElement(rootNode.getName());

    // Adding the name space if exist for root name.
    if (rootNode.getNamespace() != null) {
        rootElement.add(Namespace.get(rootNode.getNamespace()));
    }

    if ("config".equals(rootElement.getName())) {
        rootElement.add(new Namespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0"));
    }

    // Adding the attribute if exist
    Map<String, String> tagAttrMap = extBuilder.getRootTagAttributeMap();
    if (tagAttrMap != null && !tagAttrMap.isEmpty()) {
        for (Map.Entry<String, String> attr : tagAttrMap.entrySet()) {
            rootElement.addAttribute(attr.getKey(), attr.getValue());
        }
    }

    XmlCodecYdtListener listener = new XmlCodecYdtListener(XML, rootNode);
    listener.getElementStack().push(rootElement);

    // Walk through YDT and build the xml.
    YdtExtendedWalker extWalker = new DefaultYdtWalker();
    extWalker.walk(listener, rootNode);

    return rootElement.asXML();
}
 
Example #20
Source File: DocumentBuilder.java    From gocd with Apache License 2.0 5 votes vote down vote up
public static DocumentBuilder withRoot(String name, String xmlns) {
    DOMElement rootElement = new DOMElement(name);
    if (StringUtils.isNotBlank(xmlns)) {
        rootElement.setNamespace(new Namespace("", xmlns));
    }
    return new DocumentBuilder(new DOMDocument(rootElement));
}
 
Example #21
Source File: GetXMLData.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void prepareNSMap( Element l ) {
  @SuppressWarnings( "unchecked" )
  List<Namespace> namespacesList = l.declaredNamespaces();
  for ( Namespace ns : namespacesList ) {
    if ( ns.getPrefix().trim().length() == 0 ) {
      data.NAMESPACE.put( "pre" + data.NSPath.size(), ns.getURI() );
      String path = "";
      Element element = l;
      while ( element != null ) {
        if ( element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0 ) {
          path = GetXMLDataMeta.N0DE_SEPARATOR + element.getNamespacePrefix() + ":" + element.getName() + path;
        } else {
          path = GetXMLDataMeta.N0DE_SEPARATOR + element.getName() + path;
        }
        element = element.getParent();
      }
      data.NSPath.add( path );
    } else {
      data.NAMESPACE.put( ns.getPrefix(), ns.getURI() );
    }
  }

  @SuppressWarnings( "unchecked" )
  List<Element> elementsList = l.elements();
  for ( Element e : elementsList ) {
    prepareNSMap( e );
  }
}
 
Example #22
Source File: CPManifest.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor is used when creating a new CP
 * 
 * @param cp
 *            the cpcore to which this manifest belongs
 * @param identifier
 *            the identifier of the manifest
 */
public CPManifest(final CPCore cp, final String identifier) {
    super(CPCore.MANIFEST);
    this.identifier = identifier;
    schemaLocation = CPManifest.DEFAULT_SCHEMALOC;
    setNamespace(new Namespace("imsmd", DEFAULT_NMS));
    organizations = new CPOrganizations();
    resources = new CPResources();
    errors = new Vector<String>();
    this.cp = cp;
}
 
Example #23
Source File: CPManifest.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor is used when creating a new CP
 * 
 * @param cp
 *            the cpcore to which this manifest belongs
 * @param identifier
 *            the identifier of the manifest
 */
public CPManifest(final CPCore cp, final String identifier) {
    super(CPCore.MANIFEST);
    this.identifier = identifier;
    schemaLocation = CPManifest.DEFAULT_SCHEMALOC;
    setNamespace(new Namespace("imsmd", DEFAULT_NMS));
    organizations = new CPOrganizations();
    resources = new CPResources();
    errors = new Vector<String>();
    this.cp = cp;
}
 
Example #24
Source File: XmlNode.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
public XmlNode( XmlNode parent, Element node ) {

        this.node = node;

        Namespace nodeNamespace = node.getNamespace();
        if (nodeNamespace != null && !StringUtils.isNullOrEmpty(nodeNamespace.getPrefix())) {
            this.name = nodeNamespace.getPrefix() + ":" + node.getName();
        } else {
            this.name = node.getName();
        }

        this.attributes = new TreeMap<>();
        for (int i = 0; i < node.attributes().size(); i++) {
            Attribute att = node.attribute(i);
            this.attributes.put(att.getName(), att.getValue());
        }

        this.value = this.node.getTextTrim();

        this.parent = parent;

        this.children = new ArrayList<>();
        List<Element> childrenElements = this.node.elements();
        for (Element child : childrenElements) {
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                this.children.add(new XmlNode(this, child));
            }
        }
    }
 
Example #25
Source File: WFGraph.java    From EasyML with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]){

		Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
		QName rootQName = QName.get("workflow-app", rootNs); // your root element's name
		Element workflow = DocumentHelper.createElement(rootQName);
		Document doc = DocumentHelper.createDocument(workflow);
		
		workflow.addAttribute("name", "test");
		Element test = workflow.addElement("test");
		test.addText("hello");
				OutputFormat outputFormat = OutputFormat.createPrettyPrint();
				outputFormat.setEncoding("UTF-8");
				outputFormat.setIndent(true); 
				outputFormat.setIndent("    "); 
				outputFormat.setNewlines(true); 
		try {
			StringWriter stringWriter = new StringWriter();
			XMLWriter xmlWriter = new XMLWriter(stringWriter);
			xmlWriter.write(doc);
			xmlWriter.close();
			System.out.println( doc.asXML() );
			System.out.println( stringWriter.toString().trim());

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
 
Example #26
Source File: ActionNodeDef.java    From EasyML with Apache License 2.0 5 votes vote down vote up
/**
 * the detail xml configurations goes here, this will be called in append2XML
 * @param action
 */
public void generateActionXML(Element action) {
	Namespace xmlns = new Namespace("", "uri:oozie:shell-action:0.2"); // root namespace uri
	QName qName = QName.get("shell", xmlns); // your root element's name
	Element shell = action.addElement(qName);
	// action.appendChild( shell );

	generateElement(shell, "job-tracker", "${jobTracker}");
	generateElement(shell, "name-node", "${nameNode}");

	Element configuration = shell.addElement("configuration");
	createProperty(configuration, "mapred.job.queue.name", "${queueName}");
	createProperty(configuration, "mapreduce.map.memeory.mb", "10240");

	if( program.isScriptProgram() ){
		//单机脚本类型程序
		generateElement(shell, "exec", "./" + widgetId + ".startup");
	} else {
		generateElement(shell, "exec", "./run.sh");
	}

	command2XMLforShell(shell);

	if( program.isScriptProgram() ){
		generateElement(shell, "file", "${appPath}/" + widgetId
				+ ".startup");
		generateElement(shell, "file", "${appPath}/" + widgetId
				+ ".script");
	} else
		generateElement(shell, "file", "${nameNode}/" + program.getPath()
				+ "/run.sh");

	shell.addElement("capture-output");
}
 
Example #27
Source File: CamelDesignerCoreService.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private void addManifestContent(Item item, Element jobElement) {
    Element manifestElement = jobElement.addElement("RouteManifest");
    manifestElement.addAttribute(QName.get("space", Namespace.XML_NAMESPACE), "preserve");

    final DependenciesResolver resolver = new DependenciesResolver((ProcessItem) item);
    manifestElement.addElement(ManifestItem.IMPORT_PACKAGE).addText(resolver.getManifestImportPackage('\n'));
    manifestElement.addElement(ManifestItem.EXPORT_PACKAGE).addText(resolver.getManifestExportPackage('\n'));
    manifestElement.addElement(ManifestItem.REQUIRE_BUNDLE).addText(resolver.getManifestRequireBundle('\n'));
    manifestElement.addElement(ManifestItem.BUNDLE_CLASSPATH).addText(resolver.getManifestBundleClasspath('\n'));
}
 
Example #28
Source File: ElementWrapper.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean remove(Namespace namespace) {
	return element.remove( namespace );
}
 
Example #29
Source File: ModifyRequestDsml.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    ModifyRequest request = getDecorated();

    // Dn
    if ( request.getName() != null )
    {
        element.addAttribute( "dn", request.getName().getName() );
    }

    // Modifications
    Collection<Modification> modifications = request.getModifications();

    for ( Modification modification : modifications )
    {
        Element modElement = element.addElement( "modification" );

        if ( modification.getAttribute() != null )
        {
            modElement.addAttribute( "name", modification.getAttribute().getId() );

            for ( Value value : modification.getAttribute() )
            {
                if ( value.getString() != null )
                {
                    if ( ParserUtils.needsBase64Encoding( value.getString() ) )
                    {
                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
                        element.getDocument().getRootElement().add( xsdNamespace );
                        element.getDocument().getRootElement().add( xsiNamespace );

                        Element valueElement = modElement.addElement( "value" ).addText(
                            ParserUtils.base64Encode( value.getString() ) );
                        valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
                            + ParserUtils.BASE64BINARY );
                    }
                    else
                    {
                        modElement.addElement( "value" ).setText( value.getString() );
                    }
                }
            }
        }

        ModificationOperation operation = modification.getOperation();

        if ( operation == ModificationOperation.ADD_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "add" );
        }
        else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "replace" );
        }
        else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "delete" );
        }
        else if ( operation == ModificationOperation.INCREMENT_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "increment" );
        }
    }

    return element;
}
 
Example #30
Source File: AbstractBuilder.java    From gocd with Apache License 2.0 4 votes vote down vote up
private Optional<Namespace> getDefaultNameSpace() {
    return Optional.ofNullable(current().getNamespace());
}