public Tag toTag() { Tag top = new Tag("metadata"); if (modelVersion != null) top.addAttribute("modelVersion", modelVersion); new Tag(top, "groupId").addContent(group); new Tag(top, "artifactId").addContent(artifact); return top; }
public String findRecursiveAttribute(String name) { String value = getAttribute(name); if (value != null) return value; if (parent != null) return parent.findRecursiveAttribute(name); return null; }
/** * convenient method to get the contents in a StringBuilder. */ public void getContentsAsString(StringBuilder sb) { for (Object o : content) { if (o instanceof Tag) ((Tag) o).getContentsAsString(sb); else sb.append(o); } }
Tag getTag() { Tag option = new Tag("Option").addAttribute("label", label) .addAttribute("value", value); return option; }
spaces(pw, indent); pw.print('<'); pw.print(name); String value = escape(attributes.get(key)); pw.print(' '); pw.print(key); for (Object c : content) { if (c instanceof String) { formatted(pw, indent + 2, 60, escape((String) c)); } else if (c instanceof Tag) { Tag tag = (Tag) c; tag.print(indent + 2, pw); spaces(pw, indent); pw.print("</"); pw.print(name);
public boolean match(String search, Tag child, Tag mapping) { String target = child.getName(); String sn = null; String tn = null; if (search.equals("*")) return true; int s = search.indexOf(':'); if (s > 0) { sn = search.substring(0, s); search = search.substring(s + 1); } int t = target.indexOf(':'); if (t > 0) { tn = target.substring(0, t); target = target.substring(t + 1); } if (!search.equals(target)) // different tag names return false; if (mapping == null) { return tn == sn || (sn != null && sn.equals(tn)); } String suri = sn == null ? mapping.getAttribute("xmlns") : mapping.getAttribute("xmlns:" + sn); String turi = tn == null ? child.findRecursiveAttribute("xmlns") : child.findRecursiveAttribute("xmlns:" + tn); return ((turi == null) && (suri == null)) || ((turi != null) && turi.equals(suri)); }
public String compact() { StringWriter sw = new StringWriter(); print(Integer.MIN_VALUE, new PrintWriter(sw)); return sw.toString(); }
@Override public Tag toTag() { Tag top = super.toTag(); if (latest != null) new Tag(top, "latest").addContent(latest.toString()); if (release != null) new Tag(top, "release").addContent(release.toString()); Tag versioning = new Tag(top, "versioning"); Tag versionsTag = new Tag(versioning, "versions"); for (MavenVersion mv : versions) { new Tag(versionsTag, "version").addContent(mv.toString()); } new Tag(versioning, "lastUpdated", timestamp.format(new Date(lastUpdated))); return top; } }
public Tag(Tag parent, String name, Object... contents) { this(name, contents); parent.addContent(this); }
/** * Return only the tags of the first level of descendants that match the * name. */ public List<Object> getContents(String tag) { List<Object> out = new ArrayList<Object>(); for (Object o : out) { if (o instanceof Tag && ((Tag) o).getName().equals(tag)) out.add(o); } return out; }
public String getNameSpace() { return getNameSpace(name); }
public String getNameSpace(String name) { int index = name.indexOf(':'); if (index > 0) { String ns = name.substring(0, index); return findRecursiveAttribute("xmlns:" + ns); } return findRecursiveAttribute("xmlns"); }
/** * Return the attribute value or a default if not defined. */ public String getAttribute(String key, String deflt) { String answer = getAttribute(key); return answer == null ? deflt : answer; }
/** * Construct a new Tag with a name and a set of attributes. The attributes * are given as ( name, value ) ... */ public Tag(String name, String[] attributes, Object... contents) { this(name, contents); for (int i = 0; i < attributes.length; i += 2) addAttribute(attributes[i], attributes[i + 1]); }
spaces(pw, indent); pw.print('<'); pw.print(name); String value = escape(attributes.get(key)); pw.print(' '); pw.print(key); pw.print("]]>"); } else formatted(pw, indent + 2, 60, escape((String) c)); } else if (c instanceof Tag) { Tag tag = (Tag) c; tag.print(indent + 2, pw); spaces(pw, indent); pw.print("</"); pw.print(name);
public boolean match(String search, Tag child, Tag mapping) { String target = child.getName(); String sn = null; String tn = null; if (search.equals("*")) return true; int s = search.indexOf(':'); if (s > 0) { sn = search.substring(0, s); search = search.substring(s + 1); } int t = target.indexOf(':'); if (t > 0) { tn = target.substring(0, t); target = target.substring(t + 1); } if (!search.equals(target)) // different tag names return false; if (mapping == null) { return tn == sn || (sn != null && sn.equals(tn)); } String suri = sn == null ? mapping.getAttribute("xmlns") : mapping.getAttribute("xmlns:" + sn); String turi = tn == null ? child.findRecursiveAttribute("xmlns") : child.findRecursiveAttribute("xmlns:" + tn); return ((turi == null) && (suri == null)) || ((turi != null) && turi.equals(suri)); }
public XMLResourceGenerator referral(URI reference, int depth) { Tag referall = new Tag(repository, "referral"); referall.addAttribute("url", reference); if (depth > 0) referall.addAttribute("depth", depth); return this; }
/** * Return a string representation of this Tag and all its children * recursively. */ @Override public String toString() { StringWriter sw = new StringWriter(); print(0, new PrintWriter(sw)); return sw.toString(); }