private void writeState(XMLWriter writer) { writer.startTag(RepositoriesViewContentHandler.REPOSITORIES_VIEW_TAG, null, true); // Write the repositories Collection repos = Arrays.asList(getKnownRepositoryLocations()); Iterator it = repos.iterator(); while (it.hasNext()) { CVSRepositoryLocation location = (CVSRepositoryLocation) it.next(); RepositoryRoot root = getRepositoryRootFor(location); root.writeState(writer); } writer.endTag(RepositoriesViewContentHandler.REPOSITORIES_VIEW_TAG); }
public void startElement( SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) { previousCallbackWasCDATA = false; log(path.toString() + ":"); String startTag = XMLWriter.createStartTag(name, attributes); log(startTag); if (leadingCDdata != null) { String encodedText = XMLEncode.xmlEncodeText(leadingCDdata); log(encodedText); } }
protected void saveState() throws TeamException { IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); File tempFile = pluginStateLocation.append(REPOSITORIES_VIEW_FILE + ".tmp").toFile(); // $NON-NLS-1$ File stateFile = pluginStateLocation.append(REPOSITORIES_VIEW_FILE).toFile(); try { XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); try { writeState(writer); } finally { writer.close(); } if (stateFile.exists()) { stateFile.delete(); } boolean renamed = tempFile.renameTo(stateFile); if (!renamed) { throw new TeamException( new Status( IStatus.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind( CVSUIMessages.RepositoryManager_rename, new String[] {tempFile.getAbsolutePath()}), null)); } } catch (IOException e) { throw new TeamException( new Status( IStatus.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind( CVSUIMessages.RepositoryManager_save, new String[] {stateFile.getAbsolutePath()}), e)); } }
private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds) throws IOException, DataSourceException, ServletException, DazzleException { DazzleReferenceSource drs = (DazzleReferenceSource) dds; List segments = DazzleTools.getSegments(dds, req, resp); if (segments.size() == 0) { throw new DazzleException( DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command"); } // Fetch and validate the requests. Map segmentResults = new HashMap(); for (Iterator i = segments.iterator(); i.hasNext(); ) { Segment seg = (Segment) i.next(); try { Sequence seq = drs.getSequence(seg.getReference()); if (seq.getAlphabet() != DNATools.getDNA()) { throw new DazzleException( DASStatus.STATUS_SERVER_ERROR, "Sequence " + seg.toString() + " is not in the DNA alphabet"); } if (seg.isBounded()) { if (seg.getMin() < 1 || seg.getMax() > seq.length()) { throw new DazzleException( DASStatus.STATUS_BAD_COORDS, "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length()); } } segmentResults.put(seg, seq); } catch (NoSuchElementException ex) { throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex); } catch (DataSourceException ex) { throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex); } } // // Looks okay -- generate the response document // XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd"); try { xw.openTag("DASDNA"); for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) { Map.Entry me = (Map.Entry) i.next(); Segment seg = (Segment) me.getKey(); Sequence seq = (Sequence) me.getValue(); xw.openTag("SEQUENCE"); xw.attribute("id", seg.getReference()); xw.attribute("version", drs.getLandmarkVersion(seg.getReference())); if (seg.isBounded()) { xw.attribute("start", "" + seg.getStart()); xw.attribute("stop", "" + seg.getStop()); } else { xw.attribute("start", "" + 1); xw.attribute("stop", "" + seq.length()); } SymbolList syms = seq; if (seg.isBounded()) { syms = syms.subList(seg.getMin(), seg.getMax()); } if (seg.isInverted()) { syms = DNATools.reverseComplement(syms); } xw.openTag("DNA"); xw.attribute("length", "" + syms.length()); for (int pos = 1; pos <= syms.length(); pos += 60) { int maxPos = Math.min(syms.length(), pos + 59); xw.println(syms.subStr(pos, maxPos)); } xw.closeTag("DNA"); xw.closeTag("SEQUENCE"); } xw.closeTag("DASDNA"); xw.close(); } catch (Exception ex) { throw new DazzleException(ex, "Error writing DNA document"); } }
public static void main(String args[]) throws Exception { XMLElement elt = new XMLElement("FOO"); elt.setAttribute(null, "good"); XMLWriter writer = new XMLWriter(System.out); writer.write(elt); }
private void writeCommentHistory(XMLWriter writer) { writer.startTag(ELEMENT_COMMIT_HISTORY, null, false); for (int i = 0; i < previousComments.length && i < maxComments; i++) writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]); writer.endTag(ELEMENT_COMMIT_HISTORY); }
private void writeCommentTemplates(XMLWriter writer) { writer.startTag(ELEMENT_COMMENT_TEMPLATES, null, false); for (int i = 0; i < commentTemplates.length; i++) writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, commentTemplates[i]); writer.endTag(ELEMENT_COMMENT_TEMPLATES); }