Java Code Examples for org.dom4j.Attribute.getValue()

The following are Jave code examples for showing how to use getValue() of the org.dom4j.Attribute 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: parabuild-ci   File: Binder.java   View Source Code Vote up 6 votes
private static int getOptimisticLockMode(Attribute olAtt) throws MappingException {
	
	if (olAtt==null) return Versioning.OPTIMISTIC_LOCK_VERSION;
	String olMode = olAtt.getValue();
	if ( olMode==null || "version".equals(olMode) ) {
		return Versioning.OPTIMISTIC_LOCK_VERSION;
	}
	else if ( "dirty".equals(olMode) ) {
		return Versioning.OPTIMISTIC_LOCK_DIRTY;
	}
	else if ( "all".equals(olMode) ) {
		return Versioning.OPTIMISTIC_LOCK_ALL;
	}
	else if ( "none".equals(olMode) ) {
		return Versioning.OPTIMISTIC_LOCK_NONE;
	}
	else {
		throw new MappingException("Unsupported optimistic-lock style: " + olMode);
	}
}
 
Example 2
Project: atlas   File: ManifestFileUtils.java   View Source Code Vote up 6 votes
/**
 * Update the plug-in's minSdkVersion and targetSdkVersion
 *
 * @param androidManifestFile
 * @throws IOException
 * @throws DocumentException
 */
public static String getVersionName(File androidManifestFile) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    String versionName = "";
    if (androidManifestFile.exists()) {
        Document document = reader.read(androidManifestFile);// Read the XML file
        Element root = document.getRootElement();// Get the root node
        if ("manifest".equalsIgnoreCase(root.getName())) {
            List<Attribute> attributes = root.attributes();
            for (Attribute attr : attributes) {
                if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
                    versionName = attr.getValue();
                }
            }
        }
    }
    return versionName;
}
 
Example 3
Project: lams   File: HbmBinder.java   View Source Code Vote up 6 votes
private static String getClassTableName(
		PersistentClass model,
		Element node,
		String schema,
		String catalog,
		Table denormalizedSuperTable,
		Mappings mappings) {
	Attribute tableNameNode = node.attribute( "table" );
	String logicalTableName;
	String physicalTableName;
	if ( tableNameNode == null ) {
		logicalTableName = StringHelper.unqualify( model.getEntityName() );
		physicalTableName = getNamingStrategyDelegate( mappings ).determineImplicitPrimaryTableName(
				model.getEntityName(),
				model.getJpaEntityName()
		);
	}
	else {
		logicalTableName = tableNameNode.getValue();
		physicalTableName = getNamingStrategyDelegate( mappings ).toPhysicalTableName( logicalTableName );
	}
	mappings.addTableBinding( schema, catalog, logicalTableName, physicalTableName, denormalizedSuperTable );
	return physicalTableName;
}
 
Example 4
Project: lams   File: HbmBinder.java   View Source Code Vote up 6 votes
private static OptimisticLockStyle getOptimisticLockStyle(Attribute olAtt) throws MappingException {
	if ( olAtt == null ) {
		return OptimisticLockStyle.VERSION;
	}

	final String olMode = olAtt.getValue();
	if ( olMode == null || "version".equals( olMode ) ) {
		return OptimisticLockStyle.VERSION;
	}
	else if ( "dirty".equals( olMode ) ) {
		return OptimisticLockStyle.DIRTY;
	}
	else if ( "all".equals( olMode ) ) {
		return OptimisticLockStyle.ALL;
	}
	else if ( "none".equals( olMode ) ) {
		return OptimisticLockStyle.NONE;
	}
	else {
		throw new MappingException( "Unsupported optimistic-lock style: " + olMode );
	}
}
 
Example 5
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View Source Code Vote up 5 votes
/**
 *  Gets the URL to the collection's scope statement.
 *
 * @return                The URL to the collection's scope statement, or null if none.
 * @exception  Exception  If error
 */
protected String getScopeUrl() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='policies']/*[local-name()='policy'][@type='Collection scope']/@url");
	if (nodes == null || nodes.size() == 0)
		return null;
	Attribute attrib = (Attribute) nodes.get(0);
	return attrib.getValue();
}
 
Example 6
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View Source Code Vote up 5 votes
/**
 *  Gets the URL to the collection's review process statement.
 *
 * @return                The URL to the collection's review process statement.
 * @exception  Exception  If error
 */
