List of usage examples for org.xml.sax Attributes getQName
public abstract String getQName(int index);
From source file:Main.java
/** The opening tag of an element. */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { System.out.println("-" + locator.getLineNumber() + "---Opening tag of an element"); System.out.println(" Namespace: " + namespaceURI); System.out.println(" Local name: " + localName); System.out.println(" Qualified name: " + qName); for (int i = 0; i < atts.getLength(); i++) { System.out.println(" Attribute: " + atts.getQName(i) + "=\"" + atts.getValue(i) + "\""); }//w w w . j av a2 s . c om }
From source file:ezbake.thrift.utils.xml2thrift.sax.StringHandler.java
/** * This is an inherited SAX method. The handler extends it to parse XML. */// ww w . j ava 2 s . c om public void startElement(String uri, String localName, String qName, Attributes attributes) { if (qName.equalsIgnoreCase(root)) { sbEntry.setLength(0); inRootItem = true; } if (inRootItem) { sbEntry.append("<" + qName + ">"); /* Populate the attributes to the XML string */ for (int i = 0; i < attributes.getLength(); i++) { sbEntry.append("<" + attributes.getQName(i) + ">"); sbEntry.append(attributes.getValue(i)); sbEntry.append("</" + attributes.getQName(i) + ">"); } } }
From source file:com.netspective.commons.xml.AbstractContentHandler.java
public String getAttributeNames(Attributes attributes) { StringBuffer sb = new StringBuffer(" Attrs: ["); for (int i = 0; i < attributes.getLength(); i++) { sb.append(attributes.getQName(i)); sb.append("="); sb.append(attributes.getValue(i)); sb.append(" "); }/* w w w . j a v a2 s. c om*/ sb.append(attributes); sb.append("]"); return sb.toString(); }
From source file:com.threerings.miso.tile.tools.xml.FringeConfigurationParser.java
@Override protected void addRules(Digester digest) { // configure top-level constraints String prefix = "fringe"; digest.addRule(prefix, new SetPropertyFieldsRule()); // create and configure fringe config instances prefix += "/base"; digest.addObjectCreate(prefix, FringeRecord.class.getName()); ValidatedSetNextRule.Validator val; val = new ValidatedSetNextRule.Validator() { public boolean isValid(Object target) { if (((FringeRecord) target).isValid()) { return true; } else { log.warning("A FringeRecord was not added because it was " + "improperly specified [rec=" + target + "]."); return false; }//from w w w .j a v a 2s .c om } }; ValidatedSetNextRule vrule; vrule = new ValidatedSetNextRule("addFringeRecord", val) { // parse the fringe record, converting tileset names to // tileset ids @Override public void begin(String namespace, String lname, Attributes attrs) throws Exception { FringeRecord frec = (FringeRecord) digester.peek(); for (int ii = 0; ii < attrs.getLength(); ii++) { String name = attrs.getLocalName(ii); if (StringUtil.isBlank(name)) { name = attrs.getQName(ii); } String value = attrs.getValue(ii); if ("name".equals(name)) { if (_idBroker.tileSetMapped(value)) { frec.base_tsid = _idBroker.getTileSetID(value); } else { log.warning("Skipping unknown base " + "tileset [name=" + value + "]."); } } else if ("priority".equals(name)) { frec.priority = Integer.parseInt(value); } else { log.warning("Skipping unknown attribute " + "[name=" + name + "]."); } } } }; digest.addRule(prefix, vrule); // create the tileset records in each fringe record prefix += "/tileset"; digest.addObjectCreate(prefix, FringeTileSetRecord.class.getName()); val = new ValidatedSetNextRule.Validator() { public boolean isValid(Object target) { if (((FringeTileSetRecord) target).isValid()) { return true; } else { log.warning("A FringeTileSetRecord was not added because " + "it was improperly specified " + "[rec=" + target + "]."); return false; } } }; vrule = new ValidatedSetNextRule("addTileset", val) { // parse the fringe tilesetrecord, converting tileset names to ids @Override public void begin(String namespace, String lname, Attributes attrs) throws Exception { FringeTileSetRecord f = (FringeTileSetRecord) digester.peek(); for (int ii = 0; ii < attrs.getLength(); ii++) { String name = attrs.getLocalName(ii); if (StringUtil.isBlank(name)) { name = attrs.getQName(ii); } String value = attrs.getValue(ii); if ("name".equals(name)) { if (_idBroker.tileSetMapped(value)) { f.fringe_tsid = _idBroker.getTileSetID(value); } else { log.warning("Skipping unknown fringe " + "tileset [name=" + value + "]."); } } else if ("mask".equals(name)) { f.mask = Boolean.valueOf(value).booleanValue(); } else { log.warning("Skipping unknown attribute " + "[name=" + name + "]."); } } } }; digest.addRule(prefix, vrule); }
From source file:com.icesoft.faces.webapp.parser.ComponentRuleSet.java
private Attributes clone(Attributes attributes) { Attributes clone = new AttributesImpl(attributes); for (int i = 0; i < clone.getLength(); i++) { String name = attributes.getQName(i); String value = attributes.getValue(name); ((AttributesImpl) clone).setLocalName(i, name); ((AttributesImpl) clone).setValue(i, value); }//from ww w .j a v a 2s . co m return clone; }
From source file:com.icesoft.faces.webapp.parser.ComponentRuleSet.java
/** * Create clone of attributes./* ww w . java2 s. com*/ * * @param attributes Attributes to clone. * @return Cloned attributes. */ private Attributes clone(Attributes attributes) { Attributes clone = new AttributesImpl(attributes); for (int i = 0; i < clone.getLength(); i++) { String name = attributes.getQName(i); String value = attributes.getValue(name); ((AttributesImpl) clone).setLocalName(i, name); ((AttributesImpl) clone).setValue(i, value); } return clone; }
From source file:fulcrum.xml.Parser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { textBuilder.setLength(0);//from ww w. j a v a2 s. c o m Element c = new Element(qName, uri); xPathBuilder.append(FORWARD_SLASH).append(localName); addXPath(xPathBuilder.toString(), c); for (int i = 0; i < attributes.getLength(); i++) { Attribute a = new Attribute(attributes.getQName(i), attributes.getURI(i), attributes.getValue(i)); addXPath(xPathBuilder.toString() + AT + a.getLocalName(), a); c.addAttribute(a); } elements.push(c); }
From source file:com.icesoft.faces.webapp.parser.ELSetPropertiesRule.java
public void begin(Attributes attributes) throws Exception { FacesContext facesContext = FacesContext.getCurrentInstance(); HashMap values = new HashMap(); Object top = digester.peek(); for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.getLocalName(i); if ("".equals(name)) { name = attributes.getQName(i); }/* ww w . ja va2s.c o m*/ String value = attributes.getValue(i); //take a guess at the types of the JSF 1.2 tag members //we are probably better off doing this reflectively if (name != null) { values.put(name, value); if (("id".equals(name)) || ("name".equals(name)) || ("var".equals(name))) { values.put(name, value); } else if (top instanceof UIComponentTag) { //must be a JSF 1.1 tag values.put(name, value); } else if ("action".equals(name)) { values.put(name, getMethodExpression(facesContext, name, value, null)); } else if ("validator".equals(name)) { values.put(name, getMethodExpression(facesContext, name, value, null)); } else if ("actionListener".equals(name)) { values.put(name, getMethodExpression(facesContext, name, value, ActionEvent.class)); } else if ("valueChangeListener".equals(name)) { values.put(name, getMethodExpression(facesContext, name, value, ValueChangeEvent.class)); } else { values.put(name, getValueExpression(facesContext, name, value)); } if (top instanceof javax.faces.webapp.UIComponentELTag) { //special case for //com.sun.faces.taglib.jsf_core.ParameterTag //and potentially others if ("name".equals(name)) { values.put(name, getValueExpression(facesContext, name, value)); } else if ("locale".equals(name)) { values.put(name, getValueExpression(facesContext, name, value)); } } else { //reflection based code as mentioned above. More likely //to be correct, but performance may not be as good, //so only applying it in a specific case if ("name".equals(name)) { Method setNameMethod = null; try { setNameMethod = top.getClass().getMethod("setName", new Class[] { ValueExpression.class }); } catch (Exception e) { } if (null != setNameMethod) { values.put(name, getValueExpression(facesContext, name, value)); } } } } } BeanUtils.populate(top, values); }
From source file:com.mapr.xml2json.MySaxParser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); JSONObject tag = new JSONObject(); JSONArray array = new JSONArray(); int length = attributes.getLength(); for (int i = 0; i < length; i++) { JSONObject temp = new JSONObject(); String qNameVal = attributes.getQName(i); String valueVal = attributes.getValue(i); if (qNameVal != null) qNameVal = cleanQName(qNameVal); if (valueVal.trim().length() > 0) { tag.put(qNameVal, valueVal); //array.add(temp); }/* w ww . j a v a 2s.co m*/ } if (array.size() > 0) tag.put("attributes", array); // tag.put("qName",cleanQName(qName)); //log.info("After clean:" + cleanQName(qName)); stk.push(tag); }
From source file:TestModelBuilder.java
public void startElement(String namespace, String localname, String qname, Attributes atts) throws SAXException { SimpleElement element = null;//from ww w.jav a 2 s. c o m try { element = (SimpleElement) Class.forName(qname).newInstance(); } catch (Exception e) { } if (element == null) element = new SimpleElement(); for (int i = 0; i < atts.getLength(); i++) element.setAttributeValue(atts.getQName(i), atts.getValue(i)); stack.push(element); }