List of usage examples for org.xml.sax Attributes getValue
public abstract String getValue(String qName);
From source file:com.prowidesoftware.swift.io.parser.MxNodeContentHandler.java
public void startElement(final String uri, final String localName, final String qName, final org.xml.sax.Attributes atts) throws org.xml.sax.SAXException { if (log.isLoggable(Level.FINEST)) { log.finest("uri: " + uri + "\nlocalName: " + localName + "\nqName: " + qName + (atts == null ? "" : "\natts(" + atts.getLength() + "): ...")); }//from w w w. j a v a 2 s . c o m final MxNode node = new MxNode(currentNode, localName); if (atts != null) { for (int i = 0; i < atts.getLength(); i++) { node.addAttribute(atts.getLocalName(i), atts.getValue(i)); } } /* * set uri as xmlns attribute for the first node in namespace */ if (uri != null && (node.getParent() == null || !StringUtils.equals(node.getParent().getAttribute("xmlns"), uri))) { node.addAttribute("xmlns", uri); } currentNode = node; }
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 ava 2s. c o m*/ 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 va2 s .c o m*/ } }; 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.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 .j av a 2 s. c om*/ 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); }/*from w w w. j a v a2s . com*/ } 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:com.netspective.sparx.command.QueryResultDialogCommand.java
/** * * @param nc/*from www .j a va 2s. c o m*/ * @param dialog * @param rowCount * @throws SAXException * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException * @throws DataModelException */ private void createDialogFields(NavigationContext nc, Dialog dialog, int rowCount) throws SAXException, InstantiationException, IllegalAccessException, ClassNotFoundException, DataModelException { QueryResultDialog.RowFieldTemplate rowFieldTemplate = ((QueryResultDialog) dialog).getRowFieldTemplate(); TemplateProducer templateProducer = ((QueryResultDialog) dialog).getTemplateProducers().getByIndex(0); final List templateInstances = templateProducer.getInstances(); if (templateInstances.size() == 0) { log.error("There were no <row> template registered."); } // make sure to get the last template only because inheritance may have create multiples Template rowTemplate = (Template) templateInstances.get(templateInstances.size() - 1); List childFieldElements = rowTemplate.getChildren(); DialogField field = null; int fieldCount = childFieldElements.size(); GridField gridField = new GridField(); gridField.setName(QueryResultDialog.GRID_FIELD_PREFIX); dialog.addGrid(gridField); Project.DialogFieldTypeTemplate fieldTypesTemplate = nc.getProject().getFieldTypes(); Map fieldTypeInstancesMap = fieldTypesTemplate.getInstancesMap(); for (int j = 0; j < rowCount; j++) { GridFieldRow row = new GridFieldRow(); row.setName(QueryResultDialog.ROW_FIELD_PREFIX + j); gridField.addField(row); for (int k = 0; k < fieldCount; k++) { TemplateNode childFieldNode = (TemplateNode) childFieldElements.get(k); if (childFieldNode instanceof TemplateElement) { TemplateElement fieldElement = (TemplateElement) childFieldNode; String elementName = fieldElement.getElementName(); Attributes attributes = fieldElement.getAttributes(); String alternateClassName = attributes.getValue(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME); String fieldType = fieldElement.getAttributes().getValue("type"); Template fieldTemplate = (Template) fieldTypeInstancesMap.get(fieldType); XdmHandler xdmHandler = ((XdmHandler) fieldTemplate.getDefnContentHandler()); XdmParseContext pContext = (XdmParseContext) xdmHandler.getParseContext(); TemplateApplyContext applyContext = fieldTemplate.createApplyContext( fieldTemplate.getDefnContentHandler(), fieldElement.getElementName(), fieldElement.getAttributes()); // can't do a XmlDataModelSchema.createElement() since the <row> element doesn't have an actual // class implementation that would have had an createField() method so do a manual instantiation // of the dialog field class field = (DialogField) Class.forName(fieldTemplate.getAlternateClassName()).newInstance(); TemplateConsumerDefn fieldTemplateConsumer = field.getTemplateConsumerDefn(); // see if we have any templates that need to be applied XdmHandlerNodeStackEntry childEntry = new XdmHandlerNodeStackEntry(elementName, attributes, field); xdmHandler.getNodeStack().push(childEntry); String[] attrNamesToSet = fieldTemplateConsumer.getAttrNamesToApplyBeforeConsuming(); if (attrNamesToSet != null) { for (int i = 0; i < attrNamesToSet.length; i++) { String attrValue = attributes.getValue(attrNamesToSet[i]); String lowerCaseAttrName = attrNamesToSet[i].toLowerCase(); childEntry.getSchema().setAttribute(((XdmParseContext) xdmHandler.getParseContext()), childEntry.getInstance(), lowerCaseAttrName, attrValue, false); } } // create the temporary list and add the dialog-field-type template to pass to the consume call List templatesToConsume = new ArrayList(); templatesToConsume.add(fieldTemplate); fieldTemplateConsumer.consume(fieldTemplate.getDefnContentHandler(), templatesToConsume, fieldElement.getElementName(), fieldElement.getAttributes()); for (int i = 0; i < attributes.getLength(); i++) { String origAttrName = attributes.getQName(i); String lowerCaseAttrName = origAttrName.toLowerCase(); if (!childEntry.getOptions().ignoreAttribute(lowerCaseAttrName) && !lowerCaseAttrName.equals(NodeIdentifiers.ATTRNAME_ALTERNATE_CLASS_NAME) && !(xdmHandler.getNodeStack().size() < 3 && lowerCaseAttrName .startsWith(NodeIdentifiers.ATTRNAMEPREFIX_NAMESPACE_BINDING)) && !(fieldTemplateConsumer != null && fieldTemplateConsumer.isTemplateAttribute(origAttrName)) && !(origAttrName .startsWith(xdmHandler.getNodeIdentifiers().getXmlNameSpacePrefix()))) childEntry.getSchema().setAttribute(pContext, childEntry.getInstance(), lowerCaseAttrName, attributes.getValue(i), false); } row.addField(field); } } } }
From source file:com.netspective.commons.xml.AbstractContentHandler.java
public void includeInputSource(ContentHandlerNodeStackEntry activeEntry, Attributes attrs) throws ContentHandlerException, ParserConfigurationException, SAXException, IOException, TransformProcessingInstructionEncounteredException { String resourceName = attrs.getValue(NodeIdentifiers.ATTRNAME_INCLUDE_RESOURCE); String templateName = attrs.getValue(NodeIdentifiers.ATTRNAME_INCLUDE_TEMPLATE); if (resourceName != null && resourceName.length() > 0) { Resource resource = null; Object relativeTo = activeEntry.getResourceIncludeRelativeTo(); String relativeToExpr = attrs.getValue(NodeIdentifiers.ATTRNAME_INCLUDE_RESOURCE_RELATIVE_TO); if (relativeToExpr != null) relativeTo = evaluateHandlerExpression(relativeToExpr); log.trace("Including resource '" + resourceName + "' relative to '" + relativeTo + "'."); if (relativeTo instanceof Class) resource = new Resource((Class) relativeTo, resourceName); else if (relativeTo instanceof ClassLoader) resource = new Resource((ClassLoader) relativeTo, resourceName); else if (relativeTo instanceof String) { try { resource = new Resource(Class.forName((String) relativeTo), resourceName); } catch (ClassNotFoundException e) { throw new ContentHandlerException(parseContext, "The result of '" + NodeIdentifiers.ATTRNAME_INCLUDE_RESOURCE_RELATIVE_TO + "' attribute expression '" + relativeTo + "' in <" + nodeIdentifiers.getIncludeElementName() + "> (" + relativeToExpr + ") must be either a Class or a ClassLoader."); }/*from www . j ava2s . c om*/ } else if (relativeToExpr != null) throw new ContentHandlerException(parseContext, "The result of '" + NodeIdentifiers.ATTRNAME_INCLUDE_RESOURCE_RELATIVE_TO + "' attribute expression '" + relativeTo + "' in <" + nodeIdentifiers.getIncludeElementName() + "> (" + relativeToExpr + ") must be either a Class or a ClassLoader."); else resource = new Resource(activeEntry.getClass(), resourceName); ParseContext includePC = resource.getFile() != null ? activeEntry.parseInclude(parseContext, resource.getFile()) : activeEntry.parseInclude(parseContext, resource); parseContext.getErrors().addAll(includePC.getErrors()); } else if (templateName != null && templateName.length() > 0) { log.trace("Including template '" + templateName + "'."); Template template = parseContext.getTemplateCatalog() .getTemplate(nodeIdentifiers.getGenericTemplateProducer(), templateName); if (template == null) throw new SAXParseException( "Generic template '" + templateName + "' was not found in the active document.", parseContext.getLocator()); template.applyChildren( template.createApplyContext(this, nodeIdentifiers.getIncludeElementName(), attrs)); } else { String fileName = attrs.getValue(NodeIdentifiers.ATTRNAME_INCLUDE_FILE); File includeFile = parseContext.resolveFile(fileName); log.trace("Including file '" + includeFile.getAbsolutePath() + "'."); ParseContext includePC = activeEntry.parseInclude(parseContext, includeFile); parseContext.getErrors().addAll(includePC.getErrors()); } }
From source file:jp.gr.java_conf.petit_lycee.subsonico.MethodConstants.java
public void startElement(String namespaceURI, String localName, String qName, org.xml.sax.Attributes attributes) { ResponseElement elem = null;/*from w w w . j a v a2 s . c o m*/ //element???? //(error????) if (qName.equals("subsonic-response")) { //set response data response.setStatus(attributes.getValue("status")); response.setVersion(attributes.getValue("version")); if (!"ok".equals(response.getStatus())) { subsEx = new SubsonicException(); } } else if (qName.equals("error")) { if (subsEx != null) setValues(subsEx, attributes); } else if (qName.equals("directory")) { Directory p = new Directory(); p.setDir(true); elem = p; } else if (qName.equals("index")) { elem = new Index(); } else if (qName.equals("child")) { int spam = attributes.getIndex("isDir"); if (spam >= 0 && attributes.getValue(spam).equals("true")) { elem = new Directory(); } else { elem = new Media(); } } else if (qName.equals("artist")) { elem = new Directory(); } else if (qName.equals("song")) { elem = new Media(); } else if (qName.equals("license")) { elem = new License(); } if (elem != null) { setValues(elem, attributes); if (elem instanceof Entry) { Entry etr = (Entry) elem; ArrayList<Entry> list = stack.peek(); list.add(etr); stack.push(etr.children); } } }
From source file:com.aurel.track.exchange.track.importer.ImporterDataParser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { textContent = null;/*w ww . j a va2s. c o m*/ if (qName.equalsIgnoreCase(ExchangeFieldNames.ITEM)) { currentWorkItem = new ExchangeWorkItem(); currentWorkItem.setUuid(attributes.getValue(ExchangeFieldNames.UUID)); String strWorkItemID = attributes.getValue(ExchangeFieldNames.WORKITEMID); if (strWorkItemID != null) { currentWorkItem.setWorkItemID(new Integer(strWorkItemID)); } exchangeWorkItemsList.add(currentWorkItem); numberOfWorkItems++; } if (qName.equalsIgnoreCase(ExchangeFieldNames.ITEM_ATTRIBUTE)) { fieldID = attributes.getValue(ExchangeFieldNames.FIELDID); parameterCode = attributes.getValue(ExchangeFieldNames.PARAMETERCODE); isActualValue = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.HISTORY_LIST)) { historyValues = new ArrayList<ExchangeHistoryTransactionEntry>(); currentWorkItem.setHistoryValues(historyValues); } if (qName.equalsIgnoreCase(ExchangeFieldNames.TRANSACTION)) { ExchangeHistoryTransactionEntry exchangeHistoryTransactionEntry = new ExchangeHistoryTransactionEntry() .deserializeBean(ParserUtil.getAttributesMap(attributes)); historyFieldChanges = new ArrayList<ExchangeHistoryFieldEntry>(); exchangeHistoryTransactionEntry.setHistoryFieldChanges(historyFieldChanges); historyValues.add(exchangeHistoryTransactionEntry); } if (qName.equalsIgnoreCase(ExchangeFieldNames.FIELDCHANGE)) { actualHistoryFieldChange = new ExchangeHistoryFieldEntry() .deserializeBean(ParserUtil.getAttributesMap(attributes)); historyFieldChanges.add(actualHistoryFieldChange); } if (qName.equalsIgnoreCase(ExchangeFieldNames.NEWVALUE)) { isNewValue = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.OLDVALUE)) { isOldValue = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.CONSULTANT_LIST)) { consultedList = new ArrayList<Integer>(); currentWorkItem.setConsultedList(consultedList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.CONSULTANT)) { String strPerson = attributes.getValue(ExchangeFieldNames.PERSON); if (strPerson != null) { currentWorkItem.getConsultedList().add(new Integer(strPerson)); } } if (qName.equalsIgnoreCase(ExchangeFieldNames.INFORMANT_LIST)) { informedList = new ArrayList<Integer>(); currentWorkItem.setInformedList(informedList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.INFORMANT)) { String strPerson = attributes.getValue(ExchangeFieldNames.PERSON); if (strPerson != null) { currentWorkItem.getInformedList().add(new Integer(strPerson)); } } if (qName.equalsIgnoreCase(ExchangeFieldNames.BUDGET_LIST)) { budgetBeanList = new ArrayList<TBudgetBean>(); currentWorkItem.setBudgetBeanList(budgetBeanList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.BUDGET_ELEMENT)) { actualBudgetBean = new TBudgetBean().deserializeBean(ParserUtil.getAttributesMap(attributes)); actualBudgetBean.setWorkItemID(currentWorkItem.getWorkItemID()); budgetBeanList.add(actualBudgetBean); isBudgetDescription = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.PLANNED_VALUE_LIST)) { plannedValueBeanList = new ArrayList<TBudgetBean>(); currentWorkItem.setPlannedValueBeanList(plannedValueBeanList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.PLANNED_VALUE_ELEMENT)) { actualBudgetBean = new TBudgetBean().deserializeBean(ParserUtil.getAttributesMap(attributes)); actualBudgetBean.setWorkItemID(currentWorkItem.getWorkItemID()); plannedValueBeanList.add(actualBudgetBean); isBudgetDescription = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.REMAINING_BUDGET_ELEMENT)) { TActualEstimatedBudgetBean actualEstimatedBudgetBean = new TActualEstimatedBudgetBean() .deserializeBean(ParserUtil.getAttributesMap(attributes)); actualEstimatedBudgetBean.setWorkItemID(currentWorkItem.getWorkItemID()); currentWorkItem.setActualEstimatedBudgetBean(actualEstimatedBudgetBean); } if (qName.equalsIgnoreCase(ExchangeFieldNames.EXPENSE_LIST)) { expenseBeanList = new ArrayList<TCostBean>(); currentWorkItem.setExpenseBeanList(expenseBeanList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.EXPENSE_ELEMENT)) { actualCostBean = new TCostBean().deserializeBean(ParserUtil.getAttributesMap(attributes)); actualCostBean.setWorkitem(currentWorkItem.getWorkItemID()); expenseBeanList.add(actualCostBean); isCostDescription = true; } if (qName.equalsIgnoreCase(ExchangeFieldNames.ATTACHMENT_LIST)) { attachmentBeanList = new ArrayList<TAttachmentBean>(); currentWorkItem.setAttachmentBeanList(attachmentBeanList); } if (qName.equalsIgnoreCase(ExchangeFieldNames.ATTACHMENT_ELEMENT)) { actualAttachmentBean = new TAttachmentBean().deserializeBean(ParserUtil.getAttributesMap(attributes)); actualAttachmentBean.setWorkItem(currentWorkItem.getWorkItemID()); attachmentBeanList.add(actualAttachmentBean); isAttachmentDescription = true; } }
From source file:com.ibm.jaql.lang.expr.xml.XmlToJsonFn.java
@Override public void startElement(String uri, String localName, String name, Attributes attrs) throws SAXException { try {//from www .jav a 2 s . c o m SpilledJsonArray ca = new SpilledJsonArray(); int n = attrs.getLength(); for (int i = 0; i < n; i++) { name = "@" + attrs.getLocalName(i); uri = attrs.getURI(i); String v = attrs.getValue(i); BufferedJsonRecord r = new BufferedJsonRecord(); if (uri != null && uri.length() > 0) { r.add(S_XMLNS, new JsonString(uri)); } r.add(new JsonString(name), new JsonString(v)); ca.addCopy(r); } stack.push(ca); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }