* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public class OutXML extends Out{
private static final String XMLNS_XSI = "xmlns:xsi";
- public static final String XML_INFO = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
+ public static final String XML_INFO = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
public static final String XML_SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance";
-
+
private String root;
private List<Prop> props;
props.add(new Prop(tv[0],tv[1]));
}
}
-
+
public OutXML(JaxInfo jaxInfo) {
this(jaxInfo.name,genNS(jaxInfo));
}
-
+
public OutXML(InXML inXML) {
this(inXML.jaxInfo.name,genNS(inXML.jaxInfo));
}
-
+
private static String[] genNS(JaxInfo jaxInfo) {
return new String[] {"xmlns=" + jaxInfo.ns};
}
-
-
+
+
@Override
public<IN,S> void extract(IN in, Writer writer, Parse<IN,S> prs, boolean ... options) throws IOException, ParseException {
Parsed<S> p = prs.newParsed();
Stack<Level> stack = new Stack<Level>();
// If it's an IndentPrintWriter, it is pretty printing.
boolean pretty = (options.length>0&&options[0]);
-
+
IndentPrintWriter ipw;
if (pretty) {
if (writer instanceof IndentPrintWriter) {
if (pretty)ipw.inc();
break;
case Parse.END_OBJ:
- if (p.hasData())
+ if (p.hasData())
closeTag = tag(writer,writer,pretty,false,p.name, XmlEscape.convert(p.sb));
if (pretty)ipw.dec();
writer.append(level.sbw.getBuffer());
level = stack.pop();
break;
- case Parse.START_ARRAY:
+ case Parse.START_ARRAY:
level.multi = p.name;
break;
case Parse.END_ARRAY:
- if (p.hasData())
+ if (p.hasData())
closeTag = tag(writer,writer,pretty,false, p.name, XmlEscape.convert(p.sb));
level.multi=null;
break;
case Parse.ATTRIB:
- if (p.hasData())
+ if (p.hasData())
attrib(writer,pretty,p.name, XmlEscape.convert(p.sb), level);
break;
case Parse.NEXT:
writer.append(level.sbw.getBuffer());
writer.flush();
}
-
+
private class Level {
public final StringBuilderWriter sbw;
public String multi;
private Level prev;
private Map<String,String> nses;
-
+
public Level(Level level) {
sbw = new StringBuilderWriter();
multi = null;
String v = nses.get(ns);
return value.equals(v); // note: accomodates not finding NS as well
}
-
+
if (create && !rv) {
if (nses == null) nses = new HashMap<>();
nses.put(ns, value);
}
return rv;
}
-
-
-
+
+
+
}
-
+
private boolean tag(Writer fore, Writer aft, boolean pretty, boolean returns, String tag, String data) throws IOException {
fore.append('<');
fore.append(tag);
if (pretty)aft.append('\n');
return data==null;
}
-
+
private void attrib(Writer fore, boolean pretty, String tag, String value, Level level) throws IOException {
String realTag = tag.startsWith("__")?tag.substring(2):tag; // remove __
if (realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance
}
}
fore.append(' ');
- fore.append(realTag);
+ fore.append(realTag);
fore.append("=\"");
fore.append(value);
fore.append('"');