Java Code Examples for org.dom4j.Attribute

The following are top voted examples for showing how to use org.dom4j.Attribute. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: iBase4J-Common   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * Element to map
 * @param e
 * @param map
 */
public static void element2Map(Element e, Map<String, Object> map) {
    List<Object> list = e.elements();
    if (e.attributeCount() > 0) {
        for (Object attri : e.attributes()) {
            Attribute at = (Attribute)attri;
            map.put(at.getName(), at.getValue());
        }
    }
    if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
        return;
    } else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
        map.put("text", e.getText());
    }
    for (Object aList : list) {
        Element iter = (Element)aList;
        Map<String, Object> cMap = new HashMap<String, Object>();
        element2Map(iter, cMap);
        map.put(iter.getName(), cMap);
    }
}
 
Example 2
Project: automat   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
Example 3
Project: parabuild-ci   File: Binder.java   View source code 6 votes vote down vote up
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 4
Project: joai-project   File: SchemaProps.java   View source code 6 votes vote down vote up
public void init (Document  schemaDoc) {
	rootElement = schemaDoc.getRootElement();
	
	if (rootElement == null) {
		prtln ("SchemaProps ERROR: rootElement not found");
		return;
	}
	
	setProp ("namespace", rootElement.getNamespace());
	
	setDefaultProps ();
	
	for (Iterator i=rootElement.attributeIterator();i.hasNext();) {
		Attribute att = (Attribute)i.next();
		setProp (att.getName(), att.getValue());
	}
}
 
Example 5
Project: parabuild-ci   File: Binder.java   View source code 6 votes vote down vote up
public static void bindColumn(Element node, Column model, boolean isNullable) {
	Attribute lengthNode = node.attribute("length");
	if (lengthNode!=null) model.setLength( Integer.parseInt( lengthNode.getValue() ) );
	Attribute nullNode = node.attribute("not-null");
	model.setNullable( (nullNode!=null) ?
		!StringHelper.booleanValue( nullNode.getValue() ) :
		isNullable
	);
	Attribute unqNode = node.attribute("unique");
	model.setUnique( unqNode!=null && StringHelper.booleanValue( unqNode.getValue() ) );
	model.setCheckConstraint( node.attributeValue("check") );
	//Attribute qtNode = node.attribute("quote");
	//model.setQuoted( qtNode!=null && StringHelper.booleanValue( qtNode.getValue() ) );
	Attribute typeNode = node.attribute("sql-type");
	model.setSqlType( (typeNode==null) ? null : typeNode.getValue() );
}
 
Example 6
Project: atlas   File: ManifestFileUtils.java   View source code 6 votes vote down vote up
/**
 * Update the attributes of element
 *
 * @param element
 * @param properties
 */
private static void updateElement(Element element, Map<String, String> properties) {
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith("tools:")) {
            continue;
        }
        String keyNoPrefix = key;
        String[] values = StringUtils.split(key, ":");
        if (values.length > 1) {
            keyNoPrefix = values[1];
        }
        if (null == entry.getValue()) {
            continue;
        } else {
            Attribute attribute = element.attribute(keyNoPrefix);
            if (null != attribute) {
                attribute.setValue(entry.getValue());
            } else {
                element.addAttribute(key, entry.getValue());
            }
        }
    }
}
 
