@Override public void run(List<PrjElement> list) { if (!isHorizontalCRS) { parseProjcs(list, false); isHorizontalCRS = true; } else { throw new PrjParserException("Failed to parse PRJ, because of multiple horizontal CRS definition."); } } };
@Override public void run(List<PrjElement> list) { if (!isHorizontalCRS) { parseGeogcs(list, false); isHorizontalCRS = true; } else { throw new PrjParserException("Failed to parse PRJ, because of multiple horizontal CRS definition."); } } };
@Override public void run(List<PrjElement> list) { if (!isVerticalCRS) { parseVertcs(list, false); isVerticalCRS = true; } else { throw new PrjParserException("Failed to parse PRJ, because of multiple vertical CRS definition."); } } };
@Override public void run(List<PrjElement> list) { List<String> info = getAxis(list); switch (indexAxis) { case 0: params.put(PrjKeyParameters.VERTAXIS, info.get(0)); params.put(PrjKeyParameters.VERTAXISTYPE, info.get(1)); indexAxis++; break; default: throw new PrjParserException("Failed to parse PRJ. Found '" + list + "', completely unexpected!"); } } };
/** * Return the informations contains in the PrjElement in parameter if it is * a PrjStringParameter. * * @param e the PrjElement to parse */ private String getString(PrjElement e) { if (e instanceof PrjStringElement) { PrjStringElement s = (PrjStringElement) e; return s.getValue().trim(); } throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', expected some PrjStringElement."); }
@Override public void run(List<PrjElement> list) { List<String> info = getAxis(list); switch (indexAxis) { case 0: params.put(PrjKeyParameters.AXIS1, info.get(0)); params.put(PrjKeyParameters.AXIS1TYPE, info.get(1)); indexAxis++; break; case 1: params.put(PrjKeyParameters.AXIS2, info.get(0)); params.put(PrjKeyParameters.AXIS2TYPE, info.get(1)); indexAxis++; break; default: throw new PrjParserException("Failed to parse PRJ. Found '" + list + "', completely unexpected!"); } } };
/** * Read the informations contains in the PrjElement in parameter if it is a * PrjStringParameter and put it into the set of parameters. * * @param e the PrjElement to parse * @param name the key to use to put the string in the Map of parameters */ private void parseString(PrjElement e, String name) { if (e instanceof PrjStringElement) { PrjStringElement s = (PrjStringElement) e; params.put(name, s.getValue().trim()); } else { throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', expected PrjStringElement with " + name + " in it."); } }
/** * Read the informations contains in the PrjElement in parameter if it is a * PrjNumberParameter and put it into the set of parameters. * * @param e the PrjElement to parse * @param name the key to use to put the string in the Map of parameters */ private void parseNumber(PrjElement e, String name) { if (e instanceof PrjNumberElement) { PrjNumberElement n = (PrjNumberElement) e; params.put(name, String.valueOf(n.getValue())); } else { throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', expected PrjNumberElement with " + name + " in it."); } }
/** * Return the informations contains in the PrjElement in parameter if it is * a PrjNumberParameter. * * @param e the PrjElement to parse */ private double getNumber(PrjElement e) { if (e instanceof PrjNumberElement) { PrjNumberElement n = (PrjNumberElement) e; return n.getValue(); } else { throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', expected PrjNumberElement."); } } }
@Override public void run(List<PrjElement> list) { List<String> info = getAxis(list); switch (indexAxis) { case 0: params.put(PrjKeyParameters.AXIS1, info.get(0)); params.put(PrjKeyParameters.AXIS1TYPE, info.get(1)); indexAxis++; break; case 1: params.put(PrjKeyParameters.AXIS2, info.get(0)); params.put(PrjKeyParameters.AXIS2TYPE, info.get(1)); indexAxis++; break; case 2: params.put(PrjKeyParameters.AXIS3, info.get(0)); params.put(PrjKeyParameters.AXIS3TYPE, info.get(1)); indexAxis++; break; default: throw new PrjParserException("Failed to parse PRJ. Found '" + list + "', completely unexpected!"); } } };
@Override public void run(List<PrjElement> list) { if (!params.containsKey(PrjKeyParameters.AXIS1)) { List<String> info = getAxis(list); switch (indexAxis) { case 0: params.put(PrjKeyParameters.AXIS1, info.get(0)); params.put(PrjKeyParameters.AXIS1TYPE, info.get(1)); indexAxis++; break; case 1: params.put(PrjKeyParameters.AXIS2, info.get(0)); params.put(PrjKeyParameters.AXIS2TYPE, info.get(1)); indexAxis++; break; case 2: params.put(PrjKeyParameters.AXIS3, info.get(0)); params.put(PrjKeyParameters.AXIS3TYPE, info.get(1)); indexAxis++; break; default: throw new PrjParserException("Failed to parse PRJ. Found '" + list + "', completely unexpected!"); } } } };
/** * Parses a WKT PRJ String into a set of parameters. * * This is the main entry point of the parser. * * @param prjString a WKT string * @return a list of parameters * @throws PrjParserException if the PRJ cannot be parsed into a CRS for any * reason */ public Map<String, String> getParameters(String prjString) { CharBuffer s = CharBuffer.wrap(prjString); PrjElement e; try { e = parseNode(s); } catch (BufferUnderflowException ex) { throw new PrjParserException("Failed to read PRJ.", ex); } Map<String, String> prjParameters = PrjMatcher.match(e); return prjParameters; }
/** * Return the children of the PrjElement in parameter if it is an instance * of PrjNodeElement and if its name is the same as the name given in * parameter,else it throws a PrjParserException unless strict is false, it * then returns null. * * @param e the PrjElement to match * @param name the name of the desired PrjElement * @param strict true if the method must throw an exception instead of * return null */ private List<PrjElement> matchNode(PrjElement e, String name, boolean strict) { if (e instanceof PrjNodeElement) { PrjNodeElement n = (PrjNodeElement) e; if (n.getName().equalsIgnoreCase(name)) { return n.getChildren(); } } if (strict) { throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', expected PrjNodeElement[" + name + "]."); } else { return null; } }
break; default: throw new PrjParserException("weird character: " + next);
throw new PrjParserException("Failed to parse PRJ. Missing definition for an horizontal CRS or for a VerticalCRS.");
/** * Read the informations contains in the PrjElement in parameter using one * of the PrjNodeMatcher in parameter and put it into the set of parameters. * * @param e the PrjElement to parse * @param nn the PrjNodeMatcher to use to parse the given PrjElement * @param strict if true, the method throw a PrjParserException if it does * not manage to parse the PrjElement in parameter */ private void matchAnyNode(PrjElement e, PrjNodeMatcher[] nn, boolean strict) { if (e instanceof PrjNodeElement) { PrjNodeElement ne = (PrjNodeElement) e; for (PrjNodeMatcher m : nn) { if (ne.getName().equalsIgnoreCase(m.getName())) { m.run(ne.getChildren()); return; } } } if (strict) { throw new PrjParserException("Failed to parse PRJ. Found '" + e + "', completely unexpected!"); } }