List of usage examples for org.xml.sax Attributes getLength
public abstract int getLength();
From source file:com.kdmanalytics.toif.assimilator.XMLNode.java
/** * Parse the node information. Note that the "Attributes" here are XML Attributes, not KDM * attributes.//from w w w .j a v a 2 s. co m * * @param ns * @param sName * @param qName * @param attrs */ public XMLNode(String ns, String sName, String qName, Attributes attrs) { children = new ArrayList<XMLNode>(); this.sName = sName; if ("".equals(sName)) this.sName = qName; // Not namespace aware int size = attrs.getLength(); for (int i = 0; i < size; i++) { String key = attrs.getLocalName(i); // Attr name if ("".equals(key)) key = attrs.getQName(i); // Special cases // Stereotype/tag "type" is an attribute, not a reference if ("stereotype".equals(this.sName) && "type".equals(key)) addAttribute(key, attrs.getValue(key)); else if ("tag".equals(this.sName) && "type".equals(key)) addAttribute(key, attrs.getValue(key)); // Some attributes are really references else if (AttributeUtilities.isReference(key)) addReference(key, attrs.getValue(key)); // Unescape the fields which likely contain escaped HTML else if (stringFields.contains(key)) { String value = attrs.getValue(key); try { // value = StringEscapeUtils.unescapeHtml4(value); // value = StringEscapeUtils.unescapeXml(value); value = StringEscapeUtils.unescapeHtml3(value); } catch (StringIndexOutOfBoundsException e) { // String was most likely '&' which causes commons.lang3 to // throw... ignore it if (!value.contains("&")) { throw e; } } addAttribute(key, value); } // Normal attribute else { addAttribute(key, attrs.getValue(key)); } } // Use the xmiLid if it exists id = getAttribute("xmi:id"); if (id == null) id = "" + UniqueID.get(); }
From source file:it.wami.map.mongodeploy.OsmSaxHandler.java
/** * /*from www.jav a 2s. c om*/ * @param atts */ private void appendMetadata(Attributes atts) { for (int i = 0; i < atts.getLength(); i++) { //System.out.println("qName: "+atts.getQName(i)+" value: "+atts.getValue(i)); String attribute = atts.getQName(i); if (attribute == "id" || attribute == "lat" || attribute == "lon") { continue; } /*if(attribute.contains("www")){ System.exit(0); }*/ attribute = StringUtils.replace(attribute, ".", "[dot]"); //attribute.replace(".", "[dot]"); //System.out.println(attribute); entry.append(attribute, atts.getValue(i)); } }
From source file:com.rapidminer.gui.properties.OperatorPropertyPanel.java
private void appendParameterStartTag(String localName, Attributes attributes, StringBuilder parameterTextBuilder) { parameterTextBuilder.append('<'); parameterTextBuilder.append(localName); for (int i = 0; i < attributes.getLength(); i++) { parameterTextBuilder.append(' '); parameterTextBuilder.append(attributes.getLocalName(i)); parameterTextBuilder.append("=\""); parameterTextBuilder.append(attributes.getValue(i)); parameterTextBuilder.append('"'); }//from w w w . java 2s .c o m parameterTextBuilder.append(" >"); }
From source file:org.apache.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes attrs, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); final Table table = getTable(tableName); for (int i = 0; i < attrs.getLength(); i++) { Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType(); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; }/*ww w . ja v a 2 s. c om*/ switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.REAL: case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BLOB: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); query.setParameter(i + 1, attrs.getValue(i)); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: query.setParameter(i + 1, attrs.getValue(i)); } } }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java
private void processScenarioStep(Attributes attrs) throws SAXException { if (currScenario == null) { throw new SAXParseException( StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "ConfigParserHandler.malformed.configuration2", STEP_ELMT, SCENARIO_ELMT), currParseLocation);/*from ww w. ja v a 2 s .c o m*/ } String name = null; String url = null; String method = null; String username = null; String password = null; for (int i = 0; i < attrs.getLength(); i++) { String attName = attrs.getQName(i); String attValue = attrs.getValue(i); if (NAME_ATTR.equals(attName)) { name = attValue; } else if (URL_ATTR.equals(attName)) { url = attValue; } else if (METHOD_ATTR.equals(attName)) { method = attValue; } else if (USERMAME_ATTR.equals(attName)) { username = attValue; } else if (PASSWORD_ATTR.equals(attName)) { password = attValue; } } notEmpty(name, STEP_ELMT, NAME_ATTR); currStep = new WsScenarioStep(name); currStep.setUrlStr(url); currStep.setMethod(method); currStep.setCredentials(username, password); }
From source file:edu.uci.ics.jung.io.GraphMLReader.java
protected Map<String, String> getAttributeMap(Attributes atts) { Map<String, String> att_map = new HashMap<String, String>(); for (int i = 0; i < atts.getLength(); i++) att_map.put(atts.getQName(i), atts.getValue(i)); return att_map; }
From source file:com.dhenton9000.excel.ExcelParser.java
/** * {@inheritDoc}/*from w w w . ja v a2s . c o m*/ * <strong>note:</strong> this method is called from within the * XMLReader.parse method * * @param uri * @param localName * @param name * @param attributes * @throws org.xml.sax.SAXException * @see XMLReader#parse(InputSource) */ @Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { //new row found if ("row".equals(name)) { insideRow = true; rowValueMap.clear(); ++rowIndex; } // c => cell (new column found) else if ("c".equals(name)) { String cellType = attributes.getValue("t"); if (cellType != null) { nextIsString = "s".equals(cellType); } else { //LOG.debug("attr size "+attributes.getLength()); //nextIsNumber = "1".equals(attributes.getValue("s")); nextIsNumber = attributes.getLength() == 1; } colIndex = attributes.getValue("r").toCharArray()[0]; //H28 = [H,2,8] } // Clear contents cache cellContents.setLength(0); // LOG.debug(String.format("st row %d col %d name %s", rowIndex,colIndex, name)); }
From source file:jcurl.core.io.SetupSaxDeSer.java
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { // log.debug("[" + localName + "] [" + qName + "] [" + uri + "]"); final String elem = qName; final String parent = elems.size() > 0 ? (String) elems.peek() : null; final String grandParent = elems.size() > 1 ? (String) elems.get(elems.size() - 2) : null; elems.push(elem);/* w ww. j a va2 s .co m*/ if (log.isDebugEnabled()) log.debug(elems + " " + atts.getLength()); buf.setLength(0); try { // check switch (elems.size()) { case 1: if ("jcurl".equals(elem)) ; else break; return; case 2: if ("setup".equals(elem)) ; else break; return; case 3: if ("meta".equals(elem)) ; else if ("model".equals(elem)) { modelClass = Class.forName(atts.getValue("engine")); modelProps.clear(); } else if ("positions".equals(elem)) ; else if ("speeds".equals(elem)) ; else break; return; case 4: if ("event".equals(elem)) ; else if ("game".equals(elem)) ; else if ("description".equals(elem) && "model".equals(parent)) ; else if ("param".equals(elem) && "model".equals(parent)) { final String key = atts.getValue("name"); final String val = atts.getValue("val"); final String dim = atts.getValue("dim"); if (dim != null) { modelProps.put(key, new DimVal(Double.parseDouble(val), Dim.find(dim))); } else { modelProps.put(key, val); } } else if ("rock".equals(elem)) currRock = new RockIdx(atts); else break; return; case 5: if ("a".equals(elem)) if ("positions".equals(grandParent)) setup.setAngle(currRock.idx16, getDim(atts)); else if ("speeds".equals(grandParent)) setup.setSpin(currRock.idx16, getDim(atts)); else break; else if ("x".equals(elem)) if ("positions".equals(grandParent)) setup.setPosX(currRock.idx16, getDim(atts)); else if ("speeds".equals(grandParent)) setup.setSpeedX(currRock.idx16, getDim(atts)); else break; else if ("y".equals(elem)) if ("positions".equals(grandParent)) setup.setPosY(currRock.idx16, getDim(atts)); else if ("speeds".equals(grandParent)) setup.setSpeedY(currRock.idx16, getDim(atts)); else break; else if ("out".equals(elem)) if ("positions".equals(grandParent)) setup.setPosOut(currRock.idx16); else break; else if ("nearhog".equals(elem)) if ("positions".equals(grandParent)) setup.setPosNHog(currRock.idx16); else break; else if ("to_x".equals(elem)) if ("speeds".equals(grandParent)) setup.setToX(currRock.idx16, getDim(atts)); else break; else if ("to_y".equals(elem)) if ("speeds".equals(grandParent)) setup.setToY(currRock.idx16, getDim(atts)); else break; else if ("speed".equals(elem)) if ("speeds".equals(grandParent)) setup.setSpeed(currRock.idx16, getDim(atts)); else break; else if ("spin".equals(elem)) if ("speeds".equals(grandParent)) setup.setSpin(currRock.idx16, getDim(atts)); else break; else break; return; } error(new SAXParseException("unexpected element [" + elem + "]", locator)); } catch (RuntimeException e) { log.warn("error in [" + elems + "]", e); error(new SAXParseException("error in [" + elems + "]", locator, e)); } catch (ClassNotFoundException e) { log.warn("error in [" + elems + "]", e); error(new SAXParseException("error in [" + elems + "]", locator, e)); } }
From source file:Counter.java
/** Start element. */ public void startElement(String uri, String local, String raw, Attributes attrs) throws SAXException { fElements++;// w w w .j a va 2s . c om fTagCharacters++; // open angle bracket fTagCharacters += raw.length(); if (attrs != null) { int attrCount = attrs.getLength(); fAttributes += attrCount; for (int i = 0; i < attrCount; i++) { fTagCharacters++; // space fTagCharacters += attrs.getQName(i).length(); fTagCharacters++; // '=' fTagCharacters++; // open quote fOtherCharacters += attrs.getValue(i).length(); fTagCharacters++; // close quote } } fTagCharacters++; // close angle bracket }
From source file:org.apache.syncope.core.util.ImportExport.java
@Override public void startElement(final String uri, final String localName, final String qName, final Attributes atts) throws SAXException { // skip root element if (ROOT_ELEMENT.equals(qName)) { return;//from ww w. j a v a 2 s . c o m } StringBuilder queryString = new StringBuilder("INSERT INTO ").append(qName).append('('); StringBuilder values = new StringBuilder(); for (int i = 0; i < atts.getLength(); i++) { queryString.append(atts.getQName(i)); values.append('?'); if (i < atts.getLength() - 1) { queryString.append(','); values.append(','); } } queryString.append(") VALUES (").append(values).append(')'); Query query = entityManager.createNativeQuery(queryString.toString()); setParameters(qName, atts, query); query.executeUpdate(); }