Example 7
Project: atlas   File: ManifestFileUtils.java   View source code 6 votes vote down vote up
/**
 * 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 8
Project: atlas   File: ManifestFileUtils.java   View source code 6 votes vote down vote up
public static String getVersionCode(File androidManifestFile) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    String versionCode = "";
    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(), "versionCode")) {
                    versionCode = attr.getValue();
                }
            }
        }
    }
    return versionCode;
}
 
Example 9
Project: parabuild-ci   File: Binder.java   View source code 6 votes vote down vote up
private static void initOuterJoinFetchSetting(Element node, Fetchable model) {
	Attribute jfNode = node.attribute("outer-join");
	if ( jfNode==null ) {
		model.setOuterJoinFetchSetting(OuterJoinLoader.AUTO);
	}
	else {
		String eoj = jfNode.getValue();
		if ( "auto".equals(eoj) ) {
			model.setOuterJoinFetchSetting(OuterJoinLoader.AUTO);
		}
		else {
			model.setOuterJoinFetchSetting(
				"true".equals(eoj) ? OuterJoinLoader.EAGER : OuterJoinLoader.LAZY
			);
		}
	}
}
 
Example 10
Project: lams   File: HbmBinder.java   View source code 6 votes vote down vote up
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 11
Project: lams   File: HbmBinder.java   View source code 6 votes vote down vote up
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 12
Project: xpath-to-xml   File: Dom4jNavigatorSpi.java   View source code 6 votes vote down vote up
@Override
public <T> T process(T xml, Iterable<Effect> effects) throws XmlBuilderException {
    if (!canHandle(xml)) {
        throw new IllegalArgumentException("XML model is not supported");
    }
    final Node xmlNode = (Node) xml;
    final Dom4jNode<?> node;
    switch (xmlNode.getNodeType()) {
        case Node.DOCUMENT_NODE:
            node = new Dom4jDocument((Document) xmlNode);
            break;
        case Node.ELEMENT_NODE:
            node = new Dom4jElement((Element) xmlNode);
            break;
        case Node.ATTRIBUTE_NODE:
            node = new Dom4jAttribute((Attribute) xmlNode);
            break;
        default:
            throw new IllegalArgumentException("XML node type is not supported");
    }
    final Navigator<Dom4jNode> navigator = new Dom4jNavigator(xmlNode);
    for (Effect effect : effects) {
        effect.perform(navigator, node);
    }
    return xml;
}
 
Example 13
Project: iBase4J   File: XmlUtil.java   View source code 6 votes vote down vote up
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
Example 14
Project: Divinity_Original_Sin_2_zhCN   File: DOS2ToMap.java   View source code 6 votes vote down vote up
@Override
public Map toMap(Document document) {
  Map<String, String> m = new HashMap<String, String>();
  /**
   * <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");
    m.put(attribute.getValue(), e.getText());
  }
  return m;
}
 
Example 15
Project: unitimes   File: LowercaseTableNames.java   View source code 6 votes vote down vote up
protected void writeAttributes(Element element) throws IOException {
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
        Attribute attribute = element.attribute(i);
           char quote = format.getAttributeQuoteCharacter();
           if (element.attributeCount() > 2) {
               writePrintln();
               indent();
               writer.write(format.getIndent());
           } else {
           	writer.write(" ");
           }
           writer.write(attribute.getQualifiedName());
           writer.write("=");
           writer.write(quote);
           writeEscapeAttributeEntities(attribute.getValue());
           writer.write(quote);
    }
}
 
Example 16
Project: parabuild-ci   File: Binder.java   View source code 6 votes vote down vote up
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 17
Project: parabuild-ci   File: Binder.java   View source code 6 votes vote down vote up
public static void bindManyToOne(Element node, ManyToOne model, String path, boolean isNullable, Mappings mappings) 
throws MappingException {
	bindColumns(node, model, isNullable, true, path, mappings);
	initOuterJoinFetchSetting(node, model);

	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.manyToOne( 
				ReflectHelper.classForName( getClassName(classNode, mappings) ), 
				model.getReferencedPropertyName()
			) );
		}
		catch (Exception e) {
			throw new MappingException( "Could not find class: " + classNode.getValue() );
		}
	}

	Attribute fkNode = node.attribute("foreign-key");
	if (fkNode!=null) model.setForeignKeyName( node.attributeValue("foreign-key") );
}
 
Example 18
Project: Reer   File: Dom4JUtility.java   View source code 5 votes vote down vote up
public static boolean getAttributeAsBoolean(Element element, String attributeName, boolean defaultValue) {
    Attribute attribute = element.attribute(attributeName);
    if (attribute == null) {
        return defaultValue;
    }

    return "true".equals(attribute.getValue());
}
 
Example 19
Project: iBase4J-Common   File: XmlUtil.java   View source code 5 votes vote down vote up
/**
 * 将XML规范的字符串转为List对象(XML基于节点属性值的方式)
 * 
 * @param pStrXml 传入的符合XML格式规范的字符串
 * @return list 返回List对象
 */
