List of usage examples for org.dom4j DocumentException DocumentException
public DocumentException(Throwable cause)
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
/** * <pre>// w ww. j a va2 s.com * * * * * options * option name="..." property="..." [seecode="..."] [negate="true"] * [enumID name="..." seecode="..." propertyValue="..."] * ... * ... * * * * </pre> * * @param root * the XML root element that this object represents. * @param config * the build configuration from which to extract options. * @throws ConfigurationException * if unknown compiler options referenced, etc. * @throws DocumentException * if bad XML. */ SeeCodeOptionsAugmenter(Element root, IConfiguration config) throws ConfigurationException, DocumentException { if (!root.getName().equalsIgnoreCase("options")) { throw new DocumentException("Unrecognized root node " + root.getName()); } mConfig = config; List<Element> elements = Cast.toType(root.elements()); for (Element e : elements) { if (e.getName().equalsIgnoreCase("option")) { handleOptionElement(e); } else if (e.getName().equalsIgnoreCase("property")) { handlePropertyElement(e); } else if (e.getName().equalsIgnoreCase("default")) { handleDefaultElement(e); } else if (e.getName().equalsIgnoreCase("setif")) { handleSetIf(e); } else throw new DocumentException("Unknown element: " + e.getName()); } }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
/** * Process the "option" element.//w ww . j av a 2 s. c o m * * @param e * the "option" element. * @throws DocumentException * @throws ConfigurationException */ private void handleOptionElement(Element e) throws DocumentException, ConfigurationException { List<Attribute> attrs = Cast.toType(e.attributes()); String optionName = null; String propertyName = null; String namePropertyName = null; String seecodeArg = null; String negate = null; String alternatePropertyName = null; String trueValue = null; String falseValue = null; boolean setAsDefaultOnly = false; List<Element> enums = Cast.toType(e.elements()); for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("name")) optionName = value; else if (aname.equals("property")) propertyName = value; else if (aname.equals("seecode")) seecodeArg = value; else if (aname.equals("negate")) negate = value; else if (aname.equalsIgnoreCase("nameProperty")) namePropertyName = value; else if (aname.equalsIgnoreCase("defaultOnly")) { setAsDefaultOnly = !(value.equals("0") || value.equalsIgnoreCase("false")); } else if (aname.equalsIgnoreCase("alternate")) { alternatePropertyName = value; } else if (aname.equalsIgnoreCase("trueValue")) { trueValue = value; } else if (aname.equalsIgnoreCase("falseValue")) { falseValue = value; } else throw new DocumentException("Unknown attribute name: " + aname); } if (optionName == null) { throw new DocumentException("\"name\" missing in \"option\" node"); } IOption option = lookupOption(optionName); if (option == null) { throw new ConfigurationException("Unrecognized option name: " + optionName); } if (seecodeArg == null && enums.size() == 0) { seecodeArg = option.getCommand(); // if (seecodeArg==null) // throw new DocumentException("Option \"" + optionName + // "\" needs 'seecode' attribute"); } if (enums.size() == 0 && namePropertyName != null) { throw new DocumentException("nameProperty only applies to enumID options"); } boolean first = true; for (Element enumElement : enums) { if (!enumElement.getName().equalsIgnoreCase("enum")) { throw new DocumentException("Unrecognized element \"" + enumElement.getName() + "\" under option \"" + optionName + "\""); } String name = null; String scArg = null; String propertyValue = null; String booleanProperty = null; List<Attribute> eattrs = Cast.toType(enumElement.attributes()); boolean isDefault = first; // assume first is default first = false; for (Attribute a : eattrs) { String aname = a.getName(); String value = a.getValue(); if (aname.equals("name")) { name = value; } else if (aname.equals("seecode")) scArg = value; else if (aname.equalsIgnoreCase("propertyvalue")) propertyValue = value; else if (aname.equalsIgnoreCase("property")) booleanProperty = value; else throw new DocumentException("Unknown enumID attribute: " + aname); } try { if (name == null || option.getEnumCommand(name) == null) { throw new DocumentException("Unrecognized enumID id: " + name); } if (scArg == null && propertyValue == null) { scArg = option.getEnumCommand(name); if (scArg == null) throw new DocumentException("Enum \"" + name + "\" needs 'seecode' attribute"); } } catch (BuildException e1) { throw new ConfigurationException(e1.getMessage(), e1); } OptionEnum oe = new OptionEnum(option, name, scArg, propertyValue, booleanProperty, namePropertyName, isDefault); mEnumIdToOptionEnumMap.put(name, oe); mFromSeeCodeEnumMap.put(scArg, oe); } SeeCodeOption sco = new SeeCodeOption(optionName, seecodeArg, "true".equalsIgnoreCase(negate) || "1".equals(negate), propertyName, alternatePropertyName, trueValue, falseValue); mOptions.add(sco); if (seecodeArg != null) { mFromSeeCodeArgMap.put(seecodeArg, sco); } if (propertyName != null) { mFromPropertyMap.put(propertyName, sco); if (setAsDefaultOnly) this.mSetAsDefaultOnly.add(propertyName); } }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
/** * Process the "property" element.//from w ww .j a v a 2s .co m * @param e * the "property" element. * @throws DocumentException */ private void handlePropertyElement(Element e) throws DocumentException { List<Attribute> attrs = Cast.toType(e.attributes()); String propertyName = null; String propertyValue = null; for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("name")) { propertyName = value; } else if (aname.equals("value")) { propertyValue = value; } else throw new DocumentException("Unknown attribute under 'property': " + aname); } if (propertyName == null || propertyValue == null) throw new DocumentException("'name' or 'value' attributes missing for element 'property'"); mSetPropertyMap.put(propertyName, propertyValue); }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
private void handleDefaultElement(Element e) throws DocumentException { @SuppressWarnings("unchecked") List<Attribute> attrs = e.attributes(); String property = null;//w w w .j a v a 2 s . c om String defaultValue = null; String option = null; String optionValue = null; for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("property")) { property = value; } else if (aname.equals("value")) { defaultValue = value; } else if (aname.equals("option")) { option = value; } else if (aname.equals("optionvalue")) { optionValue = value; } } if (property == null || defaultValue == null || option == null || optionValue == null) { throw new DocumentException("Attributes on Default element missing"); } mDefaultList.add(new DefaultSpec(property, defaultValue, option, optionValue)); }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
@Override public Survey constructSurvey(InputStream inputStream) throws DocumentException { Document document = null;/*w w w . ja v a 2 s. c o m*/ document = new SAXReader().read(inputStream); Element rootElement = document.getRootElement(); if (!rootElement.getName().equals("survey")) { throw new DocumentException("The root element of the XML document should be 'survey'."); } return constructSurvey(rootElement); }
From source file:com.heren.turtle.entry.util.XmlUtils.java
License:Open Source License
/** * @param elements//w w w.j a va 2 s .c o m * @return * @throws DocumentException */ public static List<Map<String, String>> getEachElement(List elements) throws DocumentException { List<Map<String, String>> resultList = new ArrayList<>(); if (elements.size() > 0) { for (Iterator it = elements.iterator(); it.hasNext();) { Map<String, String> resultMap = new HashMap<>(); Element subElement = (Element) it.next(); resultMap.put("eleName", subElement.getName()); List subElements = subElement.elements(); for (Iterator subIt = subElements.iterator(); subIt.hasNext();) { Element son = (Element) subIt.next(); String name = son.getName(); String text = son.getText(); resultMap.put(name, text); } resultList.add(resultMap); } } else { throw new DocumentException("this element is disappeared"); } return resultList; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * @param elements// w w w . ja va2 s .c o m * @return * @throws DocumentException */ public static List<Map<String, String>> getEachElement(List elements) throws DocumentException { List<Map<String, String>> resultList = new ArrayList<>(); if (elements.size() > 0) { for (Object element : elements) { Map<String, String> resultMap = new HashMap<>(); Element subElement = (Element) element; resultMap.put("eleName", subElement.getName()); List subElements = subElement.elements(); for (Object subElement1 : subElements) { Element son = (Element) subElement1; String name = son.getName(); String text = son.getText(); resultMap.put(name, text); } resultList.add(resultMap); } } else { throw new DocumentException("this element is disappeared"); } return resultList; }
From source file:com.log4ic.compressor.utils.MemcachedUtils.java
License:Open Source License
@SuppressWarnings("unchecked") private static MemcachedConfig getMemcachedConfig(InputStream in) throws DocumentException { SAXReader reader = new SAXReader(); MemcachedConfig config = new MemcachedConfig(); Document doc = reader.read(in); logger.debug("??..."); List<Node> nodeList = doc.selectNodes("/memcached/servers/server"); if (nodeList.isEmpty()) { throw new DocumentException(CONFIG_FILE_PATH + " file memcached.servers server element empty!"); } else {/* w w w . j a v a 2s .c o m*/ logger.debug("???" + nodeList.size() + "."); } AddressConfig addrConf = biludAddrMapConfig(nodeList); config.builder = new XMemcachedClientBuilder(addrConf.addressMap, addrConf.widgets); Element el = (Element) doc.selectSingleNode("/memcached"); logger.debug("??..."); Attribute attr = el.attribute("connectionPoolSize"); if (attr != null) { String connPoolSize = attr.getValue(); if (StringUtils.isNotBlank(connPoolSize)) { try { config.builder.setConnectionPoolSize(Integer.parseInt(connPoolSize)); logger.debug("?" + connPoolSize); } catch (Exception e) { logger.error("???", e); } } else { logger.error("???"); } } else { logger.warn("??"); } logger.debug("??..."); attr = el.attribute("enableHeartBeat"); if (attr != null) { String enableHeartBeatS = attr.getValue(); if (StringUtils.isNotBlank(enableHeartBeatS)) { try { config.enableHeartBeat = Boolean.parseBoolean(enableHeartBeatS); logger.debug("???" + enableHeartBeatS); } catch (Exception e) { logger.error("?????", e); } } else { logger.error("?????"); } } else { logger.warn("????"); } logger.debug("?..."); attr = el.attribute("sessionIdleTimeout"); if (attr != null) { String sessionIdleTimeout = attr.getValue(); if (StringUtils.isNotBlank(sessionIdleTimeout)) { try { config.builder.getConfiguration().setSessionIdleTimeout(Long.parseLong(sessionIdleTimeout)); logger.debug("?" + sessionIdleTimeout); } catch (Exception e) { logger.error("???", e); } } else { logger.error("???"); } } else { logger.warn("??"); } //? logger.debug("?..."); attr = el.attribute("statisticsServer"); if (attr != null) { String statisticsServer = attr.getValue(); if (StringUtils.isNotBlank(statisticsServer)) { try { config.builder.getConfiguration().setStatisticsServer(Boolean.parseBoolean(statisticsServer)); logger.debug("?" + statisticsServer); } catch (Exception e) { logger.error("???", e); } } else { logger.error("???"); } } else { logger.warn("??"); } logger.debug("?..."); attr = el.attribute("statisticsInterval"); if (attr != null) { String statisticsInterval = attr.getValue(); if (StringUtils.isNotBlank(statisticsInterval)) { try { config.builder.getConfiguration().setStatisticsInterval(Long.parseLong(statisticsInterval)); logger.debug("?" + statisticsInterval); } catch (Exception e) { logger.error("???", e); } } else { logger.error("???"); } } else { logger.warn("??"); } logger.debug("????..."); attr = el.attribute("optimizeMergeBuffer"); if (attr != null) { String optimizeMergeBufferS = attr.getValue(); if (StringUtils.isNotBlank(optimizeMergeBufferS)) { try { config.optimizeMergeBuffer = Boolean.parseBoolean(optimizeMergeBufferS); logger.debug("????" + optimizeMergeBufferS); } catch (Exception e) { logger.error("??????", e); } } else { logger.error("??????"); } } else { logger.warn("?????"); } logger.debug("??..."); attr = el.attribute("mergeFactor"); if (attr != null) { String mergeFactorS = attr.getValue(); if (StringUtils.isNotBlank(mergeFactorS)) { try { config.mergeFactor = Integer.parseInt(mergeFactorS); logger.debug("?" + mergeFactorS); } catch (Exception e) { logger.error("???", e); } } else { logger.error("???"); } } else { logger.warn("??"); } logger.debug("??..."); attr = el.attribute("commandFactory"); if (attr != null) { String commandFactory = attr.getValue(); if (StringUtils.isNotBlank(commandFactory)) { try { config.builder.setCommandFactory((CommandFactory) Class.forName(commandFactory).newInstance()); logger.debug("??" + commandFactory); } catch (Exception e) { logger.error("????", e); } } else { logger.error("????"); } } else { logger.warn("???"); } config.builder.setCommandFactory(new BinaryCommandFactory()); logger.debug("..."); nodeList = doc.selectNodes("/memcached/socketOption/*"); if (!nodeList.isEmpty()) { for (Node n : nodeList) { try { attr = ((Element) n).attribute("type"); if (attr == null) { logger.error("type attribute undefined"); } else { String type = attr.getValue(); if (StringUtils.isNotBlank(type)) { String name = n.getName(); String value = n.getStringValue(); Class valueType = Class.forName(type); Constructor constructor = SocketOption.class.getConstructor(String.class, Class.class); SocketOption socketOption = (SocketOption) constructor.newInstance(name, valueType); constructor = valueType.getConstructor(String.class); config.builder.setSocketOption(socketOption, constructor.newInstance(value)); logger.debug("[" + name + "]" + value); } } } catch (NoSuchMethodException e) { logger.error("NoSuchMethodException", e); } catch (InvocationTargetException e) { logger.error("InvocationTargetException", e); } catch (InstantiationException e) { logger.error("InstantiationException", e); } catch (IllegalAccessException e) { logger.error("IllegalAccessException", e); } catch (ClassNotFoundException e) { logger.error("ClassNotFoundException", e); } } } else { logger.warn("?"); } logger.debug("Failure?..."); attr = el.attribute("failureMode"); if (attr != null) { String failureMode = attr.getValue(); if (StringUtils.isNotBlank(failureMode)) { try { config.builder.setFailureMode(Boolean.parseBoolean(failureMode)); logger.debug("Failure?" + failureMode); } catch (Exception e) { logger.error("Failure???", e); } } else { logger.error("Failure???"); } } else { logger.warn("Failure??"); } return config; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public void overlookDTD(InputStream inputStream, OutputStream outputStream) throws DocumentException { try {//w w w . j a v a 2 s. c o m Document document = read(inputStream); writeDocument(outputStream, document.getRootElement()); } catch (DocumentException e) { throw new DocumentException(e); } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } }
From source file:com.zimbra.common.localconfig.LocalConfig.java
License:Open Source License
public LocalConfig(String file) throws DocumentException, ConfigException { mConfigFile = file;/* w w w . j a v a 2 s . co m*/ if (mConfigFile == null) { mConfigFile = defaultConfigFile(); } File cf = new File(mConfigFile); if (cf.exists() && cf.canRead()) { try (FileInputStream fis = new FileInputStream(cf)) { Document document = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(fis); Element root = document.getRootElement(); if (!root.getName().equals(E_LOCALCONFIG)) throw new DocumentException("config file " + mConfigFile + " root tag is not " + E_LOCALCONFIG); for (Iterator<?> iter = root.elementIterator(E_KEY); iter.hasNext();) { Element ekey = (Element) iter.next(); String key = ekey.attributeValue(A_NAME); String value = ekey.elementText(E_VALUE); set(key, value); } } catch (IOException | XmlParseException e) { Logging.warn(String.format("Problem parsing local config file '%s'", cf), e); throw new DocumentException(String.format("Problem parsing local config file '%s'", cf)); } } else { Logging.warn("local config file `" + cf + "' is not readable"); } expandAll(); }