/** * Pull a string entry from a stanza, or null. * * @param name entry to look for * * @return the entry, or null if it was not found. */ public String getValueOrNull(String name) throws InvalidXmlException { if (!subtrees.containsKey(name)) { return null; } LinkedList <Stanza> l = subtrees.get(name); if (l.size() != 1) { throw new InvalidXmlException("More than one value found for " + name); } return l.get(0).getValue(); }
/** * Pull an entry from a stanza. * * @param name entry to look for * * @return the entry */ public List<Stanza> getChildren(String name) throws InvalidXmlException { LinkedList <Stanza> children = subtrees.get(name); if (children == null) { throw new InvalidXmlException("no entry found for " + name); } return children; }
public static DelegationKey delegationKeyFromXml(Stanza st) throws InvalidXmlException { int keyId = Integer.parseInt(st.getValue("KEY_ID")); long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE")); byte key[] = null; try { key = Hex.decodeHex(st.getValue("KEY").toCharArray()); } catch (DecoderException e) { throw new InvalidXmlException(e.toString()); } catch (InvalidXmlException e) { } return new DelegationKey(keyId, expiryDate, key); }
/** * Pull an entry from a stanza. * * @param name entry to look for * * @return the entry */ public List<Stanza> getChildren(String name) throws InvalidXmlException { LinkedList <Stanza> children = subtrees.get(name); if (children == null) { throw new InvalidXmlException("no entry found for " + name); } return children; }
/** * Pull a string entry from a stanza. * * @param name entry to look for * * @return the entry */ public String getValue(String name) throws InvalidXmlException { String ret = getValueOrNull(name); if (ret == null) { throw new InvalidXmlException("no entry found for " + name); } return ret; }
/** * Pull a string entry from a stanza. * * @param name entry to look for * * @return the entry */ public String getValue(String name) throws InvalidXmlException { String ret = getValueOrNull(name); if (ret == null) { throw new InvalidXmlException("no entry found for " + name); } return ret; }
/** * Pull an entry from a stanza. * * @param name entry to look for * * @return the entry */ public List<Stanza> getChildren(String name) throws InvalidXmlException { LinkedList <Stanza> children = subtrees.get(name); if (children == null) { throw new InvalidXmlException("no entry found for " + name); } return children; }
public static DelegationKey delegationKeyFromXml(Stanza st) throws InvalidXmlException { int keyId = Integer.parseInt(st.getValue("KEY_ID")); long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE")); byte key[] = null; try { key = Hex.decodeHex(st.getValue("KEY").toCharArray()); } catch (DecoderException e) { throw new InvalidXmlException(e.toString()); } catch (InvalidXmlException e) { } return new DelegationKey(keyId, expiryDate, key); }
public static DelegationKey delegationKeyFromXml(Stanza st) throws InvalidXmlException { int keyId = Integer.parseInt(st.getValue("KEY_ID")); long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE")); byte key[] = null; try { key = Hex.decodeHex(st.getValue("KEY").toCharArray()); } catch (DecoderException e) { throw new InvalidXmlException(e.toString()); } catch (InvalidXmlException e) { } return new DelegationKey(keyId, expiryDate, key); }
private static FsAction fsActionFromXml(Stanza st) throws InvalidXmlException { FsAction v = FSACTION_SYMBOL_MAP.get(st.getValue("PERM")); if (v == null) throw new InvalidXmlException("Invalid value for FsAction"); return v; }
@Override public void endDocument() { if (state != ParseState.EXPECT_END) { throw new InvalidXmlException("expecting </EDITS>"); } }
@Override public void endDocument() { if (state != ParseState.EXPECT_END) { throw new InvalidXmlException("expecting </EDITS>"); } }
private static FsAction fsActionFromXml(Stanza st) throws InvalidXmlException { FsAction v = FSACTION_SYMBOL_MAP.get(st.getValue("PERM")); if (v == null) throw new InvalidXmlException("Invalid value for FsAction"); return v; }
switch (state) { case EXPECT_EDITS_TAG: throw new InvalidXmlException("expected <EDITS/>"); case EXPECT_VERSION: if (!name.equals("EDITS_VERSION")) { throw new InvalidXmlException("expected </EDITS_VERSION>"); state = ParseState.EXPECT_END; } else if (!name.equals("RECORD")) { throw new InvalidXmlException("expected </EDITS> or </RECORD>"); throw new InvalidXmlException("expected </OPCODE>"); break; case EXPECT_DATA: throw new InvalidXmlException("expected <DATA/>"); case HANDLE_DATA: stanza.setValue(str); if (stanzaStack.empty()) { if (!name.equals("DATA")) { throw new InvalidXmlException("expected </DATA>"); throw new InvalidXmlException("not expecting anything after </EDITS>");
case EXPECT_EDITS_TAG: if (!name.equals("EDITS")) { throw new InvalidXmlException("you must put " + "<EDITS> at the top of the XML file! " + "Got tag " + name + " instead"); case EXPECT_VERSION: if (!name.equals("EDITS_VERSION")) { throw new InvalidXmlException("you must put " + "<EDITS_VERSION> at the top of the XML file! " + "Got tag " + name + " instead"); case EXPECT_RECORD: if (!name.equals("RECORD")) { throw new InvalidXmlException("expected a <RECORD> tag"); case EXPECT_OPCODE: if (!name.equals("OPCODE")) { throw new InvalidXmlException("expected an <OPCODE> tag"); throw new InvalidXmlException("expected a <DATA> tag"); break; case EXPECT_END: throw new InvalidXmlException("not expecting anything after </EDITS>");
private static List<XAttr> readXAttrsFromXml(Stanza st) throws InvalidXmlException { if (!st.hasChildren("XATTR")) { return null; } List<Stanza> stanzas = st.getChildren("XATTR"); List<XAttr> xattrs = Lists.newArrayListWithCapacity(stanzas.size()); for (Stanza a: stanzas) { XAttr.Builder builder = new XAttr.Builder(); builder.setNameSpace(XAttr.NameSpace.valueOf(a.getValue("NAMESPACE"))). setName(a.getValue("NAME")); String v = a.getValueOrNull("VALUE"); if (v != null) { try { builder.setValue(XAttrCodec.decodeValue(v)); } catch (IOException e) { throw new InvalidXmlException(e.toString()); } } xattrs.add(builder.build()); } return xattrs; } }
public static DelegationTokenIdentifier delegationTokenFromXml(Stanza st) throws InvalidXmlException { String kind = st.getValue("KIND"); if (!kind.equals(DelegationTokenIdentifier. HDFS_DELEGATION_KIND.toString())) { throw new InvalidXmlException("can't understand " + "DelegationTokenIdentifier KIND " + kind); } int seqNum = Integer.parseInt(st.getValue("SEQUENCE_NUMBER")); String owner = st.getValue("OWNER"); String renewer = st.getValue("RENEWER"); String realuser = st.getValue("REALUSER"); long issueDate = Long.parseLong(st.getValue("ISSUE_DATE")); long maxDate = Long.parseLong(st.getValue("MAX_DATE")); int masterKeyId = Integer.parseInt(st.getValue("MASTER_KEY_ID")); DelegationTokenIdentifier token = new DelegationTokenIdentifier(new Text(owner), new Text(renewer), new Text(realuser)); token.setSequenceNumber(seqNum); token.setIssueDate(issueDate); token.setMaxDate(maxDate); token.setMasterKeyId(masterKeyId); return token; }
/** * Pull a string entry from a stanza. * * @param name entry to look for * * @return the entry */ public String getValue(String name) throws InvalidXmlException { String ret = getValueOrNull(name); if (ret == null) { throw new InvalidXmlException("no entry found for " + name); } return ret; }
private static FsAction fsActionFromXml(Stanza st) throws InvalidXmlException { FsAction v = FSACTION_SYMBOL_MAP.get(st.getValue("PERM")); if (v == null) throw new InvalidXmlException("Invalid value for FsAction"); return v; }
@Override public void endDocument() { if (state != ParseState.EXPECT_END) { throw new InvalidXmlException("expecting </EDITS>"); } }