List of usage examples for org.xml.sax Attributes getLocalName
public abstract String getLocalName(int index);
From source file:net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashXMsgRspnHandler.CFGCashXMsgRspnContactUpdatedHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {/*www . j a v a 2 s . c o m*/ // Common XML Attributes String attrId = null; String attrRevision = null; // Contact Attributes String attrTenantId = null; String attrContactId = null; String attrContactListId = null; String attrISOTimezoneId = null; String attrFullName = null; String attrLastName = null; String attrFirstName = null; String attrCustom = null; String attrCustom2 = null; String attrCustom3 = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RspnContactUpdated"); CFGCashXMsgRspnHandler xmsgRspnHandler = (CFGCashXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGCashSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedAt")) { if (attrCreatedAt != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedBy")) { if (attrCreatedBy != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedAt")) { if (attrUpdatedAt != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedBy")) { if (attrUpdatedBy != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TenantId")) { if (attrTenantId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ContactId")) { if (attrContactId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrContactId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ContactListId")) { if (attrContactListId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrContactListId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ISOTimezoneId")) { if (attrISOTimezoneId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrISOTimezoneId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("FullName")) { if (attrFullName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrFullName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("LastName")) { if (attrLastName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrLastName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("FirstName")) { if (attrFirstName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrFirstName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Custom")) { if (attrCustom != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCustom = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Custom2")) { if (attrCustom2 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCustom2 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Custom3")) { if (attrCustom3 != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCustom3 = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrTenantId == null) || (attrTenantId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "TenantId"); } if ((attrContactId == null) || (attrContactId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ContactId"); } if ((attrContactListId == null) || (attrContactListId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ContactListId"); } if (attrFullName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "FullName"); } if ((attrRevision == null) || (attrRevision.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Revision"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types long natTenantId = Long.parseLong(attrTenantId); long natContactId = Long.parseLong(attrContactId); long natContactListId = Long.parseLong(attrContactListId); Short natISOTimezoneId; if ((attrISOTimezoneId == null) || (attrISOTimezoneId.length() <= 0)) { natISOTimezoneId = null; } else { natISOTimezoneId = new Short(Short.parseShort(attrISOTimezoneId)); } String natFullName = attrFullName; String natLastName = attrLastName; String natFirstName = attrFirstName; String natCustom = attrCustom; String natCustom2 = attrCustom2; String natCustom3 = attrCustom3; int natRevision = Integer.parseInt(attrRevision); UUID createdBy = null; if (attrCreatedBy != null) { createdBy = UUID.fromString(attrCreatedBy); } Calendar createdAt = null; if (attrCreatedAt != null) { createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt); } UUID updatedBy = null; if (attrUpdatedBy != null) { updatedBy = UUID.fromString(attrUpdatedBy); } Calendar updatedAt = null; if (attrUpdatedAt != null) { updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt); } // Instantiate a buffer for the parsed information ICFGCashContactObj obj = schemaObj.getContactTableObj().newInstance(); CFGCashContactBuff dataBuff = obj.getContactBuff(); dataBuff.setRequiredTenantId(natTenantId); dataBuff.setRequiredContactId(natContactId); dataBuff.setRequiredContactListId(natContactListId); dataBuff.setOptionalISOTimezoneId(natISOTimezoneId); dataBuff.setRequiredFullName(natFullName); dataBuff.setOptionalLastName(natLastName); dataBuff.setOptionalFirstName(natFirstName); dataBuff.setOptionalCustom(natCustom); dataBuff.setOptionalCustom2(natCustom2); dataBuff.setOptionalCustom3(natCustom3); dataBuff.setRequiredRevision(natRevision); if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } obj.copyBuffToPKey(); ICFGCashContactObj realized = (ICFGCashContactObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); } catch (RuntimeException e) { throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
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 w w w. j a v 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); } }
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() + "): ...")); }/* w ww . jav a 2 s.co 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:net.sourceforge.msscodefactory.cfbamcustom.v2_7.CFBamXmlLoader.CFBamXmlLoaderTableAddendumHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { final String S_ProcName = "startElement"; // TableRelations attributes String attrFromTable = null;/* ww w. j a va2 s. c o m*/ // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; assert qName.equals("TableAddendum"); numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("FromTable")) { if (attrFromTable != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, attrLocalName); } attrFromTable = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, "LocalName", attrLocalName); } } if ((attrFromTable == null) || (attrFromTable.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newEmptyArgumentException(getClass(), S_ProcName, 0, "FromTable"); } CFBamXmlLoader saxLoader = (CFBamXmlLoader) getParser(); if (saxLoader == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } CFLibXmlCoreContext curContext = saxLoader.getCurContext(); if (curContext == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getCurContext()"); } ICFBamSchemaObj schemaObj = saxLoader.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } if (!CFBamXmlLoader.getProcessSchema(curContext)) { return; } CFLibXmlCoreContext prevContext = curContext.getPrevContext(); ICFBamSchemaDefObj schemaDef = (ICFBamSchemaDefObj) (prevContext.getNamedValue("Object")); ICFBamTableObj fromTable = schemaObj.getTableTableObj().readTableByUNameIdx(schemaDef.getRequiredTenantId(), schemaDef.getRequiredId(), attrFromTable); if (fromTable == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, " Could not resolve FromTable \"" + attrFromTable + "\" in Schema \"" + schemaDef.getObjFullName() + "\""); } curContext.putNamedValue("FromTable", fromTable); // No scope to add here, just resolving a table context curContext.putNamedValue("Object", fromTable); }
From source file:com.adobe.acs.commons.rewriter.impl.StaticReferenceRewriteTransformerFactory.java
private Attributes rebuildAttributes(final String elementName, final Attributes attrs) { if (attributes.containsKey(elementName)) { final String[] modifyableAttributes = attributes.get(elementName); // first - check for the nostatic class boolean rewriteStatic = true; for (int i = 0; i < attrs.getLength(); i++) { final String attrName = attrs.getLocalName(i); if (ATTR_CLASS.equals(attrName)) { String attrValue = attrs.getValue(i); if (attrValue.contains(CLASS_NOSTATIC)) { rewriteStatic = false; }/*from w ww . j a v a 2 s .c o m*/ } } if (rewriteStatic) { return rebuildAttributes(elementName, attrs, modifyableAttributes); } } return attrs; }
From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) { buffer.setLength(0);/*from ww w . j a va2s . c o m*/ if (localName.equals("FIELD")) { FieldDef fldDef = new FieldDef(); fields.add(fldDef); for (int i = 0; i < attrs.getLength(); i++) { String attr = attrs.getLocalName(i); String value = attrs.getValue(i); if (attr.equals("EMPTYOK")) { fldDef.setNullable(value.equals("YES")); } else if (attr.equals("NAME")) { value = StringUtils.capitalize(value.trim()); value = StringUtils.deleteWhitespace(value); value = StringUtils.replace(value, "_", ""); if ((value.charAt(0) >= '0' && value.charAt(0) <= '9') || value.equalsIgnoreCase("New") || value.equalsIgnoreCase("Group")) { value = "Fld" + value; } String fixedStr = convertFromTwoByteUTF8(value); fixedStr = StringUtils.replace(fixedStr, ".", ""); fixedStr = StringUtils.replace(fixedStr, ":", ""); fixedStr = StringUtils.replace(fixedStr, "/", "_"); fldDef.setName(fixedStr); fldDef.setOrigName(value); } else if (attr.equals("TYPE")) { if (value.equals("TEXT")) { fldDef.setType(DataType.eText); } else if (value.equals("NUMBER")) { fldDef.setType(DataType.eNumber); } else if (value.equals("DATE")) { fldDef.setType(DataType.eDate); } else if (value.equals("TIME")) { fldDef.setType(DataType.eTime); } else { System.err.println("Unknown Type[" + value + "]"); } } } } }
From source file:com.textocat.textokit.commons.io.axml.AXMLContentHandler.java
private void onAnnotationStart(final String aType, Attributes attrs) throws SAXParseException { String type = toTypeName(aType); Annotation newAnno = new Annotation(); newAnno.setType(type);/*from w w w. ja va2s .co m*/ newAnno.setBegin(textBuilder.length()); // handle features for (int attrIndex = 0; attrIndex < attrs.getLength(); attrIndex++) { final String attrName = attrs.getLocalName(attrIndex); if ("id".equals(attrName)) { // handle as a special case String id = attrs.getValue(attrIndex); newAnno.setId(id); annoIdIndex.put(id, newAnno); } else { // handle the attr as feature name or alias String featName = attrName; if (featNameAliases.containsKey(attrName)) { featName = featNameAliases.get(attrName); } String attrVal = attrs.getValue(attrIndex); if (attrVal.startsWith("id:")) { String valId = attrVal.substring("id:".length()); fsFeatureTable.put(newAnno, featName, valId); } else if (attrVal.startsWith("ids:")) { List<String> valIds = ID_SPLITTER.splitToList(attrVal.substring("ids:".length())); fsFeatureTable.put(newAnno, featName, valIds); } else { newAnno.setFeatureStringValue(featName, attrVal); } } } // openAnnotations.addFirst(newAnno); }
From source file:com.swtxml.tinydom.TinyDomSaxHandler.java
private Map<INamespaceDefinition, Map<IAttributeDefinition, String>> processAttributes( INamespaceDefinition tagNamespace, ITagDefinition tagDefinition, Attributes attributes) { Map<INamespaceDefinition, Map<IAttributeDefinition, String>> attributeNsMap = new HashMap<INamespaceDefinition, Map<IAttributeDefinition, String>>(); for (int i = 0; i < attributes.getLength(); i++) { String uri = attributes.getURI(i); INamespaceDefinition attributeNamespace = !StringUtils.isEmpty(uri) ? getNamespace(uri) : tagNamespace; Map<IAttributeDefinition, String> attributeMap = attributeNsMap.get(attributeNamespace); if (attributeMap == null) { attributeMap = new HashMap<IAttributeDefinition, String>(); attributeNsMap.put(attributeNamespace, attributeMap); }//from w w w. j a v a 2s . com String name = attributes.getLocalName(i); String value = attributes.getValue(i); IAttributeDefinition attributeDefinition; if (attributeNamespace.equals(tagNamespace)) { attributeDefinition = tagDefinition.getAttribute(name); } else { attributeDefinition = attributeNamespace.getForeignAttribute(name); if (attributeDefinition instanceof ITagScope && !((ITagScope) attributeDefinition).isAllowedIn(tagDefinition)) { throw new ParseException("Attribute " + attributes.getQName(i) + " is not allowed for tag \"" + tagDefinition.getName() + "\""); } } if (attributeDefinition == null) { throw new ParseException("Unknown attribute \"" + attributes.getQName(i) + "\" for tag \"" + tagDefinition.getName() + "\" (available are: " + CollectionUtils.sortedToString(tagDefinition.getAttributeNames()) + ")"); } attributeMap.put(attributeDefinition, value); } if (attributeNsMap.isEmpty()) { return Collections.emptyMap(); } return attributeNsMap; }
From source file:com.kdmanalytics.toif.assimilator.XMLNode.java
/** * Parse the node information. Note that the "Attributes" here are XML Attributes, not KDM * attributes.//w w w. j av 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: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('"'); }/*w w w . jav a2s. c om*/ parameterTextBuilder.append(" >"); }