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

The following are Jave code examples for showing how to use asXML() 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: joai-project   File: CollectionAdopter.java   View Source Code Vote up 6 votes
/**
 *  Gets the ncsItemStream attribute of the CollectionAdopter object
 *
 * @param  nsdl_dc_stream  NOT YET DOCUMENTED
 * @return                 The ncsItemStream value
 * @exception  Exception   NOT YET DOCUMENTED
 */
public Element getNcsItemStream(Element nsdl_dc_stream) throws Exception {
	// return XSLTransformer.transformString (nsdl_dc, this.xslPath);
	String className = "net.sf.saxon.TransformerFactoryImpl";
	if (nsdl_dc_stream == null)
		return null;
	String nsdl_dc = nsdl_dc_stream.asXML();
	try {
		Transformer transformer =
			XSLTransformer.getTransformer(this.xslPath, className);
		String xml = XSLTransformer.transformString(nsdl_dc, transformer);
		if (xml != null && xml.trim().length() > 0)
			return DocumentHelper.parseText(xml).getRootElement();
	} catch (Throwable t) {
		prtln("transform problem: " + t.getMessage());
	}
	return null;
}
 
Example 2
Project: joai-project   File: StructureWalker.java   View Source Code Vote up 5 votes
/**
 *  Process a ModelGroup element
 *
 * @param  e              current schema Element to process
 * @param  parent         instanceDoc Element to which we attach new instanceElement
 * @exception  Exception  if this element cannot be processed
 */
private void processModelGroup(Element e, Element parent) throws Exception {
	// find the type Definition for this element's ref

	// Debugging
	prtln("\n processModelGroup()", 1);
	prtln("\t element: " + e.asXML(), 1);

	GlobalDef globalDef = getElementTypeDef(e);
	if (globalDef == null) {
		throw new Exception("processModelGroup received null globalDef for " + e.asXML());
	}

	if (!globalDef.isModelGroup()) {
		throw new Exception("processModelGroup did not get ModelGroup def for " + e.asXML());
	}

	// now we've got our model group, and we can process it just as we would a complexType?

	ModelGroup groupDef = (ModelGroup) globalDef;

	Namespace ns = groupDef.getNamespace();
	pushNS(ns);
	readerStack.push(groupDef.getSchemaReader());
	prtln("\n" + readerStack.toString(), 1);

	List children = groupDef.getChildren();
	for (Iterator i = children.iterator(); i.hasNext(); ) {
		Element childElement = (Element) i.next();
		prtln("\t...with " + childElement.getName(), 1);
		processSchemaElement(childElement, parent);
	}
	popNS();
	SchemaReader popped = readerStack.pop();
	prtln("\n readerStack (" + readerStack.size() + ") popped " + popped.getLocation().toString());
}
 
Example 3
Project: joai-project   File: StructureWalker.java   View Source Code Vote up 5 votes
/**
 *  NOT YET DOCUMENTED
 *
 * @param  e              current schema Element to process
 * @param  parent         instanceDoc Element to which we attach new instanceElement
 * @exception  Exception  if this element cannot be processed
 */
private void processAttributeGroup(Element e, Element parent) throws Exception {
	// find the type Definition for this element's ref

	// Debugging
	prtln("\n processAttributeGroup()", 1);
	prtln("\t element: " + e.asXML(), 1);

	GlobalDef globalDef = getElementTypeDef(e);
	if (globalDef == null) {
		throw new Exception("processAttributeGroup received null globalDef for " + e.asXML());
	}

	if (!globalDef.isAttributeGroup()) {
		throw new Exception("processAttributeGroup did not get attributeGroup def for " + e.asXML());
	}

	// now we've got our attributeGroup, and we can process it just as we would

	AttributeGroup groupDef = (AttributeGroup) globalDef;

	Namespace ns = groupDef.getNamespace();
	pushNS(ns);
	readerStack.push(groupDef.getSchemaReader());
	prtln("\n" + readerStack.toString(), 1);

	List attributes = groupDef.getAttributes();
	for (Iterator i = attributes.iterator(); i.hasNext(); ) {
		Element attrElement = (Element) i.next();
		prtln("\t...with " + attrElement.getName(), 1);
		processInstanceAttribute(attrElement, parent);
	}
	popNS();
	SchemaReader popped = readerStack.pop();
	prtln("\n readerStack (" + readerStack.size() + ") popped " + popped.getLocation().toString());
}
 
