Example usage for org.dom4j Element elementTextTrim

List of usage examples for org.dom4j Element elementTextTrim

Introduction

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

Prototype

String elementTextTrim(QName qname);

Source Link

Usage

From source file:com.jiuyi.doctor.call.AuthController.java

License:Open Source License

 @RequestMapping("callauth")
public void doAuth(HttpServletRequest request, HttpServletResponse response) {
   Document doc = null;/*from   w  w w .  ja  va  2  s.co  m*/
   String body = "";
   log.info(" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= starts =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ");
   try {
      // ???log
      InputStream in = request.getInputStream();
      BufferedReader bf = new BufferedReader(new InputStreamReader(in));
      String str = null;
      StringBuffer xmlfile = new StringBuffer();
      while ((str = bf.readLine()) != null) {
         xmlfile.append(str);
      }
      log.info(" --- xml body --- :" + xmlfile);
      doc = DocumentHelper.parseText(xmlfile.toString());
   } catch (DocumentException e) {
      log.error(" *** DocumentException ***", e);
   } catch (IOException e1) {
      log.error(" *** IOException ***", e1);
   }
   Element root = doc.getRootElement();
   String action = root.elementTextTrim("action");
   if (action.equals("CallAuth")) {
      // ???
      body = parseCallAuth(root);
   } else if (action.equals("CallEstablish")) {
      // ?
      body = parseCallEstablish(root);
   } else if (action.equals("Hangup")) {
      // ?
      body = parseHangup(root);
   }
   // header
   response.setHeader("Status-Code", "HTTP/1.1 200 OK");
   response.setHeader("Date", new Date() + "");
   response.setHeader("Content-Length", body.length() + "");
   try {
      //  
      OutputStream opt = response.getOutputStream();
      OutputStreamWriter out = new OutputStreamWriter(opt);
      out.write(body);
      out.flush();
   } catch (IOException e) {
      log.error(" *** IOException ***", e);
   }
   log.info("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n");
}

From source file:com.jiuyi.doctor.call.AuthController.java

License:Open Source License

 /**
 * ???//from   w w w .j  a  va  2 s.co  m
 * 
 * @param e
 *            Element
 * @return result
 */
private String parseCallAuth(Element e) {
   log.info("--- parseCallAuth   start ---");

   CallAuthen call = new CallAuthen();
   call.setType(e.elementTextTrim("type"));
   call.setOrderId(e.elementTextTrim("orderid"));
   call.setSubId(e.elementTextTrim("subid"));
   call.setCaller(e.elementTextTrim("caller"));
   call.setCalled(e.elementTextTrim("called"));
   call.setCallSid(e.elementTextTrim("callSid"));
   log.info(" --- parseCallAuth --- :" + call.toString());
   // ?

   // ?,???sessiontime
   String result = "<?xml version='1.0' encoding='UTF-8' ?><Response><statuscode>0000</statuscode><statusmsg>Success</statusmsg><record>1</record></Response>";

   return result;
}

From source file:com.jiuyi.doctor.call.AuthController.java

License:Open Source License

 /**
 * ?//from www . ja  va 2  s  .c om
 * 
 * @param e
 *            Element
 * @return result
 */
private String parseCallEstablish(Element e) {
   log.info("--- parseCallEstablish   start   ");

   CallEstablish call = new CallEstablish();
   call.setType(e.elementTextTrim("type"));
   call.setOrderId(e.elementTextTrim("orderid"));
   call.setSubId(e.elementTextTrim("subid"));
   call.setCaller(e.elementTextTrim("caller"));
   call.setCalled(e.elementTextTrim("called"));
   call.setCallSid(e.elementTextTrim("callSid"));
   log.info(" --- CallEstablish --- : " + call.toString());
   // ?

   // ?,???sessiontime
   String result = "<?xml version='1.0' encoding='UTF-8' ?><Response><statuscode>0000</statuscode><statusmsg>Success</statusmsg><billdata>ok</billdata></Response>";

   log.info("--- parseCallEstablish   end ---");

   return result;
}

From source file:com.jiuyi.doctor.call.AuthController.java

License:Open Source License

 /**
 * ?/* w  w  w  . ja v a 2s .co  m*/
 * 
 * @param e
 *            Element
 * @return result
 */
