public static void main3() { String s = "\n"; System.out.printf("quoteXmlAttribute(%s) == %s%n", s, StringUtil2.quoteXmlAttribute(s)); String s2 = StringUtil2.quoteXmlAttribute(s); System.out.printf("unquoteXmlAttribute(%s) == '%s'%n", s2, StringUtil2.unquoteXmlAttribute(s2)); }
static private void writeNcMLDimension(Variable v, Formatter out) { out.format(" shape='"); java.util.List<Dimension> dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { Dimension dim = dims.get(j); if (j != 0) out.format(" "); if (dim.isShared()) out.format("%s", StringUtil2.quoteXmlAttribute(dim.getShortName())); else out.format("%d", dim.getLength()); } out.format("'"); }
static private void writeNcMLDimension( Variable v, PrintStream out) { out.print(" shape='"); java.util.List<Dimension> dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { Dimension dim = dims.get(j); if (j != 0) out.print(" "); if (dim.isShared()) out.print(StringUtil2.quoteXmlAttribute(dim.getShortName())); else out.print(dim.getLength()); } out.print("'"); }
static private void writeNcMLDimension(Variable v, Formatter out) { out.format(" shape='"); java.util.List<Dimension> dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { Dimension dim = dims.get(j); if (j != 0) out.format(" "); if (dim.isShared()) out.format("%s", StringUtil2.quoteXmlAttribute(dim.getShortName())); else out.format("%d", dim.getLength()); } out.format("'"); }
static private void writeNcMLDimension( Variable v, PrintStream out) { out.print(" shape='"); java.util.List<Dimension> dims = v.getDimensions(); for (int j = 0; j < dims.size(); j++) { Dimension dim = dims.get(j); if (j != 0) out.print(" "); if (dim.isShared()) out.print(StringUtil2.quoteXmlAttribute(dim.getShortName())); else out.print(dim.getLength()); } out.print("'"); }
static public void writeNcML(NetcdfFile ncfile, Formatter out, WantValues showValues, String url) throws IOException { out.format("<?xml version='1.0' encoding='UTF-8'?>%n"); out.format("<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'%n"); if (url != null) out.format(" location='%s' >%n%n", StringUtil2.quoteXmlAttribute(url)); else out.format(" location='%s' >%n%n", StringUtil2.quoteXmlAttribute(URLnaming.canonicalizeWrite(ncfile.getLocation()))); if (ncfile.getId() != null) out.format(" id='%s'%n", StringUtil2.quoteXmlAttribute(ncfile.getId())); if (ncfile.getTitle() != null) out.format(" title='%s'%n", StringUtil2.quoteXmlAttribute(ncfile.getTitle())); writeNcMLGroup(ncfile, ncfile.getRootGroup(), out, new Indent(2), showValues); out.format("</netcdf>%n"); out.flush(); }
static public void writeNcML(NetcdfFile ncfile, Formatter out, WantValues showValues, String url) throws IOException { out.format("<?xml version='1.0' encoding='UTF-8'?>%n"); out.format("<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'%n"); if (url != null) out.format(" location='%s' >%n%n", StringUtil2.quoteXmlAttribute(url)); else out.format(" location='%s' >%n%n", StringUtil2.quoteXmlAttribute(URLnaming.canonicalizeWrite(ncfile.getLocation()))); if (ncfile.getId() != null) out.format(" id='%s'%n", StringUtil2.quoteXmlAttribute(ncfile.getId())); if (ncfile.getTitle() != null) out.format(" title='%s'%n", StringUtil2.quoteXmlAttribute(ncfile.getTitle())); writeNcMLGroup(ncfile, ncfile.getRootGroup(), out, new Indent(2), showValues); out.format("</netcdf>%n"); out.flush(); }
@SuppressWarnings({"ObjectToString"}) static private void writeNcMLAtt(Attribute att, Formatter out, Indent indent) { out.format("%s<attribute name='%s' value='", indent, StringUtil2.quoteXmlAttribute(att.getShortName())); if (att.isString()) { for (int i = 0; i < att.getLength(); i++) { if (i > 0) out.format("\\, "); // ?? out.format("%s", StringUtil2.quoteXmlAttribute(att.getStringValue(i))); } } else { for (int i = 0; i < att.getLength(); i++) { if (i > 0) out.format(" "); out.format("%s ", att.getNumericValue(i)); } out.format("' type='%s", att.getDataType()); } out.format("' />%n"); }
@SuppressWarnings({"ObjectToString"}) static private void writeNcMLAtt(Attribute att, PrintStream out, Indent indent) { out.print(indent); out.print("<attribute name='"+ StringUtil2.quoteXmlAttribute(att.getShortName())+"' value='"); if (att.isString()) { for (int i=0; i<att.getLength(); i++) { if (i > 0) out.print("\\, "); // ?? out.print( StringUtil2.quoteXmlAttribute(att.getStringValue(i))); } } else { for (int i=0; i<att.getLength(); i++) { if (i > 0) out.print(" "); out.print(att.getNumericValue(i) + " "); } out.print("' type='"+att.getDataType()); } out.print("' />\n"); }
@SuppressWarnings({"ObjectToString"}) static private void writeNcMLAtt(Attribute att, PrintStream out, Indent indent) { out.print(indent); out.print("<attribute name='"+ StringUtil2.quoteXmlAttribute(att.getShortName())+"' value='"); if (att.isString()) { for (int i=0; i<att.getLength(); i++) { if (i > 0) out.print("\\, "); // ?? out.print( StringUtil2.quoteXmlAttribute(att.getStringValue(i))); } } else { for (int i=0; i<att.getLength(); i++) { if (i > 0) out.print(" "); out.print(att.getNumericValue(i) + " "); } out.print("' type='"+att.getDataType()); } out.print("' />\n"); }
@SuppressWarnings({"ObjectToString"}) static private void writeNcMLAtt(Attribute att, Formatter out, Indent indent) { out.format("%s<attribute name='%s' value='", indent, StringUtil2.quoteXmlAttribute(att.getShortName())); if (att.isString()) { for (int i = 0; i < att.getLength(); i++) { if (i > 0) out.format("\\, "); // ?? out.format("%s", StringUtil2.quoteXmlAttribute(att.getStringValue(i))); } } else { for (int i = 0; i < att.getLength(); i++) { if (i > 0) out.format(" "); out.format("%s ", att.getNumericValue(i)); } out.format("' type='%s", att.getDataType()); } out.format("' />\n"); }
/** * Write the NcML representation for a file. * Note that ucar.nc2.dataset.NcMLWriter has a JDOM implementation, for complete NcML. * This method implements only the "core" NcML for plain ole netcdf files. * * @param ncfile write NcML for this file * @param os write to this Output Stream. * @param showCoords show coordinate variable values. * @param uri use this for the url attribute; if null use getLocation(). // ?? * @throws IOException on write error */ static public void writeNcML( NetcdfFile ncfile, java.io.OutputStream os, boolean showCoords, String uri) throws IOException { PrintStream out = new PrintStream( os); out.print("<?xml version='1.0' encoding='UTF-8'?>\n"); out.print("<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'\n"); // out.print(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); // out.print(" xsi:schemaLocation='http://www.unidata.edu/schemas/ncml-2.2 http://www.unidata.ucar.edu/schemas/ncml-2.2.xsd'\n"); if (uri != null) out.print(" location='"+ StringUtil2.quoteXmlAttribute(uri)+"' >\n\n"); else out.print(" location='"+ StringUtil2.quoteXmlAttribute(URLnaming.canonicalizeWrite(ncfile.getLocation()))+"' >\n\n"); if (ncfile.getId() != null) out.print(" id='"+ StringUtil2.quoteXmlAttribute(ncfile.getId())+"' >\n"); if (ncfile.getTitle() != null) out.print(" title='"+ StringUtil2.quoteXmlAttribute(ncfile.getTitle())+"' >\n"); writeNcMLGroup( ncfile, ncfile.getRootGroup(), out, new Indent(2), showCoords); out.print("</netcdf>\n"); out.flush(); }
/** * Write the NcML representation for a file. * Note that ucar.nc2.dataset.NcMLWriter has a JDOM implementation, for complete NcML. * This method implements only the "core" NcML for plain ole netcdf files. * * @param ncfile write NcML for this file * @param os write to this Output Stream. * @param showCoords show coordinate variable values. * @param uri use this for the url attribute; if null use getLocation(). // ?? * @throws IOException on write error */ static public void writeNcML( NetcdfFile ncfile, java.io.OutputStream os, boolean showCoords, String uri) throws IOException { PrintStream out = new PrintStream( os); out.print("<?xml version='1.0' encoding='UTF-8'?>\n"); out.print("<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'\n"); // out.print(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); // out.print(" xsi:schemaLocation='http://www.unidata.edu/schemas/ncml-2.2 http://www.unidata.ucar.edu/schemas/ncml-2.2.xsd'\n"); if (uri != null) out.print(" location='"+ StringUtil2.quoteXmlAttribute(uri)+"' >\n\n"); else out.print(" location='"+ StringUtil2.quoteXmlAttribute(URLnaming.canonicalizeWrite(ncfile.getLocation()))+"' >\n\n"); if (ncfile.getId() != null) out.print(" id='"+ StringUtil2.quoteXmlAttribute(ncfile.getId())+"' >\n"); if (ncfile.getTitle() != null) out.print(" title='"+ StringUtil2.quoteXmlAttribute(ncfile.getTitle())+"' >\n"); writeNcMLGroup( ncfile, ncfile.getRootGroup(), out, new Indent(2), showCoords); out.print("</netcdf>\n"); out.flush(); }
static private void writeNcMLStructure( Structure s, PrintStream out, Indent indent) throws IOException { out.print(indent); out.print("<structure name='"+ StringUtil2.quoteXmlAttribute(s.getShortName())); // any dimensions? if (s.getRank() > 0) { writeNcMLDimension( s, out); } out.print(">\n"); indent.incr(); List<Attribute> attList = s.getAttributes(); for (Attribute att : attList) { writeNcMLAtt(att, out, indent); } if (attList.size() > 0) out.print("\n"); List<Variable> varList = s.getVariables(); for (Variable v : varList) { writeNcMLVariable(v, out, indent, false); } indent.decr(); out.print(indent); out.print("</structure>\n"); }
static private void writeNcMLStructure( Structure s, PrintStream out, Indent indent) throws IOException { out.print(indent); out.print("<structure name='"+ StringUtil2.quoteXmlAttribute(s.getShortName())); // any dimensions? if (s.getRank() > 0) { writeNcMLDimension( s, out); } out.print(">\n"); indent.incr(); List<Attribute> attList = s.getAttributes(); for (Attribute att : attList) { writeNcMLAtt(att, out, indent); } if (attList.size() > 0) out.print("\n"); List<Variable> varList = s.getVariables(); for (Variable v : varList) { writeNcMLVariable(v, out, indent, false); } indent.decr(); out.print(indent); out.print("</structure>\n"); }
static private void writeNcMLStructure(Structure s, Formatter out, Indent indent, WantValues showValues) throws IOException { out.format("%s<structure name='%s", indent, StringUtil2.quoteXmlAttribute(s.getShortName())); // any dimensions? if (s.getRank() > 0) { writeNcMLDimension(s, out); } out.format(">%n"); indent.incr(); List<Attribute> attList = s.getAttributes(); for (Attribute att : attList) { writeNcMLAtt(att, out, indent); } if (attList.size() > 0) out.format("%n"); List<Variable> varList = s.getVariables(); for (Variable v : varList) { writeNcMLVariable(v, out, indent, showValues); } indent.decr(); out.format("%s</structure>%n", indent); }
static private void writeNcMLStructure(Structure s, Formatter out, Indent indent, WantValues showValues) throws IOException { out.format("%s<structure name='%s", indent, StringUtil2.quoteXmlAttribute(s.getShortName())); // any dimensions? if (s.getRank() > 0) { writeNcMLDimension(s, out); } out.format(">%n"); indent.incr(); List<Attribute> attList = s.getAttributes(); for (Attribute att : attList) { writeNcMLAtt(att, out, indent); } if (attList.size() > 0) out.format("%n"); List<Variable> varList = s.getVariables(); for (Variable v : varList) { writeNcMLVariable(v, out, indent, showValues); } indent.decr(); out.format("%s</structure>%n", indent); }
static private void writeNcMLVariable( Variable v, PrintStream out, Indent indent, boolean showCoords) throws IOException { out.print(indent); out.print("<variable name='"+ StringUtil2.quoteXmlAttribute(v.getShortName())+"' type='"+ v.getDataType()+"'");
static private void writeNcMLVariable(Variable v, Formatter out, Indent indent, WantValues showValues) throws IOException { out.format("%s<variable name='%s' type='%s'", indent, StringUtil2.quoteXmlAttribute(v.getShortName()), v.getDataType());
static private void writeNcMLVariable(Variable v, Formatter out, Indent indent, WantValues showValues) throws IOException { out.format("%s<variable name='%s' type='%s'", indent, StringUtil2.quoteXmlAttribute(v.getShortName()), v.getDataType());