public static final List parseXml2List(String pStrXml) {
    List lst = new ArrayList();
    String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    Document document = null;
    try {
        if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml;
        document = DocumentHelper.parseText(pStrXml);
    } catch (DocumentException e) {
        logger.error("==开发人员请注意:==\n将XML格式的字符串转换为XML DOM对象时发生错误啦!" + "\n详细错误信息如下:", e);
    }
    // 获取到根节点
    Element elRoot = document.getRootElement();
    // 获取根节点的所有子节点元素
    Iterator elIt = elRoot.elementIterator();
    while (elIt.hasNext()) {
        Element el = (Element)elIt.next();
        Iterator attrIt = el.attributeIterator();
        Map map = new HashMap();
        while (attrIt.hasNext()) {
            Attribute attribute = (Attribute)attrIt.next();
            map.put(attribute.getName().toLowerCase(), attribute.getData());
        }
        lst.add(map);
    }
    return lst;
}
 
Example 20
Project: alfresco-repository   File: ModelPermissionEntry.java   View source code 5 votes vote down vote up
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
{
    Attribute recipientAttribute = element.attribute(RECIPIENT);
    if (recipientAttribute != null)
    {
        recipient = recipientAttribute.getStringValue();
    }
    else
    {
        recipient = null;
    }

    Attribute accessAttribute = element.attribute(ACCESS);
    if (accessAttribute != null)
    {
        if (accessAttribute.getStringValue().equalsIgnoreCase(ALLOW))
        {
            access = AccessStatus.ALLOWED;
        }
        else if (accessAttribute.getStringValue().equalsIgnoreCase(DENY))
        {
            access = AccessStatus.DENIED;
        }
        else
        {
            throw new PermissionModelException("The default permission must be deny or allow");
        }
    }
    else
    {
        access = AccessStatus.DENIED;
    }
    
    
    Element permissionReferenceElement = element.element(PERMISSION_REFERENCE);
    QName typeQName = QName.createQName(permissionReferenceElement.attributeValue(TYPE), nspr);
    String name = permissionReferenceElement.attributeValue(NAME);
    permissionReference = PermissionReferenceImpl.getPermissionReference(typeQName, name);
}
 
Example 21
Project: GraphicsViewJambi   File: ImportSumoNetwork.java   View source code 5 votes vote down vote up
/**
 * Manage all Attribute in a Node
 * 
 * @param node
 * 		Node to Manage
 * @param subNode   
 *      Sub Node or not
 */
@SuppressWarnings("unchecked")
private void manageAttributeInfo(final Element node, final boolean subNode)
{
	final String startVorString =  (subNode == false) ? "! Start Node --  ": "! Start SubNode --  "; 
	final String startHinString =  (subNode == false) ? "  -- Start Node ! ": "  -- Start SubNode !"; 
	final String endVorString =  (subNode == false) ? "! End Node --  ": "! End SubNode --  "; 
	final String endHinString =  (subNode == false) ? "  -- End Node !": "  -- End SubNode !"; 
	
	System.out.println("! ----------------------------------------------- !");
	System.out.println(startVorString + node.getName() + startHinString);
	final List<Attribute> list = node.attributes();
	for (final Attribute attr : list)
	{
		//System.out.println(attr.getText() + "\n" );
		System.out.println("  = > " + attr.getName() + " = " + attr.getValue() + ";" );
		//Do something to match related information in Node
		
	}
 
	if (!(node.getTextTrim().equals("")))
	{
		System.out.println("Text: " + node.getText());
	}
	System.out.println(endVorString + node.getName() + endHinString);
	System.out.println("! ----------------------------------------------- !\n");
}
 
