/** * Exports the destinations to XML. * @param names the names * @param wrt the export destination. The writer is not closed * @param encoding the encoding according to IANA conventions * @param onlyASCII codes above 127 will always be escaped with &#nn; if <CODE>true</CODE>, * whatever the encoding * @throws IOException on error */ public static void exportToXML(HashMap names, Writer wrt, String encoding, boolean onlyASCII) throws IOException { wrt.write("<?xml version=\"1.0\" encoding=\""); wrt.write(SimpleXMLParser.escapeXML(encoding, onlyASCII)); wrt.write("\"?>\n<Destination>\n"); for (Iterator it = names.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry)it.next(); String key = (String)entry.getKey(); String value = (String)entry.getValue(); wrt.write(" <Name Page=\""); wrt.write(SimpleXMLParser.escapeXML(value, onlyASCII)); wrt.write("\">"); wrt.write(SimpleXMLParser.escapeXML(escapeBinaryString(key), onlyASCII)); wrt.write("</Name>\n"); } wrt.write("</Destination>\n"); wrt.flush(); }
/** Reads an XFDF form. * @param filename the file name of the form * @throws IOException on error */ public XfdfReader(String filename) throws IOException { FileInputStream fin = null; try { fin = new FileInputStream(filename); SimpleXMLParser.parse(this, fin); } finally { try{if (fin != null) {fin.close();}}catch(Exception e){} } }
/** * Exports the bookmarks to XML. Only of use if the generation is to be include in * some other XML document. * @param list the bookmarks * @param out the export destination. The writer is not closed * @param indent the indentation level. Pretty printing significant only * @param onlyASCII codes above 127 will always be escaped with &#nn; if <CODE>true</CODE>, * whatever the encoding * @throws IOException on error */ public static void exportToXMLNode(List list, Writer out, int indent, boolean onlyASCII) throws IOException { StringBuilder dep = new StringBuilder(8); for (int k = 0; k < indent; ++k) { dep.append(" "); } for (Iterator it = list.iterator(); it.hasNext();) { HashMap map = (HashMap)it.next(); String title = null; out.write(dep.toString()); out.write("<Title "); List kids = null; for (Iterator e = map.entrySet().iterator(); e.hasNext();) { Map.Entry entry = (Map.Entry) e.next(); String key = (String) entry.getKey(); if (key.equals("Title")) { title = (String) entry.getValue(); continue; } else if (key.equals("Kids")) { kids = (List) entry.getValue(); continue; } else { out.write(key); out.write("=\""); String value = (String) entry.getValue(); if (key.equals("Named") || key.equals("NamedN")) { value = SimpleNamedDestination.escapeBinaryString(value); } out.write(SimpleXMLParser.escapeXML(value, onlyASCII)); out.write("\" "); } } out.write(">"); if (title == null) { title = ""; } out.write(SimpleXMLParser.escapeXML(title, onlyASCII)); if (kids != null) { out.write("\n"); exportToXMLNode(kids, out, indent + 1, onlyASCII); out.write(dep.toString()); } out.write("</Title>\n"); } }
public void parse(Reader reader) throws IOException { SimpleXMLParser.parse(this, null, reader, true); }
/** * Exports the bookmarks to XML. Only of use if the generation is to be include in * some other XML document. * @param list the bookmarks * @param out the export destination. The writer is not closed * @param indent the indentation level. Pretty printing significant only * @param onlyASCII codes above 127 will always be escaped with &#nn; if <CODE>true</CODE>, * whatever the encoding * @throws IOException on error */ public static void exportToXMLNode(List list, Writer out, int indent, boolean onlyASCII) throws IOException { String dep = ""; for (int k = 0; k < indent; ++k) dep += " "; for (Iterator it = list.iterator(); it.hasNext();) { HashMap map = (HashMap)it.next(); String title = null; out.write(dep); out.write("<Title "); List kids = null; for (Iterator e = map.entrySet().iterator(); e.hasNext();) { Map.Entry entry = (Map.Entry) e.next(); String key = (String) entry.getKey(); if (key.equals("Title")) { title = (String) entry.getValue(); continue; } else if (key.equals("Kids")) { kids = (List) entry.getValue(); continue; } else { out.write(key); out.write("=\""); String value = (String) entry.getValue(); if (key.equals("Named") || key.equals("NamedN")) value = SimpleNamedDestination.escapeBinaryString(value); out.write(SimpleXMLParser.escapeXML(value, onlyASCII)); out.write("\" "); } } out.write(">"); if (title == null) title = ""; out.write(SimpleXMLParser.escapeXML(title, onlyASCII)); if (kids != null) { out.write("\n"); exportToXMLNode(kids, out, indent + 1, onlyASCII); out.write(dep); } out.write("</Title>\n"); } }
/** * Exports the bookmarks to XML. * @param list the bookmarks * @param wrt the export destination. The writer is not closed * @param encoding the encoding according to IANA conventions * @param onlyASCII codes above 127 will always be escaped with &#nn; if <CODE>true</CODE>, * whatever the encoding * @throws IOException on error */ public static void exportToXML(List list, Writer wrt, String encoding, boolean onlyASCII) throws IOException { wrt.write("<?xml version=\"1.0\" encoding=\""); wrt.write(SimpleXMLParser.escapeXML(encoding, onlyASCII)); wrt.write("\"?>\n<Bookmark>\n"); exportToXMLNode(list, wrt, 1, onlyASCII); wrt.write("</Bookmark>\n"); wrt.flush(); }
/** Reads an XFDF form. * @param xfdfIn the byte array with the form * @throws IOException on error */ public XfdfReader(byte xfdfIn[]) throws IOException { SimpleXMLParser.parse( this, new ByteArrayInputStream(xfdfIn)); }
/** * Import the names from XML. * @param in the XML source. The stream is not closed * @throws IOException on error * @return the names */ public static HashMap importFromXML(InputStream in) throws IOException { SimpleNamedDestination names = new SimpleNamedDestination(); SimpleXMLParser.parse(names, in); return names.xmlNames; }
/** * Import the names from XML. * @param in the XML source. The reader is not closed * @throws IOException on error * @return the names */ public static HashMap importFromXML(Reader in) throws IOException { SimpleNamedDestination names = new SimpleNamedDestination(); SimpleXMLParser.parse(names, in); return names.xmlNames; }
/** * Import the bookmarks from XML. * @param in the XML source. The stream is not closed * @throws IOException on error * @return the bookmarks */ public static List importFromXML(InputStream in) throws IOException { SimpleBookmark book = new SimpleBookmark(); SimpleXMLParser.parse(book, in); return book.topList; }
/** * Import the bookmarks from XML. * @param in the XML source. The reader is not closed * @throws IOException on error * @return the bookmarks */ public static List importFromXML(Reader in) throws IOException { SimpleBookmark book = new SimpleBookmark(); SimpleXMLParser.parse(book, in); return book.topList; }