Java Code Examples for org.w3c.dom.Document.createElement()

The following are Jave code examples for showing how to use createElement() of the org.w3c.dom.Document 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: rapidminer   File: ParameterTypeList.java   View Source Code Vote up 7 votes
@Override
public Element getXML(String key, String value, boolean hideDefault, Document doc) {
	Element element = doc.createElement("list");
	element.setAttribute("key", key);
	List<String[]> list = null;
	if (value != null) {
		list = transformString2List(value);
	} else {
		list = getDefaultValue();
	}
	if (list != null) {
		for (Object object : list) {
			Object[] entry = (Object[]) object;
			element.appendChild(valueType.getXML((String) entry[0], entry[1].toString(), false, doc));
		}
	}
	return element;
}
 
Example 2
Project: convertigo-engine   File: Monitor.java   View Source Code Vote up 6 votes
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
	Element rootElement = document.getDocumentElement();
	Element objectElement;
	Text objectText;

	objectElement = document.createElement("threads");
	rootElement.appendChild(objectElement);
	objectText = document.createTextNode("" + com.twinsoft.convertigo.beans.core.RequestableObject.nbCurrentWorkerThreads);
	objectElement.appendChild(objectText);

	objectElement = document.createElement("contexts");
	rootElement.appendChild(objectElement);
	try {
		objectText = document.createTextNode(Engine.isStarted ? "" + Engine.theApp.contextManager.getNumberOfContexts() : "0");
	} catch (Exception e) {
		objectText = document.createTextNode("0");
	}
	objectElement.appendChild(objectText);

	objectElement = document.createElement("requests");
	rootElement.appendChild(objectElement);
	long i = EngineStatistics.getAverage(EngineStatistics.REQUEST);
	if (i == -1) i = 0;
	objectText = document.createTextNode("" + i);
	objectElement.appendChild(objectText);
}
 
Example 3
Project: convertigo-engine   File: TransactionStep.java   View Source Code Vote up 6 votes
@Override
public Element toXml(Document document) throws EngineException {
	Element element = super.toXml(document);

	// Storing the transaction WSDL type
	try {
		Element wsdlTypeElement = document.createElement("wsdltype");
		if (wsdlType != null) {
			CDATASection cDATASection = document.createCDATASection(wsdlType);
			wsdlTypeElement.appendChild(cDATASection);
			element.appendChild(wsdlTypeElement);
		}
	} catch (NullPointerException e) {
		// Silently ignore
	}

	return element;
}
 
Example 4
Project: javaide   File: ResourceMerger.java   View Source Code Vote up 6 votes
@Override
protected void writeMergedItems(Document document, Node rootNode) {
    Node mergedItemsNode = document.createElement(NODE_MERGED_ITEMS);
    rootNode.appendChild(mergedItemsNode);

    for (String qualifier : mMergedItems.keySet()) {
        Map<String, ResourceItem> itemMap = mMergedItems.get(qualifier);

        Node qualifierNode = document.createElement(NODE_CONFIGURATION);
        NodeUtils.addAttribute(document, qualifierNode, null, ATTR_QUALIFIER,
                qualifier);

        mergedItemsNode.appendChild(qualifierNode);

        for (ResourceItem item : itemMap.values()) {
            Node adoptedNode = item.getAdoptedNode(document);
            if (adoptedNode != null) {
                qualifierNode.appendChild(adoptedNode);
            }
        }
    }
}
 
