Java Code Examples for org.dom4j.Element.getTextTrim()

The following are Jave code examples for showing how to use getTextTrim() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: joai-project   File: InfoXML.java   View Source Code Vote up 6 votes
/**
 * Get the text contents of the given tag. 
 * 
 * @return - the string contents of the tag
 */
private String getTagValue( String _tag, String _namespacePrefix , String _namespaceURI )
{	
	// TODO : 09/06/06 - this function is designed to provide 
	// an introduction to the INFO XML abstraction
	String objectHandle = null; // caller is responsible for handling null
	
	try {

		Element element = this.getTagElement(_tag, _namespacePrefix, _namespaceURI);
		if ( element != null )
			objectHandle = element.getTextTrim();

	}  catch ( Exception e ) {
		e.printStackTrace();
	}
	
	return objectHandle;		
}
 
Example 2
Project: lams   File: HbmBinder.java   View Source Code Vote up 6 votes
private static void parseFilterDef(Element element, Mappings mappings) {
	String name = element.attributeValue( "name" );
	LOG.debugf( "Parsing filter-def [%s]", name );
	String defaultCondition = element.getTextTrim();
	if ( StringHelper.isEmpty( defaultCondition ) ) {
		defaultCondition = element.attributeValue( "condition" );
	}
	HashMap paramMappings = new HashMap();
	Iterator params = element.elementIterator( "filter-param" );
	while ( params.hasNext() ) {
		final Element param = (Element) params.next();
		final String paramName = param.attributeValue( "name" );
		final String paramType = param.attributeValue( "type" );
		LOG.debugf( "Adding filter parameter : %s -> %s", paramName, paramType );
		final Type heuristicType = mappings.getTypeResolver().heuristicType( paramType );
		LOG.debugf( "Parameter heuristic type : %s", heuristicType );
		paramMappings.put( paramName, heuristicType );
	}
	LOG.debugf( "Parsed filter-def [%s]", name );
	FilterDefinition def = new FilterDefinition( name, defaultCondition, paramMappings );
	mappings.addFilterDefinition( def );
}
 
