Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

In this page you can find the example usage for org.dom4j Element addAttribute.

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ?/*w  w  w . j a v a  2s.  co  m*/
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFInventoryPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "INVENTORY_BALANCE_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element InventoryBalanceResponse = responseElement.addElement("Body")
            .addElement("InventoryBalanceResponse");

    try {
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element InventoryBalanceRequest = BodyElement.element("InventoryBalanceRequest");
        Element InventoryBalances = InventoryBalanceRequest.element("InventoryBalances");
        Element Status = InventoryBalanceRequest.element("Status");
        // ?1?
        if (UtilValidate.isEmpty(InventoryBalances) || "1".equals(Status.getText())) {
            setResponseMsg(InventoryBalanceResponse, "1", "");
            responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
            return "success";
        }
        List<Element> inventoryBalanceList = InventoryBalances.elements("InventoryBalance");
        for (Element inventoryBalance : inventoryBalanceList) {
            Element SkuNo = inventoryBalance.element("SkuNo");
            Element Qty = inventoryBalance.element("Qty");
            Element InventoryStatus = inventoryBalance.element("InventoryStatus");

            GenericValue invTemp = delegator.makeValue("ShunfengInventoryTemp");
            invTemp.put("baseId", delegator.getNextSeqId("ShunfengInventoryTemp"));
            invTemp.put("productId", SkuNo.getText());
            invTemp.put("availableToPromiseTotal", new BigDecimal(Qty.getText()));
            invTemp.put("quantityOnHandTotal", new BigDecimal(Qty.getText()));
            invTemp.put("inventoryStatus", InventoryStatus.getText());
            invTemp.put("pushDateTime", UtilDateTime.nowTimestamp());
            invTemp.create();
        }
        setResponseMsg(InventoryBalanceResponse, "1", "");
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
    } catch (DocumentException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        setResponseMsg(InventoryBalanceResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.getRootElement().asXML());
        e.printStackTrace();
    }
    return "success";
}

From source file:com.sf.integration.warehouse.service.SFService.java

/**
 * ??//from ww  w  .ja v  a 2  s  .c  om
 * @author sven
 * @param request
 * @param response
 * @return
 */
public static String SFOutboundListPush(HttpServletRequest request, HttpServletResponse response) {
    String logistics_interface = (String) request.getParameter("logistics_interface");

    Debug.log("====== logistics_interface SFOutboundListPush ? :" + logistics_interface);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    StringBuffer errorOrderBody = new StringBuffer();
    List<Map<String, Object>> orderList = FastList.newInstance();
    List<Map<String, Object>> shipmentList = FastList.newInstance();

    Document responseDoc = (Document) DocumentHelper.createDocument();
    Element responseElement = responseDoc.addElement("Response");
    responseElement.addAttribute("service", "SALE_ORDER_OUTBOUND_DETAIL_SERVICE");
    responseElement.addAttribute("lang", "zh-CN");
    responseElement.addElement("Head").addText("OK");
    Element PurchaseOrderInboundResponse = responseElement.addElement("Body")
            .addElement("SaleOrderOutboundDetailResponse");

    try {
        GenericValue userLogin = delegator.findOne("UserLogin", true, UtilMisc.toMap("userLoginId", "system"));
        Document doc = (Document) DocumentHelper.parseText(logistics_interface);
        Element ResponseElement = doc.getRootElement();
        Element BodyElement = ResponseElement.element("Body");
        Element PurchaseOrderInboundRequest = BodyElement.element("SaleOrderOutboundDetailRequest");
        List<Element> salesOrders = PurchaseOrderInboundRequest.elements("SaleOrders");
        for (Element salesOrder : salesOrders) {
            String sfShipmentId = salesOrder.element("SaleOrder").element("ShipmentId").getText();
            String trackingIdNumber = salesOrder.element("SaleOrder").element("WayBillNo").getText();
            String status = salesOrder.element("SaleOrder").element("DataStatus").getText();
            if (!"2900".equals(status) && !"3900".equals(status)) {
                errorOrderBody.append("SFOutboundListPush:ErpOrder[" + sfShipmentId + "],status[" + status
                        + "] ???<br/>");
                continue;
            }
            // ReceiptId ???
            GenericValue sfOrderAssoc = EntityUtil.getFirst(
                    delegator.findByAnd("SFOrderAssoc", UtilMisc.toMap("SFCallBackId", sfShipmentId)));
            if (UtilValidate.isEmpty(sfOrderAssoc)) {
                errorOrderBody.append("SFOutboundListPush:sfShipmentId not found<br/>");
                continue;
            }
            if ("SHIPMENT_OUT".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                //ofbizshipment?
                Map<String, Object> shipmentMap = UtilMisc.toMap("shipmentId",
                        sfOrderAssoc.getString("shipmentId"), "trackingIdNumber", trackingIdNumber);
                shipmentList.add(shipmentMap);
            } else if ("ORDER_OUT".equals(sfOrderAssoc.getString("localOrderTypeId"))) {
                Map<String, Object> orderMap = UtilMisc.toMap("orderId", sfOrderAssoc.getString("orderId"),
                        "orderItemShipGroupId", sfOrderAssoc.getString("shipGroupSeqId"), "trackingIdNumber",
                        trackingIdNumber);
                orderList.add(orderMap);
            }
        }

        if (UtilValidate.isNotEmpty(errorOrderBody)) {
            //?
            ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError",
                    errorOrderBody.toString(), null);
            //return "error";
        }
        if (UtilValidate.isNotEmpty(orderList)) {
            //???
            dispatcher.runSync("OMSOrderShipComplete",
                    UtilMisc.toMap("orderList", orderList, "userLogin", userLogin));
        }

        if (UtilValidate.isNotEmpty(shipmentList)) {
            //shipment??
            dispatcher.runSync("sendShipmentFromShunfeng",
                    UtilMisc.toMap("shipmentList", shipmentList, "userLogin", userLogin));
        }

        setResponseMsg(PurchaseOrderInboundResponse, "1", "");
        responseToShunfeng(request, response, responseDoc.asXML());
    } catch (DocumentException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    } catch (GenericEntityException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    } catch (GenericServiceException e) {
        ApiUtil.messageEmailNotification(dispatcher, delegator, "SFShipmentPushError", e.getMessage(), null);
        setResponseMsg(PurchaseOrderInboundResponse, "2", e.getMessage());
        responseToShunfeng(request, response, responseDoc.asXML());
        e.printStackTrace();
    }
    return "success";
}