Example 5
Project: EspressoViews   File: QueryDefinitionParser.java   View Source Code Vote up 6 votes
public static void storeIniSettings( String iniFile, String iniSettingName,String iniSettingValue){
	Document doc= getXmlDocument((new File (iniFile)).getAbsolutePath() );	
	Node lastDir = getElementByTagName(doc,iniSettingName );
	if (lastDir==null ){//neues ini setting tag kreieren
		Element neuesElement = doc.createElement(iniSettingName);
		neuesElement.appendChild(doc.createTextNode(iniSettingValue));
		getElementByTagName(doc,"ROOT" ).appendChild(neuesElement);
	}
	else 
		if (lastDir.hasChildNodes()){//altes ini setting �berschreiben
			lastDir.getFirstChild().setTextContent(iniSettingValue); 
		}
	if (lastDir!= null && !lastDir.hasChildNodes()){//ini setting im leeren tag schreiben 
		lastDir.appendChild(doc.createTextNode(iniSettingValue)); 
	}
	storeXmlDocToFile(iniFile, doc);	
}
 
Example 6
Project: javaide   File: NodeUtils.java   View Source Code Vote up 6 votes
static Node duplicateNode(Document document, Node node) {
    Node newNode;
    if (node.getNamespaceURI() != null) {
        newNode = document.createElementNS(node.getNamespaceURI(), node.getLocalName());
    } else {
        newNode = document.createElement(node.getNodeName());
    }

    // copy the attributes
    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0 ; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);

        Attr newAttr;
        if (attr.getNamespaceURI() != null) {
            newAttr = document.createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
            newNode.getAttributes().setNamedItemNS(newAttr);
        } else {
            newAttr = document.createAttribute(attr.getName());
            newNode.getAttributes().setNamedItem(newAttr);
        }

        newAttr.setValue(attr.getValue());
    }

    // then duplicate the sub-nodes.
    NodeList children = node.getChildNodes();
    for (int i = 0 ; i < children.getLength() ; i++) {
        Node child = children.item(i);
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Node duplicatedChild = duplicateNode(document, child);
        newNode.appendChild(duplicatedChild);
    }

    return newNode;
}
 
Example 7
Project: convertigo-engine   File: DeleteAll.java   View Source Code Vote up 6 votes
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
	Element root = document.getDocumentElement();
	Element response = document.createElement("response");

	try {
		Engine.theApp.databaseObjectsManager.symbolsDeleteAll();
		response.setAttribute("state", "success");
		response.setAttribute("message","All global symbols have been successfully deleted!");
	} catch (Exception e) {
		Engine.logAdmin.error("Error during deleting the global symbols!\n" + e.getMessage());
		
		response.setAttribute("state", "error");
		response.setAttribute("message","Error during deleting the global symbols!\n" + e.getMessage());
	}
	root.appendChild(response);		
}
 
Example 8
Project: tablasco   File: HtmlFormatter.java   View Source Code Vote up 5 votes
private static Document createNewDocument(Metadata metadata)
{
    Document document = DOCUMENT_BUILDER.value().newDocument();
    Element html = document.createElement("html");
    document.appendChild(html);

    Element head = document.createElement("head");
    html.appendChild(head);

    Element script = document.createElement("script");
    script.appendChild(document.createTextNode(getVisibilityFunction()));
    head.appendChild(script);

    Element style = document.createElement("style");
    style.setAttribute("type", "text/css");
    style.appendChild(document.createTextNode(getCSSDefinitions()));
    head.appendChild(style);

    Element meta = document.createElement("meta");
    meta.setAttribute("http-equiv", "Content-type");
    meta.setAttribute("content", "text/html;charset=UTF-8");
    head.appendChild(meta);

    head.appendChild(ResultCell.createNodeWithText(document, "title", "Test Results"));

    Element body = document.createElement("body");
    html.appendChild(body);

    Element div = document.createElement("div");
    div.setAttribute("class", "metadata");
    if (metadata != null)
    {
        div.appendChild(ResultCell.createNodeWithText(document, "i", metadata.toString()));
    }
    body.appendChild(div);

    return document;
}
 
