⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.java

📁 非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应用程序更漂亮更易操作。 官网:www.zkoss.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		//3: nested content		final int nestedFrom = ++j, nestedTo;		for (int depth = 0;; ++j) {			if (j >= to)				throw new ServletException(MWeb.DSP_ACTION_NOT_TERMINATED,					new Object[] {actnm, new Integer(action.getLineNumber())});			cc = ctx.content.charAt(j);			if (j + 1 < to) {				if (cc == '<') {					final int oldLines = ctx.nLines;					k = j + 1;					ended = ctx.content.charAt(k) == '/';					k = skipWhitespaces(ctx, ended ? k + 1: k, to);					int l = nextSeparator(ctx, k, to);					if (l >= to || ctx.content.charAt(l) != ':'					|| !prefix.equals(ctx.content.substring(k, l))) {						ctx.nLines = oldLines;						continue; //bypass					}					k = skipWhitespaces(ctx, l + 1, to);					l = nextSeparator(ctx, k, to);					if (l >= to || !actnm.equals(ctx.content.substring(k, l))) {						ctx.nLines = oldLines;						continue; //bypass					}					l = skipWhitespaces(ctx, l, to);					if (l >= to || (ended && ctx.content.charAt(l) != '>')) {						ctx.nLines = oldLines;						continue; //bypass					}					if (ended) {						if (--depth < 0) {							nestedTo = j;							j = l;							break; //done						}					} else {						++depth;					}					j = l;					continue;				} else if (cc == '$' && ctx.content.charAt(j + 1) == '{') {					j = endOfEL(ctx, j, to);					continue;				}			}			if (cc == '\n') ++ctx.nLines;		}		parse0(ctx, action, nestedFrom, nestedTo); //recursive		return j;	}	private static boolean startsWith(String content, int from, int to, String s) {		for (int j = 0, len = s.length(); ; ++from, ++j) {			if (j >= len) return true;			if (from >= to || content.charAt(from) != s.charAt(j)) return false;		}	}	private static int skipWhitespaces(Context ctx, int from, int to) {		for (; from < to; ++from) {			final char cc = ctx.content.charAt(from);			if (cc == '\n') ++ctx.nLines;			else if (!Character.isWhitespace(cc))				break;		}		return from;	}	private static int nextSeparator(Context ctx, int from, int to) {		for (; from < to; ++from) {			final char cc = ctx.content.charAt(from);			if ((cc < '0' || cc > '9') && (cc < 'a' || cc > 'z')			&& (cc < 'A' || cc > 'Z') && cc != '_')				break;		}		return from;	}	/** Parses the attributes.	 */	private static int parseAttrs(Context ctx, Map attrs, String actnm,	int from, int to)	throws javax.servlet.ServletException {		for (int j, k = from;;) {			j = skipWhitespaces(ctx, k, to);			k = nextSeparator(ctx, j, to);			if (k >= to)				throw new ServletException(MWeb.DSP_ACTION_NOT_TERMINATED,					new Object[] {actnm, new Integer(ctx.nLines)});			if (j == k) return j;			final String attrnm = ctx.content.substring(j, k);			k = skipWhitespaces(ctx, k, to);			j = skipWhitespaces(ctx, k + 1, to);			if (j >= to || ctx.content.charAt(k) != '=')				throw new ServletException(MWeb.DSP_ATTRIBUTE_VALUE_REQUIRED,					new Object[] {actnm, attrnm, new Integer(ctx.nLines)});			final char quot = ctx.content.charAt(j);			if (quot != '"' && quot != '\'')				throw new ServletException(MWeb.DSP_ATTRIBUTE_VALUE_QUOTE_REQUIRED,					new Object[] {actnm, attrnm, new Integer(ctx.nLines)});			final StringBuffer sbval = new StringBuffer();			for (k = ++j;; ++k) {				if (k >= to)					throw new ServletException(MWeb.DSP_ATTRIBUTE_VALUE_QUOTE_REQUIRED,						new Object[] {actnm, attrnm, new Integer(ctx.nLines)});				final char cc = ctx.content.charAt(k);				if (cc == '\n')					throw new ServletException(MWeb.DSP_ATTRIBUTE_VALUE_QUOTE_REQUIRED,						new Object[] {actnm, attrnm, new Integer(ctx.nLines)});				if (cc == quot) {					++k;					break; //found				}				sbval.append(cc);				if (cc == '\\' && ++k < to)					sbval.setCharAt(sbval.length() - 1, ctx.content.charAt(k));			}			attrs.put(attrnm, sbval.toString());		}	}	/** Applies attributes.	 */	private static final	void applyAttrs(String actnm, ActionNode action, Map attrs)	throws javax.servlet.ServletException {		for (Iterator it = attrs.entrySet().iterator(); it.hasNext();) {			final Map.Entry me = (Map.Entry)it.next();			final String attrnm = (String)me.getKey();			final String attrval = (String)me.getValue();			try {				action.addAttribute(attrnm, attrval);			} catch (NoSuchMethodException ex) {				throw new ServletException(MWeb.DSP_ATTRIBUTE_NOT_FOUND,					new Object[] {actnm, attrnm, new Integer(action.getLineNumber())});			} catch (ClassCastException ex) {				throw new ServletException(MWeb.DSP_ATTRIBUTE_INVALID_VALUE,					new Object[] {actnm, attrnm, attrval, new Integer(action.getLineNumber())}, ex);			}		}	}	/** Parses an EL expression starting at from.	 * @return the position of }.	 */	private static int parseEL(Context ctx, Node parent, int from, int to)	throws javax.servlet.ServletException {		int j = endOfEL(ctx, from, to); //point to }		parent.addChild(new ELNode(ctx.content.substring(from, j + 1)));		return j;	}	/** Returns the position of '}'. */	private static int endOfEL(Context ctx, int from, int to)	throws javax.servlet.ServletException {		for (int j = from + 2;; ++j) {			if (j >= to)				throw new ServletException(MWeb.EL_NOT_TERMINATED, new Integer(ctx.nLines));			final char cc = ctx.content.charAt(j);			if (cc == '}') {				return j;			} else if (cc == '\'' || cc == '"') {				while (++j < to) {					final char c2 = ctx.content.charAt(j);					if (c2 == cc) break;					if (cc == '\n')						throw new ServletException("Illegal EL expression: non-terminaled "+cc+" at line "+ctx.nLines+" character "+j);					if (c2 == '\\' && ++j < to && ctx.content.charAt(j) == '\n')						++ctx.nLines;				}			} else if (cc == '\n') {				++ctx.nLines;			}		}	}	/** Adds a text node. */	private static void addText(Node parent, StringBuffer sb) {		if (sb.length() > 0) {			parent.addChild(new TextNode(sb.toString()));			sb.setLength(0);		}	}	/** Context used during parsing. */	private static class Context {		private final String content;		private final SimpleMapper mapper;		/** (String prefix, Map(String name, Class class)). */		private final Map _actions = new HashMap();		private final Locator locator;		private int nLines;		/** Whether the page action is defined. */		private boolean pageDefined;		private Context(String content, FunctionMapper fm, Locator loc) {			this.content = content;			this.mapper = new SimpleMapper(fm);			this.locator = loc;			this.nLines = 1;		}		private boolean hasPrefix(String prefix) {			return _actions.containsKey(prefix);		}		private Class getActionClass(String prefix, String actnm) {			final Map acts = (Map)_actions.get(prefix);			return acts != null ? (Class)acts.get(actnm): null;		}		private void loadTaglib(String prefix, String uri)		throws javax.servlet.ServletException, IOException {			if (D.ON && log.debugable()) log.debug("Loading "+prefix+" at "+uri);			if (this.locator == null)				throw new ServletException("Unable to load "+uri+" because locator is not specified");			final URL url = this.locator.getResource(uri);			if (url == null)				throw new FileNotFoundException(uri);			try {				loadTaglib0(prefix, url);			} catch (IOException ex) {				throw ex;			} catch (Exception ex) {				throw ServletException.Aide.wrap(ex);			}		}		private void loadTaglib0(String prefix, URL url)		throws Exception {			final Element root = new SAXBuilder(true, false, true)				.build(url).getRootElement();			mapper.load(prefix, root);			final Map acts = new HashMap();			for (Iterator it = root.getElements("tag").iterator();			it.hasNext();) {				final Element e = (Element)it.next();				final String name = IDOMs.getRequiredElementValue(e, "name");				final String clsName = IDOMs.getRequiredElementValue(e, "tag-class");				final Class cls = Classes.forNameByThread(clsName);				if (!Action.class.isAssignableFrom(cls))					throw new ServletException(cls+" doesn't implement "+Action.class);				acts.put(name, cls);//				if (D.ON && log.finerable()) log.finer("Action "+prefix+":"+name+" are added");			}			if (!acts.isEmpty())				_actions.put(prefix, acts);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -