Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.lzw.work.cms.manager.PreCarRegisterManager.java

public void getCarInfoByCarNumber() {
    try {//w  w w .  j  a  v  a  2 s.  c o  m
        TmriJaxRpcOutAccessServiceStub trias = new TmriJaxRpcOutAccessServiceStub();
        TmriJaxRpcOutAccessServiceStub.QueryObjectOut qo = new TmriJaxRpcOutAccessServiceStub.QueryObjectOut();

        HttpServletRequest request = ServletActionContext.getRequest();

        String hpzl = request.getParameter("hpzl");
        String hphm = request.getParameter("hphm");

        if (hpzl == null || "".equals(hpzl.trim()) || hphm == null || "".equals(hphm.trim())) {
            return;
        }

        qo.setJkid("01C21");
        qo.setJkxlh(
                "7F1C0909010517040815E3FF83F5F3E28BCC8F9B818DE7EA88DFD19EB8C7D894B9B9BCE0BFD8D6D0D0C4A3A8D0C5CFA2BCE0B9DCCFB5CDB3A3A9");
        qo.setUTF8XmlDoc("<root><QueryCondition><hphm>" + hphm + "</hphm><hpzl>" + hpzl
                + "</hpzl></QueryCondition></root>");
        qo.setXtlb("01");

        String returnXML = trias.queryObjectOut(qo).getQueryObjectOutReturn();
        String xml = URLCodeUtil.urlDecode(returnXML);
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        Element dataElecmet = root.element("body").element("veh");

        if (dataElecmet != null) {
            Map<String, String> dataMap = new HashMap<String, String>();
            for (Object o : dataElecmet.elements()) {
                Element element = (Element) o;
                String key = element.getName();
                String value = element.getText();
                dataMap.put(key, value);
            }
            pw.print(JSONObject.fromObject(dataMap));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.lzw.work.cms.manager.PreCarRegisterManager.java

public void getCarInfoByCarNumberConvert() {
    try {// w  w  w  . ja  v a 2s  . co m
        TmriJaxRpcOutAccessServiceStub trias = new TmriJaxRpcOutAccessServiceStub();
        TmriJaxRpcOutAccessServiceStub.QueryObjectOut qo = new TmriJaxRpcOutAccessServiceStub.QueryObjectOut();

        HttpServletRequest request = ServletActionContext.getRequest();

        String hpzl = request.getParameter("hpzl");
        String hphm = request.getParameter("hphm");

        if (hpzl == null || "".equals(hpzl.trim()) || hphm == null || "".equals(hphm.trim())) {
            return;
        }

        qo.setJkid("01C21");
        qo.setJkxlh(
                "7F1C0909010517040815E3FF83F5F3E28BCC8F9B818DE7EA88DFD19EB8C7D894B9B9BCE0BFD8D6D0D0C4A3A8D0C5CFA2BCE0B9DCCFB5CDB3A3A9");
        qo.setUTF8XmlDoc("<root><QueryCondition><hphm>" + hphm + "</hphm><hpzl>" + hpzl
                + "</hpzl></QueryCondition></root>");
        qo.setXtlb("01");

        String returnXML = trias.queryObjectOut(qo).getQueryObjectOutReturn();
        String xml = URLCodeUtil.urlDecode(returnXML);
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        Element dataElecmet = root.element("body").element("veh");

        if (dataElecmet != null) {
            Map<String, String> dataMap = new HashMap<String, String>();
            for (Object o : dataElecmet.elements()) {
                Element element = (Element) o;
                String key = element.getName();
                String value = element.getText();

                dataMap.put(key, CommonUtil.convertCode(key, value));
            }
            String clxh = (String) dataMap.get("clxh");
            if (clxh != null) {
                String ggbh = trafficDBManager.getFirstGGBH(clxh);
                dataMap.put("ggbh", ggbh);
            }

            pw.print(JSONObject.fromObject(dataMap));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.lzw.work.cms.manager.PreCarRegisterManager.java

public void getCarInfo2ByCarNumber() {
    try {/*from   w w w .ja  va2s .c o  m*/
        TmriJaxRpcOutAccessServiceStub trias = new TmriJaxRpcOutAccessServiceStub();
        TmriJaxRpcOutAccessServiceStub.QueryObjectOut qo = new TmriJaxRpcOutAccessServiceStub.QueryObjectOut();

        HttpServletRequest request = ServletActionContext.getRequest();

        String hpzl = request.getParameter("hpzl");
        String hphm = request.getParameter("hphm");
        String sf = request.getParameter("sf");
        System.out.println("sf" + sf);
        if (sf != null) {
            sf = URLEncoder.encode(sf, "UTF-8");

        }
        System.out.println("sf" + sf);

        if (hpzl == null || "".equals(hpzl.trim()) || hphm == null || "".equals(hphm.trim())) {
            return;
        }

        qo.setJkid("01C49");
        qo.setJkxlh(
                "7F1C0909010517040815E3FF83F5F3E28BCC8F9B818DE7EA88DFD19EB8C7D894B9B9BCE0BFD8D6D0D0C4A3A8D0C5CFA2BCE0B9DCCFB5CDB3A3A9");
        qo.setUTF8XmlDoc("<root><QueryCondition><hphm>" + hphm + "</hphm><hpzl>" + hpzl + "</hpzl><sf>" + sf
                + "</sf></QueryCondition></root>");
        qo.setXtlb("01");

        String returnXML = trias.queryObjectOut(qo).getQueryObjectOutReturn();
        String xml = URLCodeUtil.urlDecode(returnXML);
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        System.out.println(root.asXML());
        Element dataElecmet = root.element("body").element("veh");

        if (dataElecmet != null) {
            Map<String, String> dataMap = new HashMap<String, String>();
            for (Object o : dataElecmet.elements()) {
                Element element = (Element) o;
                String key = element.getName();
                String value = element.getText();

                dataMap.put(key, CommonUtil.convertCode(key, value));
            }
            String clxh = (String) dataMap.get("clxh");
            if (clxh != null) {
                String ggbh = trafficDBManager.getFirstGGBH(clxh);
                dataMap.put("ggbh", ggbh);
            }

            pw.print(JSONObject.fromObject(dataMap));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.bot.RPSLSPlayerBotProcessor.java

License:Apache License

@Override
public void processIncoming(Packet packet) {
    if (packet instanceof Message) {
        Message message = (Message) packet;
        JID fromJID = packet.getFrom();/*from www.j  a v  a2s. c  o  m*/
        JID toJID = packet.getTo();
        packet.setTo(fromJID);

        Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
        Element meta = mmx.element(Constants.MMX_META);
        if (meta == null) {
            LOGGER.info("No meta in the message with id:{}", message.getID());
            return;
        }
        //Simulate SDK ack
        String originalMessageId = packet.getID();
        String from = fromJID.toString();
        String to = toJID.toString();

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Attempting to deliver ack");
        }
        IQ ackIQ = BotRegistrationImpl.buildAckIQ(from, to, originalMessageId);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
        }
        connection.sendPacket(ackIQ);
        String metaJSON = meta.getText();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Meta JSON:{}", metaJSON);
        }
        RPSLSGameInfo gameInfo = GsonData.getGson().fromJson(metaJSON, RPSLSGameInfo.class);

        if (gameInfo.getType() == RPSLSMessageType.INVITATION) {
            //process an invitation
            //step 1. Send an acceptance
            //step 2. Send a choice after 2 seconds.
            processRPSLSInvitationMessage(fromJID, toJID, gameInfo);
        } else {
            //ignore the other types
            LOGGER.info("Ignoring a message with type:{} message:{}", gameInfo.getType(), message);
        }
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.AppHandler.java

License:Apache License

/**
 * <pre>// www  .ja  va  2s  .c  om
 *  <iq type="set" from="admin@jabber-domain/resource" ...>
 *    <reg xlms="com.magnet:mmx:app" command="create" type="application/json" ...>
 *    {
 *      "appName": "...",
 *      "gcm":
 *      {
 *        "googleApiKey" : "...",
 *        "googleProjectId" : "..."
 *      },
 *      "apns":
 *      {
 *        "cert" : "...",
 *        "pwd" : "..."
 *      }
 *    }
 *    </reg>
 *  </iq>
 *
 *  <iq type="result"...>
 *    <reg xlms="com.magnet:mmx:app" ctype="application/json" ...>
 *    {
 *      "appKey": "...",
 *      "apiKey": "...",
 *      "serverUser": "...",
 *      "serverKey": "..."
 *    }
 *    </reg>
 *  </iq>
 * </pre>
 */
private IQ handleCreateApp(IQ iq) throws UnauthorizedException {
    Element element = iq.getChildElement();
    JID from = iq.getFrom();

    if (!Helper.isAppMgmtPermitted(from)) {
        Log.warn(from + " has no admin privilege to register application");
        throw new UnauthorizedException("No admin privilege to register application");
    }

    // Register for server push notification and generate app-key/api-key.
    String payload = element.getText();
    AppCreate.Request appRqt = AppCreate.Request.fromJson(payload);

    APNS apns = appRqt.getApns();
    String apnsCertInBase64 = null;
    String apnsPwd = null;
    String apnsEncryptedPwd = null;
    if (apns != null) {
        apnsCertInBase64 = apns.getCert();
        apnsPwd = apns.getPwd();
        apnsEncryptedPwd = AuthFactory.encryptPassword(apnsPwd);
    }

    GCM gcm = appRqt.getGcm();
    String googleApiKey = null;
    String googleProjectId = null;
    if (gcm != null) {
        googleApiKey = appRqt.getGcm().getGoogleApiKey();
        googleProjectId = appRqt.getGcm().getGoogleProjectId();
    }

    AppCreate.Response appResp = null;
    try {
        appResp = mmxAppManager.createApp(appRqt.getAppName(), appRqt.getServerUserId(),
                appRqt.getServerUserKey(), appRqt.getGuestSecret(), googleApiKey, googleProjectId, apnsPwd,
                (appRqt.getOwnerId() == null ? from.getNode() : appRqt.getOwnerId()), appRqt.getOwnerEmail(),
                false);
    } catch (AppAlreadyExistsException e) {
        Log.warn(e.getMessage(), e);
        return IQUtils.createErrorIQ(iq, e.getMessage(), StatusCode.CONFLICT);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
        return IQUtils.createErrorIQ(iq, e.getMessage(), StatusCode.INTERNAL_ERROR);
    }

    IQ response = IQUtils.createResultIQ(iq, appResp.toJson());

    Log.debug("Sending back: " + response);

    return response;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.AppHandler.java

License:Apache License

/**
 * <pre>/*from   www  .j av a  2s  . c  o  m*/
 *  <iq type="set" from="admin@jabber-domain/resource" ...>
 *    <reg xlms="com.magnet:mmx:app" command="read" type="application/json" ...>
 *    {
 *      "appKey": "...",
 *    }
 *    </reg>
 *  </iq>
 *
 *  <iq type="result"...>
 *    <reg xlms="com.magnet:mmx:app" ctype="application/json" ...>
 *    {
 *      "appName": "...",
 *      "apiKey": "...",
 *      "serverUser": "...",
 *      "serverKey": "...",
 *      "gcm":
 *      {
 *        "googleApiKey" : "...",
 *        "googleProjectId" : "..."
 *      },
 *      "apns":
 *      {
 *        "pwd" : "..."
 *      }
 *    }
 *    </reg>
 *  </iq>
 * </pre>
 */
private IQ handleReadApps(IQ iq) throws UnauthorizedException {
    Element element = iq.getChildElement();

    JID from = iq.getFrom();
    if (Helper.isAppMgmtPermitted(from)) {
        throw new UnauthorizedException("No admin privilege to register application");
    }

    String payload = element.getText();
    AppRead.Request appRqt = AppRead.Request.fromJson(payload);

    AppRead.Response appResp = null;
    try {
        appResp = mmxAppManager.getApp(appRqt.getAppId());
    } catch (AppDoesntExistException e) {
        return IQUtils.createErrorIQ(iq, e.getMessage(), 1);
    }

    // TODO: How do we set the serverKey?

    IQ response = IQUtils.createResultIQ(iq, appResp.toJson());

    return response;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.AppHandler.java

License:Apache License

private IQ handleReadMyApps(IQ iq) throws UnauthorizedException {
    Element element = iq.getChildElement();

    JID from = iq.getFrom();// w  w w  .j a  va2s  . c o  m
    if (!Helper.isAppMgmtPermitted(from)) {
        throw new UnauthorizedException("No admin privilege to register application");
    }

    String payload = element.getText();
    MyAppsRead.Request appRqt = MyAppsRead.Request.fromJson(payload);

    MyAppsRead.Response appResp = new MyAppsRead.Response();
    try {
        AppDAO appDAO = new AppDAOImpl(new OpenFireDBConnectionProvider());
        List<AppEntity> list = appDAO.getAppsForOwner(from.getNode());
        for (AppEntity e : list) {
            AppRead.Response response = new AppRead.Response();
            response.setAppName(e.getName());
            response.setAppId(e.getAppId());
            response.setOwnerId(e.getOwnerId());
            response.setOwnerEmail(e.getOwnerEmail());
            response.setApiKey(e.getAppAPIKey());
            response.setGuestUserSecret(e.getGuestSecret());
            response.setServerUserId(e.getServerUserId());
            appResp.addResponse(response);
        }
    } catch (Throwable t) {
        return IQUtils.createErrorIQ(iq, t.getMessage(), 1);
    }

    IQ response = IQUtils.createResultIQ(iq, appResp.toJson());

    return response;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.AppHandler.java

License:Apache License

/**
 * <pre>/*from w  ww .j av a  2s.c o  m*/
 *  <iq type="set" from="admin@jabber-domain/resource" ...>
 *    <reg xlms="com.magnet:mmx:app" command="update" type="application/json" ...>
 *    {
 *      "appKey": "...",
 *      "appName": "...",
 *      "gcm":
 *      {
 *        "googleApiKey" : "...",
 *        "googleProjectId" : "..."
 *      },
 *      "apns":
 *      {
 *        "cert" : "...",
 *        "pwd" : "..."
 *      }
 *    }
 *    </reg>
 *  </iq>
 *
 *  <iq type="result"...>
 *    <reg xlms="com.magnet:mmx:app" ctype="application/json" ... />
 *  </iq>
 * </pre>
 */
private IQ handleUpdateApp(IQ iq) throws UnauthorizedException {
    Element element = iq.getChildElement();

    JID from = iq.getFrom();
    if (!Helper.isAppMgmtPermitted(from)) {
        throw new UnauthorizedException("No admin privilege to register application");
    }

    String payload = element.getText();
    AppUpdate appUpdateRqt = AppUpdate.fromJson(payload);

    String apnsCertInBase64 = appUpdateRqt.getApns().getCert();
    /*String apnsCertPath = null;
      if (appUpdateRqt.getApns() != null && apnsCertInBase64 != null) {
         // Save APNS cert to file system.
         try {
    apnsCertPath = databaseHandler.getApnsCertPath(appUpdateRqt.getAppId());
         } catch (AppDoesntExistException e) {
    return IQUtils.createError(iq, Constants.MMX_APP_REG,
    Constants.MMX_NS_APP, e.getMessage(), 1);
         }
         if (apnsCertPath == null) {
    // No APNS cert was stored before. Create one.
    try {
       String userName = databaseHandler.getServerUser(appUpdateRqt.getAppId());
       XMPPServer server = XMPPServer.getInstance();
       User user = server.getUserManager().getUser(userName);
       apnsCertPath = saveAPNSCertForApp(user, apnsCertInBase64);
    } catch (AppDoesntExistException | UserNotFoundException e) {
       return IQUtils.createError(iq, Constants.MMX_APP_REG,
      Constants.MMX_NS_APP, e.getMessage(), 1);
    }
         } else {
    updateAPNSCertForApp(apnsCertPath, apnsCertInBase64);
         }
      }*/

    AppRead.Response appReadResp = null;
    MMXStatus appResp = null;
    try {
        mmxAppManager.updateApp(appUpdateRqt.getAppId(), appUpdateRqt.getAppName(),
                appUpdateRqt.getGcm().getGoogleApiKey(), appUpdateRqt.getGcm().getGoogleProjectId(),
                apnsCertInBase64, appUpdateRqt.getApns().getPwd());
    } catch (AppDoesntExistException e) {
        return IQUtils.createErrorIQ(iq, e.getMessage(), StatusCode.NOT_FOUND);
    }

    IQ response = IQUtils.createResultIQ(iq, appResp.toJson());

    return response;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.AppHandler.java

License:Apache License

/**
 * <pre>//from w w w .j av a 2 s.  c o  m
 *  <iq type="set" from="admin@jabber-domain/resource" ...>
 *    <reg xlms="com.magnet:mmx:app" command="delete" type="application/json" ...>
 *    {
 *      "app-key": "..."
 *    }
 *    </reg>
 *  </iq>
 *
 *  <iq type="result"...>
 *    <reg xlms="com.magnet:mmx:app" ctype="application/json" ... />
 *  </iq>
 * </pre>
 */
private IQ handleDeleteApp(IQ iq) throws UnauthorizedException {
    XMPPServer server = XMPPServer.getInstance();
    Element element = iq.getChildElement();

    JID from = iq.getFrom();
    if (!Helper.isAppMgmtPermitted(from)) {
        throw new UnauthorizedException("No admin privilege to register application");
    }

    String payload = element.getText();
    AppDelete.Request appDeleteRqt = AppDelete.Request.fromJson(payload);

    MMXStatus appResp = null;
    try {
        mmxAppManager.deleteApp(appDeleteRqt.getAppId());
        appResp = new MMXStatus();
        appResp.setCode(HttpServletResponse.SC_OK);
    } catch (AppDoesntExistException e) {
        return IQUtils.createErrorIQ(iq, e.getMessage(), StatusCode.NOT_FOUND);
    } catch (UserNotFoundException e) {
        return IQUtils.createErrorIQ(iq, e.getMessage(), StatusCode.INTERNAL_ERROR);
    }
    return IQUtils.createResultIQ(iq, appResp.toJson());
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.handler.DeviceHandler.java

License:Apache License

@Override
public IQ handleIQ(IQ iq) throws UnauthorizedException {
    LOGGER.info("handleIQ is called");
    AppDAO dao = new AppDAOImpl(new OpenFireDBConnectionProvider());
    JID fromJID = iq.getFrom();/*w ww.  j ava  2  s  .  c o m*/
    String appId = JIDUtil.getAppId(fromJID);

    AppEntity appEntity = dao.getAppForAppKey(appId);
    if (appEntity == null) {
        return IQUtils.createErrorIQ(iq, DeviceOperationStatusCode.INVALID_APP_ID.getMessage(),
                DeviceOperationStatusCode.INVALID_APP_ID.getCode());
    }
    /*
      retrieve the command that we are processing
     */
    Element element = iq.getChildElement();
    String payload = element.getText();
    String command = element.attributeValue(COMMAND_KEY);
    if (command == null || command.isEmpty() || command.trim().isEmpty()) {
        return IQUtils.createErrorIQ(iq, DeviceOperationStatusCode.INVALID_COMMAND_VALUE.getMessage(),
                DeviceOperationStatusCode.INVALID_COMMAND_VALUE.getCode());
    }

    Constants.DeviceCommand deviceCommand = null;
    try {
        deviceCommand = Constants.DeviceCommand.valueOf(command.toUpperCase());
    } catch (IllegalArgumentException e) {
        LOGGER.info("Invalid device command string:" + command, e);
    }
    if (deviceCommand == null) {
        return IQUtils.createErrorIQ(iq, DeviceOperationStatusCode.INVALID_COMMAND_VALUE.getMessage(),
                DeviceOperationStatusCode.INVALID_COMMAND_VALUE.getCode());
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Processing command:" + deviceCommand.toString());
    }

    switch (deviceCommand) {
    case REGISTER:
        return processRegistration(iq, fromJID, appEntity, payload);
    case UNREGISTER:
        return processDeRegistration(iq, fromJID, appEntity, payload);
    case QUERY:
        return processQuery(iq, fromJID, appEntity, payload);
    case GETTAGS:
        return processGetTags(iq, fromJID, appEntity, payload);
    case SETTAGS:
        return processSetTags(iq, fromJID, appEntity, payload);
    case ADDTAGS:
        return processAddTags(iq, fromJID, appEntity, payload);
    case REMOVETAGS:
        return processRemoveTags(iq, fromJID, appEntity, payload);
    }
    return null;
}