List of usage examples for org.xml.sax Attributes getValue
public abstract String getValue(String qName);
From source file:com.atlassian.jira.action.admin.OfbizImportHandler.java
private void recordProperties(final String qName, final Attributes attributes, final String entityName, final Map<String, String> store) { if (entityName.equals(qName)) { final String id = attributes.getValue("id"); final String value = attributes.getValue("value"); if ((id != null) && (value != null)) { store.put(id, value);/*from ww w .j a va 2 s. co m*/ } } }
From source file:MapTranslater.java
public void startElement(String namespaceURI, String sName, // simple name String qName, // qualified name Attributes attrs) throws SAXException { echoText();//from ww w . j a v a 2s. c o m String eName = sName; // element name if ("".equals(eName)) { eName = qName; // not namespaceAware } if (isMapElem(eName)) { // New map elem starts. Now we have to look for its names... jaName = null; enName = null; enNameOnly = null; deName = null; } else if (eName.equals("tag")) { String key = attrs.getValue("k"); if (key.equals("name:en") || (key.equals("name:ja_rm") && enName == null)) enName = attrs.getValue("v"); else if (key.equals("name:de")) deName = attrs.getValue("v"); else if (key.equals("name") || key.equals("name:ja")) jaName = attrs.getValue("v"); if (key.equals("name:en")) enNameOnly = attrs.getValue("v"); } emit("<" + eName); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { String aName = attrs.getLocalName(i); // Attr name if ("".equals(aName)) { aName = attrs.getQName(i); } emit(" "); emit(aName + "=\"" + StringEscapeUtils.escapeXml(attrs.getValue(i)) + "\""); } } emit(">"); }
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);/* w w w .j a va 2 s . com*/ 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.dotosoft.dot4command.config.xml.ConfigRegisterRule.java
/** * <p>Register the top {@link com.dotosoft.dot4command.chain.Command} if appropriate.</p> * * @param namespace the namespace URI of the matching element, or an * empty string if the parser is not namespace aware or the element has * no namespace/*from w ww .j av a 2s. co m*/ * @param name the local name if the parser is namespace aware, or just * the element name otherwise * @param attributes The attribute list of this element */ @Override public void begin(String namespace, String name, Attributes attributes) throws Exception { // Is the top object a Command? Object top = getDigester().peek(0); if ((top == null) || !(top instanceof Command)) { return; } /* All commands can consume a generic context. Here we depend on * the configuration being correct because the rule binding is * dynamic. */ Command<String, Object, Map<String, Object>> command = (Command<String, Object, Map<String, Object>>) top; // Is the next object a Catalog or a Chain? Object next = getDigester().peek(1); if (next == null) { return; } // Register the top element appropriately if (next instanceof Catalog) { String nameValue = attributes.getValue(nameAttribute); if (nameValue != null) { /* We are dynamically building a catalog and assigning * generics to the most base types possible. */ Catalog<String, Object, Map<String, Object>> catalog = (Catalog<String, Object, Map<String, Object>>) next; command.setParent(catalog); catalog.addCommand(nameValue, command); } } else if (next instanceof Chain) { /* Like above - the chain is being dynamically generated, * so we can add a generic context signature at compile-time. */ Chain<String, Object, Map<String, Object>> chain = (Chain<String, Object, Map<String, Object>>) next; command.setParent(chain); chain.addCommand(command); } }
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.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);/* w ww.ja v a2 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: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); }/* w w w . j a va 2 s.c o m*/ 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.determinato.feeddroid.parser.RssParser.java
/** * {@inheritDoc}/* w w w .j av a 2 s. c om*/ */ public void startElement(String uri, String name, String qName, Attributes attrs) { if (mId == -1 && name.equals("title") && (mState & STATE_IN_ITEM) == 0) { mState |= STATE_IN_TITLE; return; } Integer state = mStateMap.get(name); if (state != null) { mState |= state.intValue(); if (state.intValue() == STATE_IN_ITEM) mPostBuf = new ChannelPost(); else if ((mState & STATE_IN_ITEM) != 0 && state.intValue() == STATE_IN_ITEM_LINK) { String href = attrs.getValue("href"); if (href != null) mPostBuf.link = href; } else if ((mState & STATE_IN_ITEM) != 0 && state.intValue() == STATE_MEDIA_CONTENT) { String url = attrs.getValue("url"); String type = attrs.getValue("type"); if (!TextUtils.isEmpty(url) && FeedDroidUtils.isPodcast(type)) { Log.d(TAG, "Podcast: " + url); mPostBuf.podcastUrl = url; mPostBuf.podcastMimeType = type; } } } }
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;//from ww w . j av a2s. co 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.sshtools.daemon.configuration.ServerConfiguration.java
/** * * * @param uri/*ww w . ja v a 2s . c o m*/ * @param localName * @param qname * @param attrs * * @throws SAXException */ public void startElement(String uri, String localName, String qname, Attributes attrs) throws SAXException { if (currentElement == null) { if (!qname.equals("ServerConfiguration")) { throw new SAXException("Unexpected root element " + qname); } } else { if (currentElement.equals("ServerConfiguration")) { if (qname.equals("ServerHostKey")) { //String algorithm = attrs.getValue("AlgorithmName"); String privateKey = attrs.getValue("PrivateKeyFile"); if (privateKey == null) { throw new SAXException("Required attributes missing from <ServerHostKey> element"); } log.debug("ServerHostKey PrivateKeyFile=" + privateKey); File f = new File(privateKey); if (!f.exists()) { privateKey = ConfigurationLoader.getConfigurationDirectory() + privateKey; f = new File(privateKey); } try { if (f.exists()) { SshPrivateKeyFile pkf = SshPrivateKeyFile.parse(f); SshPrivateKey key = pkf.toPrivateKey(null); serverHostKeys.put(key.getAlgorithmName(), key); } else { log.warn("Private key file '" + privateKey + "' could not be found"); } } catch (InvalidSshKeyException ex) { log.warn("Failed to load private key '" + privateKey, ex); } catch (IOException ioe) { log.warn("Failed to load private key '" + privateKey, ioe); } } else if (qname.equals("Subsystem")) { String type = attrs.getValue("Type"); String name = attrs.getValue("Name"); String provider = attrs.getValue("Provider"); if ((type == null) || (name == null) || (provider == null)) { throw new SAXException("Required attributes missing from <Subsystem> element"); } log.debug("Subsystem Type=" + type + " Name=" + name + " Provider=" + provider); allowedSubsystems.put(name, new AllowedSubsystem(type, name, provider)); } else if (!qname.equals("AuthenticationBanner") && !qname.equals("MaxConnections") && !qname.equals("MaxAuthentications") && !qname.equals("ListenAddress") && !qname.equals("Port") && !qname.equals("CommandPort") && !qname.equals("TerminalProvider") && !qname.equals("AllowedAuthentication") && !qname.equals("RequiredAuthentication") && !qname.equals("AuthorizationFile") && !qname.equals("UserConfigDirectory") && !qname.equals("AllowTcpForwarding")) { throw new SAXException("Unexpected <" + qname + "> element after SshAPIConfiguration"); } } } currentElement = qname; }