Java Code Examples for org.dom4j.Element.setText()

The following are Jave code examples for showing how to use setText() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: gitplex-mit   File: DatabaseMigrator.java   View Source Code Vote up 6 votes
private void migrateIntegrationStrategy(Element integrationStrategyElement) {
	if (integrationStrategyElement != null) {
		integrationStrategyElement.setName("mergeStrategy");
		switch (integrationStrategyElement.getText()) {
		case "MERGE_ALWAYS":
			integrationStrategyElement.setText("ALWAYS_MERGE");
			break;
		case "MERGE_WITH_SQUASH":
			integrationStrategyElement.setText("SQUASH_MERGE");
			break;
		case "REBASE_SOURCE_ONTO_TARGET":
			integrationStrategyElement.setText("REBASE_MERGE");
			break;
		case "REBASE_TARGET_ONTO_SOURCE":
			integrationStrategyElement.setText("MERGE_IF_NECESSARY");
			break;
		}
	}
}
 
Example 2
Project: iBase4J-Common   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将Dto转换为符合XML标准规范格式的字符串(基于节点值形式)
 * 
 * @param map 传入的Dto对象
 * @param pRootNodeName 根结点名
 * @return string 返回XML格式字符串
 */
public static final String parseDto2XmlHasHead(Map map, String pRootNodeName) {
    Document document = DocumentHelper.createDocument();
    // 增加一个根元素节点
    document.addElement(pRootNodeName);
    Element root = document.getRootElement();
    Iterator keyIterator = map.keySet().iterator();
    while (keyIterator.hasNext()) {
        String key = (String)keyIterator.next();
        String value = (String)map.get(key);
        Element leaf = root.addElement(key);
        leaf.setText(value);
    }
    // 将XML的头声明信息截去
    // String outXml = document.asXML().substring(39);
    String outXml = document.asXML();
    return outXml;
}
 
Example 3
Project: iBase4J-Common   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将List数据类型转换为符合XML格式规范的字符串(基于节点值的方式)
 * 
 * @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
 * @param pRootNodeName 根节点名称
 * @param pFirstNodeName 行节点名称
 * @return string 返回XML格式字符串
 */
public static final String parseList2XmlBasedNode(List pList, String pRootNodeName, String pFirstNodeName) {
    Document document = DocumentHelper.createDocument();
    Element output = document.addElement(pRootNodeName);
    for (int i = 0; i < pList.size(); i++) {
        Map map = (Map)pList.get(i);
        Element elRow = output.addElement(pFirstNodeName);
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry)it.next();
            Element leaf = elRow.addElement((String)entry.getKey());
            leaf.setText(String.valueOf(entry.getValue()));
        }
    }
    String outXml = document.asXML().substring(39);
    return outXml;
}
 
Example 4
Project: automat   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将Dto转换为符合XML标准规范格式的字符串(基于节点值形式)
 * 
 * @param dto 传入的Dto对象
 * @param pRootNodeName 根结点名
 * @return string 返回XML格式字符串
 */
public static final String parseDto2Xml(Map map, String pRootNodeName) {
	Document document = DocumentHelper.createDocument();
	// 增加一个根元素节点
	document.addElement(pRootNodeName);
	Element root = document.getRootElement();
	Iterator keyIterator = map.keySet().iterator();
	while (keyIterator.hasNext()) {
		String key = (String) keyIterator.next();
		String value = (String) map.get(key);
		Element leaf = root.addElement(key);
		leaf.setText(value);
	}
	// 将XML的头声明信息截去
	String outXml = document.asXML().substring(39);
	return outXml;
}
 
Example 5
Project: Divinity_Original_Sin_2_zhCN   File: TextUtils.java   View Source Code Vote up 6 votes
/**
 * 替换空格等
 * 
 * @throws UnsupportedEncodingException
 */
