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

The following are Jave code examples for showing how to use attribute() 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: parabuild-ci   File: Binder.java   View Source Code Vote up 6 votes
public static void bindSimpleValue(Element node, SimpleValue model, boolean isNullable, String path, Mappings mappings) 
throws MappingException {
	model.setType( getTypeFromXML(node) );

	Attribute formulaNode = node.attribute("formula");
	if (formulaNode!=null) {
		Formula f = new Formula();
		f.setFormula( formulaNode.getText() );
		model.setFormula(f);
	}
	else {
		bindColumns(node, model, isNullable, true, path, mappings);
	}

	Attribute fkNode = node.attribute("foreign-key");
	if (fkNode!=null) model.setForeignKeyName( fkNode.getValue() );
}
 
Example 2
Project: GraphicsViewJambi   File: ExportNetworkToXML.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public boolean addJunctionConnection(final String id, final String fromNode, 
									  final String from_x, final String from_y, 
									  final String toNode, 
									  final String to_x, final String to_y, 
									  final String dir)
{
	String s = "intconnction[@fromNode='"+fromNode+"' and @toNode='"+toNode+"']";
	List<Element> list = junction.selectNodes(s);
	if(list.isEmpty())
	{
		intconnction = junction.addElement("intconnction");
		intconnction.addAttribute("id", id);
		intconnction.addAttribute("numLanes", "1");
		intconnction.addAttribute("fromNode", fromNode);
		intconnction.addAttribute("from_x", from_x);
		intconnction.addAttribute("from_y", from_y);
		intconnction.addAttribute("toNode", toNode);
		intconnction.addAttribute("to_x", to_x);
		intconnction.addAttribute("to_y", to_y);
		intconnction.addAttribute("dir", dir);
		return true;
	}
	else
	{
		Iterator<Element> iter = list.iterator();
		//System.out.println(list.size());
		while (iter.hasNext())
		{
			Element ele = iter.next();
			Attribute attr = ele.attribute("numLanes");
			Integer numLanes = Integer.parseInt(attr.getValue())+1;
			attr.setValue(numLanes.toString());
		}
		//System.out.println("有重复的lane");
		return false;
	}
}
 
Example 3
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path,
		boolean isNullable, Mappings mappings) {
	Attribute formulaNode = node.attribute( "formula" );
	if ( formulaNode != null ) {
		Formula f = new Formula();
		f.setFormula( formulaNode.getText() );
		simpleValue.addFormula( f );
	}
	else {
		bindColumns( node, simpleValue, isNullable, true, path, mappings );
	}
}
 
Example 4
Project: parabuild-ci   File: CheckMessages.java   View Source Code Vote up 5 votes
public Attribute checkAttribute(Node node, String attrName) throws DocumentException {
	if (!(node instanceof Element))
		throw new CheckMessagesException("Node is not an element", this, node);
	Element element = (Element) node;
	Attribute attr = element.attribute(attrName);
	if (attr == null)
		throw new CheckMessagesException("Missing " + attrName + " attribute", this, node);
	return attr;
}
 
Example 5
Project: alfresco-repository   File: GlobalPermissionEntry.java   View Source Code Vote up 5 votes
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
{
    Attribute authorityAttribute = element.attribute(AUTHORITY);
    if(authorityAttribute != null)
    {
        authority = authorityAttribute.getStringValue();
    }
    Attribute permissionAttribute = element.attribute(PERMISSION);
    if(permissionAttribute != null)
    {
        permissionReference = permissionModel.getPermissionReference(null, permissionAttribute.getStringValue());
    }

}
 
Example 6
Project: parabuild-ci   File: Binder.java   View Source Code Vote up 5 votes
private static Type getTypeFromXML(Element node) throws MappingException {
	Type type;
	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
	}
	else {
		type = TypeFactory.heuristicType( typeNode.getValue() );
		if (type==null) throw new MappingException( "Could not interpret type: " + typeNode.getValue() );
	}
	return type;
}
 