Example 9
Project: Logisim   File: SvgCreator.java   View Source Code Vote up 5 votes
public static Element createOval(Document doc, Oval oval) {
	double x = oval.getX();
	double y = oval.getY();
	double width = oval.getWidth();
	double height = oval.getHeight();
	Element elt = doc.createElement("ellipse");
	elt.setAttribute("cx", "" + (x + width / 2));
	elt.setAttribute("cy", "" + (y + height / 2));
	elt.setAttribute("rx", "" + (width / 2));
	elt.setAttribute("ry", "" + (height / 2));
	populateFill(elt, oval);
	return elt;
}
 
Example 10
Project: incubator-netbeans   File: JTableHeaderEditor.java   View Source Code Vote up 5 votes
@Override
public Node storeToXML(Document doc) {
    Object value = getValue();
    org.w3c.dom.Element el = null;
    if (value instanceof FormTableHeader) {
        FormTableHeader header = (FormTableHeader)value;
        el = doc.createElement(XML_TABLE_HEADER);
        el.setAttribute(ATTR_RESIZING, Boolean.toString(header.isResizingAllowed()));
        el.setAttribute(ATTR_REORDERING, Boolean.toString(header.isReorderingAllowed()));
    }
    return el;
}
 
Example 11
Project: octoBubbles   File: PersistenceManager.java   View Source Code Vote up 5 votes
private static void addInterfaceNode(Document doc, ClassNode node, Element parent, Graph pGraph, boolean isChild){
    Element umlClass = doc.createElement("UML:Interface");
    if(isChild){
        umlClass.setAttribute("namespace", ((Element)parent.getParentNode()).getAttribute("xmi.id"));
    } else {
        umlClass.setAttribute("namespace", pGraph.getId());
    }
    umlClass.setAttribute("name", node.getTitle());
    umlClass.setAttribute("xmi.id", node.getId());
    Element classifierFeature = doc.createElement("UML:Classifier.feature");
    umlClass.appendChild(classifierFeature);

    int attIdCount = 0;
    int opIdCount = 0;
    if(node.getAttributes() != null){
        String attributes[] = node.getAttributes().split("\\r?\\n");
        for(String att : attributes){
            Element attribute = doc.createElement("UML:Attribute");
            attribute.setAttribute("name", att);
            attribute.setAttribute("xmi.id", "att" + ++attIdCount + "_" + node.getId());
            classifierFeature.appendChild(attribute);
        }
    }
    if(node.getOperations() != null){
        String operations[] = node.getOperations().split("\\r?\\n");
        for(String op : operations) {
            Element operation = doc.createElement("UML:Operation");
            operation.setAttribute("name", op);
            operation.setAttribute("xmi.id", "oper" + ++opIdCount + "_" + node.getId());
            classifierFeature.appendChild(operation);
        }
    }
    parent.appendChild(umlClass);
}
 
Example 12
Project: rapidminer   File: PlotterConfigurationModel.java   View Source Code Vote up 5 votes
public static Element writeToXML(Document document, PlotterConfigurationModel model) {
	Element parameters = document.createElement("plottersettings");
	parameters.setAttribute("plotter", model.getPlotter().getPlotterName());
	for (String key : model.settings.getParameterSettings().keySet()) {
		Element parameter = document.createElement("setting");
		parameter.setAttribute("key", key);
		parameter.setAttribute("value", model.settings.getParameterSettings().get(key).toString());
		parameters.appendChild(parameter);
	}
	return parameters;
}
 
Example 13
Project: ChronoBike   File: CFPacPut.java   View Source Code Vote up 5 votes
@Override
protected Element ExportCustom(Document root)
{
	Element eAdd = root.createElement("Put") ;
	if (m_PutFile != null)
	{
		Element e = root.createElement("File") ;
		m_PutFile.ExportTo(e, root) ;
		eAdd.appendChild(e) ;
	}
	return eAdd ;
}
 
Example 14
Project: convertigo-engine   File: XMLVector.java   View Source Code Vote up 5 votes
public Node writeXml(Document document) throws Exception {
    Element element = document.createElement(getClass().getName());
    
    for(E object : this){
    	Node objectNode = XMLUtils.writeObjectToXml(document, object);
    	element.appendChild(objectNode);
    }
    
    return element;
}
 