public static Document replaceSpace(Document document) {
  // 获取根节点元素对象
  Element root = document.getRootElement();
  // 子节点
  List<Element> list = root.elements();
  // 使用递归
  Iterator<Element> iterator = list.iterator();
  while (iterator.hasNext()) {
    Element e = iterator.next();
    String text = e.getText();
    if (text != null && !"".equals(text)) {
      text = text.replaceAll(" ", "");
      e.setText(text);
    }
  }
  return document;
}
 
Example 6
Project: joai-project   File: MdeNode.java   View Source Code Vote up 6 votes
/**
 *  Insert an HTML comment into the html source.
 *
 * @param  e  NOT YET DOCUMENTED
 * @param  s  NOT YET DOCUMENTED
 */
protected void insertHtmlComment(Element e, String s) {
	prtln("\ninsertHtmlComment()");
	Element comment = df.createElement("st__htmlComment");
	comment.setText(s);
	Element parent = e.getParent();

	if (parent != null) {
		List children = parent.elements();
		int index = children.indexOf(e);
		children.add(index, comment);
	}
	else {
		// prtlnErr("PARENT NOT FOUND");
	}
}
 
Example 7
Project: ofmeet-openfire-plugin   File: OfMeetPlugin.java   View Source Code Vote up 6 votes
public void sessionDestroyed(Session session)
{
	Log.debug("OfMeet Plugin -  sessionDestroyed "+ session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());

	boolean skypeAvailable = XMPPServer.getInstance().getPluginManager().getPlugin("ofskype") != null;

	if (OfMeetAzure.skypeids.containsKey(session.getAddress().getNode()))
	{
		String sipuri = OfMeetAzure.skypeids.remove(session.getAddress().getNode());

		IQ iq = new IQ(IQ.Type.set);
		iq.setFrom(session.getAddress());
		iq.setTo(XMPPServer.getInstance().getServerInfo().getXMPPDomain());

		Element child = iq.setChildElement("request", "http://igniterealtime.org/protocol/ofskype");
		child.setText("{'action':'stop_skype_user', 'sipuri':'" + sipuri + "'}");
		XMPPServer.getInstance().getIQRouter().route(iq);

		Log.info("OfMeet Plugin - closing skype session " + sipuri);
	}
}
 
Example 8
Project: JAVA-   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将List数据类型转换为符合XML格式规范的字符串(基于节点值的方式)
 * 
 * @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
 * @param pRootNodeName 根节点名称
 * @param pFirstNodeName 行节点名称
 * @return string 返回XML格式字符串
 */
public static final String parseList2XmlBasedNode(List pList, String pRootNodeName, String pFirstNodeName) {
	Document document = DocumentHelper.createDocument();
	Element output = document.addElement(pRootNodeName);
	for (int i = 0; i < pList.size(); i++) {
		Map map = (Map) pList.get(i);
		Element elRow = output.addElement(pFirstNodeName);
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			Element leaf = elRow.addElement((String) entry.getKey());
			leaf.setText(String.valueOf(entry.getValue()));
		}
	}
	String outXml = document.asXML().substring(39);
	return outXml;
}
 
Example 9
Project: joai-project   File: RendererImpl.java   View Source Code Vote up 5 votes
/**
 *  Creates the JSP element to render an input helper for the specified path
 *
 * @param  xpath  NOT YET DOCUMENTED
 * @return        The inputHelper value
 */
public Element getInputHelperElement(String xpath) {
	Element inputHelper = null;
	if (!this.isEditMode())
		return null;
	String inputHelperPath = this.rhelper.getInputHelperFile(xpath);
	if (inputHelperPath != null) {
		String path = "/editor/input_helpers/" + inputHelperPath;
		inputHelper = df.createElement("div")
			.addAttribute("class", "input-helper");
		inputHelper.setText("<%@ include file=\"" + path + "\" %>");
	}
	return inputHelper;
}
 
Example 10
Project: joai-project   File: MdeNode.java   View Source Code Vote up 5 votes
/**
 *  Adds a feature to the HtmlComment attribute of the MdeNode object
 *
 * @param  e  The feature to be added to the HtmlComment attribute
 * @param  s  The feature to be added to the HtmlComment attribute
 */