Example 7
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "inheritance" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
		Attribute attr = element.attribute( "strategy" );
		InheritanceType strategy = InheritanceType.SINGLE_TABLE;
		if ( attr != null ) {
			String value = attr.getValue();
			if ( "SINGLE_TABLE".equals( value ) ) {
				strategy = InheritanceType.SINGLE_TABLE;
			}
			else if ( "JOINED".equals( value ) ) {
				strategy = InheritanceType.JOINED;
			}
			else if ( "TABLE_PER_CLASS".equals( value ) ) {
				strategy = InheritanceType.TABLE_PER_CLASS;
			}
			else {
				throw new AnnotationException(
						"Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "strategy", strategy );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( Inheritance.class );
	}
	else {
		return null;
	}
}
 
Example 8
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static final void makeVersion(Element node, SimpleValue model) {

		// VERSION UNSAVED-VALUE
		Attribute nullValueNode = node.attribute( "unsaved-value" );
		if ( nullValueNode != null ) {
			model.setNullValue( nullValueNode.getValue() );
		}
		else {
			model.setNullValue( "undefined" );
		}

	}
 
Example 9
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static boolean isCallable(Element element, boolean supportsCallable)
		throws MappingException {
	Attribute attrib = element.attribute( "callable" );
	if ( attrib != null && "true".equals( attrib.getValue() ) ) {
		if ( !supportsCallable ) {
			throw new MappingException( "callable attribute not supported yet!" );
		}
		return true;
	}
	return false;
}
 
Example 10
Project: Divinity_Original_Sin_2_zhCN   File: DOS2Replace.java   View Source Code Vote up 5 votes
@Override
public Document replaceAll(Document document, Map<String, String> pro) {
  /**
   * <contentList> <content contentuid=
   * "h00007224gb454g4b8bgb762g7865d9ee3dbb">如果不是这样的话!哈,开玩笑啦,我们在一起很合适,就像面包上的果酱。你想和我组队吗?我敢说你们需要一点野兽风味!</content>
   * <content contentuid="h0001d8b9g13d6g4605g85e9g708fe1e537c8">定制</content> </contentList>
   */
  // 获取根节点元素对象
  Element root = document.getRootElement();
  // 子节点
  List<Element> list = root.elements();
  // 使用递归
  Iterator<Element> iterator = list.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 text = e.getText();
    String newText = (String) pro.get(contentuid);
    if (newText != null && !"".equals(newText)) {
      e.setText(newText);
      // System.out.println(contentuid + "=" + text + "|" + newText);
      // System.out.println(contentuid + "=" + newText);
    }
  }
  return document;
}
 
Example 11
Project: parabuild-ci   File: Filter.java   View Source Code Vote up 5 votes
private Matcher getMatcher(Element element) throws FilterException {
	// These will be either BugCode, Method, or Or elements.
	String name = element.getName();
	if (name.equals("BugCode")) {
		return new BugCodeMatcher(element.valueOf("@name"));
	} else if (name.equals("Method")) {
		Attribute nameAttr = element.attribute("name");
		Attribute paramsAttr = element.attribute("params");
		Attribute returnsAttr = element.attribute("returns");

		if (nameAttr == null)
			throw new FilterException("Missing name attribute in Method element");

		if ((paramsAttr != null || returnsAttr != null) && (paramsAttr == null || returnsAttr == null))
			throw new FilterException("Method element must have both params and returns attributes if either is used");

		if (paramsAttr == null)
			return new MethodMatcher(nameAttr.getValue());
		else
			return new MethodMatcher(nameAttr.getValue(), paramsAttr.getValue(), returnsAttr.getValue());
	} else if (name.equals("Or")) {
		OrMatcher orMatcher = new OrMatcher();
		Iterator i = element.elementIterator();
		while (i.hasNext()) {
			orMatcher.addChild(getMatcher((Element) i.next()));
		}
		return orMatcher;
	} else
		throw new FilterException("Unknown element: " + name);
}
 
Example 12
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
public static void bindSimpleValue(Element node, SimpleValue simpleValue, boolean isNullable,
		String path, Mappings mappings) throws MappingException {
	bindSimpleValueType( node, simpleValue, mappings );

	bindColumnsOrFormula( node, simpleValue, path, isNullable, mappings );

	Attribute fkNode = node.attribute( "foreign-key" );
	if ( fkNode != null ) simpleValue.setForeignKeyName( fkNode.getValue() );
}
 
Example 13
Project: parabuild-ci   File: Binder.java   View Source Code Vote up 4 votes
private static void makeIdentifier(Element node, SimpleValue model, Mappings mappings)
        throws MappingException {
	//GENERATOR

	Element subnode = node.element("generator");
	if ( subnode!=null ) {
		model.setIdentifierGeneratorStrategy( subnode.attributeValue("class") );

		Properties params = new Properties();

		if ( mappings.getSchemaName()!=null ) {
			params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
		}

		params.setProperty( PersistentIdentifierGenerator.TABLE, model.getTable().getName() );

		params.setProperty(
			PersistentIdentifierGenerator.PK,
			( (Column) model.getColumnIterator().next() ).getName()
		);

		Iterator iter = subnode.elementIterator("param");
		while( iter.hasNext() ) {
			Element childNode = (Element) iter.next();
			params.setProperty(
				childNode.attributeValue("name"),
				childNode.getText()
			);
		}

		model.setIdentifierGeneratorProperties(params);
	}

	model.getTable().setIdentifierValue(model);

	// ID UNSAVED-VALUE
	Attribute nullValueNode = node.attribute("unsaved-value");
	if (nullValueNode!=null) {
		model.setNullValue( nullValueNode.getValue() );
	}
	else {
		model.setNullValue("null");
	}
}
 
