List of usage examples for javax.xml.stream XMLStreamReader nextTag
public int nextTag() throws XMLStreamException;
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void _load_1_0(GTDModel model, XMLStreamReader r) throws XMLStreamException { if (checkTagStart(r, "folders")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "folder")) { //$NON-NLS-1$ String type = r.getAttributeValue(null, "type").trim(); //$NON-NLS-1$ Folder ff = null;//from ww w . j av a 2 s .c o m if ("NOTE".equals(type)) { //$NON-NLS-1$ ff = model.getInBucketFolder(); } else { ff = model.createFolder(r.getAttributeValue(null, "name"), FolderType.valueOf(type)); //$NON-NLS-1$ } r.nextTag(); while (checkTagStart(r, "action")) { //$NON-NLS-1$ int i = Integer.parseInt(r.getAttributeValue(null, "id")); //$NON-NLS-1$ Date cr = new Date(Long.parseLong(r.getAttributeValue(null, "created"))); //$NON-NLS-1$ Date re = r.getAttributeValue(null, "resolved") == null ? null //$NON-NLS-1$ : new Date(Long.parseLong(r.getAttributeValue(null, "resolved"))); //$NON-NLS-1$ String d = r.getAttributeValue(null, "description"); //$NON-NLS-1$ if (d != null) { d = d.replace("\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } Action a = new Action(i, cr, re, d); a.setResolution(Action.Resolution.toResolution(r.getAttributeValue(null, "resolution"))); //$NON-NLS-1$ String s = r.getAttributeValue(null, "start"); //$NON-NLS-1$ if (s != null) a.setStart(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "remind"); //$NON-NLS-1$ if (s != null) a.setRemind(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "due"); //$NON-NLS-1$ if (s != null) a.setDue(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "type"); //$NON-NLS-1$ if (s != null) a.setType(ActionType.valueOf(s)); s = r.getAttributeValue(null, "url"); //$NON-NLS-1$ if (s != null) { try { a.setUrl(new URL(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } ff.add(a); if (a.getId() > model.getLastActionID()) { model.setLastActionID(a.getId()); } findTagEnd(r, "action"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "folder"); //$NON-NLS-1$ r.nextTag(); } } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void _load_2_0(GTDModel model, XMLStreamReader r) throws XMLStreamException { HashMap<Integer, Action> withProject = new HashMap<Integer, Action>(); HashMap<Integer, Action> queued = new HashMap<Integer, Action>(); if (checkTagStart(r, "folders")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "folder")) { //$NON-NLS-1$ Folder ff;// w ww . j av a 2 s.com String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { ff = model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.valueOf(r.getAttributeValue(null, "type"))); //$NON-NLS-1$ } else { String s = r.getAttributeValue(null, "type").replace("NOTE", "INBUCKET"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ff = model.createFolder(r.getAttributeValue(null, "name"), FolderType.valueOf(s)); //$NON-NLS-1$ } String s = r.getAttributeValue(null, "closed"); //$NON-NLS-1$ if (s != null) ff.setClosed(Boolean.parseBoolean(s)); s = r.getAttributeValue(null, "description"); //$NON-NLS-1$ if (s != null) { s = s.replace("\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!ff.isInBucket()) { ff.setDescription(s); } r.nextTag(); while (checkTagStart(r, "action")) { //$NON-NLS-1$ int i = Integer.parseInt(r.getAttributeValue(null, "id")); //$NON-NLS-1$ Date cr = new Date(Long.parseLong(r.getAttributeValue(null, "created"))); //$NON-NLS-1$ Date re = r.getAttributeValue(null, "resolved") == null ? null //$NON-NLS-1$ : new Date(Long.parseLong(r.getAttributeValue(null, "resolved"))); //$NON-NLS-1$ String d = r.getAttributeValue(null, "description"); //$NON-NLS-1$ if (d != null) { d = d.replace("\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } Action a = new Action(i, cr, re, d); s = r.getAttributeValue(null, "type"); //$NON-NLS-1$ if (s != null) a.setType(ActionType.valueOf(s)); s = r.getAttributeValue(null, "url"); //$NON-NLS-1$ if (s != null) { try { a.setUrl(new URL(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } s = r.getAttributeValue(null, "start"); //$NON-NLS-1$ if (s != null) a.setStart(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "remind"); //$NON-NLS-1$ if (s != null) a.setRemind(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "due"); //$NON-NLS-1$ if (s != null) a.setDue(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "queued"); //$NON-NLS-1$ if (s != null) a.setQueued(Boolean.parseBoolean(s)); s = r.getAttributeValue(null, "project"); //$NON-NLS-1$ if (s != null) a.setProject(Integer.parseInt(s)); s = r.getAttributeValue(null, "priority"); //$NON-NLS-1$ if (s != null) a.setPriority(Priority.valueOf(s)); a.setResolution(Action.Resolution.toResolution(r.getAttributeValue(null, "resolution"))); //$NON-NLS-1$ ff.add(a); if (a.getProject() != null) { withProject.put(a.getId(), a); } if (a.isQueued()) { queued.put(a.getId(), a); } if (a.getId() > model.getLastActionID()) { model.setLastActionID(a.getId()); } findTagEnd(r, "action"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "folder"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "folders"); //$NON-NLS-1$ //r.nextTag(); } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "projects")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "project")) { //$NON-NLS-1$ Project pp; String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { pp = (Project) model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.PROJECT); } else { pp = (Project) model.createFolder(r.getAttributeValue(null, "name"), FolderType.PROJECT); //$NON-NLS-1$ } pp.setClosed(Boolean.parseBoolean(r.getAttributeValue(null, "closed"))); //$NON-NLS-1$ pp.setGoal(r.getAttributeValue(null, "goal")); //$NON-NLS-1$ String s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = withProject.remove(ii); if (a != null) { pp.add(a); } } } } r.nextTag(); findTagEnd(r, "project"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "projects"); //$NON-NLS-1$ } for (Action a : withProject.values()) { if (a.getProject() != null) { Project p = model.getProject(a.getProject()); if (p != null) { p.add(a); } else { System.err.println("Project " + p + " in action " + a + " does not exsist."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ a.setProject(null); } } } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "queue")) { //$NON-NLS-1$ Folder f = model.getQueue(); String s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = queued.remove(ii); if (a != null) { f.add(a); } } } } r.nextTag(); findTagEnd(r, "queue"); //$NON-NLS-1$ r.nextTag(); } for (Action a : queued.values()) { if (a.isQueued()) { System.err.println("Action " + a + " is queued but not in queue list."); //$NON-NLS-1$ //$NON-NLS-2$ model.getQueue().add(a); } } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void _load_2_1(GTDModel model, XMLStreamReader r) throws XMLStreamException { HashMap<Integer, Action> withProject = new HashMap<Integer, Action>(); HashMap<Integer, Action> queued = new HashMap<Integer, Action>(); if (checkTagStart(r, "lists")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "list")) { //$NON-NLS-1$ Folder ff;//from w w w. j a va 2s . co m String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { ff = model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.valueOf(r.getAttributeValue(null, "type"))); //$NON-NLS-1$ } else { String s = r.getAttributeValue(null, "type").replace("NOTE", "INBUCKET"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ff = model.createFolder(r.getAttributeValue(null, "name"), FolderType.valueOf(s)); //$NON-NLS-1$ } String s = r.getAttributeValue(null, "closed"); //$NON-NLS-1$ if (s != null) ff.setClosed(Boolean.parseBoolean(s)); s = r.getAttributeValue(null, "description"); //$NON-NLS-1$ if (s != null) { s = s.replace("\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!ff.isInBucket()) { ff.setDescription(s); } r.nextTag(); while (checkTagStart(r, "action")) { //$NON-NLS-1$ int i = Integer.parseInt(r.getAttributeValue(null, "id")); //$NON-NLS-1$ Date cr = new Date(Long.parseLong(r.getAttributeValue(null, "created"))); //$NON-NLS-1$ Date re = r.getAttributeValue(null, "resolved") == null ? null //$NON-NLS-1$ : new Date(Long.parseLong(r.getAttributeValue(null, "resolved"))); //$NON-NLS-1$ String d = r.getAttributeValue(null, "description"); //$NON-NLS-1$ if (d != null) { d = d.replace("\\n", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } Action a = new Action(i, cr, re, d); s = r.getAttributeValue(null, "type"); //$NON-NLS-1$ if (s != null) a.setType(ActionType.valueOf(s)); s = r.getAttributeValue(null, "url"); //$NON-NLS-1$ if (s != null) { try { a.setUrl(new URL(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } s = r.getAttributeValue(null, "start"); //$NON-NLS-1$ if (s != null) a.setStart(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "remind"); //$NON-NLS-1$ if (s != null) a.setRemind(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "due"); //$NON-NLS-1$ if (s != null) a.setDue(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "queued"); //$NON-NLS-1$ if (s != null) a.setQueued(Boolean.parseBoolean(s)); s = r.getAttributeValue(null, "project"); //$NON-NLS-1$ if (s != null) a.setProject(Integer.parseInt(s)); s = r.getAttributeValue(null, "priority"); //$NON-NLS-1$ if (s != null) a.setPriority(Priority.valueOf(s)); a.setResolution(Action.Resolution.toResolution(r.getAttributeValue(null, "resolution"))); //$NON-NLS-1$ ff.add(a); if (a.getProject() != null) { withProject.put(a.getId(), a); } if (a.isQueued()) { queued.put(a.getId(), a); } if (a.getId() > model.getLastActionID()) { model.setLastActionID(a.getId()); } findTagEnd(r, "action"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "list"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "lists"); //$NON-NLS-1$ //r.nextTag(); } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "projects")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "project")) { //$NON-NLS-1$ Project pp; String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { pp = (Project) model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.PROJECT); } else { pp = (Project) model.createFolder(r.getAttributeValue(null, "name"), FolderType.PROJECT); //$NON-NLS-1$ } pp.setClosed(Boolean.parseBoolean(r.getAttributeValue(null, "closed"))); //$NON-NLS-1$ pp.setGoal(r.getAttributeValue(null, "goal")); //$NON-NLS-1$ String s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = withProject.remove(ii); if (a != null) { pp.add(a); } } } } r.nextTag(); findTagEnd(r, "project"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "projects"); //$NON-NLS-1$ } for (Action a : withProject.values()) { if (a.getProject() != null) { Project p = model.getProject(a.getProject()); if (p != null) { p.add(a); } else { System.err.println("Project " + p + " in action " + a + " does not exsist."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ a.setProject(null); } } } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "queue")) { //$NON-NLS-1$ Folder f = model.getQueue(); String s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = queued.remove(ii); if (a != null) { f.add(a); } } } } r.nextTag(); findTagEnd(r, "queue"); //$NON-NLS-1$ r.nextTag(); } for (Action a : queued.values()) { if (a.isQueued()) { System.err.println("Action " + a + " is queued but not in queue list."); //$NON-NLS-1$ //$NON-NLS-2$ model.getQueue().add(a); } } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void _load_2_2(GTDModel model, XMLStreamReader r) throws XMLStreamException { HashMap<Integer, Action> withProject = new HashMap<Integer, Action>(); HashMap<Integer, Action> queued = new HashMap<Integer, Action>(); if (checkTagStart(r, "lists")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "list")) { //$NON-NLS-1$ Folder ff;/*from w w w .jav a2 s.c om*/ String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { ff = model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.valueOf(r.getAttributeValue(null, "type"))); //$NON-NLS-1$ } else { String s = r.getAttributeValue(null, "type").replace("NOTE", "INBUCKET"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ff = model.createFolder(r.getAttributeValue(null, "name"), FolderType.valueOf(s)); //$NON-NLS-1$ } String s = r.getAttributeValue(null, "closed"); //$NON-NLS-1$ if (s != null) ff.setClosed(Boolean.parseBoolean(s)); s = StringEscapeUtils.unescapeJava(r.getAttributeValue(null, "description")); //$NON-NLS-1$ if (!ff.isInBucket()) { ff.setDescription(s); } Date cr = null, mo = null, re = null; s = r.getAttributeValue(null, "created"); //$NON-NLS-1$ if (s != null) { cr = new Date(Long.parseLong(s)); } s = r.getAttributeValue(null, "modified"); //$NON-NLS-1$ if (s != null) { mo = new Date(Long.parseLong(s)); } s = r.getAttributeValue(null, "resolved"); //$NON-NLS-1$ if (s != null) { re = new Date(Long.parseLong(s)); } ff.setDates(cr, mo, re); r.nextTag(); while (checkTagStart(r, "action")) { //$NON-NLS-1$ int i = Integer.parseInt(r.getAttributeValue(null, "id")); //$NON-NLS-1$ cr = new Date(Long.parseLong(r.getAttributeValue(null, "created"))); //$NON-NLS-1$ re = r.getAttributeValue(null, "resolved") == null ? null //$NON-NLS-1$ : new Date(Long.parseLong(r.getAttributeValue(null, "resolved"))); //$NON-NLS-1$ mo = r.getAttributeValue(null, "modified") == null ? null //$NON-NLS-1$ : new Date(Long.parseLong(r.getAttributeValue(null, "modified"))); //$NON-NLS-1$ String d = StringEscapeUtils.unescapeJava(r.getAttributeValue(null, "description")); //$NON-NLS-1$ Action a = new Action(i, cr, re, d, mo); s = r.getAttributeValue(null, "type"); //$NON-NLS-1$ if (s != null) a.setType(ActionType.valueOf(s)); s = r.getAttributeValue(null, "url"); //$NON-NLS-1$ if (s != null) { try { a.setUrl(new URL(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } s = r.getAttributeValue(null, "start"); //$NON-NLS-1$ if (s != null) a.setStart(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "remind"); //$NON-NLS-1$ if (s != null) a.setRemind(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "due"); //$NON-NLS-1$ if (s != null) a.setDue(new Date(Long.parseLong(s))); s = r.getAttributeValue(null, "queued"); //$NON-NLS-1$ if (s != null) a.setQueued(Boolean.parseBoolean(s)); s = r.getAttributeValue(null, "project"); //$NON-NLS-1$ if (s != null) a.setProject(Integer.parseInt(s)); s = r.getAttributeValue(null, "priority"); //$NON-NLS-1$ if (s != null) a.setPriority(Priority.valueOf(s)); a.setResolution(Action.Resolution.toResolution(r.getAttributeValue(null, "resolution"))); //$NON-NLS-1$ ff.add(a); if (a.getProject() != null) { withProject.put(a.getId(), a); } if (a.isQueued()) { queued.put(a.getId(), a); } if (a.getId() > model.getLastActionID()) { model.setLastActionID(a.getId()); } findTagEnd(r, "action"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "list"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "lists"); //$NON-NLS-1$ //r.nextTag(); } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "projects")) { //$NON-NLS-1$ r.nextTag(); while (checkTagStart(r, "project")) { //$NON-NLS-1$ Project pp; String id = r.getAttributeValue(null, "id"); //$NON-NLS-1$ if (id != null) { pp = (Project) model.createFolder(Integer.parseInt(id), r.getAttributeValue(null, "name"), //$NON-NLS-1$ FolderType.PROJECT); } else { pp = (Project) model.createFolder(r.getAttributeValue(null, "name"), FolderType.PROJECT); //$NON-NLS-1$ } pp.setClosed(Boolean.parseBoolean(r.getAttributeValue(null, "closed"))); //$NON-NLS-1$ pp.setGoal(r.getAttributeValue(null, "goal")); //$NON-NLS-1$ String s = StringEscapeUtils.unescapeJava(r.getAttributeValue(null, "description")); //$NON-NLS-1$ if (s != null) { pp.setDescription(s); } Date cr = null, mo = null, re = null; s = r.getAttributeValue(null, "created"); //$NON-NLS-1$ if (s != null) { cr = new Date(Long.parseLong(s)); } s = r.getAttributeValue(null, "modified"); //$NON-NLS-1$ if (s != null) { mo = new Date(Long.parseLong(s)); } s = r.getAttributeValue(null, "resolved"); //$NON-NLS-1$ if (s != null) { re = new Date(Long.parseLong(s)); } pp.setDates(cr, mo, re); s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = withProject.remove(ii); if (a != null) { pp.add(a); } } } } r.nextTag(); findTagEnd(r, "project"); //$NON-NLS-1$ r.nextTag(); } findTagEnd(r, "projects"); //$NON-NLS-1$ } for (Action a : withProject.values()) { if (a.getProject() != null) { Project p = model.getProject(a.getProject()); if (p != null) { p.add(a); } else { System.err.println("Project " + p + " in action " + a + " does not exsist."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ a.setProject(null); } } } if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } // read projects r.nextTag(); if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; } if (checkTagStart(r, "queue")) { //$NON-NLS-1$ Folder f = model.getQueue(); String s = r.getAttributeValue(null, "actions"); //$NON-NLS-1$ if (s != null && s.trim().length() > 0) { String[] ss = s.trim().split(","); //$NON-NLS-1$ for (int i = 0; i < ss.length; i++) { if (ss[i].trim().length() > 0) { int ii = Integer.parseInt(ss[i].trim()); Action a = queued.remove(ii); if (a != null) { f.add(a); } } } } r.nextTag(); findTagEnd(r, "queue"); //$NON-NLS-1$ r.nextTag(); } for (Action a : queued.values()) { if (a.isQueued()) { System.err.println("Action " + a + " is queued but not in queue list."); //$NON-NLS-1$ //$NON-NLS-2$ model.getQueue().add(a); } } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
private static void findTagEnd(XMLStreamReader r, String tag) throws XMLStreamException { while (!r.getLocalName().equals(tag) || XMLStreamReader.END_ELEMENT != r.getEventType()) { if (r.getEventType() == XMLStreamReader.END_DOCUMENT) { return; }/*from w w w. j a v a 2s . c o m*/ r.nextTag(); } }
From source file:org.gtdfree.model.GTDDataXMLTools.java
static public DataHeader load(GTDModel model, InputStream in) throws XMLStreamException, IOException { model.setSuspendedForMultipleChanges(true); model.getDataRepository().suspend(true); XMLStreamReader r; try {/*from ww w. j ava 2 s . c om*/ // buffer size is same as default in 1.6, we explicitly request it so, not to brake if defaut changes. BufferedInputStream bin = new BufferedInputStream(in, 8192); bin.mark(8191); Reader rr = new InputStreamReader(bin); CharBuffer b = CharBuffer.allocate(96); rr.read(b); b.position(0); //System.out.println(b); Pattern pattern = Pattern.compile("<\\?.*?encoding\\s*?=.*?\\?>", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ Matcher matcher = pattern.matcher(b); // reset back to start of file bin.reset(); // we check if encoding is defined in xml, by the book encoding on r should be null if not defined in xml, // but in reality it can be arbitrary if not defined in xml. So we have to check ourselves. if (matcher.find()) { //System.out.println(matcher); // if defined, then XML parser will pick it up and use it r = XMLInputFactory.newInstance().createXMLStreamReader(bin); Logger.getLogger(GTDDataXMLTools.class).info("XML declared encoding: " + r.getEncoding() //$NON-NLS-1$ + ", system default encoding: " + Charset.defaultCharset()); //$NON-NLS-1$ } else { //System.out.println(matcher); // if not defined, then we assume it is generated by gtd-free version 0.4 or some local editor, // so we assume system default encoding. r = XMLInputFactory.newInstance().createXMLStreamReader(new InputStreamReader(bin)); Logger.getLogger(GTDDataXMLTools.class) .info("XML assumed system default encoding: " + Charset.defaultCharset()); //$NON-NLS-1$ } r.nextTag(); if ("gtd-data".equals(r.getLocalName())) { //$NON-NLS-1$ DataHeader dh = new DataHeader(null, r.getAttributeValue(null, "version"), //$NON-NLS-1$ r.getAttributeValue(null, "modified")); //$NON-NLS-1$ if (dh.version != null) { if (dh.version.equals("2.0")) { //$NON-NLS-1$ r.nextTag(); _load_2_0(model, r); return dh; } } String s = r.getAttributeValue(null, "lastActionID"); //$NON-NLS-1$ if (s != null) { try { model.setLastActionID(Integer.parseInt(s)); } catch (Exception e) { Logger.getLogger(GTDDataXMLTools.class).debug("Internal error.", e); //$NON-NLS-1$ } } if (dh.version != null) { if (dh.version.equals("2.1")) { //$NON-NLS-1$ r.nextTag(); _load_2_1(model, r); return dh; } if (dh.version.startsWith("2.2")) { //$NON-NLS-1$ r.nextTag(); _load_2_2(model, r); return dh; } } throw new IOException("XML gtd-free data with version number " + dh.version //$NON-NLS-1$ + " can not be imported. Data version is newer then supported versions. Update your GTD-Free application to latest version."); //$NON-NLS-1$ } _load_1_0(model, r); return null; } catch (XMLStreamException e) { if (e.getNestedException() != null) { Logger.getLogger(GTDDataXMLTools.class).debug("Parse error.", e.getNestedException()); //$NON-NLS-1$ } else { Logger.getLogger(GTDDataXMLTools.class).debug("Parse error.", e); //$NON-NLS-1$ } throw e; } catch (IOException e) { throw e; } finally { model.setSuspendedForMultipleChanges(false); model.getDataRepository().suspend(false); } }
From source file:org.maodian.flyingcat.xmpp.state.SASLCommandTest.java
@Test public void testPlainMechanismSuccess() throws Exception { String inXML = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AGp1bGlldAByMG0zMG15cjBtMzA=</auth>"; Writer writer = new StringWriter(); XMLStreamReader xmlsr1 = newXMLStreamReader(new StringReader(inXML)); XMLStreamWriter xmlsw = newXMLStreamWriter(writer); // skipt start document xmlsr1.nextTag(); State state = cmd.execute(xmlsr1, xmlsw); Reader reader = new StringReader(writer.toString()); XMLStreamReader xmlsr = XMLInputFactoryHolder.getXMLInputFactory().createXMLStreamReader(reader); xmlsr.next();/*from ww w . j a v a 2s . c o m*/ QName qname = new QName(XmppNamespace.SASL, "success"); assertEquals(qname, xmlsr.getName()); assertTrue(state instanceof AuthenticatedStreamState); }
From source file:org.mule.module.xml.filters.AbstractJaxpFilter.java
public Node toDOMNode(Object src) throws Exception { if (src instanceof Node) { return (Document) src; } else if (src instanceof org.dom4j.Document) { org.dom4j.Document dom4j = (org.dom4j.Document) src; DOMDocument dom = new DOMDocument(); dom.setDocument(dom4j);/*from w ww . j a v a 2 s. c om*/ return dom; } else if (src instanceof OutputHandler) { OutputHandler handler = ((OutputHandler) src); ByteArrayOutputStream output = new ByteArrayOutputStream(); handler.write(RequestContext.getEvent(), output); InputStream stream = new ByteArrayInputStream(output.toByteArray()); return getDocumentBuilderFactory().newDocumentBuilder().parse(stream); } else if (src instanceof byte[]) { ByteArrayInputStream stream = new ByteArrayInputStream((byte[]) src); return getDocumentBuilderFactory().newDocumentBuilder().parse(stream); } else if (src instanceof InputStream) { return getDocumentBuilderFactory().newDocumentBuilder().parse((InputStream) src); } else if (src instanceof String) { return getDocumentBuilderFactory().newDocumentBuilder() .parse(new InputSource(new StringReader((String) src))); } else if (src instanceof XMLStreamReader) { XMLStreamReader xsr = (XMLStreamReader) src; // StaxSource requires that we advance to a start element/document event if (!xsr.isStartElement() && xsr.getEventType() != XMLStreamConstants.START_DOCUMENT) { xsr.nextTag(); } return getDocumentBuilderFactory().newDocumentBuilder().parse(new InputSource()); } else if (src instanceof DelayedResult) { DelayedResult result = ((DelayedResult) src); DOMResult domResult = new DOMResult(); result.write(domResult); return domResult.getNode(); } else { return (Node) xmlToDom.transform(src); } }
From source file:org.mule.module.xml.util.XMLUtils.java
/** * Convert our object to a Source type efficiently. *//* ww w . j av a2 s. c om*/ public static javax.xml.transform.Source toXmlSource(javax.xml.stream.XMLInputFactory xmlInputFactory, boolean useStaxSource, Object src) throws Exception { if (src instanceof javax.xml.transform.Source) { return (Source) src; } else if (src instanceof byte[]) { ByteArrayInputStream stream = new ByteArrayInputStream((byte[]) src); return toStreamSource(xmlInputFactory, useStaxSource, stream); } else if (src instanceof InputStream) { return toStreamSource(xmlInputFactory, useStaxSource, (InputStream) src); } else if (src instanceof String) { if (useStaxSource) { return new StaxSource(xmlInputFactory.createXMLStreamReader(new StringReader((String) src))); } else { return new StreamSource(new StringReader((String) src)); } } else if (src instanceof org.dom4j.Document) { return new DocumentSource((org.dom4j.Document) src); } else if (src instanceof org.xml.sax.InputSource) { return new SAXSource((InputSource) src); } // TODO MULE-3555 else if (src instanceof XMLStreamReader) { XMLStreamReader xsr = (XMLStreamReader) src; // StaxSource requires that we advance to a start element/document event if (!xsr.isStartElement() && xsr.getEventType() != XMLStreamConstants.START_DOCUMENT) { xsr.nextTag(); } return new StaxSource((XMLStreamReader) src); } else if (src instanceof org.w3c.dom.Document || src instanceof org.w3c.dom.Element) { return new DOMSource((org.w3c.dom.Node) src); } else if (src instanceof DelayedResult) { DelayedResult result = ((DelayedResult) src); DOMResult domResult = new DOMResult(); result.write(domResult); return new DOMSource(domResult.getNode()); } else if (src instanceof OutputHandler) { OutputHandler handler = ((OutputHandler) src); ByteArrayOutputStream output = new ByteArrayOutputStream(); handler.write(RequestContext.getEvent(), output); return toStreamSource(xmlInputFactory, useStaxSource, new ByteArrayInputStream(output.toByteArray())); } else { return null; } }
From source file:org.netbeans.jbatch.modeler.spec.core.Definitions.java
public static Definitions load(ModelerFile file, String definitionId) { File savedFile = file.getFile(); Definitions definition_Load = null;// w ww . j a v a 2 s. com boolean definitionExist = false; XMLStreamReader xsr = null; try { if (savedFile.length() != 0) { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource(savedFile); xsr = xif.createXMLStreamReader(xml); xsr.nextTag(); if (definitionId == null) { while (xsr.hasNext() && !definitionExist) { if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("definitions") && xsr.getAttributeValue(null, "id") == null) { definitionExist = true; } else { xsr.next(); } } } else { while (xsr.hasNext() && !definitionExist) { if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("definitions") && definitionId.equals(xsr.getAttributeValue(null, "id"))) { definitionExist = true; } else { xsr.next(); } } } } JAXBContext jobContext; Unmarshaller jobUnmarshaller; // if (jobContext == null) { jobContext = JAXBContext.newInstance(new Class<?>[] { ShapeDesign.class, Definitions.class }); // } // if (jobUnmarshaller == null) { jobUnmarshaller = jobContext.createUnmarshaller(); jobUnmarshaller.setEventHandler(new ValidateJAXB()); // } if (definitionExist) { definition_Load = jobUnmarshaller.unmarshal(xsr, Definitions.class).getValue();//new StreamSource(savedFile) } if (xsr != null) { xsr.close(); } } catch (XMLStreamException ex) { Exceptions.printStackTrace(ex); } catch (JAXBException ex) { // io.getOut().println("Exception: " + ex.toString()); ex.printStackTrace(); System.out.println("Document XML Not Exist"); } return definition_Load; }