Example 22
Project: bdf2   File: AbstractConverter.java   View source code 5 votes vote down vote up
protected void buildCommonGraphCellElement(Element element,Element targetElement){
	for(Object obj:element.attributes()){
		Attribute attr=(Attribute)obj;
		String name=attr.getName();
		if(name.equals("name") || name.equals("g")){
			continue;
		}
		targetElement.addAttribute(attr.getName(),attr.getValue());
	}
}
 
Example 23
Project: alfresco-repository   File: NodePermission.java   View source code 5 votes vote down vote up
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
{
   Attribute nodeRefAttribute = element.attribute(NODE_REF);
   if(nodeRefAttribute != null)
   {
       nodeRef = new NodeRef(nodeRefAttribute.getStringValue());
   }
   
   Attribute inheritFromParentAttribute = element.attribute(INHERIT_FROM_PARENT);
   if(inheritFromParentAttribute != null)
   {
       inheritPermissionsFromParent = Boolean.parseBoolean(inheritFromParentAttribute.getStringValue());
   }
   else
   {
       inheritPermissionsFromParent = true;
   }
   
   // Node Permissions Entry

   for (Iterator npit = element.elementIterator(NODE_PERMISSION); npit.hasNext(); /**/)
   {
       Element permissionEntryElement = (Element) npit.next();
       ModelPermissionEntry permissionEntry = new ModelPermissionEntry(nodeRef);
       permissionEntry.initialise(permissionEntryElement, nspr, permissionModel);
       permissionEntries.add(permissionEntry);
   }
    
}
 
Example 24
Project: alfresco-repository   File: GlobalPermissionEntry.java   View source code 5 votes vote down vote up
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 25
Project: automat   File: XmlUtil.java   View source code 5 votes vote down vote up
/**
 * 将XML规范的字符串转为List对象(XML基于节点属性值的方式)
 * 
 * @param pStrXml 传入的符合XML格式规范的字符串
 * @return list 返回List对象
 */
public static final List parseXml2List(String pStrXml) {
	List lst = new ArrayList();
	String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	Document document = null;
	try {
		if (pStrXml.indexOf("<?xml") < 0)
			pStrXml = strTitle + pStrXml;
		document = DocumentHelper.parseText(pStrXml);
	} catch (DocumentException e) {
		log.error("==开发人员请注意:==\n将XML格式的字符串转换为XML DOM对象时发生错误啦!" + "\n详细错误信息如下:", e);
	}
	// 获取到根节点
	Element elRoot = document.getRootElement();
	// 获取根节点的所有子节点元素
	Iterator elIt = elRoot.elementIterator();
	while (elIt.hasNext()) {
		Element el = (Element) elIt.next();
		Iterator attrIt = el.attributeIterator();
		Map map = new HashMap();
		while (attrIt.hasNext()) {
			Attribute attribute = (Attribute) attrIt.next();
			map.put(attribute.getName().toLowerCase(), attribute.getData());
		}
		lst.add(map);
	}
	return lst;
}
 
Example 26
Project: ats-framework   File: XmlNode.java   View source code 5 votes vote down vote up
public XmlNode( XmlNode parent, Element node ) {

        this.node = node;

        Namespace nodeNamespace = node.getNamespace();
        if (nodeNamespace != null && !StringUtils.isNullOrEmpty(nodeNamespace.getPrefix())) {
            this.name = nodeNamespace.getPrefix() + ":" + node.getName();
        } else {
            this.name = node.getName();
        }

        this.attributes = new TreeMap<>();
        for (int i = 0; i < node.attributes().size(); i++) {
            Attribute att = node.attribute(i);
            this.attributes.put(att.getName(), att.getValue());
        }

        this.value = this.node.getTextTrim();

        this.parent = parent;

        this.children = new ArrayList<>();
        List<Element> childrenElements = this.node.elements();
        for (Element child : childrenElements) {
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                this.children.add(new XmlNode(this, child));
            }
        }
    }
 