Example 14
Project: lams   File: HbmBinder.java   View Source Code Vote up 4 votes
private static void makeIdentifier(Element node, SimpleValue model, Mappings mappings) {

		// GENERATOR
		Element subnode = node.element( "generator" );
		if ( subnode != null ) {
			final String generatorClass = subnode.attributeValue( "class" );
			model.setIdentifierGeneratorStrategy( generatorClass );

			Properties params = new Properties();
			// YUCK!  but cannot think of a clean way to do this given the string-config based scheme
			params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer() );

			if ( mappings.getSchemaName() != null ) {
				params.setProperty(
						PersistentIdentifierGenerator.SCHEMA,
						mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getSchemaName() )
				);
			}
			if ( mappings.getCatalogName() != null ) {
				params.setProperty(
						PersistentIdentifierGenerator.CATALOG,
						mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getCatalogName() )
				);
			}

			Iterator iter = subnode.elementIterator( "param" );
			while ( iter.hasNext() ) {
				Element childNode = (Element) iter.next();
				params.setProperty( childNode.attributeValue( "name" ), childNode.getTextTrim() );
			}

			model.setIdentifierGeneratorProperties( params );
		}

		model.getTable().setIdentifierValue( model );

		// ID UNSAVED-VALUE
		Attribute nullValueNode = node.attribute( "unsaved-value" );
		if ( nullValueNode != null ) {
			model.setNullValue( nullValueNode.getValue() );
		}
		else {
			if ( "assigned".equals( model.getIdentifierGeneratorStrategy() ) ) {
				model.setNullValue( "undefined" );
			}
			else {
				model.setNullValue( null );
			}
		}
	}
 
Example 15
Project: alfresco-repository   File: Permission.java   View Source Code Vote up 4 votes
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
{
    super.initialise(element, nspr, permissionModel);
    
    Attribute att = element.attribute(EXPOSE);
    if (att != null)
    {
        isExposed = Boolean.parseBoolean(att.getStringValue());
    }
    else
    {
        isExposed = true;
    }
    
    att = element.attribute(REQUIRES_TYPE);
    if (att != null)
    {
        requiresType = Boolean.parseBoolean(att.getStringValue());
    }
    else
    {
        requiresType = true;
    }
    
    Attribute defaultPermissionAttribute = element.attribute(DEFAULT_PERMISSION);
    if(defaultPermissionAttribute != null)
    {
        if(defaultPermissionAttribute.getStringValue().equalsIgnoreCase(ALLOW))
        {
            defaultPermission = AccessStatus.ALLOWED;  
        }
        else if(defaultPermissionAttribute.getStringValue().equalsIgnoreCase(DENY))
        {
            defaultPermission = AccessStatus.DENIED;  
        }
        else
        {
            throw new PermissionModelException("The default permission must be deny or allow");
        }
    }
    else
    {
        defaultPermission = AccessStatus.DENIED;
    }
    
    for (Iterator gtgit = element.elementIterator(GRANTED_TO_GROUP); gtgit.hasNext(); /**/)
    {
        QName qName;
        Element grantedToGroupsElement = (Element) gtgit.next();
        Attribute typeAttribute = grantedToGroupsElement.attribute(GTG_TYPE);
        if (typeAttribute != null)
        {
            qName = QName.createQName(typeAttribute.getStringValue(), nspr);
        }
        else
        {
            qName = getTypeQName();
        }

        String grantedName = grantedToGroupsElement.attributeValue(GTG_NAME);
        
        grantedToGroups.add(PermissionReferenceImpl.getPermissionReference(qName, grantedName));
    }
}
 
Example 16
Project: lams   File: HbmBinder.java   View Source Code Vote up 4 votes
public static void bindOneToOne(Element node, OneToOne oneToOne, String path, boolean isNullable,
		Mappings mappings) throws MappingException {

	bindColumns( node, oneToOne, isNullable, false, null, mappings );

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

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

	initOuterJoinFetchSetting( node, oneToOne );
	initLaziness( node, oneToOne, mappings, true );

	String embed = node.attributeValue( "embed-xml" );
	// sometimes embed is set to the default value when not specified in the mapping,
	// so can't seem to determine if an attribute was explicitly set;
	// log a warning if embed has a value different from the default.
	if ( !StringHelper.isEmpty( embed ) &&  !"true".equals( embed ) ) {
		LOG.embedXmlAttributesNoLongerSupported();
	}
	oneToOne.setEmbedded( "true".equals( embed ) );

	Attribute fkNode = node.attribute( "foreign-key" );
	if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() );

	Attribute ukName = node.attribute( "property-ref" );
	if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() );
	oneToOne.setReferenceToPrimaryKey( oneToOne.getReferencedPropertyName() == null );

	oneToOne.setPropertyName( node.attributeValue( "name" ) );

	oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );

	String cascade = node.attributeValue( "cascade" );
	if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
		if ( oneToOne.isConstrained() ) {
			throw new MappingException(
					"one-to-one attribute [" + path + "] does not support orphan delete as it is constrained"
			);
		}
	}
}
 