Example 3
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 6 votes
private void getEnumerated(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "enumerated" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Enumerated.class );
		String enumerated = subElement.getTextTrim();
		if ( "ORDINAL".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.ORDINAL );
		}
		else if ( "STRING".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.STRING );
		}
		else if ( StringHelper.isNotEmpty( enumerated ) ) {
			throw new AnnotationException( "Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example 4
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 6 votes
private void getTemporal(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "temporal" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Temporal.class );
		String temporal = subElement.getTextTrim();
		if ( "DATE".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.DATE );
		}
		else if ( "TIME".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIME );
		}
		else if ( "TIMESTAMP".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIMESTAMP );
		}
		else if ( StringHelper.isNotEmpty( temporal ) ) {
			throw new AnnotationException( "Unknown TemporalType: " + temporal + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example 5
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 6 votes
private static void buildUniqueConstraints(AnnotationDescriptor annotation, Element element) {
	List uniqueConstraintElementList = element.elements( "unique-constraint" );
	UniqueConstraint[] uniqueConstraints = new UniqueConstraint[uniqueConstraintElementList.size()];
	int ucIndex = 0;
	Iterator ucIt = uniqueConstraintElementList.listIterator();
	while ( ucIt.hasNext() ) {
		Element subelement = (Element) ucIt.next();
		List<Element> columnNamesElements = subelement.elements( "column-name" );
		String[] columnNames = new String[columnNamesElements.size()];
		int columnNameIndex = 0;
		Iterator it = columnNamesElements.listIterator();
		while ( it.hasNext() ) {
			Element columnNameElt = (Element) it.next();
			columnNames[columnNameIndex++] = columnNameElt.getTextTrim();
		}
		AnnotationDescriptor ucAnn = new AnnotationDescriptor( UniqueConstraint.class );
		copyStringAttribute( ucAnn, subelement, "name", false );
		ucAnn.setValue( "columnNames", columnNames );
		uniqueConstraints[ucIndex++] = AnnotationFactory.create( ucAnn );
	}
	annotation.setValue( "uniqueConstraints", uniqueConstraints );
}
 
Example 6
Project: ureport   File: DatasetValueParser.java   View Source Code Vote up 6 votes
private PropertyExpressionCondition parseCondition(Element ele) {
	PropertyExpressionCondition condition=new PropertyExpressionCondition();				
	String property=ele.attributeValue("property");
	condition.setLeftProperty(property);
	condition.setLeft(property);
	condition.setOp(Op.parse(ele.attributeValue("op")));
	for(Object o:ele.elements()){
		if(o==null || !(o instanceof Element)){
			continue;
		}
		Element e=(Element)o;
		if(!e.getName().equals("value")){
			continue;
		}
		String expr=e.getTextTrim();
		condition.setRightExpression(ExpressionUtils.parseExpression(expr));
		condition.setRight(expr);
		break;
	}
	String join=ele.attributeValue("join");
	if(StringUtils.isNotBlank(join)){
		condition.setJoin(Join.valueOf(join));
	}
	return condition;
}
 
Example 7
Project: ExcelUtils   File: ParseXMLUtil.java   View Source Code Vote up 5 votes
/**
 *
 * 将xml单元格元素解析到ExcelStruct中
 *
 * @param excelStruct Excel导入描述文件的结构
 * @param list 单元格元素list
 */
private static List<ImportCellDesc> getImportCellDescList(ExcelStruct excelStruct, List list){
    if(list == null || list.size() <= 0){
        return null;
    }
    // 获取CDATA区内的内容
    Element cdataElem = (Element) list.get(0);
    String cdataStr = cdataElem.getTextTrim();
    List<ImportCellDesc> importCells = changeCDATAToList(excelStruct, cdataStr);
    return importCells;
}
 
Example 8
Project: joai-project   File: Standard.java   View Source Code Vote up 5 votes
/**
 *  Returns children as Standard instances in same order as the XML Element
 *  defining this Standard
 *
 * @return    The children value
 */
public List getChildren() {
	if (this.children == null) {
		this.children = new ArrayList();
		try {
			Element hasChild = element.element("children");
			if (hasChild == null) {
				// prtln ("Leaf node: " + this.getId());
				return this.children;
			}
			List childElements = hasChild.elements("child");
			for (Iterator i = childElements.iterator(); i.hasNext(); ) {
				Element childElement = (Element) i.next();
				String childId = childElement.getTextTrim();
				// prtln ("childId: " + childId);
				Standard std = this.getStd(childId);
				if (std == null) {
					prtln("WARNING: ASN Document error: std not found for " + childId);
					continue;
				}
				this.addChild(std);
			}
		} catch (Throwable t) {
			prtln("trouble getting children for " + this.getId() + ": " + t.getMessage());
			t.printStackTrace();
			System.exit(1);
		}
	}
	return children;
}
 
Example 9
Project: joai-project   File: StdElement.java   View Source Code Vote up 5 votes
/**
 *  Gets the textual content of the named subelement of provided element.
 *
 *@param  e               element containing subelement
 *@param  subElementName  name of subelement
 *@return                 the textual content of named subelement
 */
public String getSubElementText(Element e, String subElementName, String defaultVal) {
	Element sub = e.element(subElementName);
	if (sub == null) {
		prtln("getSubElementText could not find subElement for " + subElementName);
		return defaultVal;
	}
	return sub.getTextTrim();
}
 
Example 10
Project: joai-project   File: GlobalDeclaration.java   View Source Code Vote up 5 votes
public void extractDocumentation () {
	Element docElement = (Element) this.element.selectSingleNode (this.xsdPrefix + ":annotation/"  +
								                                  this.xsdPrefix + ":documentation");
	if (docElement != null) {
		String docString = docElement.getTextTrim();
		if (docString != null && docString.length() > 0)
			this.documentation = docString;
		else
			this.documentation = null;
	}
}
 
Example 11
Project: joai-project   File: AttributeGroup.java   View Source Code Vote up 5 votes
public void extractDocumentation () {
	Element docElement = (Element) this.element.selectSingleNode (this.xsdPrefix + ":attribute/"  +
																  this.xsdPrefix + ":annotation/"  +
								                                  this.xsdPrefix + ":documentation");
	if (docElement != null) {
		this.documentation = docElement.getTextTrim();
	}
}
 
Example 12
Project: joai-project   File: GenericType.java   View Source Code Vote up 5 votes
/**  Find documentation within this type definition. */
public void extractDocumentation() {
	Element docElement = (Element) this.element.selectSingleNode(this.xsdPrefix + ":annotation/" +
		this.xsdPrefix + ":documentation");
	if (docElement != null) {
		String docString = docElement.getTextTrim();
		if (docString != null && docString.length() > 0)
			this.documentation = docString;
		else
			this.documentation = null;
	}
}
 
Example 13
Project: joai-project   File: DocMap.java   View Source Code Vote up 5 votes
/**
 *  Return true if the specified node is an Element and has either a
 *  sub-element, or an attribute (even if they are empty), OR content.
 *
 * @param  xpath  xpath to the node to be evaluated for children
 * @return        true if sub-elements, or attributes, false otherwise or if
 *      node is not an Element
 */
public boolean hasChildren(String xpath) {
	// prtln ("\nhasChildren: " + xpath);
	if (xpath == null || xpath.trim().length() == 0)
		return false;
	Node node = doc.selectSingleNode(xpath);
	if (node == null) {
		prtlnErr("\thasChildren() could not find node: (" + xpath + ")");
		return false;
	}

	if (node.getNodeType() != Node.ELEMENT_NODE) {
		prtlnErr("hasChildern() called with an non-Element - returning false");
		return false;
	}

	Element e = (Element) node;

	// we used to check for "hasText" but why would we want to do that here???
	/*
		We DO want to check in the case of an element that can contain text which ALSO
		has attributes. So we can do this check IF the typeDef is the right kind ...
	*/
	boolean hasText = (e.getTextTrim() != null && e.getTextTrim().length() > 0);
	if (hasText)
		return true;

	return (e.elements().size() > 0 ||
		e.attributeCount() > 0);
}
 
Example 14
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void parseFilter(Element filterElement, Filterable filterable, Mappings model) {
	final String name = filterElement.attributeValue( "name" );
	String condition = filterElement.getTextTrim();
	if ( StringHelper.isEmpty(condition) ) {
		condition = filterElement.attributeValue( "condition" );
	}
	//TODO: bad implementation, cos it depends upon ordering of mapping doc
	//      fixing this requires that Collection/PersistentClass gain access
	//      to the Mappings reference from Configuration (or the filterDefinitions
	//      map directly) sometime during Configuration.build
	//      (after all the types/filter-defs are known and before building
	//      persisters).
	if ( StringHelper.isEmpty(condition) ) {
		condition = model.getFilterDefinition(name).getDefaultFilterCondition();
	}
	if ( condition==null) {
		throw new MappingException("no filter condition found for filter: " + name);
	}
	Iterator aliasesIterator = filterElement.elementIterator("aliases");
	java.util.Map<String, String> aliasTables = new HashMap<String, String>();
	while (aliasesIterator.hasNext()){
		Element alias = (Element) aliasesIterator.next();
		aliasTables.put(alias.attributeValue("alias"), alias.attributeValue("table"));
	}
	LOG.debugf( "Applying filter [%s] as [%s]", name, condition );
	String autoAliasInjectionText = filterElement.attributeValue("autoAliasInjection");
	boolean autoAliasInjection = StringHelper.isEmpty(autoAliasInjectionText) ? true : Boolean.parseBoolean(autoAliasInjectionText);
	filterable.addFilter(name, condition, autoAliasInjection, aliasTables, null);
}
 
Example 15
Project: zookeeper-test-demo   File: XmlPublishTask.java   View Source Code Vote up 5 votes
@Override
public void publish(Client zkClient) {
	Set<Map.Entry<String, Document>> docEntries = xmlsMap.entrySet();
	Element rootEle = null;
	try {
		for (Map.Entry<String, Document> docEntry : docEntries) {
			String zkPath = docEntry.getKey();
			Document xmlResource = docEntry.getValue();
			rootEle = xmlResource.getRootElement();
			List<Element> paramsList = rootEle.elements("params");
			for (Element paramEle : paramsList) {
				String paramName = paramEle.attributeValue("name");
				List<Element> paramList = paramEle.elements("param");
				for (Element param : paramList) {
					String paramKey = param.attributeValue("name");
					String content = param.getTextTrim();
					ZkNodeUtil.createOrUpdateZnode(zkClient, zkPath + "/" + paramName + "/" + paramKey, content);
				}

			}
		}

	} catch (Exception e) {
		getLogger().error(e.getMessage(), e);
		e.printStackTrace();
	}
}
 
Example 16
Project: headb   File: HXmlUtils.java   View Source Code Vote up 5 votes
public String getOrmType() {
	Map<String,Object> valueCacheMap=this.xmlCache.getValueMap();
	String path="config/orm";
	if(null!=valueCacheMap.get(path)){
		return (String) valueCacheMap.get(path);
	}
	Element rootElement = document.getRootElement();
	Element hqlsElement = rootElement.element(ORM );
	if (null == hqlsElement) {
		return null;
	}
	 valueCacheMap.put(path, hqlsElement.getTextTrim());
     return hqlsElement.getTextTrim();
}
 
Example 17
Project: minlia-iot   File: XmlSignatureAnnotationHelper.java   View Source Code Vote up 5 votes
/**
 * 预检验签名
 *
 * @param xml xml字符串
 * @param salt partnerApiKey
 * @param clazz 类型
 * @return 是否通过验证
 */
@SuppressWarnings("unchecked")
public static boolean prepareCheckSign(String xml, String salt, Boolean excludeSaltParameter,
    Class<?> clazz,
    SignatureAlgorithmic algorithmic, String saltParameterPrefix, String charset,
    CaseControl caseControl, String delimiter) {
  Field signField = signField(clazz);
  XmlElement xmlElementAnnotation = signField.getAnnotation(XmlElement.class);
  try {
    Document document = DocumentHelper.parseText(xml);
    Element rootElement = document.getRootElement();
    List<FieldPaired> fieldPaireds = new LinkedList<>();
    String targetSign = null;
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext(); ) {
      Element element = iterator.next();
      if (element.getName().equals(xmlElementAnnotation.name())) {
        targetSign = element.getTextTrim();
      } else {
        String text = element.getTextTrim();
        if (StringUtils.isNotBlank(text)) {
          fieldPaireds.add(new FieldPaired(element.getName(), text));
        }
      }
    }
    if (StringUtils.isBlank(targetSign)) {
      log.warn("Sign shoud not be empty.");
    }
    String signStr = "";

    signStr = makeSignBySinpleFieldList(fieldPaireds, salt, excludeSaltParameter, algorithmic,
        saltParameterPrefix, charset, caseControl, delimiter);
    return signStr.equals(targetSign);
  } catch (DocumentException e) {
    e.printStackTrace();
    return false;
  }
}
 
Example 18
Project: uflo   File: ProcessParser.java   View Source Code Vote up 4 votes
public Object parse(Element element,long processId,boolean parseChildren) {
	ProcessDefinition process=new ProcessDefinition();
	process.setId(processId);
	process.setEventHandlerBean(unescape(element.attributeValue("event-handler-bean")));
	process.setName(unescape(element.attributeValue("name")));
	process.setStartProcessUrl(unescape(element.attributeValue("start-process-url")));
	process.setKey(unescape(element.attributeValue("key")));
	process.setCategoryId(unescape(element.attributeValue("category-id")));
	String effectDateStr=unescape(element.attributeValue("effect-date"));
	if(StringUtils.isNotEmpty(effectDateStr)){
		SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			process.setEffectDate(sd.parse(effectDateStr));
		} catch (ParseException e) {
			log.error("Process definition "+process.getName()+" effect date is invalid:"+effectDateStr);
		}
	}
	if(StringUtils.isEmpty(process.getCategoryId())){
		process.setCategoryId(EnvironmentUtils.getEnvironment().getCategoryId());
	}
	Element descElement=element.element("description");
	if(descElement!=null){
		String desc=descElement.getTextTrim();
		desc=(desc.length()>120?desc.substring(0,120):desc);
		process.setDescription(unescape(desc));
	}
	if(parseChildren){
		List<Node> nodes=new ArrayList<Node>();
		List<Swimlane> swimlanes=new ArrayList<Swimlane>();
		for(Object obj:element.elements()){
			if(!(obj instanceof Element)){
				continue;
			}
			Element childElement=(Element)obj;
			for(Parser parser:parsers){
				if(!parser.support(childElement)){
					continue;
				}
				Object processElement=parser.parse(childElement,processId,parseChildren);
				if(processElement instanceof Node){
					Node node=(Node)processElement;
					node.setProcessId(processId);
					nodes.add(node);
				}
				if(processElement instanceof StartNode){
					process.setStartNode((StartNode)processElement);
				}
				if(processElement instanceof Swimlane){
					swimlanes.add((Swimlane)processElement);
				}
				break;
			}
		}
		process.setSwimlanes(swimlanes);
		process.setNodes(nodes);
	}
	if(parseChildren){
		process.setDiagram(buildProcessDiagram(process));			
	}
	return process;
}
 
Example 19
Project: lams   File: XMLContext.java   View Source Code Vote up 4 votes
private void setAccess(Element unitElement, Default defaultType) {
	if ( unitElement != null ) {
		String access = unitElement.getTextTrim();
		setAccess( access, defaultType );
	}
}
 
Example 20
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 4 votes
private static void copyStringElement(Element element, AnnotationDescriptor ad, String annotationAttribute) {
	String discr = element.getTextTrim();
	ad.setValue( annotationAttribute, discr );
}