Java Code Examples for org.dom4j.tree.DefaultElement#addAttribute()

The following examples show how to use org.dom4j.tree.DefaultElement#addAttribute() . 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: CPOrganization.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {

      final DefaultElement orgaElement = new DefaultElement(CPCore.ORGANIZATION);

      orgaElement.addAttribute(CPCore.IDENTIFIER, identifier);
      orgaElement.addAttribute(CPCore.STRUCTURE, structure);

      final DefaultElement titleElement = new DefaultElement(CPCore.TITLE);
      titleElement.setText(title);
      orgaElement.add(titleElement);

      if (metadata != null) {
          metadata.buildDocument(orgaElement);
      }
      for (final Iterator<CPItem> itItem = items.iterator(); itItem.hasNext();) {
          final CPItem item = itItem.next();
          item.buildDocument(orgaElement);
      }
      parent.add(orgaElement);

  }
 
Example 2
Source File: CPOrganization.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {

      final DefaultElement orgaElement = new DefaultElement(CPCore.ORGANIZATION);

      orgaElement.addAttribute(CPCore.IDENTIFIER, identifier);
      orgaElement.addAttribute(CPCore.STRUCTURE, structure);

      final DefaultElement titleElement = new DefaultElement(CPCore.TITLE);
      titleElement.setText(title);
      orgaElement.add(titleElement);

      if (metadata != null) {
          metadata.buildDocument(orgaElement);
      }
      for (final Iterator<CPItem> itItem = items.iterator(); itItem.hasNext();) {
          final CPItem item = itItem.next();
          item.buildDocument(orgaElement);
      }
      parent.add(orgaElement);

  }
 
Example 3
Source File: CPResource.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      // String base = "";
      // if(xmlbase != null && !xmlbase.equals("")) base="
      // xml:base=\""+xmlbase+"\"";

      // TODO: xml base imlement !!!

      final DefaultElement resourceElement = new DefaultElement(CPCore.RESOURCE);

      resourceElement.addAttribute(CPCore.IDENTIFIER, identifier);
      resourceElement.addAttribute(CPCore.TYPE, type);
      resourceElement.addAttribute(CPCore.HREF, href);
      if (!xmlbase.equals("")) {
          resourceElement.addAttribute(CPCore.BASE, xmlbase);
      }

      if (metadata != null) {
          metadata.buildDocument(resourceElement);
      }

      // build files
      for (final Iterator<CPFile> itFiles = files.iterator(); itFiles.hasNext();) {
          final CPFile file = itFiles.next();
          file.buildDocument(resourceElement);
      }

      // build dependencies
      for (final Iterator<CPDependency> itDep = dependencies.iterator(); itDep.hasNext();) {
          final CPDependency dep = itDep.next();
          dep.buildDocument(resourceElement);
      }

      parent.add(resourceElement);
  }
 
Example 4
Source File: CPItem.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement itemElement = new DefaultElement(CPCore.ITEM);

      itemElement.addAttribute(CPCore.IDENTIFIER, identifier);
      if (!identifierRef.equals("")) {
          itemElement.addAttribute(CPCore.IDENTIFIERREF, identifierRef);
      }
      itemElement.addAttribute(CPCore.ISVISIBLE, isVisibleString());

      if (metadata != null) {
          metadata.buildDocument(itemElement);
      }

      final DefaultElement titleElement = new DefaultElement(CPCore.TITLE);
      titleElement.setText(title);
      itemElement.add(titleElement);

      for (final Iterator<CPItem> itItem = items.iterator(); itItem.hasNext();) {
          final CPItem item = itItem.next();
          item.buildDocument(itemElement);
      }

      parent.add(itemElement);

  }
 
Example 5
Source File: CPFile.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement fileElement = new DefaultElement(CPCore.FILE);
      fileElement.addAttribute(CPCore.HREF, href);
      if (metadata != null) {
          metadata.buildDocument(fileElement);
      }
      parent.add(fileElement);
  }
 
Example 6
Source File: CPDependency.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement depElement = new DefaultElement(CPCore.DEPENDENCY);
      depElement.addAttribute(CPCore.IDENTIFIERREF, identifierRef);
      parent.add(depElement);
  }
 