protected void addHtmlComment(Element e, String s) {
	prtln("\ninsertHtmlComment()");
	Element comment = df.createElement("st__htmlComment");
	comment.setText(s);
	e.add(comment);
}
 
Example 11
Project: joai-project   File: RendererImpl.java   View Source Code Vote up 5 votes
/**
 *  Creates an optionalItemControl Element that allows user to add or delete an
 *  optional Element to/from the instance document
 *
 * @param  xpath  NOT YET DOCUMENTED
 * @return        The optionalItemControl Element
 */
public Element getOptionalItemControl(String xpath) {
	// prtln ("getOptionalItemControl()");
	// test for whether the element exists
	Element baseDiv = df.createElement("div");
	this.rhelper.embedDebugInfo(baseDiv, "RenderImpl - getOptionalItemControl");

	Element elementNotExists = rhelper.nodeNotExistsTest(xpath);
	baseDiv.add(elementNotExists);

	Element newItemAction = elementNotExists.addElement("span")
		.addAttribute("class", "action-button");

	Element newItemLink = newItemAction.addElement("a")
		.addAttribute("href", "javascript:doNewElement(" + RendererHelper.jspQuotedString(xpath) + ")");
	rhelper.attachToolHelp(newItemLink, "Specify the contents of this optional element");
	newItemLink.setText("choose");

	Element elementExists = rhelper.nodeExistsTest(xpath);
	baseDiv.add(elementExists);

	Element delItemAction = elementExists.addElement("span")
		.addAttribute("class", "action-button");

	Element delItemLink = delItemAction.addElement("a")
		.addAttribute("href", "javascript:doDeleteElement(" + RendererHelper.jspQuotedString(xpath) + ")");
	rhelper.attachToolHelp(delItemLink, "remove this optional element");
	delItemLink.setText("remove");
	return baseDiv;
}
 
Example 12
Project: minlia-iot   File: AbstractAnnotationApiSerializer.java   View Source Code Vote up 5 votes
/**
 * 添加节点
 */
private void addElement(Element rootElement, String elementName, Object obj, boolean required) {
  if (obj == null && !required) {
    return;
  }
  Assert.notNull(obj, elementName);
  Class<?> clazz = obj.getClass();
  Element element = rootElement.addElement(elementName);
  if (clazz == Integer.class || clazz == Long.class) {
    element.setText(obj.toString());
  } else {
    element.addCDATA(obj.toString());
  }
}
 
Example 13
Project: bdf2   File: BindingConfigConverter.java   View Source Code Vote up 5 votes
public Element convert(ComponentInfo component, RuleSet ruleSet,
		Element rootElement) throws Exception {
	String name=BindingConfig.class.getSimpleName();
	XmlNode node=BindingConfig.class.getAnnotation(XmlNode.class);
	if(node!=null && StringHelper.isNotEmpty(node.nodeName())){
		name=node.nodeName();
	}
	Rule rule=ruleSet.getRule(name);
	BaseElement element = fillElement(component,ruleSet,rule,rootElement);
	String[] dsInfo=this.retriveDataSetAndDataPath(component);
	if(dsInfo!=null){
		String dataPath=dsInfo[1];
		int pos=dataPath.lastIndexOf(".");
		if(pos!=-1){
			dataPath=dataPath.substring(pos+1);
		}
		Element childrenPropertyElement=new BaseElement("Property");
		childrenPropertyElement.addAttribute("name", "childrenProperty");
		childrenPropertyElement.setText(dataPath);
		element.add(childrenPropertyElement);
	}
	if(component.getChildren()!=null){
		for(ComponentInfo c:component.getChildren()){
			this.buildChildren(element,c,ruleSet,rootElement);							
		}
	}
	return element;
}
 
Example 14
Project: joai-project   File: GuardedPath.java   View Source Code Vote up 5 votes
public Element asElement () {
	Element guardedpath = df.createElement ("guarded-path");
	Element path = guardedpath.addElement ("path");
	path.setText (getPath());
	Element description = guardedpath.addElement ("description");
	description.setText (getDescription());
	Element role = guardedpath.addElement ("role");
	String roleStr = getRole() == null ? "" : getRole().toString();
	role.setText (roleStr);
	return guardedpath;
}
 
