Package dk.brics.relaxng.converter

Examples of dk.brics.relaxng.converter.RNGParser


   */
  public static Map<String,SequenceNode> loadXMLSchema(URL url, XMLGraph xg) throws ParseException {
    boolean extend = xg != null;
    String u = url.toString();
    Map<String,SequenceNode> types = new HashMap<String,SequenceNode>();
    RNGParser rngparser = new RNGParser();
    RestrRelaxNG2XMLGraph rrng2xg = new RestrRelaxNG2XMLGraph(xg, datatypes);
    if (u.endsWith(".xsd")) {
      XMLSchema2RestrRelaxNG xsd2rrng = new XMLSchema2RestrRelaxNG(datatypes);
      if (extend)
        rrng2xg.extend(rngparser.parse(xsd2rrng.convert(url), url));
      else
        xg = rrng2xg.convert(rngparser.parse(xsd2rrng.convert(url), url));
      Map<String,String> m1 = xsd2rrng.getNameMap();
      Map<String,String> m2 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m3 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m3.get(m2.get(e.getValue())));
    } else if (u.endsWith(".dtd")) {
      DTD2RestrRelaxNG dtd2rrng = new DTD2RestrRelaxNG();
      if (extend)
        rrng2xg.extend(rngparser.parse(dtd2rrng.convert(url), url));
      else
        xg = rrng2xg.convert(rngparser.parse(dtd2rrng.convert(url), url));
      Map<String,String> m1 = dtd2rrng.getNameMap();
      Map<String,String> m2 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m3 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m3.get(m2.get(e.getValue())));
    } else if (u.endsWith(".rrng") || u.endsWith(".rng")) {
      Grammar rrng = rngparser.parse(url);
      if (!rrng.check(System.err))
        throw new ParseException("Schema is not Restricted RELAX NG " + url);
      if (extend)
        rrng2xg.extend(rrng);
      else
        xg = rrng2xg.convert(rrng);
      Map<String,String> m1 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m2 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m2.get(e.getValue()));
    } else
      throw new ParseException("Unrecognized schema type " + url);
View Full Code Here


   */
  public static Map<String,SequenceNode> loadXMLSchema(URL url, XMLGraph xg) throws ParseException {
    boolean extend = xg != null;
    String u = url.toString();
    Map<String,SequenceNode> types = new HashMap<String,SequenceNode>();
    RNGParser rngparser = new RNGParser();
    RestrRelaxNG2XMLGraph rrng2xg = new RestrRelaxNG2XMLGraph(xg, datatypes);
    if (u.endsWith(".xsd")) {
      XMLSchema2RestrRelaxNG xsd2rrng = new XMLSchema2RestrRelaxNG(datatypes);
      if (extend)
        rrng2xg.extend(rngparser.parse(xsd2rrng.convert(url), url));
      else
        xg = rrng2xg.convert(rngparser.parse(xsd2rrng.convert(url), url));
      Map<String,String> m1 = xsd2rrng.getNameMap();
      Map<String,String> m2 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m3 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m3.get(m2.get(e.getValue())));
    } else if (u.endsWith(".dtd")) {
      DTD2RestrRelaxNG dtd2rrng = new DTD2RestrRelaxNG();
      if (extend)
        rrng2xg.extend(rngparser.parse(dtd2rrng.convert(url), url));
      else
        xg = rrng2xg.convert(rngparser.parse(dtd2rrng.convert(url), url));
      Map<String,String> m1 = dtd2rrng.getNameMap();
      Map<String,String> m2 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m3 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m3.get(m2.get(e.getValue())));
    } else if (u.endsWith(".rrng") || u.endsWith(".rng")) {
      Grammar rrng = rngparser.parse(url);
      if (!rrng.check(System.err))
        throw new ParseException("Schema is not Restricted RELAX NG " + url);
      if (extend)
        rrng2xg.extend(rrng);
      else
        xg = rrng2xg.convert(rrng);
      Map<String,String> m1 = rngparser.getTopLevelNewNames();
      Map<String,SequenceNode> m2 = rrng2xg.getDefineNodes();
      for (Map.Entry<String,String> e : m1.entrySet())
        types.put(e.getKey(), m2.get(e.getValue()));
    } else
      throw new ParseException("Unrecognized schema type " + url);
View Full Code Here

TOP

Related Classes of dk.brics.relaxng.converter.RNGParser

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.