Example 7
Source File: CPResource.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      // String base = "";
      // if(xmlbase != null && !xmlbase.equals("")) base="
      // xml:base=\""+xmlbase+"\"";

      // TODO: xml base imlement !!!

      final DefaultElement resourceElement = new DefaultElement(CPCore.RESOURCE);

      resourceElement.addAttribute(CPCore.IDENTIFIER, identifier);
      resourceElement.addAttribute(CPCore.TYPE, type);
      resourceElement.addAttribute(CPCore.HREF, href);
      if (!xmlbase.equals("")) {
          resourceElement.addAttribute(CPCore.BASE, xmlbase);
      }

      if (metadata != null) {
          metadata.buildDocument(resourceElement);
      }

      // build files
      for (final Iterator<CPFile> itFiles = files.iterator(); itFiles.hasNext();) {
          final CPFile file = itFiles.next();
          file.buildDocument(resourceElement);
      }

      // build dependencies
      for (final Iterator<CPDependency> itDep = dependencies.iterator(); itDep.hasNext();) {
          final CPDependency dep = itDep.next();
          dep.buildDocument(resourceElement);
      }

      parent.add(resourceElement);
  }
 
Example 8
Source File: CPItem.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement itemElement = new DefaultElement(CPCore.ITEM);

      itemElement.addAttribute(CPCore.IDENTIFIER, identifier);
      if (!identifierRef.equals("")) {
          itemElement.addAttribute(CPCore.IDENTIFIERREF, identifierRef);
      }
      itemElement.addAttribute(CPCore.ISVISIBLE, isVisibleString());

      if (metadata != null) {
          metadata.buildDocument(itemElement);
      }

      final DefaultElement titleElement = new DefaultElement(CPCore.TITLE);
      titleElement.setText(title);
      itemElement.add(titleElement);

      for (final Iterator<CPItem> itItem = items.iterator(); itItem.hasNext();) {
          final CPItem item = itItem.next();
          item.buildDocument(itemElement);
      }

      parent.add(itemElement);

  }
 
Example 9
Source File: CPFile.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement fileElement = new DefaultElement(CPCore.FILE);
      fileElement.addAttribute(CPCore.HREF, href);
      if (metadata != null) {
          metadata.buildDocument(fileElement);
      }
      parent.add(fileElement);
  }
 
Example 10
Source File: CPDependency.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public void buildDocument(final DefaultElement parent) {
      final DefaultElement depElement = new DefaultElement(CPCore.DEPENDENCY);
      depElement.addAttribute(CPCore.IDENTIFIERREF, identifierRef);
      parent.add(depElement);
  }
 
Example 11
Source File: XmppDecoderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void buildXmppStanza() {
    xmppStanzaElement = new DefaultElement("iq");
    xmppStanzaElement.addAttribute("type", "set");
    xmppStanzaElement.addAttribute("from", "[email protected]");
    xmppStanzaElement.addAttribute("to", "xmpp.onosproject.org");
    Element pubsub = new DefaultElement("pubsub",
                                        new org.dom4j.Namespace("", "http://jabber.org/protocol/pubsub"));
    Element subscribe = new DefaultElement("subscribe");
    subscribe.addAttribute("node", "test");
    pubsub.add(subscribe);
    xmppStanzaElement.add(pubsub);
}
 
Example 12
Source File: StackHttp2.java    From mts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a specific Msg
 */
