List of usage examples for javax.xml.stream XMLStreamReader getAttributeValue
public String getAttributeValue(String namespaceURI, String localName);
From source file:org.flowable.cmmn.converter.util.ListenerXmlConverterUtil.java
public static FlowableListener convertToListener(XMLStreamReader xtr) { FlowableListener listener = new FlowableListener(); CmmnXmlUtil.addXMLLocation(listener, xtr); if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_CLASS))) { listener.setImplementation(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_CLASS)); listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS); } else if (StringUtils .isNotEmpty(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_EXPRESSION))) { listener.setImplementation(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_EXPRESSION)); listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); } else if (StringUtils .isNotEmpty(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_DELEGATEEXPRESSION))) { listener.setImplementation(//from w w w .jav a2 s.c o m xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_DELEGATEEXPRESSION)); listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); } listener.setEvent(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_EVENT)); listener.setSourceState(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_SOURCE_STATE)); listener.setTargetState(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_TARGET_STATE)); listener.setOnTransaction(xtr.getAttributeValue(null, CmmnXmlConstants.ATTRIBUTE_LISTENER_ON_TRANSACTION)); return listener; }
From source file:org.gephi.statistics.StatisticsModelImpl.java
public void readXML(XMLStreamReader reader) throws XMLStreamException { Collection<? extends StatisticsUI> uis = Lookup.getDefault().lookupAll(StatisticsUI.class); Collection<? extends StatisticsBuilder> builders = Lookup.getDefault().lookupAll(StatisticsBuilder.class); boolean end = false; while (reader.hasNext() && !end) { int type = reader.next(); switch (type) { case XMLStreamReader.START_ELEMENT: String name = reader.getLocalName(); if ("report".equalsIgnoreCase(name)) { String classStr = reader.getAttributeValue(null, "class"); Class reportClass = null; for (StatisticsBuilder builder : builders) { if (builder.getStatisticsClass().getName().equals(classStr)) { reportClass = builder.getStatisticsClass(); }/* ww w . j ava 2 s .c om*/ } if (reportClass != null) { String report = reader.getAttributeValue(null, "value"); report = unembedImages(report); reportMap.put(reportClass, report); } } break; case XMLStreamReader.END_ELEMENT: if ("statisticsmodel".equalsIgnoreCase(reader.getLocalName())) { end = true; } break; } } }
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();//from w w w. ja v a 2s . com while (checkTagStart(r, "folder")) { //$NON-NLS-1$ String type = r.getAttributeValue(null, "type").trim(); //$NON-NLS-1$ Folder ff = null; 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();//from ww w . jav 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();// ww w . j a v a2 s. com 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 w w w .ja v 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 public DataHeader load(GTDModel model, InputStream in) throws XMLStreamException, IOException { model.setSuspendedForMultipleChanges(true); model.getDataRepository().suspend(true); XMLStreamReader r; try {/*from ww w. ja v a 2s .co m*/ // 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.jwebsocket.config.xml.JWebSocketConfigHandler.java
/** * Read the map of plug-in specific settings * @param aStreamReader//from w w w . j a va2s . c om * the stream reader object * @return the list of domains for the engine * @throws XMLStreamException * in case of stream exception */ public static Map<String, Object> getSettings(XMLStreamReader aStreamReader) throws XMLStreamException { Map<String, Object> lSettings = new FastMap<String, Object>(); while (aStreamReader.hasNext()) { aStreamReader.next(); if (aStreamReader.isStartElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(SETTING)) { String lKey = aStreamReader.getAttributeValue(null, "key"); String lType = aStreamReader.getAttributeValue(null, "type"); aStreamReader.next(); String lValue = aStreamReader.getText(); if (lKey != null && lValue != null) { if ("json".equalsIgnoreCase(lType)) { JSONObject lJSON = null; try { lJSON = new JSONObject(lValue); } catch (JSONException lEx) { // TODO: handle invalid JSON code in settings properly! } lSettings.put(lKey, lJSON); } else { lSettings.put(lKey, lValue); } } } } if (aStreamReader.isEndElement()) { String lElementName = aStreamReader.getLocalName(); if (lElementName.equals(SETTINGS)) { break; } } } return lSettings; }
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;/*from w w w .ja v a 2 s .c om*/ 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; }
From source file:org.netbeans.jbatch.modeler.spec.core.Definitions.java
public static void unload(ModelerFile file, List<String> definitionIdList) { File savedFile = file.getFile(); if (definitionIdList.isEmpty()) { return;//from w w w.j a va2 s.c om } try { File cloneSavedFile = File.createTempFile("TMP", "job"); FileUtils.copyFile(savedFile, cloneSavedFile); BufferedReader br = new BufferedReader(new FileReader(savedFile)); String line = null; while ((line = br.readLine()) != null) { System.out.println("pre savedFile : " + line); } XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = xof.createXMLStreamWriter(new FileWriter(savedFile)); xsw.setDefaultNamespace("http://jbatchsuite.java.net"); xsw.writeStartDocument(); xsw.writeStartElement("jbatchnb", "root", "http://jbatchsuite.java.net"); xsw.writeNamespace("jbatch", "http://xmlns.jcp.org/xml/ns/javaee"); xsw.writeNamespace("jbatchnb", "http://jbatchsuite.java.net"); xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); xsw.writeNamespace("java", "http://jcp.org/en/jsr/detail?id=270"); xsw.writeNamespace("nbm", "http://nbmodeler.java.net"); if (cloneSavedFile.length() != 0) { try { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource(cloneSavedFile); XMLStreamReader xsr = xif.createXMLStreamReader(xml); xsr.nextTag(); while (xsr.getEventType() == XMLStreamConstants.START_ELEMENT) { // Def Y N // Tag N(D) Y(D) // ________________ // T T // ---------------- // // Def Y N // Tag Y(S) N(S) // ________________ // S S // ---------------- // // Def Y N // Tag Y(D) N(S) // ________________ // T S // ---------------- // // (D) => Different // (S) => Same // Y => Id Exist // N => Def Id is null // T => Transform // S => Skip if (xsr.getLocalName().equals("definitions")) { // if (definitionId == null) { // if (xsr.getAttributeValue(null, "id") != null) { // transformXMLStream(xsr, xsw); // } // } else { if (xsr.getAttributeValue(null, "id") == null) { System.out.println("transformXMLStream " + null); transformXMLStream(xsr, xsw); } else { if (!definitionIdList.contains(xsr.getAttributeValue(null, "id"))) { System.out.println("transformXMLStream " + xsr.getAttributeValue(null, "id")); transformXMLStream(xsr, xsw); } else { System.out.println("skipXMLStream " + xsr.getAttributeValue(null, "id")); skipXMLStream(xsr); } } // } } System.out.println( "pre xsr.getEventType() : " + xsr.getEventType() + " " + xsr.getLocalName()); xsr.nextTag(); System.out.println( "post xsr.getEventType() : " + xsr.getEventType() + " " + xsr.getLocalName()); } } catch (XMLStreamException ex) { Exceptions.printStackTrace(ex); } } xsw.writeEndDocument(); xsw.close(); br = new BufferedReader(new FileReader(savedFile)); line = null; while ((line = br.readLine()) != null) { System.out.println("post savedFile : " + line); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (XMLStreamException ex) { Exceptions.printStackTrace(ex); } }