From source file:com.smartwork.im.StreamError.java

License:Open Source License

/**
 * Sets the text description of the error. Optionally, a language code
 * can be specified to indicate the language of the description.
 *
 * @param text the text description of the error.
 * @param language the language code of the description, or <tt>null</tt> to specify
 *      no language code.// w  w w .  j  a v  a 2  s .co  m
 */
public void setText(String text, String language) {
    Element textElement = element.element("text");
    // If text is null, clear the text.
    if (text == null) {
        if (textElement != null) {
            element.remove(textElement);
        }
        return;
    }

    if (textElement == null) {
        textElement = docFactory.createElement("text", ERROR_NAMESPACE);
        if (language != null) {
            textElement.addAttribute(QName.get("lang", "xml", "http://www.w3.org/XML/1998/namespace"),
                    language);
        }
        element.add(textElement);
    }
    textElement.setText(text);
}

From source file:com.sun.tools.xjc.reader.dtd.bindinfo.DOM4JLocator.java

License:Open Source License

/** Sets the location information to a specified element. */
public static void setLocationInfo(Element e, Locator loc) {
    e.addAttribute(QName.get(systemId, locationNamespace), loc.getSystemId());
    e.addAttribute(QName.get(column, locationNamespace), Integer.toString(loc.getLineNumber()));
    e.addAttribute(QName.get(line, locationNamespace), Integer.toString(loc.getColumnNumber()));
}

From source file:com.sun.voip.server.VideobridgeCallAgent.java

License:Open Source License

public void initiateCall() throws IOException {
    String domainName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();

    try {/*from w ww.  j a va 2s. c  o m*/
        InetSocketAddress isaLocal = callHandler.getReceiveAddress();

        int localRTPPort = isaLocal.getPort();
        int localRTCPPort = localRTPPort + 1;
        int remoteRTPPort = nextRTPPort;
        int remoteRTCPPort = remoteRTPPort + 1;

        synchronized (nextRTPPort) {
            nextRTPPort++;

            if (nextRTPPort > stopRTPPort)
                nextRTPPort = startRTPPort;
        }
        setState(CallState.INVITED);

        IQ iq = new IQ(IQ.Type.set);
        iq.setFrom(cp.getCallOwner());
        iq.setTo(domainName);

        String id = "rayo-" + System.currentTimeMillis();

        Element colibri = iq.setChildElement("colibri", "urn:xmpp:rayo:colibri:1");
        colibri.addAttribute("videobridge", cp.getConferenceId());
        colibri.addAttribute("localrtpport", String.valueOf(remoteRTPPort));
        colibri.addAttribute("localrtcpport", String.valueOf(remoteRTCPPort));
        colibri.addAttribute("remotertpport", String.valueOf(localRTPPort));
        colibri.addAttribute("remotertcpport", String.valueOf(localRTCPPort));
        colibri.addAttribute("codec", cp.getMediaPreference().equals("PCM/48000/2") ? "opus" : "pcmu");
        RayoPlugin.component.sendPacket(iq);
        setState(CallState.ANSWERED);

        InetSocketAddress isaRemote = new InetSocketAddress("localhost", remoteRTPPort);
        setEndpointAddress(isaRemote, (byte) (cp.getMediaPreference().equals("PCM/48000/2") ? 111 : 0),
                (byte) 0, (byte) 0);
        setState(CallState.ESTABLISHED);

    } catch (Exception e) {

        Logger.println("Call " + cp + ":  VideobridgeCallAgent: initiateCall exception ");
        e.printStackTrace();
    }
}

From source file:com.synesoft.fisp.app.common.utils.XmlFileUtil.java

License:Open Source License

/**
 * add attribute for element//from www.  j a v  a2  s.com
 * 
 * @param attName
 * @param attValue
 * @param element
 */
public static void addAttribute(String attName, String attValue, Element element) {
    element.addAttribute(attName, attValue);
}

From source file:com.taobao.android.builder.tools.manifest.AtlasProxy.java

License:Apache License

public static void addAtlasProxyClazz(Document document, Set<String> nonProxyChannels, Result result) {

    Element root = document.getRootElement();// 

    List<? extends Node> serviceNodes = root.selectNodes("//@android:process");

    String packageName = root.attribute("package").getStringValue();

    Set<String> processNames = new HashSet<>();
    processNames.add(packageName);/*from w ww  .  java  2  s. c o  m*/

    for (Node node : serviceNodes) {
        if (null != node && StringUtils.isNotEmpty(node.getStringValue())) {
            String value = node.getStringValue();
            processNames.add(value);
        }
    }

    processNames.removeAll(nonProxyChannels);

    List<String> elementNames = Lists.newArrayList("activity", "service", "provider");

    Element applicationElement = root.element("application");

    for (String processName : processNames) {

        boolean isMainPkg = packageName.equals(processName);
        //boolean isMainPkg = true;
        String processClazzName = processName.replace(":", "").replace(".", "_");

        for (String elementName : elementNames) {

            String fullClazzName = "ATLASPROXY_" + (isMainPkg ? "" : (packageName.replace(".", "_") + "_"))
                    + processClazzName + "_" + StringUtils.capitalize(elementName);

            if ("activity".equals(elementName)) {
                result.proxyActivities.add(fullClazzName);
            } else if ("service".equals(elementName)) {
                result.proxyServices.add(fullClazzName);
            } else {
                result.proxyProviders.add(fullClazzName);
            }

            Element newElement = applicationElement.addElement(elementName);
            newElement.addAttribute("android:name", ATLAS_PROXY_PACKAGE + "." + fullClazzName);

            if (!packageName.equals(processName)) {
                newElement.addAttribute("android:process", processName);
            }

            boolean isProvider = "provider".equals(elementName);
            if (isProvider) {
                newElement.addAttribute("android:authorities", ATLAS_PROXY_PACKAGE + "." + fullClazzName);
            }

        }

    }

}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

/**
 * ?manifestapplication nameAtlasBridgeApplication
 * namemeta-data?/*from www. j  ava2  s  . co m*/
 */
private static void replaceManifestApplicationName(Document document) {
    // meta-data?
    Element root = document.getRootElement();// 
    Element applicationElement = root.element("application");
    String realApplicationClassName = applicationElement.attributeValue("name");
    applicationElement.addAttribute("name", "android.taobao.atlas.startup.AtlasBridgeApplication");

    Element metaData = applicationElement.addElement("meta-data");
    metaData.addAttribute("android:name", "REAL_APPLICATION");
    metaData.addAttribute("android:value", realApplicationClassName);
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

private static void addMultiDexMetaData(Document document) {
    // meta-data?
    Element root = document.getRootElement();// 
    Element applicationElement = root.element("application");

    Element metaData = applicationElement.addElement("meta-data");
    metaData.addAttribute("android:name", "multidex_enable");
    metaData.addAttribute("android:value", "true");
}