Example 4
Project: joai-project   File: AttributeGroup.java   View Source Code Vote up 5 votes
/**
 *  NOT YET DOCUMENTED
 *
 * @return    NOT YET DOCUMENTED
 */
public String toString() {
	String s = "AttributeGroup: " + name;
	s += super.toString();
		String nl = "\n\t";
	for (Iterator i=getAttributes().iterator();i.hasNext();) {
		Element e = (Element)i.next();
		s += nl + e.asXML();
	}
	return s;
}
 
Example 5
Project: minlia-iot   File: AbstractAnnotationApiSerializer.java   View Source Code Vote up 5 votes
public String serializeAsXml(T body) {
  Class<?> clazz = body.getClass();
  Element rootElement = DocumentHelper
      .createElement(clazz.getAnnotation(XmlRootElement.class).name());
  Document document = DocumentHelper.createDocument(rootElement);
  checkRequestPropertyValidAndAddElement(rootElement, body);
  printXML(document);
  return rootElement.asXML();
}
 
Example 6
Project: sbc-qsystem   File: NetCommander.java   View Source Code Vote up 5 votes
/**
 * Сохранение конфигурации главного табло - ЖК или плазмы. Это XML-файл лежащий в папку
 * приложения mainboard.xml
 *
 * @param netProperty параметры соединения с сервером
 */
public static void saveBoardConfig(INetProperty netProperty, Element boardConfig) {
    QLog.l().logger().info("Сохранение конфигурации главного табло - ЖК или плазмы.");
    // загрузим ответ
    final CmdParams params = new CmdParams();
    params.textData = boardConfig.asXML();
    try {
        send(netProperty, Uses.TASK_SAVE_BOARD_CONFIG, params);
    } catch (QException e) {
        throw new ClientException(Locales.locMes("bad_response") + "\n" + e.toString());
    }
}
 
Example 7
Project: joai-project   File: DataStreamWrapper.java   View Source Code Vote up 4 votes
public String getMeta (String _format) {
	Element meta = DocumentHelper.createElement ("meta");
	meta.add(this.getDataStream( _format).createCopy());
	return meta.asXML();
}
 
Example 8
Project: joai-project   File: StructureWalker.java   View Source Code Vote up 4 votes
/**
 *  Create an attribute in the instanceDocument and a schemaNode for this
 *  attribute, using the attribute type if specified, or the type specified in
 *  the schema element otherwise.<p>
 *
 *  NOTE: the attribute name may not be present in the schema element for this
 *  attribute if a reference is involved.
 *
 * @param  e              schema Element representing the attribute
 * @param  parent         The parent of this attribute in the instance Document
 * @param  attrName       The attribute name
 * @param  attrType       typeName (if present) overrides type specified in
 *      schema element
 * @exception  Exception  Description of the Exception
 */