Example 15
Project: joai-project   File: ActionPath.java   View Source Code Vote up 5 votes
public Element asElement () {
	Element actionPath = df.createElement ("action-path");
	Element path = actionPath.addElement ("path");
	path.setText (getPath());
	Element description = actionPath.addElement ("description");
	description.setText (getDescription());
	return actionPath;
}
 
Example 16
Project: bdf2   File: AbstractBuilder.java   View Source Code Vote up 5 votes
protected Element createPropertyElement(String name,String value){
	Element element=new BaseElement("Property");
	element.addAttribute("name", name);
	if(value!=null){
		element.setText(value);			
	}
	return element;
}
 
Example 17
Project: joai-project   File: DCSSchemEditAction.java   View Source Code Vote up 5 votes
private String makeJsonError (String msg) {
	Element err = DocumentHelper.createElement ("error");
	if (msg == null)
		msg = "unknown error";
	err.setText(msg);
	Document responseDoc = DocumentHelper.createDocument(err);
	try {
		org.json.JSONObject json = org.json.XML.toJSONObject(responseDoc.asXML());
		return json.toString();
	} catch (Throwable e) {
		prtlnErr ("WARNING: unable to construct json error structure");
	}
		
	return "error"; 
}
 
Example 18
Project: joai-project   File: ViewerRenderer.java   View Source Code Vote up 5 votes
/**
 *  Formats the label and value for the current node.<p>
 *
 *  NOTE: this probably shouldn't be here, since it is misnamed (it does not
 *  have anything to do with "input"). To fix this problem we have to change
 *  super classes to differentiate between renders that create edit inputs and
 *  those that simply display values.
 *
 * @param  xpath       NOT YET DOCUMENTED
 * @param  label       NOT YET DOCUMENTED
 * @param  inputField  NOT YET DOCUMENTED
 * @return             The labelledInputField_1 value
 */
public Element getRenderedField_1(String xpath, Label label, Element inputField) {
	prtln("getRenderedField()");
	// prtln ("inputField: " + Dom4jUtils.prettyPrint(inputField));


	Element table = df.createElement("table")
		.addAttribute("class", "input-field-table");

	Element row = table.addElement("tr")
		.addAttribute("class", "form-row");

	// LABEL cell
	Element labelCell = row.addElement("td")
		.addAttribute("class", "label-cell");

	rhelper.attachToolHelp(labelCell, xpath);
	labelCell.add(label.getElement());

	// INPUT cell
	Element emptyTest = missingValueTest(xpath);
	Element debugging = emptyTest.addElement("span")
		.addAttribute("class", "element-error-msg");
	debugging.setText("missing value");

	Element notEmptyTest = hasValueTest(xpath);
	notEmptyTest.add(inputField);

	Element inputFieldCell = row.addElement("td")
		.addAttribute("class", "input-cell");
	inputFieldCell.add(emptyTest);
	inputFieldCell.add(notEmptyTest);

	return table;
}
 