Example 17
Project: lams   File: Configuration.java   View Source Code Vote up 4 votes
private void parseMappingElement(Element mappingElement, String name) {
	final Attribute resourceAttribute = mappingElement.attribute( "resource" );
	final Attribute fileAttribute = mappingElement.attribute( "file" );
	final Attribute jarAttribute = mappingElement.attribute( "jar" );
	final Attribute packageAttribute = mappingElement.attribute( "package" );
	final Attribute classAttribute = mappingElement.attribute( "class" );

	if ( resourceAttribute != null ) {
		final String resourceName = resourceAttribute.getValue();
		LOG.debugf( "Session-factory config [%s] named resource [%s] for mapping", name, resourceName );
		addResource( resourceName );
	}
	else if ( fileAttribute != null ) {
		final String fileName = fileAttribute.getValue();
		LOG.debugf( "Session-factory config [%s] named file [%s] for mapping", name, fileName );
		addFile( fileName );
	}
	else if ( jarAttribute != null ) {
		final String jarFileName = jarAttribute.getValue();
		LOG.debugf( "Session-factory config [%s] named jar file [%s] for mapping", name, jarFileName );
		addJar( new File( jarFileName ) );
	}
	else if ( packageAttribute != null ) {
		final String packageName = packageAttribute.getValue();
		LOG.debugf( "Session-factory config [%s] named package [%s] for mapping", name, packageName );
		addPackage( packageName );
	}
	else if ( classAttribute != null ) {
		final String className = classAttribute.getValue();
		LOG.debugf( "Session-factory config [%s] named class [%s] for mapping", name, className );
		try {
			addAnnotatedClass( ReflectHelper.classForName( className ) );
		}
		catch ( Exception e ) {
			throw new MappingException(
					"Unable to load class [ " + className + "] declared in Hibernate configuration <mapping/> entry",
					e
			);
		}
	}
	else {
		throw new MappingException( "<mapping> element in configuration specifies no known attributes" );
	}
}
 
Example 18
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 19
Project: joai-project   File: FrameworkTester.java   View Source Code Vote up 4 votes
Document getEditableDocument1 (String filePath, MetaDataFramework framework) throws Exception, DocumentException {
	String rawXml;
	try {
		rawXml = Files.readFile (filePath).toString();
	} catch (IOException e) {
		throw new Exception (e.getMessage());
	}
	rawXml = SchemEditUtils.expandAmpersands(rawXml);
	// prtln (rawXml);
	Document doc = null;
	try {
		doc = Dom4jUtils.getXmlDocument(rawXml);
	} catch (DocumentException de) {
		throw new Exception (de.getMessage());
	} 
	// pp (doc);
	Element root = doc.getRootElement();
	Attribute schemaLocAtt = root.attribute ("schemaLocation");
	
	if (schemaLocAtt == null) {
		throw new Exception ("couldn't find schemaLocation attribute") ;
	}

	String targetNameSpace = schemaLocAtt.getText().split("\\s")[0];
	// prtln ("Document target namespace: " + targetNameSpace);
	
	String schemaLoc = schemaLocAtt.getText().split("\\s")[1];
	// prtln ("Document schema location: " + schemaLoc);

	String schemaHelperTNS = framework.getSchemaHelper().getTargetNamespace();
	
	if (!targetNameSpace.equals(schemaHelperTNS)) {
		throw new Exception ("document target namespace does not match schema helper (" + schemaHelperTNS + ")");
	}
	
	if (!schemaLoc.equals(framework.getSchemaURI())) {
		throw new Exception ("schema location does not match metadata framework (" + framework.getSchemaURI() + ")");
	}
	
	// doc = Dom4jUtils.localizeXml(doc, root.getName());
	doc = Dom4jUtils.localizeXml(doc);

	pp (doc);
	return doc;
}
 
Example 20
Project: lams   File: HbmBinder.java   View Source Code Vote up 3 votes
/**
 * Called for arrays and primitive arrays
 */
public static void bindArray(Element node, Array array, String prefix, String path,
		Mappings mappings, java.util.Map inheritedMetas) throws MappingException {

	bindCollection( node, array, prefix, path, mappings, inheritedMetas );

	Attribute att = node.attribute( "element-class" );
	if ( att != null ) array.setElementClassName( getClassName( att, mappings ) );

}