private String parseHangup(Element e) {
   log.info("---parseHangup   start---");
   // ? CallHangup
   CallHangup call = new CallHangup();
   call.setType(e.elementTextTrim("type"));
   call.setOrderId(e.elementTextTrim("orderid"));
   call.setSubId(e.elementTextTrim("subid"));
   call.setCaller(e.elementTextTrim("caller"));
   call.setCalled(e.elementTextTrim("called"));
   call.setByeType(e.elementTextTrim("byeType"));
   call.setStarttime(e.elementTextTrim("starttime"));
   call.setEndtime(e.elementTextTrim("endtime"));
   call.setBilldata(e.elementTextTrim("billdata"));
   call.setCallSid(e.elementTextTrim("callSid"));
   call.setRecordurl(e.elementTextTrim("recordurl"));

   log.info(" --- CallHangup --- : " + call.toString());
   // ?

   // ?
   String result = "<?xml version='1.0' encoding='UTF-8'?><Response><statuscode>0000</statuscode><statusmsg>Success</statusmsg><totalfee>0.120000</totalfee></Response>";

   return result;
}

From source file:com.liferay.portlet.PortletPreferencesSerializer.java

License:Open Source License

public static PortletPreferences fromDefaultXML(String xml) throws PortalException, SystemException {

    PortletPreferencesImpl prefs = new PortletPreferencesImpl();

    if (Validator.isNull(xml)) {
        return prefs;
    }// w  ww .  j  ava  2s  .c  om

    Map preferences = prefs.getPreferences();

    try {
        Document doc = new SAXReader().read(new StringReader(xml));

        Element root = doc.getRootElement();

        Iterator itr1 = root.elements("preference").iterator();

        while (itr1.hasNext()) {
            Element prefEl = (Element) itr1.next();

            String name = prefEl.elementTextTrim("name");

            List values = new ArrayList();

            Iterator itr2 = prefEl.elements("value").iterator();

            while (itr2.hasNext()) {
                Element valueEl = (Element) itr2.next();

                /*if (valueEl.nodeCount() <= 0) {
                   values.add(valueEl.getText());
                }
                else {
                   values.add(valueEl.node(0).asXML());
                }*/

                values.add(valueEl.getTextTrim());
            }

            boolean readOnly = GetterUtil.get(prefEl.elementText("read-only"), false);

            Preference preference = new Preference(name, (String[]) values.toArray(new String[0]), readOnly);

            preferences.put(name, preference);
        }

        return prefs;
    } catch (DocumentException de) {
        throw new SystemException(de);
    }
}

From source file:com.mgmtp.perfload.core.common.config.XmlConfigReader.java

License:Apache License

/**
 * Reads the contents of the XML file into a {@link TestplanConfig} object.
 * //from www  .  j a va2 s  .c  o m
 * @return the Config object
 */
public TestplanConfig readConfig() throws Exception {
    Element testplan = loadDocument().getRootElement();

    ListMultimap<ProcessKey, LoadProfileEvent> loadProfileEvents = readLoadProfileEvents(testplan);
    List<TestJar> testJars = readTestJars(testplan);

    int totalProcessCount = loadProfileEvents.keySet().size();
    int totalThreadCount = loadProfileEvents.size();

    String guiceModule = testplan.elementTextTrim("module");
    PropertiesMap properties = readProperties(testplan);

    Map<ProcessKey, TestConfig> testConfigs = newHashMapWithExpectedSize(totalProcessCount);
    for (Entry<ProcessKey, Collection<LoadProfileEvent>> entry : loadProfileEvents.asMap().entrySet()) {
        ProcessKey key = entry.getKey();
        Collection<LoadProfileEvent> events = entry.getValue();
        testConfigs.put(key, new TestConfig(key.getProcessId(), guiceModule, properties, events));
    }

    long startTimeOfLastEvent = 0;
    for (LoadProfileEvent loadProfileEvent : loadProfileEvents.values()) {
        startTimeOfLastEvent = Math.max(startTimeOfLastEvent, loadProfileEvent.getStartTime());
    }

    List<String> jvmArgs = readJvmArgs(testplan);

    List<ProcessConfig> processConfigs = newArrayListWithCapacity(loadProfileEvents.keySet().size());
    for (ProcessKey key : loadProfileEvents.keySet()) {
        processConfigs.add(new ProcessConfig(key.getProcessId(), key.getDaemonId(), jvmArgs));
    }

    return new TestplanConfig(testplanFile, loadProfileEvents, testJars, testConfigs, processConfigs,
            totalProcessCount, totalThreadCount, startTimeOfLastEvent);
}

From source file:com.mgmtp.perfload.core.common.config.XmlConfigReader.java

License:Apache License