Example 19
Project: joai-project   File: MdeRepeatingSubstitutionGroup.java   View Source Code Vote up 4 votes
protected Element getSubstitutionGroupNewItemControl() {

		Element newItemAction = df.createElement("div")
				.addAttribute("class", "action-button");
		//make a drop-down menu with choices, and present as controller
		
		/*
			do not present control if there are no children 
			- this case is handled elsewhere (search for "required choice")
			-- but should it be handled here?
		*/
		Element notEmptyTest = newItemAction.addElement("logic__notEmpty")
			.addAttribute("name", formBeanName)
			.addAttribute("property", "membersOf(" + xpath + "/*)");
			
		notEmptyTest = newItemAction;

		// tests whether the instance document can accept a new child given
		// schema constraints
		Element canAcceptTest = notEmptyTest.addElement("logic__equal")
			.addAttribute("name", formBeanName)
			.addAttribute("property", "acceptsNewSubstitionGroupMember(" + xpath + ")")
			.addAttribute("value", "true");
			
		String elementId = "${id}_controller";
		String Name = XPathUtils.getNodeName(normalizedXPath);
		
		Element newItemPrompt = canAcceptTest.addElement("div");
		newItemPrompt.setText("add " + XPathUtils.getNodeName (xpath));
		rhelper.attachToolHelp(newItemPrompt, "Choose a field to add from the pulldown menu");
		
		// wrap prompt and select in div
		Element selectWrapper = canAcceptTest.addElement ("div");
		this.embedDebugInfo(selectWrapper, "MdeRepeatingSubstitutionGroup - selectWrapper");
		
		
		// tmpArg is initialized to "" so the "-- choice --" option is selected,
		// rather than one of the choices
		Element tmpArgInit = selectWrapper.addElement("jsp__setProperty")
				.addAttribute("name", formBeanName)
				.addAttribute("property", "tmpArg")
				.addAttribute("value", "");		
				
		// the select element for making a choice
		Element newItemSelect = selectWrapper.addElement("html__select")
				.addAttribute("name", formBeanName)
				.addAttribute("property", "tmpArg")
				.addAttribute("onchange", "doNewChoice (this.value)");

		// the permissible choices for this element
		Element newChoiceOptions = newItemSelect.addElement("html__optionsCollection")
				.addAttribute("property", "substitutionGroupOptions(" + xpath + ")");

		rhelper.attachToolHelp(newItemSelect, "Choose an element to create");
		
		// wrap the newItemAction in a table. the left cell is the controller, and the right is blank
		Element table = df.createElement("table")
			.addAttribute ("class", "input-field-table");
		
		Element row = table.addElement ("tr")
			.addAttribute ("class", "form-row");
			
		Element controllerCell = row.addElement ("td")
			.addAttribute ("class", "action-box")
			.addAttribute ("nowrap", "1");
			
		controllerCell.add (newItemAction);
		
		Element emptyCell = row.addElement ("td")
			.addAttribute ("width", "95%");
		emptyCell.setText (" ");
		
		return table;
		
	}
 
Example 20
Project: ofmeet-openfire-plugin   File: OfMeetAzure.java   View Source Code Vote up 4 votes
public String authenticateUser(String username, String password)
  {
String userName = username.toLowerCase();
      final String[] parts = userName.split( "@", 2 );

      if ( parts.length > 1 )
      {
	String email = parts[0] + "@" + parts[1];
	email = email.toLowerCase();

	Log.debug( "OfMeetAzure login " + email);

	if (!authenticateByAzureAD(email, password))
	{
		Log.error( "access denied, unknown ([email protected]) " + email );
		return parts[0];
	}

	userName = (parts[0] + "_" + parts[1]).replaceAll("\\.", "_");
	User user = null;

	try {
		user = userManager.getUser(userName);
	}
	catch (UserNotFoundException e) {

		try {
			user = userManager.createUser(userName, password, givenName + " " + familyName, email);
		}
		catch (Exception e1) {
			Log.error( "access denied, cannot create username (user.domain) " + userName, e1);
			return userName;
		}
	}

	updateDomainGroup(userName, parts[1], givenName + " " + familyName);

	user.setPassword(accessToken);

	if (skypeids.containsKey(userName) == false)
	{
		boolean skypeAvailable = XMPPServer.getInstance().getPluginManager().getPlugin("ofskype") != null;

		if (skypeAvailable)
		{
			skypeids.put(userName, username);

			IQ iq = new IQ(IQ.Type.set);
			iq.setFrom(userName + "@" + XMPPServer.getInstance().getServerInfo().getXMPPDomain());
			iq.setTo(XMPPServer.getInstance().getServerInfo().getXMPPDomain());

			Element child = iq.setChildElement("request", "http://igniterealtime.org/protocol/ofskype");
			child.setText("{'action':'start_skype_user', 'password':'" + password + "', 'sipuri':'" + username + "'}");
			XMPPServer.getInstance().getIQRouter().route(iq);
		}
	}
}

return userName;
  }