List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:edu.umd.cfar.lamp.viper.examples.textline.AttributeWrapperTextline.java
/** * Creates a new instance of TextlineModel from an XML element. * //ww w . j a v a 2 s .c o m * @return a TextlineModel object corresponding to the given XML * serialization */ public Object setValue(Element el, Node container) { if (el.hasAttribute(AT_X) && el.hasAttribute(AT_Y) && el.hasAttribute(AT_W) && el.hasAttribute(AT_H) && el.hasAttribute(AT_R) && el.hasAttribute(AT_OCC) && el.hasAttribute(AT_OFF) && el.hasAttribute(AT_TXT)) { int x = Integer.parseInt(el.getAttribute(AT_X)); int y = Integer.parseInt(el.getAttribute(AT_Y)); int w = Integer.parseInt(el.getAttribute(AT_W)); int h = Integer.parseInt(el.getAttribute(AT_H)); int r = Integer.parseInt(el.getAttribute(AT_R)); String text = el.getAttribute(AT_TXT).toString(); String occ = el.getAttribute(AT_OCC).toString(); String off = el.getAttribute(AT_OFF).toString(); String[] tok; // stores tokens temporarily // convert space-separated list of occlusion *pairs* to ArrayList of // IntPairs ArrayList occAL = new ArrayList(); tok = occ.split(" "); if (tok[0] != "") { // IMPORTANT: skip if it's empty if (tok.length % 2 != 0) throw new BadAttributeDataException("Odd number of occlusions in a textline object"); for (int i = 0; i < tok.length; i += 2) { // notice the // step-by-two // increase occAL.add(new IntPair(Integer.parseInt(tok[i]), Integer.parseInt(tok[i + 1]))); } } // convert space-separated list of offsets to ArrayList object ArrayList offAL = new ArrayList(); tok = off.split(" "); if (tok[0] != "") { // IMPORTANT: skip if it's empty for (int i = 0; i < tok.length; i++) { offAL.add(new Integer(tok[i])); } } return new TextlineModel(x, y, w, h, r, text, occAL, offAL); // create // new // TextlineModel // object } else { throw new BadAttributeDataException("Missing an attribute for dimensions of a textline object"); } }
From source file:org.jdal.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}/*from w w w. j a v a 2s. c om*/ */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String tableModelBeanName = name + LIST_TABLE_MODEL_SUFFIX; String tablePanelBeanName = name + TABLE_PANEL_SUFFIX; String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; if (element.hasAttribute(SERVICE_ATTRIBUTE)) dataSource = element.getAttribute(SERVICE_ATTRIBUTE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); // create ListTableModel BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListTableModel.class); bdb.setScope(scope); bdb.addPropertyValue("modelClass", entity); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableModelBeanName, bdb); // create PageableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(PageableTable.class); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyReference(TABLE_MODEL, tableModelBeanName); bdb.addPropertyValue(NAME, pageableTableBeanName); if (element.hasAttribute(TABLE_SERVICE)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(TABLE_SERVICE), element.getAttribute(TABLE_SERVICE)); if (element.hasAttribute(FILTER)) bdb.addPropertyReference(FILTER, element.getAttribute(FILTER)); if (element.hasAttribute(SHOW_MENU)) bdb.addPropertyValue(Conventions.attributeNameToPropertyName(SHOW_MENU), element.getAttribute(SHOW_MENU)); if (element.hasAttribute(MESSAGE_SOURCE)) bdb.addPropertyReference(MESSAGE_SOURCE, element.getAttribute(MESSAGE_SOURCE)); registerBeanDefinition(element, parserContext, pageableTableBeanName, bdb); // create TablePanel String tablePanelClassName = "org.jdal.swing.table.TablePanel"; if (element.hasAttribute(TABLE_PANEL_CLASS)) tablePanelClassName = element.getAttribute(TABLE_PANEL_CLASS); bdb = BeanDefinitionBuilder.genericBeanDefinition(tablePanelClassName); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); bdb.addPropertyReference(TABLE, pageableTableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyReference(PERSISTENT_SERVICE, dataSource); if (element.hasAttribute(FILTER_VIEW)) bdb.addPropertyReference(Conventions.attributeNameToPropertyName(FILTER_VIEW), element.getAttribute(FILTER_VIEW)); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); registerBeanDefinition(element, parserContext, tablePanelBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:com.github.fritaly.svngraph.Update.java
public Update(Element element) throws ParseException { validateElement(element, "path"); this.kind = Kind.getKind(element.getAttribute("kind")); this.action = Action.getAction(element.getAttribute("action")); this.path = element.getTextContent(); if (element.hasAttribute("copyfrom-path")) { this.copyFromPath = element.getAttribute("copyfrom-path"); }/*from w w w . j a v a 2 s .c om*/ if (element.hasAttribute("copyfrom-rev")) { this.copyFromRev = Long.parseLong(element.getAttribute("copyfrom-rev")); } if (element.hasAttribute("text-mods")) { this.merge = Boolean.parseBoolean(element.getAttribute("text-mods")); } }
From source file:org.jboss.windup.config.spring.namespace.java.JavaClassificationBeanParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder .rootBeanDefinition(JavaClassifyingDecorator.class); beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex")); beanBuilder.addPropertyValue("matchDescription", element.getAttribute("description")); if (element.hasAttribute("source-type")) { beanBuilder.addPropertyValue("sourceType", element.getAttribute("source-type")); }// ww w. jav a2s. c o m if (element.hasAttribute("effort")) { beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort"))); } SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "hints", parserContext); SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "decorators", parserContext); return beanBuilder.getBeanDefinition(); }
From source file:com.concursive.connect.web.modules.api.beans.Transaction.java
/** * Builds a list of TransactionItems from XML * * @param transactionElement Description of Parameter *//*from w w w .j a va 2s .co m*/ public void build(Element transactionElement) { if (transactionElement.hasAttributes()) { // Use client transaction id if (transactionElement.hasAttribute("id")) { this.setId(transactionElement.getAttribute("id")); } // Use a different processor than the default if (transactionElement.hasAttribute("processor")) { } } // The default processor ArrayList<Element> objectElements = new ArrayList<Element>(); XMLUtils.getAllChildren(transactionElement, objectElements); LOG.debug("Transaction items: " + objectElements.size()); for (Element objectElement : objectElements) { TransactionItem thisItem = new TransactionItem(objectElement, packetContext, transactionContext); if (thisItem.getName().equals("meta")) { LOG.trace("Meta data found"); meta = (TransactionMeta) thisItem.getObject(); } else { LOG.trace("Adding transaction item: " + thisItem.getName()); this.add(thisItem); } } }
From source file:ar.com.zauber.commons.conversion.spring.schema.SimplePropertyFieldDefinitionParser.java
/** @see AbstractSingleBeanDefinitionParser#doParse(Element, ParserContext, * BeanDefinitionBuilder) */ @SuppressWarnings("unchecked") protected final void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder bean) { final String targetPropertyName = element.getAttribute("target"); String sourcePropertyName;/* w w w. j a va 2 s . c om*/ Converter converter; bean.addConstructorArgValue(targetPropertyName); if (element.hasAttribute("source")) { sourcePropertyName = element.getAttribute("source"); } else { sourcePropertyName = targetPropertyName; } final List<?> l = parserContext.getDelegate().parseListElement(element, bean.getBeanDefinition()); final BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SinglePropertyConverter.class) .addConstructorArgValue(sourcePropertyName); if (element.hasAttribute("converter-ref")) { bean.addConstructorArgValue( bdb.addConstructorArgReference(element.getAttribute("converter-ref")).getBeanDefinition()); } else if (l.size() == 1) { bean.addConstructorArgValue(bdb.addConstructorArgValue(l.iterator().next()).getBeanDefinition()); } else { converter = new IdentityConverter(); bean.addConstructorArgValue(new SinglePropertyConverter(sourcePropertyName, converter)); } configureSetter(bean, element); }
From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}//w w w. j a v a2s . c o m */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String tableBeanName = name + TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS; String tableClass = DEFAULT_TABLE_CLASS; if (element.hasAttribute(DATA_SOURCE)) dataSource = element.getAttribute(DATA_SOURCE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); if (element.hasAttribute(PAGEABLE_TABLE_CLASS)) pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS); if (element.hasAttribute(TABLE_CLASS)) tableClass = element.getAttribute(TABLE_CLASS); // create PageableTable BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass); bdb.setScope(scope); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyValue(NAME, pageableTableBeanName); bdb.addPropertyReference(TABLE, tableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyValue(ENTITY_CLASS, entity); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null, bdb.getBeanDefinition()); BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName); // Test Decorators like aop:scoped-proxy NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName())) continue; NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(n.getNamespaceURI()); if (handler != null) { holder = handler.decorate(n, holder, parserContext); } } parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // create ConfigurableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT); if (element.hasAttribute(SELECTABLE)) { bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE)); } else { // set selectable by default bdb.addPropertyValue(SELECTABLE, true); } // parse columns NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:de.erdesignerng.model.serializer.xml20.XMLSubjectAreaSerializer.java
@Override public void deserialize(Model aModel, Document aDocument) { NodeList theElements = aDocument.getElementsByTagName(SUBJECTAREA); for (int i = 0; i < theElements.getLength(); i++) { Element theElement = (Element) theElements.item(i); SubjectArea theSubjectArea = new SubjectArea(); deserializeProperties(theElement, theSubjectArea); theSubjectArea.setColor(new Color(Integer.parseInt(theElement.getAttribute(COLOR)))); if (theElement.hasAttribute(VISIBLE)) { theSubjectArea.setVisible(TRUE.equals(theElement.getAttribute(VISIBLE))); }/*w w w . ja va2 s . co m*/ NodeList theTables = theElement.getElementsByTagName(ITEM); for (int j = 0; j < theTables.getLength(); j++) { Element theItemElement = (Element) theTables.item(j); String theTableId = theItemElement.getAttribute(TABLEREFID); String theViewId = theItemElement.getAttribute(VIEWREFID); String theCommentId = theItemElement.getAttribute(COMMENTREFID); if (!StringUtils.isEmpty(theTableId)) { Table theTable = aModel.getTables().findBySystemId(theTableId); if (theTable == null) { throw new IllegalArgumentException("Cannot find table with id " + theTableId); } theSubjectArea.getTables().add(theTable); } if (!StringUtils.isEmpty(theViewId)) { View theView = aModel.getViews().findBySystemId(theViewId); if (theView == null) { throw new IllegalArgumentException("Cannot find view with id " + theTableId); } theSubjectArea.getViews().add(theView); } if (!StringUtils.isEmpty(theCommentId)) { Comment theComment = aModel.getComments().findBySystemId(theCommentId); if (theComment == null) { throw new IllegalArgumentException("Cannot find comment with id " + theCommentId); } theSubjectArea.getComments().add(theComment); } } aModel.getSubjectAreas().add(theSubjectArea); } }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
private boolean isValid(final Element element) { boolean value = false; if (element != null) { if (element.hasAttribute(VALUE_NIL) && VALUE_TRUE.equals(element.getAttributeNode(VALUE_NIL).getNodeValue())) { value = false;/*from w w w .j a va 2 s. c o m*/ } else { final Node child = element.getFirstChild(); value = child != null; } } return value; }
From source file:org.alfresco.web.config.ConfigRuntime.java
/** * @param configElem//from ww w .j a v a 2 s . c o m * @param attrName * @param attrValue * @return */ protected boolean manageAttribute(Element configElem, String attrName, String attrValue) { boolean status = false; if (attrValue != null && !attrValue.equals("")) { if (!configElem.hasAttribute(attrName) || !configElem.getAttribute(attrName).equals(attrValue)) { status = true; } configElem.setAttribute(attrName, attrValue); } else { if (configElem.hasAttribute(attrName)) { configElem.removeAttribute(attrName); status = true; } } return status; }