protected String getReviewProcessUrl() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/*[local-name()='collectionRecord']/*[local-name()='general']/*[local-name()='reviewProcess']/@url");
	if (nodes.size() > 1)
		prtln("More than one review process URL!");
	if (nodes.size() == 0)
		return null;
	Attribute attrib = (Attribute) nodes.get(0);
	return attrib.getValue();
}
 
Example 7
Project: lams   File: Configuration.java   View Source Code Vote up 5 votes
public void add(XmlDocument metadataXml) {
	final Document document = metadataXml.getDocumentTree();
	final Element hmNode = document.getRootElement();
	Attribute packNode = hmNode.attribute( "package" );
	String defaultPackage = packNode != null ? packNode.getValue() : "";
	Set<String> entityNames = new HashSet<String>();
	findClassNames( defaultPackage, hmNode, entityNames );
	for ( String entity : entityNames ) {
		hbmMetadataByEntityNameXRef.put( entity, metadataXml );
	}
	this.hbmMetadataToEntityNamesMap.put( metadataXml, entityNames );
}
 
Example 8
Project: lams   File: Configuration.java   View Source Code Vote up 5 votes
private String getClassName(Attribute name, String defaultPackage) {
	if ( name == null ) {
		return null;
	}
	String unqualifiedName = name.getValue();
	if ( unqualifiedName == null ) {
		return null;
	}
	if ( unqualifiedName.indexOf( '.' ) < 0 && defaultPackage != null ) {
		return defaultPackage + '.' + unqualifiedName;
	}
	return unqualifiedName;
}
 
Example 9
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void bindImport(Element importNode, Mappings mappings) {
	String className = getClassName( importNode.attribute( "class" ), mappings );
	Attribute renameNode = importNode.attribute( "rename" );
	String rename = ( renameNode == null ) ?
					StringHelper.unqualify( className ) :
					renameNode.getValue();
	LOG.debugf( "Import: %s -> %s", rename, className );
	mappings.addImport( className, rename );
}
 
Example 10
Project: parabuild-ci   File: Binder.java   View Source Code Vote up 5 votes
public static void bindOneToOne(Element node, OneToOne model, boolean isNullable, Mappings mappings) throws MappingException {
	//bindColumns(node, model, isNullable, false, null, mappings);
	initOuterJoinFetchSetting(node, model);

	Attribute constrNode = node.attribute("constrained");
	boolean constrained = constrNode!=null && constrNode.getValue().equals("true");
	model.setConstrained(constrained);

	model.setForeignKeyType(
		constrained ?
		ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
		ForeignKeyDirection.FOREIGN_KEY_TO_PARENT
	);

	Attribute fkNode = node.attribute("foreign-key");
	if (fkNode!=null) model.setForeignKeyName( fkNode.getValue() );
	
	Attribute ukName = node.attribute("property-ref");
	if (ukName!=null) model.setReferencedPropertyName( ukName.getValue() );
	
	Attribute classNode = node.attribute("class");
	if (classNode!=null) {
		try {
			model.setType( TypeFactory.oneToOne(
				ReflectHelper.classForName( getClassName(classNode, mappings) ),
				model.getForeignKeyType(),
				model.getReferencedPropertyName()
			) );
		}
		catch (Exception e) {
			throw new MappingException( "Could not find class: " + classNode.getValue() );
		}
	}

}
 
Example 11
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void bindUniqueKey(Attribute uniqueKeyAttribute, Table table, Column column, Mappings mappings) {
	if ( uniqueKeyAttribute != null && table != null ) {
		StringTokenizer tokens = new StringTokenizer( uniqueKeyAttribute.getValue(), ", " );
		while ( tokens.hasMoreTokens() ) {
			table.getOrCreateUniqueKey( tokens.nextToken() ).addColumn( column );
		}
	}
}
 
Example 12
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings)
		throws MappingException {
	String typeName = null;

	Properties parameters = new Properties();

	Attribute typeNode = node.attribute( "type" );
       if ( typeNode == null ) {
           typeNode = node.attribute( "id-type" ); // for an any
       }
       else {
           typeName = typeNode.getValue();
       }

	Element typeChild = node.element( "type" );
	if ( typeName == null && typeChild != null ) {
		typeName = typeChild.attribute( "name" ).getValue();
		Iterator typeParameters = typeChild.elementIterator( "param" );

		while ( typeParameters.hasNext() ) {
			Element paramElement = (Element) typeParameters.next();
			parameters.setProperty(
					paramElement.attributeValue( "name" ),
					paramElement.getTextTrim()
				);
		}
	}

	resolveAndBindTypeDef(simpleValue, mappings, typeName, parameters);
}
 
Example 13
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
public static String getTypeFromXML(Element node) throws MappingException {
	// TODO: handle TypeDefs
	Attribute typeNode = node.attribute( "type" );
	if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any
	if ( typeNode == null ) return null; // we will have to use reflection
	return typeNode.getValue();
}
 
Example 14
Project: pub-service   File: Utils.java   View Source Code Vote up 4 votes
public static String parseDOM4J(Document doc) {    
    Element root = doc.getRootElement();
    Attribute resultAttr=root.attribute("result");
    String result=resultAttr.getValue();
    return result;
}
 
Example 15
Project: lams   File: NamedSQLQuerySecondPass.java   View Source Code Vote up 4 votes
public void doSecondPass(Map persistentClasses) throws MappingException {
	String queryName = queryElem.attribute( "name" ).getValue();
	if (path!=null) queryName = path + '.' + queryName;

	boolean cacheable = "true".equals( queryElem.attributeValue( "cacheable" ) );
	String region = queryElem.attributeValue( "cache-region" );
	Attribute tAtt = queryElem.attribute( "timeout" );
	Integer timeout = tAtt == null ? null : Integer.valueOf( tAtt.getValue() );
	Attribute fsAtt = queryElem.attribute( "fetch-size" );
	Integer fetchSize = fsAtt == null ? null : Integer.valueOf( fsAtt.getValue() );
	Attribute roAttr = queryElem.attribute( "read-only" );
	boolean readOnly = roAttr != null && "true".equals( roAttr.getValue() );
	Attribute cacheModeAtt = queryElem.attribute( "cache-mode" );
	String cacheMode = cacheModeAtt == null ? null : cacheModeAtt.getValue();
	Attribute cmAtt = queryElem.attribute( "comment" );
	String comment = cmAtt == null ? null : cmAtt.getValue();

	java.util.List<String> synchronizedTables = new ArrayList<String>();
	Iterator tables = queryElem.elementIterator( "synchronize" );
	while ( tables.hasNext() ) {
		synchronizedTables.add( ( (Element) tables.next() ).attributeValue( "table" ) );
	}
	boolean callable = "true".equals( queryElem.attributeValue( "callable" ) );

	NamedSQLQueryDefinition namedQuery;
	Attribute ref = queryElem.attribute( "resultset-ref" );
	String resultSetRef = ref == null ? null : ref.getValue();
	if ( StringHelper.isNotEmpty( resultSetRef ) ) {
		namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName )
				.setQuery( queryElem.getText() )
				.setResultSetRef( resultSetRef )
				.setQuerySpaces( synchronizedTables )
				.setCacheable( cacheable )
				.setCacheRegion( region )
				.setTimeout( timeout )
				.setFetchSize( fetchSize )
				.setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) )
				.setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) )
				.setReadOnly( readOnly )
				.setComment( comment )
				.setParameterTypes( HbmBinder.getParameterTypes( queryElem ) )
				.setCallable( callable )
				.createNamedQueryDefinition();
		//TODO check there is no actual definition elemnents when a ref is defined
	}
	else {
		ResultSetMappingDefinition definition = buildResultSetMappingDefinition( queryElem, path, mappings );
		namedQuery = new NamedSQLQueryDefinitionBuilder().setName( queryName )
				.setQuery( queryElem.getText() )
				.setQueryReturns( definition.getQueryReturns() )
				.setQuerySpaces( synchronizedTables )
				.setCacheable( cacheable )
				.setCacheRegion( region )
				.setTimeout( timeout )
				.setFetchSize( fetchSize )
				.setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) )
				.setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) )
				.setReadOnly( readOnly )
				.setComment( comment )
				.setParameterTypes( HbmBinder.getParameterTypes( queryElem ) )
				.setCallable( callable )
				.createNamedQueryDefinition();
	}

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Named SQL query: %s -> %s", namedQuery.getName(), namedQuery.getQueryString() );
	}
	mappings.addSQLQuery( queryName, namedQuery );
}
 
Example 16
Project: lams   File: HbmBinder.java   View Source Code Vote up 4 votes
private static void bindPersistentClassCommonValues(Element node, PersistentClass entity,
		Mappings mappings, java.util.Map inheritedMetas) throws MappingException {
	// DISCRIMINATOR
	Attribute discriminatorNode = node.attribute( "discriminator-value" );
	entity.setDiscriminatorValue( ( discriminatorNode == null )
		? entity.getEntityName()
		: discriminatorNode.getValue() );

	// DYNAMIC UPDATE
	Attribute dynamicNode = node.attribute( "dynamic-update" );
	entity.setDynamicUpdate(
			dynamicNode != null && "true".equals( dynamicNode.getValue() )
	);

	// DYNAMIC INSERT
	Attribute insertNode = node.attribute( "dynamic-insert" );
	entity.setDynamicInsert(
			insertNode != null && "true".equals( insertNode.getValue() )
	);

	// IMPORT
	mappings.addImport( entity.getEntityName(), entity.getEntityName() );
	if ( mappings.isAutoImport() && entity.getEntityName().indexOf( '.' ) > 0 ) {
		mappings.addImport(
				entity.getEntityName(),
				StringHelper.unqualify( entity.getEntityName() )
			);
	}

	// BATCH SIZE
	Attribute batchNode = node.attribute( "batch-size" );
	if ( batchNode != null ) entity.setBatchSize( Integer.parseInt( batchNode.getValue() ) );

	// SELECT BEFORE UPDATE
	Attribute sbuNode = node.attribute( "select-before-update" );
	if ( sbuNode != null ) entity.setSelectBeforeUpdate( "true".equals( sbuNode.getValue() ) );

	// OPTIMISTIC LOCK MODE
	Attribute olNode = node.attribute( "optimistic-lock" );
	entity.setOptimisticLockStyle( getOptimisticLockStyle( olNode ) );

	entity.setMetaAttributes( getMetas( node, inheritedMetas ) );

	// PERSISTER
	Attribute persisterNode = node.attribute( "persister" );
	if ( persisterNode != null ) {
		try {
			entity.setEntityPersisterClass( ReflectHelper.classForName(
					persisterNode
							.getValue()
			) );
		}
		catch (ClassNotFoundException cnfe) {
			throw new MappingException( "Could not find persister class: "
				+ persisterNode.getValue() );
		}
	}

	// CUSTOM SQL
	handleCustomSQL( node, entity );

	Iterator tables = node.elementIterator( "synchronize" );
	while ( tables.hasNext() ) {
		entity.addSynchronizedTable( ( (Element) tables.next() ).attributeValue( "table" ) );
	}

	Attribute abstractNode = node.attribute( "abstract" );
	Boolean isAbstract = abstractNode == null
			? null
	        : "true".equals( abstractNode.getValue() )
					? Boolean.TRUE
                    : "false".equals( abstractNode.getValue() )
							? Boolean.FALSE
                            : null;
	entity.setAbstract( isAbstract );
}
 
Example 17
Project: pub-service   File: SmsSenderLT.java   View Source Code Vote up 4 votes
private static String parseDOM4J(Document doc) {    
    Element root = doc.getRootElement();
    Attribute resultAttr=root.attribute("result");
    String result=resultAttr.getValue();
    return result;
}
 
Example 18
Project: lams   File: HbmBinder.java   View Source Code Vote up 4 votes
public static void bindJoinedSubclass(Element node, JoinedSubclass joinedSubclass,
		Mappings mappings, java.util.Map inheritedMetas) throws MappingException {

	bindClass( node, joinedSubclass, mappings, inheritedMetas );
	inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from
																// <joined-subclass>

	// joined subclasses
	Attribute schemaNode = node.attribute( "schema" );
	String schema = schemaNode == null ?
			mappings.getSchemaName() : schemaNode.getValue();

	Attribute catalogNode = node.attribute( "catalog" );
	String catalog = catalogNode == null ?
			mappings.getCatalogName() : catalogNode.getValue();

	Table mytable = mappings.addTable(
			schema,
			catalog,
			getClassTableName( joinedSubclass, node, schema, catalog, null, mappings ),
			getSubselect( node ),
			false
		);
	joinedSubclass.setTable( mytable );
	bindComment(mytable, node);

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Mapping joined-subclass: %s -> %s", joinedSubclass.getEntityName(), joinedSubclass.getTable().getName() );
	}

	// KEY
	Element keyNode = node.element( "key" );
	SimpleValue key = new DependantValue( mappings, mytable, joinedSubclass.getIdentifier() );
	joinedSubclass.setKey( key );
	key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );
	bindSimpleValue( keyNode, key, false, joinedSubclass.getEntityName(), mappings );

	// model.getKey().setType( new Type( model.getIdentifier() ) );
	joinedSubclass.createPrimaryKey();
	joinedSubclass.createForeignKey();

	// CHECK
	Attribute chNode = node.attribute( "check" );
	if ( chNode != null ) mytable.addCheckConstraint( chNode.getValue() );

	// properties
	createClassProperties( node, joinedSubclass, mappings, inheritedMetas );

}
 
Example 19
Project: lams   File: HbmBinder.java   View Source Code Vote up 4 votes
private static void bindManyToManySubelements(
        Collection collection,
        Element manyToManyNode,
        Mappings model) throws MappingException {
	// Bind the where
	Attribute where = manyToManyNode.attribute( "where" );
	String whereCondition = where == null ? null : where.getValue();
	collection.setManyToManyWhere( whereCondition );

	// Bind the order-by
	Attribute order = manyToManyNode.attribute( "order-by" );
	String orderFragment = order == null ? null : order.getValue();
	collection.setManyToManyOrdering( orderFragment );

	// Bind the filters
	Iterator filters = manyToManyNode.elementIterator( "filter" );
	if ( ( filters.hasNext() || whereCondition != null ) &&
	        collection.getFetchMode() == FetchMode.JOIN &&
	        collection.getElement().getFetchMode() != FetchMode.JOIN ) {
		throw new MappingException(
		        "many-to-many defining filter or where without join fetching " +
		        "not valid within collection using join fetching [" + collection.getRole() + "]"
			);
	}
	final boolean debugEnabled = LOG.isDebugEnabled();
	while ( filters.hasNext() ) {
		final Element filterElement = ( Element ) filters.next();
		final String name = filterElement.attributeValue( "name" );
		String condition = filterElement.getTextTrim();
		if ( StringHelper.isEmpty(condition) ) condition = filterElement.attributeValue( "condition" );
		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"));
		}
		if ( debugEnabled ) {
			LOG.debugf( "Applying many-to-many filter [%s] as [%s] to role [%s]", name, condition, collection.getRole() );
		}
		String autoAliasInjectionText = filterElement.attributeValue("autoAliasInjection");
		boolean autoAliasInjection = StringHelper.isEmpty(autoAliasInjectionText) ? true : Boolean.parseBoolean(autoAliasInjectionText);
		collection.addManyToManyFilter(name, condition, autoAliasInjection, aliasTables, null);
	}
}
 
Example 20
Project: Divinity_Original_Sin_2_zhCN   File: DOS2Extract.java   View Source Code Vote up 4 votes
/**
 * 从两个xml中提取增量文本xml
 * 
 * @param document
 * @param documentInc
 * @param autoMaxDiffereceLimit 定义差异度超过 xx % 才会添加到增量文本中
 * @param printAll 是否打印结果
 * @return
 * @throws Exception
 */