@Override
public Msg parseMsgFromXml(ParseFromXmlContext context, Element root, Runner runner) throws Exception {
    MsgHttp2 msg = (MsgHttp2) super.parseMsgFromXml(context, root, runner);

    //
    // Try to find the channel
    //
    String channelName = root.attributeValue("channel");
    //part to don't have regression
    if (channelName == null || channelName.equalsIgnoreCase("")) {
        channelName = root.attributeValue("connectionName");
    }

    String remoteUrl = root.attributeValue("remoteURL");
    //part to don't have regression
    if (remoteUrl == null || remoteUrl.equalsIgnoreCase("")) {
        remoteUrl = root.attributeValue("server");
    }

    //
    // If the message is not a request, it is a response.
    // The channel to use will be obtained from the
    // channel of the transaction-associated request.
    if (msg.isRequest()) {
        ChannelHttp2 channel = null;
        // case the channelName is specified
        if (channelName != null && !channelName.equalsIgnoreCase("")) {
            channel = (ChannelHttp2) getChannel(channelName);
        }
        // case the remoteXXX is specified
        if (remoteUrl != null && !remoteUrl.equalsIgnoreCase("")) {
            channel = (ChannelHttp2) getChannel(remoteUrl);
            if (channel == null) {
                //part to don't have regression
                DefaultElement defaultElement = new DefaultElement("openChannelHTTP2");
                defaultElement.addAttribute("remoteURL", remoteUrl);
                defaultElement.addAttribute("name", remoteUrl);
                channel = (ChannelHttp2) this.parseChannelFromXml(defaultElement, runner, StackFactory.PROTOCOL_HTTP2);
                openChannel(channel);
                channel = (ChannelHttp2) getChannel(remoteUrl);
            }
        }
        if (channel == null) {
            throw new ExecutionException("The channel named " + channelName + " does not exist");
        }
        //Set transactionId in message for a request
        TransactionId transactionId1 = new TransactionId(UUID.randomUUID().toString());
        msg.setTransactionId(transactionId1);
        msg.setChannel(channel);
    } else {
        TransactionId transactionId = new TransactionId(root.attributeValue("transactionId"));
        Trans transaction = getInTransaction(transactionId);
        msg.setTransactionId(transactionId);
        msg.setTransaction(transaction);
        msg.setChannel(transaction.getBeginMsg().getChannel());
        msg.setListenpoint(transaction.getBeginMsg().getListenpoint());

        if (channelName != null) {
            throw new ExecutionException("You can not specify the \"channel\" attribute while sending a response (provided by the HTTP2 protocol).");
        }
        if (remoteUrl != null) {
            throw new ExecutionException("You can not specify the \"remoteURL\" attribute while sending a response (provided by the HTTP2 protocol).");
        }

    }
    return msg;
}
 
Example 13
Source File: StackHttp.java    From mts with GNU General Public License v3.0 4 votes vote down vote up
/** Creates a specific HTTP Msg */
@Override
public Msg parseMsgFromXml(ParseFromXmlContext context, Element root, Runner runner) throws Exception
{
    Msg msg = super.parseMsgFromXml(context, root, runner);
    
    //
    // Try to find the channel
    //
    String channelName = root.attributeValue("channel");
    //part to don't have regression
    if (channelName == null || channelName.equalsIgnoreCase(""))
    {
        channelName = root.attributeValue("connectionName");
    }

    String remoteUrl = root.attributeValue("remoteURL");
    //part to don't have regression
    if (remoteUrl == null || remoteUrl.equalsIgnoreCase(""))
    {
    	remoteUrl = root.attributeValue("server");
    }

    //
    // If the message is not a request, it is a response.
    // The channel to use will be obtained from the
    // channel of the transaction-associated request.
    if (msg.isRequest())
    {
        Channel channel = null;
    	// case the channelName is specified
        if (channelName != null && !channelName.equalsIgnoreCase(""))
        {           
        	channel = getChannel(channelName);
        }
    	// case the remoteXXX is specified
        if (remoteUrl != null && !remoteUrl.equalsIgnoreCase(""))
        {
        	channel = getChannel(remoteUrl);
        	if (channel == null)
        	{
             //part to don't have regression
          DefaultElement defaultElement = new DefaultElement("openChannelHTTP");
          defaultElement.addAttribute("remoteURL", remoteUrl);
          defaultElement.addAttribute("name", remoteUrl);
          channel = this.parseChannelFromXml(defaultElement, runner, StackFactory.PROTOCOL_HTTP);
          openChannel(channel);
             channel = getChannel(remoteUrl);
        	}
        }
        if (channel == null)
        {
            throw new ExecutionException("The channel named " + channelName + " does not exist");
        }
        // call to getTransactionId to generate it NOW (important)
        // it can be generated now because this is a request from xml
        msg.getTransactionId();
        msg.setChannel(channel);
    }
    else
    {        	
        if (channelName != null)
        {
            throw new ExecutionException("You can not specify the \"channel\" attribute while sending a response (provided by the HTTP protocol).");
        }
        if (remoteUrl != null)
        {
            throw new ExecutionException("You can not specify the \"remoteURL\" attribute while sending a response (provided by the HTTP protocol).");
        }
    }
    return msg;
}