Example 15
Project: convertigo-engine   File: Get.java   View Source Code Vote up 5 votes
private Element createElementActionBaseAttr(Document document, String id, String label, String className, boolean isEnabled, String menubarPath) {
	Element newAction = document.createElement("action");
	newAction.setAttribute("id", id);
	newAction.setAttribute("label", label);

	// Action class
	newAction.setAttribute("class", className);
	newAction.setAttribute("icon", computeIconNameCSS(id));
	newAction.setAttribute("isEnabled", Boolean.toString(isEnabled));

	// menubarPath = category
	newAction.setAttribute("menubarPath", menubarPath);

	return newAction;
}
 
Example 16
Project: convertigo-engine   File: WebServiceTranslator.java   View Source Code Vote up 5 votes
private void handleSimpleVariable(Document inputDocument, SOAPElement parameter, String parameterName, String parameterValue, Element transactionVariablesElement) {	
	Element item = inputDocument.createElement("variable");
	item.setAttribute("name", parameterName);
	
	// Structured value?
	if (parameter.hasChildNodes() && (parameter.getChildNodes().getLength() > 1 || parameter.getFirstChild().getNodeType() == Node.ELEMENT_NODE)) {
		appendNodes(parameter.getChildNodes(), item);
		Engine.logBeans.debug("   Adding structured requestable variable '" + parameterName + "'");
	}
	else {
		item.setAttribute("value", parameterValue);
		Engine.logBeans.debug("   Adding requestable variable '" + parameterName + "' = '" + Visibility.maskValue(parameterValue) +"'");
	}
	transactionVariablesElement.appendChild(item);
}
 
Example 17
Project: convertigo-engine   File: XMLUtils.java   View Source Code Vote up 5 votes
private static void copyNodeWithoutNamespace(Document document, Node parentNode, Node sourceNode) {
	Node destinationNode;
	if (sourceNode instanceof Document) {
		destinationNode = parentNode;
	} else {
		if (sourceNode instanceof Element) {
			String localName = XMLUtils.getLocalName(sourceNode);
			destinationNode = document.createElement(localName);
			
			// Copy attributes
			NamedNodeMap attributes = sourceNode.getAttributes();
			for (int i = 0; i < attributes.getLength(); i++) {
				Node sourceAttribute = attributes.item(i);
				
				String prefix = XMLUtils.getPrefix(sourceAttribute);
				
				if (!prefix.equalsIgnoreCase("xmlns")) {
					((Element) destinationNode).setAttribute(XMLUtils.getLocalName(sourceAttribute),
							sourceAttribute.getNodeValue());
				}
			}
		} else {
			destinationNode = document.importNode(sourceNode, false);
		}
		
		parentNode.appendChild(destinationNode);
	}
	
	NodeList childNodes = sourceNode.getChildNodes();
	int len = childNodes.getLength();
	for (int i = 0; i < len; i++) {
		XMLUtils.copyNodeWithoutNamespace(document, destinationNode, childNodes.item(i));
	}
}
 
Example 18
Project: convertigo-engine   File: AbstractResponse.java   View Source Code Vote up 5 votes
public Element toXml(Document document, String qname) throws Exception {
	Element response = document.createElement("response");
	response.setAttribute("state", "success");
	response.setAttribute("name", getClass().getSimpleName());
	if (qname != null) {
		response.setAttribute("qname", qname);
	}

	return response;
}
 