@Override
public Document extractIncrement(Document document, Document documentInc,
    int autoMaxDiffereceLimit, boolean print) throws Exception {
  if (autoMaxDiffereceLimit > 0) {
    double f = autoMaxDiffereceLimit * 1.0 / 100.0;
    /**
     * 以第一个文本为比较基准,比较两版汉化文本,输出差异程度
     */
    List<DiffResult> list =
        TextUtils.diff(documentInc, document, documentToMap, true, false, false);
    List<DiffResult> result = new ArrayList<DiffResult>(list.size());
    List<DiffResult> ignore = new ArrayList<DiffResult>(list.size());
    for (DiffResult res : list) {
      if (res.getDifference() >= f) {
        result.add(res);
      } else {
        ignore.add(res);
      }
    }
    /**
     * 根据节点数据,生成增量文本xml
     */
    boolean buildNew = false;
    Document doc = extractIncrement(result, buildNew, print);
    if (print) {
      System.out.println("\n\n----------------------------以下文本低于差异度" + (autoMaxDiffereceLimit)
          + "%不会替换生成增量文本-----------------");
      // 打印不处理的部分
      for (DiffResult nodeResult : ignore) {
        System.out.println(nodeResult.getContentuid() + "="
            + (buildNew ? (nodeResult.getText() + "|" + nodeResult.getNewText())
                : (nodeResult.getNewText() + "|" + nodeResult.getText())));
      }
    }
    return doc;
  }
  Map<String, String> mOri = documentToMap.toMap(document);
  // 获取根节点元素对象
  Element root = documentInc.getRootElement();
  // 子节点
  List<Element> es = root.elements();
  // 使用递归
  Iterator<Element> iterator = es.iterator();
  while (iterator.hasNext()) {
    Element e = iterator.next();
    Attribute attribute = e.attribute("contentuid");
    // System.out.println("属性"+attribute.getName() +":" + attribute.getValue());
    String contentuid = attribute.getValue();
    String newText = e.getText().trim();
    String text = (String) mOri.get(contentuid);
    if (("".equals(text) && "".equals(newText)) || (text.trim().equals(newText))) {
      e.detach();
    } else {
      if (print)
        System.out.println(contentuid + "=" + text + "|" + newText);
    }
  }

  return documentInc;
}