private void createAttribute(Element e, Element parent, String attrName, GlobalDef attrType) throws Exception {
	Attribute a = null;

	prtln("\nCREATE ATTRIBUTE() attrName: (" + attrName + ")", 1);
	if (attrType == null) {
		prtln("\t" + "no attrType provided");
	}
	else {
		prtln("\t ... attribute typeName - " + attrType.getQualifiedName(), 1);
		// prtln ("\t" + "attrType provided: " + attrType.toString());
	}

	/*
	 *  we don't bother qualifying the attribute unless it's name is qualified
	 */
	if (NamespaceRegistry.isQualified(attrName)) {
		// resolve prefix and create qualified attribute name
		prtln("\t attrName is qualified");
		String prefix = NamespaceRegistry.getNamespacePrefix(attrName);
		Namespace attrNS = namespaces.getNSforPrefix(prefix);
		QName qname = df.createQName(NamespaceRegistry.stripNamespacePrefix(attrName), attrNS);
		a = df.createAttribute(parent, qname, "");
	}
	else {
		a = df.createAttribute(parent, attrName, "");
	}

	prtln("\n\t attribute: " + a.asXML(), 1);
	parent.add(a);
	String xpath = getPath(a);
	SchemaNode schemaNode = null;
	GlobalDef globalDef = null;

	globalDef = getElementTypeDef(e);

	if (globalDef == null) {
		throw new Exception("createAttribute got a null globalDef for " + e.asXML());
	}
	if (attrType != null) {
		prtln("\n\t CreateAttribute() instantiating SchemaNode with explicitly provided attrTypeDef", 1);
		schemaNode = new SchemaNode(e, globalDef, xpath, schemaNodeMap, attrType);
	}
	else {
		prtln("\n\tCreateAttribute() instantiating SchemaNode with implicitly provided attrTypeDef (" +
			globalDef.getQualifiedName() + ")", 1);

		schemaNode = new SchemaNode(e, globalDef, xpath, schemaNodeMap);
	}
	schemaNodeMap.setValue(xpath, schemaNode);
	prtln("\nexiting create attribute\n------------------------\n", 1);
}
 
Example 9
Project: etagate   File: GateSetting.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
	private void buildAppObject(Vertx vertx,WebClient webclient,AppContain appinfo, Element appNode) {

		String name = appNode.attributeValue("name");

		if (S.isBlank(name))
			return;

		
		
		boolean cutname = "true".equalsIgnoreCase(appNode.attributeValue("cutContextPath")) ? true : false;
		String timeout = appNode.attributeValue("timeout");
		String dev = appNode.attributeValue("dev");
		String circuit_maxfail = appNode.attributeValue("maxfail");
		String circuit_reset = appNode.attributeValue("resetsecond");
		String depend = appNode.attributeValue("depend");

//		System.out.println(circuit_maxfail+"  "+circuit_reset);
		
		List<Element> nodes = appNode.elements(NODE_TAG);
		List<Element> include = appNode.elements(INCLUDE_TAG);
		
		if(nodes==null || nodes.isEmpty())
			throw new NullPointerException("Tag <app> must contains at least one <node> tag. \r\n"+appNode.asXML());

		NodeStragegy ns = createNodeStrategy(appNode);
		DevModeSupport devmode = new DevModeSupport();
		
		App a = new App(vertx,webclient,name,ns,appinfo);
		a.setCutAppName(cutname);
		if (S.isNotBlank(timeout))
			a.setTimeout(Integer.parseInt(timeout));
		if("true".equals(dev))
			a.setDevmode(devmode);
		if(S.isNotBlank(circuit_maxfail))
			a.setCircuitMaxfail(Integer.parseInt(circuit_maxfail));
		if(S.isNotBlank(circuit_reset))
			a.setCircuitReset(Long.parseLong(circuit_reset)*1000);
		if(this.inside_address!=null)
			a.setInside_address(this.inside_address);
		if(S.isNotBlank(depend))
			a.setDepends(depend);

		if (nodes != null && !nodes.isEmpty()) {
			nodes.forEach(n -> {
				String host = n.attributeValue("host");
				String port = n.attributeValue("port");
				String weight = n.attributeValue("weight");				
				if(S.isBlank(weight))
					a.addNode(vertx,host, Integer.parseInt(port),1);
				else
					a.addNode(vertx,host, Integer.parseInt(port), Integer.parseInt(weight));
			});
		}

		if (include != null && !include.isEmpty()) {
			include.forEach(i -> {
				a.addRoutePath(i.attributeValue("path"));
			});
		}

		appinfo.addAppObject(a);

		log.info("[{}] route path /{} for [{}]" ,vertx.getOrCreateContext().deploymentID(), name, name);

	}