Example 19
Project: uroborosql   File: CoberturaCoverageHandler.java   View Source Code Vote up 4 votes
synchronized void write() throws IOException, ParserConfigurationException, TransformerException {
	if (!updated) {//更新が無い場合は書き込みしない
		return;
	}

	List<PackageSummary> packageNodes = summaryPackages();

	DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
	Document document = documentBuilder.newDocument();

	Element coverage = document.createElement("coverage");

	coverage.setAttribute("timestamp", String.valueOf(System.currentTimeMillis()));
	coverage.setAttribute("complexity", "0");
	coverage.setAttribute("version", "0.1");

	document.appendChild(coverage);
	Element sources = document.createElement("sources");
	coverage.appendChild(sources);
	Element source = document.createElement("source");
	source.setTextContent(sourcesDirPath.toString());
	sources.appendChild(source);

	Element packages = document.createElement("packages");
	coverage.appendChild(packages);

	//packages内のrenderとカバレッジ集計
	CoverageSummaryTotal total = renderPackages(document, packages, packageNodes);

	CoverageSummary lines = total.line;
	coverage.setAttribute("lines-valid", String.valueOf(lines.valid));
	coverage.setAttribute("lines-covered", String.valueOf(lines.covered));
	coverage.setAttribute("lines-rate", String.valueOf(lines.getRate()));

	CoverageSummary branches = total.branch;
	coverage.setAttribute("branches-valid", String.valueOf(branches.valid));
	coverage.setAttribute("branches-covered", String.valueOf(branches.covered));
	coverage.setAttribute("branches-rate", String.valueOf(branches.getRate()));

	write(document);

	//書込が終了したので「更新なし」にする
	updated = false;
}
 
Example 20
Project: oscm   File: PaymentServiceProviderBean.java   View Source Code Vote up 4 votes
/**
 * Sets the transaction related attributes in the given document.
 * 
 * @param doc
 *            The root document, used to generate elements.
 * @param request
 *            The request the information will be added to as sub-elements.
 * @param useGlobalChannel
 *            Indicates whether the supplier's channel id should be used or
 *            the global channel id. Deregistration must use the global one,
 *            as the registration is based on it, too. Not to be used for
 *            debit operations.
 * @return The transaction element for further processing.
 * @throws PSPIdentifierForSellerException
 *             Thrown in case the supplier's psp identifier setting cannot
 *             be evaluated.
 */
private Element setTransactionXMLAttributes(Document doc, Element request,
        boolean useGlobalChannel, RequestData data)
        throws PSPIdentifierForSellerException {

    String txnMode = data
            .getProperty(HeidelpayConfigurationKey.PSP_TXN_MODE.name());
    String userLogin = data
            .getProperty(HeidelpayConfigurationKey.PSP_USER_LOGIN.name());
    String userPwd = data
            .getProperty(HeidelpayConfigurationKey.PSP_USER_PWD.name());

    Element transaction = doc
            .createElement(HeidelpayXMLTags.XML_ELEMENT_TRANSACTION);
    transaction.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_MODE, txnMode);
    transaction.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_RESPONSE,
            TRANSACTION_RESPONSE_VALUE);

    String channelId = null;
    if (useGlobalChannel) {
        channelId = data
                .getProperty(HeidelpayConfigurationKey.PSP_TRANSACTION_CHANNEL
                        .name());
    } else {
        channelId = data.getPspIdentifier();
        if (channelId == null) {
            // Charging cannot succeed, so mark the operation as failed by
            // throwing an exception
            PSPIdentifierForSellerException mpi = new PSPIdentifierForSellerException(
                    "Supplier organization '" + data.getOrganizationKey()
                            + "' is missing the pspIdentifier setting");
            logger.logWarn(
                    Log4jLogger.SYSTEM_LOG,
                    mpi,
                    LogMessageIdentifier.WARN_DEBIT_FAILED_NO_PSPIDENTIFIER_SETTING);
            throw mpi;
        }
    }
    transaction.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_CHANNEL,
            channelId);
    request.appendChild(transaction);

    Element user = doc.createElement(HeidelpayXMLTags.XML_ELEMENT_USER);
    user.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_LOGIN, userLogin);
    user.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_PASSWORD, userPwd);
    transaction.appendChild(user);

    return transaction;
}