List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.sipfoundry.voicemail.DistributionsReader.java
License:Contributor Agreement License
@SuppressWarnings("unchecked") @Override// w w w . j a v a 2 s .c o m public Distributions readObject(Document doc) { Distributions ds = new Distributions(); m_root = doc.getRootElement(); List<Element> lists = m_root.selectNodes("list"); for (Element list : lists) { String index = list.valueOf("index"); List<Element> destinations = list.selectNodes("destination"); Vector<String> dests = new Vector<String>(); for (Element destination : destinations) { dests.add(destination.getTextTrim()); } ds.addList(index, dests); } return ds; }
From source file:org.sipfoundry.voicemail.mailbox.MessageDescriptorReader.java
License:Contributor Agreement License
@SuppressWarnings("unchecked") @Override// w ww . ja va2 s . c o m public MessageDescriptor readObject(Document doc) { MessageDescriptor md = new MessageDescriptor(); m_root = doc.getRootElement(); md.setId(valueOf("id")); md.setFromUri(valueOf("from")); md.setDurationSecs(valueOf("durationsecs")); md.setTimestamp(valueOf("timestamp")); md.setSubject(valueOf("subject")); md.setPriority((Priority.valueOfById(valueOf("priority")))); List<Element> recipients = m_root.selectNodes("otherrecipient"); for (Element recipient : recipients) { md.addOtherRecipient(recipient.getTextTrim()); } md.setAudioFormat(valueOf("format")); return md; }
From source file:org.sipfoundry.voicemail.MessageDescriptorReader.java
License:Contributor Agreement License
@SuppressWarnings("unchecked") @Override/*from ww w . j a v a2 s . com*/ public MessageDescriptor readObject(Document doc) { MessageDescriptor md = new MessageDescriptor(); m_root = doc.getRootElement(); md.setId(valueOf("id")); md.setFromUri(valueOf("from")); md.setDurationSecs(valueOf("durationsecs")); md.setTimestamp(valueOf("timestamp")); md.setSubject(valueOf("subject")); md.setPriority((Priority.valueOfById(valueOf("priority")))); List<Element> recipients = m_root.selectNodes("otherrecipient"); for (Element recipient : recipients) { md.addOtherRecipient(recipient.getTextTrim()); } return md; }
From source file:org.springframework.extensions.config.ServerElementReader.java
License:Apache License
/** * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) */// w ww .j av a2s . c o m @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { ServerConfigElement configElement = new ServerConfigElement(); if (element != null) { if (ServerConfigElement.CONFIG_ELEMENT_ID.equals(element.getName()) == false) { throw new ConfigException("ServerElementReader can only parse config elements of type '" + ServerConfigElement.CONFIG_ELEMENT_ID + "'"); } Element schemeElem = element.element(ELEMENT_SCHEME); if (schemeElem != null) { configElement.setScheme(schemeElem.getTextTrim()); } Element hostnameElem = element.element(ELEMENT_HOSTNAME); if (hostnameElem != null) { configElement.setHostName(hostnameElem.getTextTrim()); } Element portElem = element.element(ELEMENT_PORT); if (portElem != null) { try { Integer port = new Integer(portElem.getTextTrim()); configElement.setPort(port); } catch (NumberFormatException e) { throw new ConfigException("Server port is not a number", e); } } } return configElement; }
From source file:org.springframework.extensions.config.xml.elementreader.GenericElementReader.java
License:Apache License
/** * Creates a ConfigElementImpl object from the given element. * // w ww . ja va2s .c o m * @param element The element to parse * @return The GenericConfigElement representation of the given element */ @SuppressWarnings("unchecked") protected GenericConfigElement createConfigElement(Element element) { // get the name and value of the given element String name = element.getName(); // create the config element object and populate with value // and attributes GenericConfigElement configElement = new GenericConfigElement(name); if ((element.hasContent()) && (element.hasMixedContent() == false)) { String value = element.getTextTrim(); if (value != null && value.length() > 0) { if (propertyConfigurer != null) { value = propertyConfigurer.resolveValue(value); } configElement.setValue(value); } } Iterator<Attribute> attrs = element.attributeIterator(); while (attrs.hasNext()) { Attribute attr = attrs.next(); String attrName = attr.getName(); String attrValue = attr.getValue(); if (propertyConfigurer != null) { attrValue = propertyConfigurer.resolveValue(attrValue); } configElement.addAttribute(attrName, attrValue); } return configElement; }
From source file:org.springframework.extensions.surf.extensibility.Customization.java
License:Apache License
/** * <p>Retrieves the list of JavaScript resource dependencies specified within the supplied * configuration customization element.<p> * // w w w. j a v a 2 s . c o m * @param elementName The name of the element to look for. * @param dependencyElementName The dependency element to look for * @param sourceElement The element to search within. * @return A {@link List} of the JavaScript dependencies. */ @SuppressWarnings("unchecked") private List<String> getJavaScriptDependencies(String elementName, String dependencyElementName, Element sourceElement) { List<String> dependencies = new ArrayList<String>(); Element el = sourceElement.element(elementName); if (el != null) { List<Element> elementList = el.elements(dependencyElementName); for (Element element : elementList) { dependencies.add(element.getTextTrim()); } } return dependencies; }
From source file:org.springframework.extensions.surf.extensibility.Customization.java
License:Apache License
/** * <p>Creates a {@link Map} of CSS media types to lists of dependencies for that type. This map is generated * from the content defined within children of the supplied {@link Element}.</p> * <p>CSS depdendencies are defined as follows: * <pre>//from w w w .j a v a 2s. c o m * <{@code dependencies}> * <{@code css}><{@code}/css> * <{@code css media="screen"}><{@code}/css> * <{@code css media="print"}><{@code}/css> * <{@code /dependencies}></pre> * If no "media" attribute is specified then "screen" will be used by default. * </p> * * @param elementName String * @param dependencyElementName String * @param sourceElement Element * @return Map */ @SuppressWarnings("unchecked") private Map<String, List<String>> getCssDependencies(String elementName, String dependencyElementName, Element sourceElement) { Map<String, List<String>> dependencies = new HashMap<String, List<String>>(); Element el = sourceElement.element(elementName); if (el != null) { List<Element> elementList = el.elements(dependencyElementName); for (Element element : elementList) { String media = element.attributeValue(CSS_MEDIA); if (media == null) { // If no media attribute is set then use the default media type... media = DEFAULT_CSS_MEDIA; } // Get the list of dependencies specific to the requested media type... List<String> mediaSpecificDependencies = dependencies.get(media); if (mediaSpecificDependencies == null) { // If no other dependencies for the requested media have not been added yet // then create a new list to hold them and add it to the map... mediaSpecificDependencies = new ArrayList<String>(); dependencies.put(media, mediaSpecificDependencies); } // Add the dependency to the list... mediaSpecificDependencies.add(element.getTextTrim()); } } return dependencies; }
From source file:org.springframework.extensions.surf.extensibility.XMLHelper.java
License:Apache License
public static String getStringData(String elementName, Element element, boolean required) { String str = null;//from w w w . j a v a 2 s .c o m Element el = element.element(elementName); if (el != null) { str = el.getTextTrim(); } else if (required) { if (logger.isErrorEnabled()) { logger.error("The required element <" + elementName + "> was not found in element <" + element.getName() + ">"); } // TODO: Throw exception here? } return str; }
From source file:org.springframework.extensions.surf.extensibility.XMLHelper.java
License:Apache License
@SuppressWarnings("unchecked") public static Map<String, String> getProperties(String elementName, Element sourceElement) { Map<String, String> props = new HashMap<String, String>(); Element el = sourceElement.element(elementName); if (el != null) { List<Element> elementList = el.elements(); for (Element element : elementList) { props.put(element.getName(), element.getTextTrim()); }/*w w w . j a v a2s .c om*/ } return props; }
From source file:org.springframework.extensions.webscripts.DescriptionImpl.java
License:Apache License
@SuppressWarnings("unchecked") public void parse(Element elem) { if (this.validateRootElement(elem, ROOT_ELEMENT_NAME)) { super.parse(elem); // validate short name String shortName = this.getShortName(); if (shortName == null || shortName.length() == 0) { throw new WebScriptException("Expected <shortname> value"); }// ww w .j ava2s . c o m // retrieve kind String kind = null; String attrKindValue = elem.attributeValue("kind"); if (attrKindValue != null) { kind = attrKindValue.trim(); } // retrieve family[] Set<String> familys = new TreeSet<String>(); List<Element> familyElements = elem.elements("family"); if (familyElements == null || familyElements.size() > 0) { Iterator<Element> iterFamily = familyElements.iterator(); while (iterFamily.hasNext()) { // retrieve family element Element familyElement = (Element) iterFamily.next(); String family = familyElement.getTextTrim(); familys.add(family); } } // retrieve urls List urlElements = elem.elements("url"); if (urlElements == null || urlElements.size() == 0) { throw new WebScriptException("Expected at least one <url> element"); } List<String> uris = new ArrayList<String>(4); Iterator iterElements = urlElements.iterator(); while (iterElements.hasNext()) { // retrieve url element Element urlElement = (Element) iterElements.next(); // retrieve url template String template = urlElement.getTextTrim(); if (template == null || template.length() == 0) { // NOTE: for backwards compatibility only template = urlElement.attributeValue("template"); if (template == null || template.length() == 0) { throw new WebScriptException("Expected <url> element value"); } } uris.add(template); } // retrieve authentication RequiredAuthentication reqAuth = RequiredAuthentication.none; String runAs = null; Element authElement = elem.element("authentication"); if (authElement != null) { String reqAuthStr = authElement.getTextTrim(); if (reqAuthStr == null || reqAuthStr.length() == 0) { throw new WebScriptException("Expected <authentication> value"); } try { reqAuth = RequiredAuthentication.valueOf(reqAuthStr); } catch (IllegalArgumentException e) { throw new WebScriptException("Authentication '" + reqAuthStr + "' is not a valid value"); } String runAsStr = authElement.attributeValue("runas"); if (runAsStr != null) { runAsStr = runAsStr.trim(); if (runAsStr.length() != 0) { if (!this.getStore().isSecure()) { throw new WebScriptException("runas user declared for script in insecure store"); } runAs = runAsStr; } } } // retrieve transaction TransactionParameters trxParams = new TransactionParameters(); RequiredTransaction reqTrx = (reqAuth == RequiredAuthentication.none) ? RequiredTransaction.none : RequiredTransaction.required; TransactionCapability trxCapability = TransactionCapability.readwrite; int bufferSize = 4096; Element trxElement = elem.element("transaction"); if (trxElement != null) { // requires... String reqTrxStr = trxElement.getTextTrim(); if (reqTrxStr != null && reqTrxStr.length() > 0) { try { reqTrx = RequiredTransaction.valueOf(reqTrxStr); } catch (IllegalArgumentException e) { throw new WebScriptException("Transaction '" + reqTrxStr + "' is not a valid value"); } } // capability... String capabilityStr = trxElement.attributeValue("allow"); if (capabilityStr != null) { try { trxCapability = TransactionCapability.valueOf(capabilityStr); } catch (IllegalArgumentException e) { throw new WebScriptException( "Transaction allow '" + capabilityStr + "' is not a valid value"); } } // buffer size String bufferSizeStr = trxElement.attributeValue("buffersize"); if (bufferSizeStr != null) { try { bufferSize = new Integer(bufferSizeStr); } catch (NumberFormatException e) { throw new WebScriptException("Buffer size '" + bufferSizeStr + "' is not a valid integer"); } } } trxParams.setRequired(reqTrx); trxParams.setCapability(trxCapability); trxParams.setBufferSize(bufferSize); // retrieve lifecycle Lifecycle lifecycle = Lifecycle.none; Element lifecycleElement = elem.element("lifecycle"); if (lifecycleElement != null) { String reqLifeStr = lifecycleElement.getTextTrim(); if (reqLifeStr == null || reqLifeStr.length() == 0) { throw new WebScriptException("Expected <lifecycle> value"); } try { lifecycle = Lifecycle.valueOf(reqLifeStr); } catch (IllegalArgumentException e) { throw new WebScriptException("Lifecycle '" + reqLifeStr + "' is not a valid value"); } } // retrieve format String defaultFormat = "html"; String defaultFormatMimetype = null; FormatStyle formatStyle = FormatStyle.any; Element formatElement = elem.element("format"); if (formatElement != null) { // establish if default is set explicitly String attrDefaultValue = formatElement.attributeValue("default"); if (attrDefaultValue != null) { defaultFormat = (attrDefaultValue.length() == 0) ? null : attrDefaultValue; } // establish format declaration style String formatStyleStr = formatElement.getTextTrim(); if (formatStyleStr != null && formatStyleStr.length() > 0) { try { formatStyle = FormatStyle.valueOf(formatStyleStr); } catch (IllegalArgumentException e) { throw new WebScriptException("Format Style '" + formatStyle + "' is not a valid value"); } } } // retrieve negotiation NegotiatedFormat[] negotiatedFormats = null; List negotiateElements = elem.elements("negotiate"); if (negotiateElements.size() > 0) { negotiatedFormats = new NegotiatedFormat[negotiateElements.size() + (defaultFormatMimetype == null ? 0 : 1)]; int iNegotiate = 0; Iterator iterNegotiateElements = negotiateElements.iterator(); while (iterNegotiateElements.hasNext()) { Element negotiateElement = (Element) iterNegotiateElements.next(); String accept = negotiateElement.attributeValue("accept"); if (accept == null || accept.length() == 0) { throw new WebScriptException("Expected 'accept' attribute on <negotiate> element"); } String format = negotiateElement.getTextTrim(); if (format == null || format.length() == 0) { throw new WebScriptException("Expected <negotiate> value"); } negotiatedFormats[iNegotiate++] = new NegotiatedFormat(new MediaType(accept), format); } if (defaultFormatMimetype != null) { negotiatedFormats[iNegotiate++] = new NegotiatedFormat(new MediaType(defaultFormatMimetype), defaultFormat); } } // retrieve caching Cache cache = new Cache(); Element cacheElement = elem.element("cache"); if (cacheElement != null) { Element neverElement = cacheElement.element("never"); if (neverElement != null) { String neverStr = neverElement.getTextTrim(); boolean neverBool = (neverStr == null || neverStr.length() == 0) ? true : Boolean.valueOf(neverStr); cache.setNeverCache(neverBool); } Element publicElement = cacheElement.element("public"); if (publicElement != null) { String publicStr = publicElement.getTextTrim(); boolean publicBool = (publicStr == null || publicStr.length() == 0) ? true : Boolean.valueOf(publicStr); cache.setIsPublic(publicBool); } Element revalidateElement = cacheElement.element("mustrevalidate"); if (revalidateElement != null) { String revalidateStr = revalidateElement.getTextTrim(); boolean revalidateBool = (revalidateStr == null || revalidateStr.length() == 0) ? true : Boolean.valueOf(revalidateStr); cache.setMustRevalidate(revalidateBool); } } // retrieve formdata multipart processing setting boolean multipartProcessing = true; Element formdataElement = elem.element("formdata"); if (formdataElement != null) { String strProcessing = formdataElement.attributeValue("multipart-processing"); if (strProcessing == null || strProcessing.length() == 0) { throw new WebScriptException("Expected 'multipart-processing' attribute on <formdata> value"); } multipartProcessing = Boolean.parseBoolean(strProcessing); } // retrieve arguments ArgumentTypeDescription[] arguments = null; Element argsElement = elem.element("args"); if (argsElement != null) { List<Element> argElements = argsElement.elements("arg"); arguments = new ArgumentTypeDescription[argElements.size()]; int iArg = 0; Iterator<Element> iterArgElements = argElements.iterator(); while (iterArgElements.hasNext()) { Element argElement = iterArgElements.next(); ArgumentTypeDescription argument = new ArgumentTypeDescription(); argument.parse(argElement); argument.setRequired(true); Pattern p = Pattern.compile(argument.getShortName() + "=\\{[a-zA-Z0-9]*\\?\\}"); for (String uriStr : uris) { Matcher m = p.matcher(uriStr); if (m.find()) { argument.setRequired(false); continue; } } arguments[iArg++] = argument; } } // retrieve request formats TypeDescription[] requestTypes = null; Element requestsElement = elem.element("requests"); if (requestsElement != null) { List<Element> requestElements = requestsElement.elements("request"); requestTypes = new TypeDescription[requestElements.size()]; int iRequest = 0; Iterator<Element> iterRequestElements = requestElements.iterator(); while (iterRequestElements.hasNext()) { Element requestElement = iterRequestElements.next(); // check if it uses type reference if (requestElement.attribute(TypeDescription.ROOT_ELEMENT_NAME) != null) { String refTypeId = requestElement.attribute(TypeDescription.ROOT_ELEMENT_NAME).getText(); TypeDescription requestType = new TypeDescription(); requestType.setId(refTypeId); requestTypes[iRequest++] = requestType; } else { if (requestElement.element(TypeDescription.ROOT_ELEMENT_NAME) != null) { TypeDescription requestType = new TypeDescription(); requestType.parse(requestElement.element(TypeDescription.ROOT_ELEMENT_NAME)); requestTypes[iRequest++] = requestType; } } } } // retrieve response formats TypeDescription[] responseTypes = null; Element responsesElement = elem.element("responses"); if (responsesElement != null) { List<Element> responseElements = responsesElement.elements("response"); responseTypes = new TypeDescription[responseElements.size()]; int iResponse = 0; Iterator<Element> iterresponseElements = responseElements.iterator(); while (iterresponseElements.hasNext()) { Element responseElement = iterresponseElements.next(); // check if it uses type reference if (responseElement.attribute(TypeDescription.ROOT_ELEMENT_NAME) != null) { String refTypeId = responseElement.attribute(TypeDescription.ROOT_ELEMENT_NAME).getText(); TypeDescription responseType = new TypeDescription(); responseType.setId(refTypeId); responseTypes[iResponse++] = responseType; } else { if (responseElement.element(TypeDescription.ROOT_ELEMENT_NAME) != null) { TypeDescription responseType = new TypeDescription(); responseType.parse(responseElement.element(TypeDescription.ROOT_ELEMENT_NAME)); responseTypes[iResponse++] = responseType; } } } } this.setScriptPath(scriptPath); this.setKind(kind); this.setLifecycle(lifecycle); this.setShortName(shortName); this.setFamilys(familys); this.setRequiredAuthentication(reqAuth); this.setRunAs(runAs); this.setRequiredTransactionParameters(trxParams); this.setRequiredCache(cache); this.setUris(uris.toArray(new String[uris.size()])); this.setDefaultFormat(defaultFormat); this.setNegotiatedFormats(negotiatedFormats); this.setFormatStyle(formatStyle); this.setMultipartProcessing(multipartProcessing); this.setArguments(arguments); this.setRequestTypes(requestTypes); this.setResponseTypes(responseTypes); } }