Example 27
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View source code 5 votes vote down vote up
/**
 *  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 28
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View source code 5 votes vote down vote up
/**
 *  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 29
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View source code 5 votes vote down vote up
/**
 *  Gets the format of the records in this collection.
 *
 * @return                The records format.
 * @exception  Exception  If error
 */
protected String getFormatOfRecords() throws Exception {
	List nodes = getDom4jDoc().selectNodes("/*[local-name()='collectionRecord']/*[local-name()='access']/*[local-name()='key']/@libraryFormat");
	if (nodes.size() != 1)
		throw new Exception("Unable to get format of records. Wrong number of elements: " + nodes.size());
	Attribute attrib = (Attribute) nodes.get(0);
	return attrib.getValue();
}
 
Example 30
Project: joai-project   File: DleseCollectionFileIndexingWriter.java   View source code 5 votes vote down vote up
/**
 *  Gets the status of the collection based on the values in the collection-level record.
 *
 * @param  doc  A dlese_collect XML Document
 * @return      The currentCollectionStatus value
 */
public final static String getCurrentCollectionStatus(org.dom4j.Document doc) {
	List nodes = doc.selectNodes("/*[local-name()='collectionRecord']/*[local-name()='approval']/*[local-name()='collectionStatuses']/*[local-name()='collectionStatus']");

	if (nodes == null || nodes.size() == 0)
		return "Error: no collectionStatus elements found in the XML";

	Collections.sort(nodes, new CollectionAccessionStatusComparator());

	Element collectionStatus = (Element) nodes.get(0);
	Attribute collecitonState = collectionStatus.attribute("state");

	return collecitonState.getText();
}
 
Example 31
Project: parabuild-ci   File: Filter.java   View source code 5 votes vote down vote up
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 32
Project: joai-project   File: StructureWalker.java   View source code 5 votes vote down vote up
/**
 *  Gets the path attribute of the StructureWalker object
 *
 * @param  a  Description of the Parameter
 * @return    The path value
 */
public String getPath(Attribute a) {
	prtln("getPath: attribute: " + a.asXML(), 1);
	prtln(" ... attributeName: " + a.getName(), 1);
	prtln(" ... qualifiedName: " + a.getQualifiedName(), 1);
	Element parent = a.getParent();
	if (parent == null) {
		prtln(" ... parent is null!", 1);
	}
	// return getPath((Node) a);
	return getPath(parent) + "/@" + a.getQualifiedName();
}
 
Example 33
Project: joai-project   File: SchemaReader.java   View source code 5 votes vote down vote up
/**
 *  Determines the targetNamespace of the schema document. If a "targetNamespace" is explicitly declared, then
 this is returned. Otherwise, the "defaultTargetNamespaceURI" is used.
 *
 * @param  defaultTargetNamespaceURI  NOT YET DOCUMENTED
 * @return                            The targetNamespace value
 */
private String getTargetNamespaceUri(String defaultTargetNamespaceURI) {
	Attribute tnsAttribute = root.attribute("targetNamespace");
	if (tnsAttribute != null)
		return tnsAttribute.getText();
	else
		return defaultTargetNamespaceURI;
}
 
Example 34
Project: parabuild-ci   File: Binder.java   View source code 5 votes vote down vote up
private static String getClassName(Attribute att, Mappings model) {
	String result = att.getValue();
	if (result==null) return null;
	if ( result.indexOf('.')<0 && model.getDefaultPackage()!=null ) {
		result = model.getDefaultPackage() + StringHelper.DOT + result;
	}
	return result;
}
 