private ListMultimap<ProcessKey, LoadProfileEvent> readLoadProfileEvents(final Element testplan)
        throws IOException {
    ListMultimap<ProcessKey, LoadProfileEvent> eventsByProcess = ArrayListMultimap.create();
    String loadProfile = testplan.elementTextTrim("loadProfile");

    // relative to testplan
    File loadProfileConfigFile = new File(new File(testplanFile.getParentFile(), "loadprofiles"), loadProfile);

    try (BufferedReader br = new BufferedReader(
            new InputStreamReader(new FileInputStream(loadProfileConfigFile), "UTF-8"))) {
        StrTokenizer st = StrTokenizer.getCSVInstance();
        st.setDelimiterChar(';');

        for (String line = null; (line = br.readLine()) != null;) {
            // ignore line that are blank, commented out, or represent markers
            if (isBlank(line) || startsWith(line, "#") || MARKER_PATTERN.matcher(line).matches()) {
                continue;
            }/*from  w  w  w . ja v a2 s  .  co m*/

            st.reset(line);
            String[] tokens = st.getTokenArray();

            long startTime = Long.parseLong(tokens[0]);
            String operation = tokens[1];
            String target = tokens[2];
            int daemonId = Integer.parseInt(tokens[3]);
            int processId = Integer.parseInt(tokens[4]);

            eventsByProcess.put(new ProcessKey(daemonId, processId),
                    new LoadProfileEvent(startTime, operation, target, daemonId, processId));
        }
    }

    return eventsByProcess;
}

From source file:com.mingsoft.weixin.util.XmlUtils.java

License:Open Source License

/**
 * ?xml??document??key?//from www .j  a v  a 2  s .  c  om
 * 
 * @param str
 *            
 * @param key
 *            ??
 * @return ??stringnull
 */
public static String getString(String str, String key) {
    try {
        Document document = DocumentHelper.parseText(str);
        Element root = document.getRootElement();
        return root.elementTextTrim(key);
    } catch (Exception e) {
        e.printStackTrace();
        LOG.debug("Exception?xml:" + str);
        LOG.debug("Exception?key:" + key);
    }
    return null;
}

From source file:com.pureinfo.srm.config.EduOfficeConfig.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *//*from   www  .j  a v  a  2 s .co  m*/
public void fromXML(Element _element) throws PureException {
    m_sCode = _element.elementTextTrim("code");
    m_sName = _element.elementTextTrim("name");
    m_sSerialNo = _element.elementTextTrim("serial-no");
}

From source file:com.pureinfo.srm.config.SRMConfigHelper.java

License:Open Source License

/**
 * Initiates this helper./* ww  w .ja va 2  s. c  o  m*/
 */
private void init() {
    logger.info("SRM system configuration: to load ...");

    try {
        String sResource = ClassResourceUtil.mapFullPath(XML_BINDER, true);
        Element xml = XMLUtil.fileToElement(sResource);
        this.setVersion(xml.elementTextTrim("version"));
        this.setEdition(xml.elementTextTrim("edition"));

        if (m_bUniversityEdition) {
            // to load university configuration
            m_universityConfig = new UniversityConfig();
            m_universityConfig.fromXML(xml.element("university"));

            // to validate serial no
            String[] args;
            try {
                args = SNDecoder.decode(m_universityConfig.getSerialNo(), 5);
            } catch (Exception ex) {
                throw new Exception("www.pureinfo.com.cn");
            }
            if (!m_universityConfig.getCode().equals(args[0])
                    || !m_universityConfig.getName().equals(args[1])) {
                throw new Exception("www.pureinfo.com.cn");
            }

            m_lRegisterExpiredTime = Long.parseLong(args[4]);
            if (System.currentTimeMillis() >= m_lRegisterExpiredTime) {
                throw new Exception("www.pureinfo.com.cn");
            }
        } else {
            // to load edu-office configuration
            m_eduOfficeConfig = new EduOfficeConfig();
            m_eduOfficeConfig.fromXML(xml.element("edu-office"));

            // to validate serial no
            String[] args;
            try {
                args = SNDecoder.decode(m_eduOfficeConfig.getSerialNo(), 5);
            } catch (Exception ex) {
                throw new Exception("www.pureinfo.com.cn");
            }
            if (!m_eduOfficeConfig.getCode().equals(args[0]) || !m_eduOfficeConfig.getName().equals(args[1])) {
                throw new Exception("www.pureinfo.com.cn");
            }
            m_lRegisterExpiredTime = Long.parseLong(args[4]);
            if (System.currentTimeMillis() >= m_lRegisterExpiredTime) {
                throw new Exception("www.pureinfo.com.cn");
            }
        } // endif

        // to load the modules config
        m_modulesConfig = new ModulesConfig(m_universityConfig.getCode());
        m_modulesConfig.fromXML(xml.element("modules"));

        // OK!
        m_bRegistered = true;
        logger.info("SRM system configuration: loaded and registered");
    } catch (Exception ex) {
        throw new PureRuntimeException(SRMExceptionTypes.CONFIG_LOAD, XML_BINDER, ex);
    }
}