Java tutorial
//package com.java2s; /* * Copyright (C) Mike Murphy 2003-2015 <mike.murphy@xmlactions.org><mwjmurphy@gmail.com> * * 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. See the License for the specific language governing * permissions and limitations under the License. */ public class Main { /** * check if we should process non namespace'd elements as pager elements * kludge around xmlns="...riostl...", * targetNamespace="http://www.riostl.com/schema" * schemaLocation="http://www.riostl.com/schema/... * */ private static boolean findRiostlAsNonNamespace(String xml) { //if (findFor(xml, "xmlns=")) // return true; if (findFor(xml, "targetNamespace") != null) return true; else if (findFor(xml, "xmlns=") != null) return true; //else if (findFor(xml, "schemaLocation")) // return true; else return false; } private static String findFor(String xml, String pattern) { String ref = findUriFor(xml, pattern); if (ref != null) { String uri = ref.toLowerCase(); if (isAxelNS(uri)) { return ref; } } return null; } private static String findUriFor(String xml, String pattern) { int index = xml.indexOf(pattern); if (index > -1) { index += pattern.length(); } int start = -1, end = -1; for (; index > -1 && index < xml.length(); index++) { char c = xml.charAt(index); if (c == '=' || isWhiteSpace(c)) { continue; } if (c == '\"') { if (start == -1) { start = index; end = xml.indexOf('"', index + 1); break; } } else { // got a character that wasn't a whitespace or wasn't a = or wasn't a ". break; } } if (start > -1 && end > -1) { String ref = xml.substring(start + 1, end); return ref; } return null; } private static String findUriFor(String xml, String pattern, int fromIndex) { int start = -1, end = -1; for (int index = fromIndex; index < xml.length(); index++) { char c = xml.charAt(index); if (c == '=' || isWhiteSpace(c)) { continue; } if (c == '\"') { if (start == -1) { start = index; } else { end = index; } } else { // got a character that wasn't a whitespace or wasn't a = or wasn't a ". break; } } if (start > -1 && end > -1) { String ref = xml.substring(start + 1, end); return ref; } return null; } private static boolean isAxelNS(String ns) { if (ns.indexOf("uxml.net") >= 0 || ns.indexOf("xmlactions.org") >= 0 || ns.indexOf("jdhtml.com") >= 0 || ns.indexOf("riostl") >= 0) { return true; } return false; } /** * Checks if a char is a whitespace. * <p> * whitespace = ' ' || 0x09 || 0x0a || 0x0d * </p> * @param b - the char to check * @return true if char is a whitespace else false if not */ public static boolean isWhiteSpace(char b) { // TAB LF CR if (b == ' ' || b == 0x09 || b == 0x0a || b == 0x0d) { return (true); } return (false); } }