Example 35
Project: joai-project   File: SchemEditForm.java   View source code 5 votes vote down vote up
/**
 *  Return true if the node specified by key exists in the instance document
 *  and it has a required attribute in the instance document.
 *
 * @param  key  a jsp-encoded xpath
 * @return      The nodeExistsWithRequiredAttribute value
 */
public String getNodeExistsWithRequiredAttribute(String key) {
	String xpath = XPathUtils.decodeXPath(key);
	Node node = docMap.selectSingleNode(xpath);
	if (node == null) {
		return FALSE;
	}
	if (node.getNodeType() != Node.ELEMENT_NODE) {
		return FALSE;
	}
	Element element = (Element) node;
	if (element.attributes().isEmpty()) {
		return FALSE;
	}

	/* check attributes for a required one */
	for (Iterator i = element.attributeIterator(); i.hasNext(); ) {
		Attribute attribute = (Attribute) i.next();
		String attPath = xpath + "/@" + attribute.getQualifiedName();
		SchemaNode schemaNode = this.schemaHelper.getSchemaNode(attPath);
		if (schemaNode == null) {
			// prtln ("schemaNode not found for attribute (" + attPath + ")");
			continue;
		}
		if (schemaNode.isRequired())
			return TRUE;
	}
	return FALSE;
}
 
Example 36
Project: gen_code   File: ConfigParser.java   View source code 5 votes vote down vote up
/**
 * 将指定节点的属性设置到对象里面
 * @param obj 对象
 * @param element 节点
 * @param tempflag 模板化标识
 * @return 返回结果
 */
public static <T> T fillObj(T obj, Element element,boolean tempflag){
    if(element!=null){
        List<Attribute> attributes = element.attributes();
        for(Attribute a:attributes){
            AnalysisObject.invokeSetter(obj,a.getName(),
                    tempflag?FreeMarkerUtil.render(a.getValue()):a.getValue());
        }
    }
    return obj;
}
 
Example 37
Project: atlas   File: ManifestFileUtils.java   View source code 5 votes vote down vote up
private static void fillFullClazzName(Element root, String packageName, String type) {
    List<? extends Node> applicatNodes = root.selectNodes("//" + type);
    for (Node node : applicatNodes) {
        Element element = (Element)node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (attribute.getValue().startsWith(".")) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }
}
 
Example 38
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
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 39
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
public static void bindClass(Element node, PersistentClass persistentClass, Mappings mappings,
		java.util.Map inheritedMetas) throws MappingException {
	// transfer an explicitly defined entity name
	// handle the lazy attribute
	Attribute lazyNode = node.attribute( "lazy" );
	boolean lazy = lazyNode == null ?
			mappings.isDefaultLazy() :
			"true".equals( lazyNode.getValue() );
	// go ahead and set the lazy here, since pojo.proxy can override it.
	persistentClass.setLazy( lazy );

	String entityName = node.attributeValue( "entity-name" );
	if ( entityName == null ) entityName = getClassName( node.attribute("name"), mappings );
	if ( entityName==null ) {
		throw new MappingException( "Unable to determine entity name" );
	}
	persistentClass.setEntityName( entityName );
	persistentClass.setJpaEntityName( StringHelper.unqualify( entityName ) );

	bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas );
	bindDom4jRepresentation( node, persistentClass, mappings, inheritedMetas );
	bindMapRepresentation( node, persistentClass, mappings, inheritedMetas );

	Iterator itr = node.elementIterator( "fetch-profile" );
	while ( itr.hasNext() ) {
		final Element profileElement = ( Element ) itr.next();
		parseFetchProfile( profileElement, mappings, entityName );
	}

	bindPersistentClassCommonValues( node, persistentClass, mappings, inheritedMetas );
}
 
Example 40
Project: lams   File: HbmBinder.java   View source code 5 votes vote down vote up
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;
}