List of usage examples for javax.xml.stream XMLStreamReader getEventType
public int getEventType();
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readCopy(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();/*from w w w.j a va2 s.c o m*/ // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ jumpToEndTag(reader, "Meta"); //$NON-NLS-1$ reader.nextTag(); } // Item+ boolean continueCopy = true; do { switch (reader.getEventType()) { case XMLEvent.START_ELEMENT: final DMItem item = readItem(reader, null); reader.nextTag(); final Status status = this.commandHandler.copy(item.getTargetURI(), item.getSourceURI()); this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Copy", item.getTargetURI(), //$NON-NLS-1$ item.getSourceURI(), String.valueOf(status.getCode())); // Fire copy event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.copy(item.getTargetURI(), item.getSourceURI(), status); } break; case XMLEvent.END_ELEMENT: continueCopy = false; break; default: break; } } while (continueCopy); }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readSequence(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();/*from w w w .j av a 2 s. com*/ // CmdID final String cmdID = reader.getElementText(); reader.nextTag(); // Meta? final DMMeta globalMeta; if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$ globalMeta = readMeta(reader); reader.nextTag(); } else { globalMeta = new DMMeta(); } // Procces the sequence element this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Sequence", null, null, //$NON-NLS-1$ String.valueOf(StatusCode.OK.getCode())); boolean continueSequence = true; do { switch (reader.getEventType()) { case XMLEvent.START_ELEMENT: switch (getKey(reader.getLocalName())) { case ADD: readAdd(reader, globalMeta); break; case COPY: readCopy(reader); break; case DELETE: readDelete(reader); break; case GET: readGet(reader); break; case REPLACE: readReplace(reader, globalMeta); break; case EXEC: readExec(reader, globalMeta); break; default: break; } reader.nextTag(); break; case XMLEvent.END_ELEMENT: continueSequence = false; break; default: break; } } while (continueSequence); }
From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java
@SuppressWarnings("unchecked") protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception { ExtensionElement extensionElement = new ExtensionElement(); extensionElement.setName(xtr.getLocalName()); if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) { extensionElement.setNamespace(xtr.getNamespaceURI()); }// w w w . j a va2 s .c o m if (StringUtils.isNotEmpty(xtr.getPrefix())) { extensionElement.setNamespacePrefix(xtr.getPrefix()); } BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes); boolean readyWithExtensionElement = false; while (readyWithExtensionElement == false && xtr.hasNext()) { xtr.next(); if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) { if (StringUtils.isNotEmpty(xtr.getText().trim())) { extensionElement.setElementText(xtr.getText().trim()); } } else if (xtr.isStartElement()) { ExtensionElement childExtensionElement = parseExtensionElement(xtr); extensionElement.addChildElement(childExtensionElement); } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) { readyWithExtensionElement = true; } } return extensionElement; }
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();/*from ww w . j av a 2 s . c om*/ while (checkTagStart(r, "folder")) { //$NON-NLS-1$ Folder ff; 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();/*from w w w . j a va2 s .c om*/ while (checkTagStart(r, "list")) { //$NON-NLS-1$ Folder ff; 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();/*from ww w . j av a 2 s .co m*/ while (checkTagStart(r, "list")) { //$NON-NLS-1$ Folder ff; 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
static private boolean checkTagStart(XMLStreamReader r, String tag) throws XMLStreamException { return tag.equals(r.getLocalName()) && r.getEventType() == XMLStreamReader.START_ELEMENT; }
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.modeldriven.fuml.xmi.stream.StreamReader.java
@SuppressWarnings("unchecked") public Collection read(InputStream stream) { List<Object> results = new ArrayList<Object>(); InputStream source = stream;// ww w. j a va2 s .c om StreamContext context = null; try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setXMLResolver(new XMLResolver() { @Override public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException { // TODO Auto-generated method stub return null; } }); /* XStream xstream = new XStream(new StaxDriver() { protected XMLStreamReader createParser(Reader xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } protected XMLStreamReader createParser(InputStream xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } }); */ //factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,Boolean.FALSE); //factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,Boolean.TRUE); //set the IS_COALESCING property to true , if application desires to //get whole text data as one event. //factory.setProperty(XMLInputFactory.IS_COALESCING , Boolean.TRUE); factory.setEventAllocator(new EventAllocator()); allocator = factory.getEventAllocator(); XMLStreamReader streamReader = factory.createXMLStreamReader(stream); int eventType = streamReader.getEventType(); StreamNode node = null; StreamNode parent = null; int level = 0; int ignoredNodeLevel = -1; while (streamReader.hasNext()) { eventType = streamReader.next(); //if (log.isDebugEnabled()) // log.debug(this.getEventTypeString(eventType)); switch (eventType) { case XMLEvent.START_ELEMENT: level++; if (ignoredNodeLevel >= 0) break; XMLEvent event = allocateXMLEvent(streamReader); if (level == 1) { if (context != null) throw new XmiException("existing context unexpected"); context = new StreamContext(event); } // debugging if (event.toString().contains("plasma:PlasmaType")) { int foo = 1; foo++; } node = new StreamNode(event, context); if (node.isIgnored()) { if (log.isDebugEnabled()) { Location loc = event.getLocation(); String msg = "start ignoring elements - level: " + String.valueOf(level) + " - line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "] - "; log.debug(msg); } ignoredNodeLevel = level; break; } logEventInfo(event); parent = null; if (nodes.size() > 0) { parent = nodes.peek(); parent.add(node); node.setParent(parent); if (isRootNode(node, context)) results.add(node); } else { if (isRootNode(node, context)) results.add(node); } nodes.push(node); fireStreamNodeCreated(node, parent); break; case XMLEvent.END_ELEMENT: if (ignoredNodeLevel >= 0) { if (ignoredNodeLevel == level) { if (log.isDebugEnabled()) { event = allocateXMLEvent(streamReader); Location loc = event.getLocation(); String msg = "end ignoring elements - level: " + String.valueOf(level) + " - line:col[" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "] - "; log.debug(msg); } ignoredNodeLevel = -1; } level--; break; } level--; node = nodes.pop(); parent = null; if (nodes.size() > 0) parent = nodes.peek(); fireStreamNodeCompleted(node, parent); break; case XMLEvent.CHARACTERS: if (ignoredNodeLevel >= 0) break; node = nodes.peek(); event = allocateXMLEvent(streamReader); String data = event.asCharacters().getData(); if (data != null) { data = data.trim(); if (data.length() > 0) { if (log.isDebugEnabled()) log.debug("CHARACTERS: '" + data + "'"); if (data.length() > 0) { node = nodes.peek(); node.addCharactersEvent(event); } } } break; default: if (log.isDebugEnabled()) { event = allocateXMLEvent(streamReader); logEventInfo(event); } break; } } if (results.size() > 1) throw new XmiException("found multiple root nodes (" + results.size() + ")"); } catch (XMLStreamException e) { throw new XmiException(e); } finally { try { source.close(); } catch (IOException e) { } } return results; }
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 w w .ja v a2s .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); } }