Package net.sourceforge.ganttproject.export

Examples of net.sourceforge.ganttproject.export.TaskVisitor


        addAttribute("progress", "%", attrs);
        addAttribute("assigned-to", i18n("human"), attrs);
        addAttribute("notes", i18n("notes"), attrs);
        addAttribute("duration", i18n("duration"), attrs);
        startPrefixedElement("tasks", attrs, handler);
        TaskVisitor visitor = new TaskVisitor() {
            AttributesImpl myAttrs = new AttributesImpl();
            protected String serializeTask(Task t, int depth) throws Exception {
              addAttribute("depth", depth, myAttrs);
                startPrefixedElement("task", myAttrs, handler);
                {
                  addAttribute("id", "tpd1", myAttrs);
                  int priority = t.getPriority();
                  if (priority<0 || priority>2) {
                    priority = 1;
                  }
                  final String[] priorities = new String[] {i18n("low"), i18n("normal"), i18n("hight")};
                  textElement("priority", myAttrs, priorities[priority], handler);
                }

                addAttribute("id", "tpd3", myAttrs);
                textElement("name", myAttrs, t.getName(), handler);

                addAttribute("id", "tpd4", myAttrs);
                textElement("begin", myAttrs, t.getStart().toString(), handler);

                addAttribute("id", "tpd5", myAttrs);
                textElement("end", myAttrs, t.getEnd().toString(), handler);
                textElement("milestone", myAttrs, Boolean.valueOf(
                        t.isMilestone()).toString(), handler);

                addAttribute("id", "tpd7", myAttrs);
                textElement("progress", myAttrs, String.valueOf(t
                        .getCompletionPercentage()), handler);

                addAttribute("id", "tpd6", myAttrs);
                textElement("duration", myAttrs, String.valueOf(t.getDuration().getLength()), handler);

                final List attachments = t.getAttachments();
                for (int i=0; i<attachments.size(); i++) {
                  Document nextAttachment = (Document)attachments.get(i);
                  URI nextUri = nextAttachment.getURI();
                  if (nextUri!=null) {
                    String strUri = URLDecoder.decode(nextUri.toString(), "utf-8");
                    if (strUri.startsWith("file:")) {
                      if (strUri.endsWith("/")) {
                        strUri = strUri.replaceAll("/+$", "");
                      }
                      int lastSlash = strUri.lastIndexOf('/');
                      if (lastSlash >= 0) {
                        addAttribute("display-name", strUri.substring(lastSlash+1), myAttrs);
                      }
                    }
                    textElement("attachment", myAttrs, strUri, handler);
                  }
                  else {
                    textElement("attachment", myAttrs, nextAttachment.getPath(), handler);
                  }
                }
                {
                  ProjectResource coordinator = t.getAssignmentCollection().getCoordinator();
                  if (coordinator!=null) {
                    addAttribute("id", "tpd8", myAttrs);
                    textElement("coordinator", myAttrs, coordinator.getName(), handler);
                  }
                }
                StringBuffer usersS = new StringBuffer();
                ResourceAssignment[] assignments = t.getAssignments();
                if (assignments.length > 0) {
                    for (int j = 0; j < assignments.length; j++) {
                      addAttribute("resource-id", assignments[j].getResource().getId(), myAttrs);
                      emptyElement("assigned-resource", myAttrs, handler);
                        usersS.append(assignments[j].getResource().getName());
                        if (j<assignments.length-1) {
                          usersS.append(getAssignedResourcesDelimiter());
                        }
                    }
                }

                addAttribute("id", "tpdResources", myAttrs);
                textElement("assigned-to", myAttrs, usersS.toString(), handler);
                if (t.getNotes()!=null && t.getNotes().length()>0) {
                  textElement("notes", myAttrs, t.getNotes(), handler);
                }
                if (t.getColor()!=null) {
                    textElement("color", myAttrs, getHexaColor(t.getColor()),
                            handler);
                }
                {
                  AttributesImpl attrs = new AttributesImpl();
                  CustomColumnsValues customValues = t.getCustomValues();
                  for (Iterator it = getCustomColumnStorage().getCustomColums().iterator();
                       it.hasNext();) {
                    CustomColumn nextColumn = (CustomColumn) it.next();
                    Object value = customValues.getValue(nextColumn.getName());
                    String valueAsString = value==null ? "" : value.toString();
                    addAttribute("id", nextColumn.getId(), attrs);
                    textElement("custom-field", attrs, valueAsString, handler);
                  }
                }
                endPrefixedElement("task", handler);
                return "";
            }
        };
        try {
            visitor.visit(taskManager);
        } catch (Exception e) {
            throw new ExportException("Failed to write tasks", e);
        }
        endPrefixedElement("tasks", handler);
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.ganttproject.export.TaskVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.