rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
public ClassCastException(String s)
public ClassCastException()
public ClassCastException(String s) { super(s); }
super(s);
public ClassCastException(String s) { super(s); }
public NoClassDefFoundError(String s) { super(s);
public NoClassDefFoundError() {
public NoClassDefFoundError(String s) { super(s); }
public final VmField getField(VmConstFieldRef fieldRef) { return getField(fieldRef.getName(), fieldRef.getSignature());
public final VmField getField(String name, String signature) { VmField f = getDeclaredField(name, signature); if (f != null) { return f; } if (superClass != null) { f = superClass.getField(name, signature); if (f != null) { return f; } } final int cnt = getNoInterfaces(); for (int i = 0; i < cnt; i++) { f = allInterfaceTable[i].getField(name, signature); if (f != null) { return f; } } return null;
public final VmField getField(VmConstFieldRef fieldRef) { return getField(fieldRef.getName(), fieldRef.getSignature()); }
public ArithmeticException(String s) { super(s);
public ArithmeticException() {
public ArithmeticException(String s) { super(s); }
CopyOfNode(TemplateNode children, TemplateNode next, Expr select)
CopyOfNode(Expr select)
CopyOfNode(TemplateNode children, TemplateNode next, Expr select) { super(children, next); this.select = select; }
super(children, next);
CopyOfNode(TemplateNode children, TemplateNode next, Expr select) { super(children, next); this.select = select; }
return new CopyOfNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet), select.clone(stylesheet));
TemplateNode ret = new CopyOfNode(select.clone(stylesheet)); if (children != null) { ret.children = children.clone(stylesheet); } if (next != null) { ret.next = next.clone(stylesheet); } return ret;
TemplateNode clone(Stylesheet stylesheet) { return new CopyOfNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet), select.clone(stylesheet)); }
public abstract Object evaluate(Node context, int pos, int len);
public Object evaluate(Object item, QName returnType) throws XPathExpressionException { Object ret = null; Node context = null; if (item instanceof Node) { context = (Node) item; ret = evaluate(context, 1, 1); if (XPathConstants.STRING == returnType && !(ret instanceof String)) { ret = _string(context, ret); } else if (XPathConstants.NUMBER == returnType && !(ret instanceof Double)) { ret = new Double(_number(context, ret)); } else if (XPathConstants.BOOLEAN == returnType && !(ret instanceof Boolean)) { ret = _boolean(context, ret) ? Boolean.TRUE : Boolean.FALSE; } else if (XPathConstants.NODE == returnType) { if (ret instanceof Collection) { Collection ns = (Collection) ret; switch (ns.size()) { case 0: ret = null; break; case 1: ret = (Node) ns.iterator().next(); break; default: throw new XPathExpressionException("multiple nodes in node-set"); } } else if (ret != null) { throw new XPathExpressionException("return value is not a node-set"); } } else if (XPathConstants.NODESET == returnType) { if (ret != null && !(ret instanceof Collection)) { throw new XPathExpressionException("return value is not a node-set"); } } } return ret; }
public abstract Object evaluate(Node context, int pos, int len);
public static <T> void sort(List<T> l, Comparator<? super T> c)
public static <T extends Comparable<? super T>> void sort(List<T> l)
public static <T> void sort(List<T> l, Comparator<? super T> c) { T[] a = (T[]) l.toArray(); Arrays.sort(a, c); ListIterator<T> i = l.listIterator(); for (int pos = 0, alen = a.length; pos < alen; pos++) { i.next(); i.set(a[pos]); } }
T[] a = (T[]) l.toArray(); Arrays.sort(a, c); ListIterator<T> i = l.listIterator(); for (int pos = 0, alen = a.length; pos < alen; pos++) { i.next(); i.set(a[pos]); }
sort(l, null);
public static <T> void sort(List<T> l, Comparator<? super T> c) { T[] a = (T[]) l.toArray(); Arrays.sort(a, c); ListIterator<T> i = l.listIterator(); for (int pos = 0, alen = a.length; pos < alen; pos++) { i.next(); i.set(a[pos]); } }
public static String getEncodingOfClass(Class clazz)
public static String getEncodingOfClass(String type, boolean descriptor)
public static String getEncodingOfClass(Class clazz) { return getEncodingOfClass(clazz.getName(), true); }
return getEncodingOfClass(clazz.getName(), true);
if (! descriptor || type.charAt(0) == '[') return type.replace('.', '/'); if (type.equals("boolean")) return "Z"; if (type.equals("byte")) return "B"; if (type.equals("short")) return "S"; if (type.equals("char")) return "C"; if (type.equals("int")) return "I"; if (type.equals("long")) return "J"; if (type.equals("float")) return "F"; if (type.equals("double")) return "D"; if (type.equals("void")) return "V"; return 'L' + type.replace('.', '/') + ';';
public static String getEncodingOfClass(Class clazz) { return getEncodingOfClass(clazz.getName(), true); }
Provider p[] = Security.getProviders();
Provider[] p = Security.getProviders();
public SecureRandom() { Provider p[] = Security.getProviders(); //Format of Key: SecureRandom.algname String key; String classname = null; int i; Enumeration e; for (i = 0; i < p.length; i++) { e = p[i].propertyNames(); while (e.hasMoreElements()) { key = (String) e.nextElement(); if (key.startsWith("SECURERANDOM.")) { if ((classname = p[i].getProperty(key)) != null) { try { secureRandomSpi = (SecureRandomSpi) Class. forName(classname).newInstance(); provider = p[i]; return; } catch (Throwable ignore) { } } } } } // Nothing found. Fall back to SHA1PRNG secureRandomSpi = new gnu.java.security.provider.SHA1PRNG(); }
catch (Throwable ignore) { }
catch (Throwable t) { }
public SecureRandom() { Provider p[] = Security.getProviders(); //Format of Key: SecureRandom.algname String key; String classname = null; int i; Enumeration e; for (i = 0; i < p.length; i++) { e = p[i].propertyNames(); while (e.hasMoreElements()) { key = (String) e.nextElement(); if (key.startsWith("SECURERANDOM.")) { if ((classname = p[i].getProperty(key)) != null) { try { secureRandomSpi = (SecureRandomSpi) Class. forName(classname).newInstance(); provider = p[i]; return; } catch (Throwable ignore) { } } } } } // Nothing found. Fall back to SHA1PRNG secureRandomSpi = new gnu.java.security.provider.SHA1PRNG(); }
Provider p[] = Security.getProviders();
Provider[] p = Security.getProviders();
public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException { Provider p[] = Security.getProviders(); for (int i = 0; i < p.length; i++) { try { return getInstance(algorithm, p[i]); } catch (NoSuchAlgorithmException ignored) { } } // None found. throw new NoSuchAlgorithmException(algorithm); }
catch (NoSuchAlgorithmException ignored)
catch (NoSuchAlgorithmException e)
public static SecureRandom getInstance(String algorithm) throws NoSuchAlgorithmException { Provider p[] = Security.getProviders(); for (int i = 0; i < p.length; i++) { try { return getInstance(algorithm, p[i]); } catch (NoSuchAlgorithmException ignored) { } } // None found. throw new NoSuchAlgorithmException(algorithm); }
byte tmp[] = new byte[numBytes];
byte[] tmp = new byte[numBytes];
public static byte[] getSeed(int numBytes) { byte tmp[] = new byte[numBytes]; new Random().nextBytes(tmp); return tmp; //return secureRandomSpi.engineGenerateSeed( numBytes ); }
byte tmp[] = new byte[numBits / 8 + (1 * (numBits % 8))];
byte[] tmp = new byte[numBits / 8 + (1 * (numBits % 8))];
protected final int next(int numBits) { if (numBits == 0) return 0; byte tmp[] = new byte[numBits / 8 + (1 * (numBits % 8))]; secureRandomSpi.engineNextBytes(tmp); randomBytesUsed += tmp.length; counter++; int ret = 0; for (int i = 0; i < tmp.length; i++) ret |= (tmp[i] & 0xFF) << (8 * i); long mask = (1L << numBits) - 1; return (int) (ret & mask); }
public void dropComplete (boolean success)
public void dropComplete(boolean success) throws NotImplementedException
public void dropComplete (boolean success) { // FIXME: implement this }
public void add(Permission permission) { if (isReadOnly()) { throw new SecurityException("readonly"); } if (!(permission instanceof PropertyPermission)) { throw new IllegalArgumentException(); }
public void add(Permission permission) { if (isReadOnly()) throw new SecurityException("readonly"); if (! (permission instanceof PropertyPermission)) throw new IllegalArgumentException();
public void add(Permission permission) { if (isReadOnly()) { throw new SecurityException("readonly"); } if (!(permission instanceof PropertyPermission)) { throw new IllegalArgumentException(); } PropertyPermission pp = (PropertyPermission) permission; final String name = pp.getName(); if (name.equals("*")) { all_allowed = true; } final PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) { // Old implies pp. pp = old; } else if ((pp.actions | old.actions) != pp.actions) { // Here pp doesn't imply old; the only case left is both // actions. pp = new PropertyPermission(name, "read,write"); } } permissions.put(name, pp); }
final String name = pp.getName(); if (name.equals("*")) {
String name = pp.getName(); if (name.equals("*"))
public void add(Permission permission) { if (isReadOnly()) { throw new SecurityException("readonly"); } if (!(permission instanceof PropertyPermission)) { throw new IllegalArgumentException(); } PropertyPermission pp = (PropertyPermission) permission; final String name = pp.getName(); if (name.equals("*")) { all_allowed = true; } final PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) { // Old implies pp. pp = old; } else if ((pp.actions | old.actions) != pp.actions) { // Here pp doesn't imply old; the only case left is both // actions. pp = new PropertyPermission(name, "read,write"); } } permissions.put(name, pp); }
} final PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) { pp = old; } else if ((pp.actions | old.actions) != pp.actions) {
PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) pp = old; else if ((pp.actions | old.actions) != pp.actions)
public void add(Permission permission) { if (isReadOnly()) { throw new SecurityException("readonly"); } if (!(permission instanceof PropertyPermission)) { throw new IllegalArgumentException(); } PropertyPermission pp = (PropertyPermission) permission; final String name = pp.getName(); if (name.equals("*")) { all_allowed = true; } final PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) { // Old implies pp. pp = old; } else if ((pp.actions | old.actions) != pp.actions) { // Here pp doesn't imply old; the only case left is both // actions. pp = new PropertyPermission(name, "read,write"); } } permissions.put(name, pp); }
}
public void add(Permission permission) { if (isReadOnly()) { throw new SecurityException("readonly"); } if (!(permission instanceof PropertyPermission)) { throw new IllegalArgumentException(); } PropertyPermission pp = (PropertyPermission) permission; final String name = pp.getName(); if (name.equals("*")) { all_allowed = true; } final PropertyPermission old = (PropertyPermission) permissions.get(name); if (old != null) { if ((pp.actions | old.actions) == old.actions) { // Old implies pp. pp = old; } else if ((pp.actions | old.actions) != pp.actions) { // Here pp doesn't imply old; the only case left is both // actions. pp = new PropertyPermission(name, "read,write"); } } permissions.put(name, pp); }
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission;
public boolean implies(Permission permission) { if (! (permission instanceof PropertyPermission)) return false; PropertyPermission toImply = (PropertyPermission) permission;
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
if (actions == 0) { return true; }
if (actions == 0) return true;
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
if (name.equals("*")) { return false; }
if (name.equals("*")) return false;
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
if (name.endsWith("*")) {
if (name.endsWith("*"))
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
}
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
if (prefixLength < 0) { return false; }
if (prefixLength < 0) return false;
public boolean implies(Permission permission) { if (!(permission instanceof PropertyPermission)) { return false; } final PropertyPermission toImply = (PropertyPermission) permission; int actions = toImply.actions; if (all_allowed) { int all_actions = ((PropertyPermission) permissions.get("*")).actions; actions &= ~all_actions; if (actions == 0) { return true; } } String name = toImply.getName(); if (name.equals("*")) { return false; } int prefixLength = name.length(); if (name.endsWith("*")) { prefixLength -= 2; } while (true) { PropertyPermission forName = (PropertyPermission) permissions .get(name); if (forName != null) { actions &= ~forName.actions; if (actions == 0) { return true; } } prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) { return false; } name = name.substring(0, prefixLength + 1) + '*'; } }
setActions(actions.toLowerCase());
setActions(actions);
public PropertyPermission(String name, String actions) { super(name); if (actions == null) throw new IllegalArgumentException(); setActions(actions.toLowerCase()); }
private ScrollingButton createDecreaseButton()
ScrollingButton createDecreaseButton()
private ScrollingButton createDecreaseButton() { if (decrButton == null) decrButton = new ScrollingButton(SwingConstants.SOUTH); if (tabPane.getTabPlacement() == SwingConstants.TOP || tabPane.getTabPlacement() == SwingConstants.BOTTOM) decrButton.setDirection(SwingConstants.WEST); else decrButton.setDirection(SwingConstants.NORTH); return decrButton; }
private ScrollingButton createIncreaseButton()
ScrollingButton createIncreaseButton()
private ScrollingButton createIncreaseButton() { if (incrButton == null) incrButton = new ScrollingButton(SwingConstants.NORTH); if (tabPane.getTabPlacement() == SwingConstants.TOP || tabPane.getTabPlacement() == SwingConstants.BOTTOM) incrButton.setDirection(SwingConstants.EAST); else incrButton.setDirection(SwingConstants.SOUTH); return incrButton; }
private Point findPointForIndex(int index)
Point findPointForIndex(int index)
private Point findPointForIndex(int index) { int tabPlacement = tabPane.getTabPlacement(); int selectedIndex = tabPane.getSelectedIndex(); Insets insets = getSelectedTabPadInsets(tabPlacement); int w = 0; int h = 0; if (tabPlacement == TOP || tabPlacement == BOTTOM) { if (index > 0) { w += rects[index - 1].x + rects[index - 1].width; if (index > selectedIndex) w -= insets.left + insets.right; } } else { if (index > 0) { h += rects[index - 1].y + rects[index - 1].height; if (index > selectedIndex) h -= insets.top + insets.bottom; } } Point p = new Point(w, h); return p; }
public void setEnabled(boolean b) { super.setEnabled(b); getModel().setEnabled(b); repaint(); }
public void setEnabled(boolean b) { super.setEnabled(b); getModel().setEnabled(b); }
public void setEnabled(boolean b) { super.setEnabled(b); getModel().setEnabled(b); repaint(); }
currentPeer.setVisible(true);
currentPeer.show();
public void show() { // We must set visible before showing the peer. Otherwise the // peer could post paint events before visible is true, in which // case lightweight components are not initially painted -- // Container.paint first calls isShowing () before painting itself // and its children. if(!isVisible()) { this.visible = true; // Avoid NullPointerExceptions by creating a local reference. ComponentPeer currentPeer=peer; if (currentPeer != null) currentPeer.setVisible(true); // The JDK repaints the component before invalidating the parent. // So do we. if (isShowing()) repaint(); // Invalidate the parent if we have one. The component itself must // not be invalidated. We also avoid NullPointerException with // a local reference here. Container currentParent = parent; if (currentParent != null) currentParent.invalidate(); ComponentEvent ce = new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN); getToolkit().getSystemEventQueue().postEvent(ce); } }
public int getInt(Object key)
int getInt(Object key)
public int getInt(Object key) { Object o = get(key); return o instanceof Integer ? ((Integer) o).intValue() : 0; }
static public String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon i, int vert_a, int hor_i, int vert_text_pos, int hor_text_pos, Rectangle vr, Rectangle ir, Rectangle tr, int gap) { int next_x = 0; int next_y = 0; ir.height = ir.width = ir.y = ir.x = 0;
public static String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) {
static public String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon i, int vert_a, int hor_i, int vert_text_pos, int hor_text_pos, Rectangle vr, Rectangle ir, Rectangle tr, int gap) { // view rect 'vr' already ok, // we need to compute ir (icon rect) and tr (text-rect) int next_x = 0;//vr.x; int next_y = 0;//vr.y; ir.height = ir.width = ir.y = ir.x = 0; if (i != null) { ir.x = vr.x; ir.y = vr.y; ir.width = i.getIconWidth(); ir.height = i.getIconWidth(); next_x += gap + i.getIconWidth(); next_y += gap + i.getIconHeight(); } tr.x = next_x; tr.y = vr.y + (vr.height/2); tr.width = fm.stringWidth(text); tr.height = fm.getHeight() + fm.getAscent()/2; return text; }
if (i != null) { ir.x = vr.x; ir.y = vr.y; ir.width = i.getIconWidth(); ir.height = i.getIconWidth();
static public String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon i, int vert_a, int hor_i, int vert_text_pos, int hor_text_pos, Rectangle vr, Rectangle ir, Rectangle tr, int gap) { // view rect 'vr' already ok, // we need to compute ir (icon rect) and tr (text-rect) int next_x = 0;//vr.x; int next_y = 0;//vr.y; ir.height = ir.width = ir.y = ir.x = 0; if (i != null) { ir.x = vr.x; ir.y = vr.y; ir.width = i.getIconWidth(); ir.height = i.getIconWidth(); next_x += gap + i.getIconWidth(); next_y += gap + i.getIconHeight(); } tr.x = next_x; tr.y = vr.y + (vr.height/2); tr.width = fm.stringWidth(text); tr.height = fm.getHeight() + fm.getAscent()/2; return text; }
next_x += gap + i.getIconWidth(); next_y += gap + i.getIconHeight(); } tr.x = next_x; tr.y = vr.y + (vr.height/2);
static public String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon i, int vert_a, int hor_i, int vert_text_pos, int hor_text_pos, Rectangle vr, Rectangle ir, Rectangle tr, int gap) { // view rect 'vr' already ok, // we need to compute ir (icon rect) and tr (text-rect) int next_x = 0;//vr.x; int next_y = 0;//vr.y; ir.height = ir.width = ir.y = ir.x = 0; if (i != null) { ir.x = vr.x; ir.y = vr.y; ir.width = i.getIconWidth(); ir.height = i.getIconWidth(); next_x += gap + i.getIconWidth(); next_y += gap + i.getIconHeight(); } tr.x = next_x; tr.y = vr.y + (vr.height/2); tr.width = fm.stringWidth(text); tr.height = fm.getHeight() + fm.getAscent()/2; return text; }
tr.width = fm.stringWidth(text); tr.height = fm.getHeight() + fm.getAscent()/2; return text; }
if (horizontalAlignment == LEADING) { if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) horizontalAlignment = RIGHT; else horizontalAlignment = LEFT; } else if (horizontalAlignment == TRAILING) { if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) horizontalAlignment = LEFT; else horizontalAlignment = RIGHT; } return layoutCompoundLabel(fm, text, icon, verticalAlignment, horizontalAlignment, verticalTextPosition, horizontalTextPosition, viewR, iconR, textR, textIconGap); }
static public String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon i, int vert_a, int hor_i, int vert_text_pos, int hor_text_pos, Rectangle vr, Rectangle ir, Rectangle tr, int gap) { // view rect 'vr' already ok, // we need to compute ir (icon rect) and tr (text-rect) int next_x = 0;//vr.x; int next_y = 0;//vr.y; ir.height = ir.width = ir.y = ir.x = 0; if (i != null) { ir.x = vr.x; ir.y = vr.y; ir.width = i.getIconWidth(); ir.height = i.getIconWidth(); next_x += gap + i.getIconWidth(); next_y += gap + i.getIconHeight(); } tr.x = next_x; tr.y = vr.y + (vr.height/2); tr.width = fm.stringWidth(text); tr.height = fm.getHeight() + fm.getAscent()/2; return text; }
else return defaultController.activate (this); } else
public boolean activateController() { if (controller == null) return false; return controller.activate(this); }
return controller;
return controller == null ? (no_controller ? null : defaultController) : controller;
public IIOParamController getController() { return controller; }
return sourceBands;
if (sourceBands == null) return null; int[] sourceBandsCopy = new int[sourceBands.length]; System.arraycopy (sourceBands, 0, sourceBandsCopy, 0, sourceBands.length); return sourceBandsCopy;
public int[] getSourceBands() { return sourceBands; }
}
public void setController(IIOParamController controller) { this.controller = controller; }
this.sourceBands = sourceBands;
int[] sourceBandsCopy = new int[sourceBands.length]; System.arraycopy (sourceBands, 0, sourceBandsCopy, 0, sourceBands.length); this.sourceBands = sourceBandsCopy;
public void setSourceBands(int[] sourceBands) { this.sourceBands = sourceBands; }
if (sourceRegion != null) { int num_rows = (sourceRegion.height - subsamplingYOffset + sourceYSubsampling - 1) / sourceYSubsampling; int num_columns = (sourceRegion.width - subsamplingXOffset + sourceXSubsampling - 1) / sourceXSubsampling; if (num_rows <= 0 || num_columns <= 0) throw new IllegalStateException("zero pixels in source region"); }
public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion != null && (sourceRegion.x < 0 || sourceRegion.y < 0 || sourceRegion.width <= 0 || sourceRegion.height <= 0)) throw new IllegalArgumentException("illegal source region"); // FIXME: Throw IllegalStateException. this.sourceRegion = sourceRegion; }
if (subsamplingXOffset < 0 || subsamplingYOffset < 0) throw new IllegalArgumentException("subsampling offset < 0"); if (sourceRegion != null) { int num_rows = (sourceRegion.height - subsamplingYOffset + sourceYSubsampling - 1) / sourceYSubsampling; int num_columns = (sourceRegion.width - subsamplingXOffset + sourceXSubsampling - 1) / sourceXSubsampling; if (num_rows <= 0 || num_columns <= 0) throw new IllegalStateException("subsampling parameters would" + " produce zero pixel samples" + " in source region"); }
public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling, int subsamplingXOffset, int subsamplingYOffset) { this.sourceXSubsampling = sourceXSubsampling; this.sourceYSubsampling = sourceYSubsampling; this.subsamplingXOffset = subsamplingXOffset; this.subsamplingYOffset = subsamplingYOffset; }
public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); System.out.println("JFrame.getPrefSize(): " + d + " , comp=" + countComponents() + ", layout=" + getLayout()); return d; }
public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); System.out.println("JFrame.getPrefSize(): " + d + " , comp="+ getComponentCount () + ", layout=" + getLayout()); return d; }
public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); System.out.println("JFrame.getPrefSize(): " + d + " , comp=" + countComponents() + ", layout=" + getLayout()); return d; }
JRootPane() { setLayout(createRootLayout());
JRootPane() { setLayout(createRootLayout()); setBackground(UIManager.getColor("control")); getGlassPane(); getLayeredPane(); getContentPane();
JRootPane() { setLayout(createRootLayout()); getGlassPane(); getLayeredPane(); getContentPane(); setDoubleBuffered(true); updateUI(); }
getGlassPane(); getLayeredPane(); getContentPane(); setDoubleBuffered(true); updateUI(); }
setDoubleBuffered(true); updateUI(); }
JRootPane() { setLayout(createRootLayout()); getGlassPane(); getLayeredPane(); getContentPane(); setDoubleBuffered(true); updateUI(); }
public void setContentPane(Container p) { contentPane = p; getLayeredPane().add(contentPane, 0); }
public void setContentPane(Container p) { contentPane = p; getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER); }
public void setContentPane(Container p) { contentPane = p; getLayeredPane().add(contentPane, 0); }
if (p != null && !(p instanceof LightweightPeer))
if (p != null && ! (p instanceof LightweightPeer)) {
public void update(Graphics g) { // It seems that the JDK clears the background of containers like Panel // and Window (within this method) but not of 'plain' Containers or // JComponents. This could // lead to the assumption that it only clears heavyweight containers. // However that is not quite true. In a test with a custom Container // that overrides isLightweight() to return false, the background is // also not cleared. So we do a check on !(peer instanceof LightweightPeer) // instead. ComponentPeer p = peer; if (p != null && !(p instanceof LightweightPeer)) g.clearRect(0, 0, getWidth(), getHeight()); paint(g); }
backCleared = true; }
public void update(Graphics g) { // It seems that the JDK clears the background of containers like Panel // and Window (within this method) but not of 'plain' Containers or // JComponents. This could // lead to the assumption that it only clears heavyweight containers. // However that is not quite true. In a test with a custom Container // that overrides isLightweight() to return false, the background is // also not cleared. So we do a check on !(peer instanceof LightweightPeer) // instead. ComponentPeer p = peer; if (p != null && !(p instanceof LightweightPeer)) g.clearRect(0, 0, getWidth(), getHeight()); paint(g); }
visitChildren(g, GfxPaintVisitor.INSTANCE, false);
visitChildren(g, GfxPaintVisitor.INSTANCE, !backCleared); backCleared = false;
public void paint(Graphics g) { if (!isShowing()) return; // Visit heavyweights as well, in case they were // erased when we cleared the background for this container. visitChildren(g, GfxPaintVisitor.INSTANCE, false); }
if (type == null) { resolve(); }
public VmType<?> getType() { return type; }
if (authority.length() != 0) { sb.append(" }
if (authority.length() != 0 || file.startsWith(" sb.append(" else
protected String toExternalForm(URL url) { String protocol; String file; String ref; String authority; protocol = url.getProtocol(); authority = url.getAuthority(); if (authority == null) authority = ""; file = url.getFile(); ref = url.getRef(); // Guess a reasonable size for the string buffer so we have to resize // at most once. int size = protocol.length() + authority.length() + file.length() + 24; StringBuffer sb = new StringBuffer(size); if (protocol.length() > 0) { sb.append(protocol); sb.append(":"); } if (authority.length() != 0) { sb.append("//").append(authority); } sb.append(file); if (ref != null) sb.append('#').append(ref); return sb.toString(); }
final static void checkArraySize(int arraylength, int offset, int length)
static final void checkArraySize(int arraylength, int offset, int length)
final static void checkArraySize(int arraylength, int offset, int length) { if ((offset < 0) || (length < 0) || (arraylength < length + offset)) throw new IndexOutOfBoundsException (); }
public static boolean equals(byte[] a1, byte[] a2)
public static boolean equals(boolean[] a1, boolean[] a2)
public static boolean equals(byte[] a1, byte[] a2) { // Quick test which saves comparing elements of the same array, and also // catches the case that both are null. if (a1 == a2) return true; if (null == a1 || null == a2) return false; // If they're the same length, test each element if (a1.length == a2.length) { int i = a1.length; while (--i >= 0) if (a1[i] != a2[i]) return false; return true; } return false; }
public void update (byte[] buffer)
public void update (int bval)
public void update (byte[] buffer) { update(buffer, 0, buffer.length); }
update(buffer, 0, buffer.length);
int s1 = checksum & 0xffff; int s2 = checksum >>> 16; s1 = (s1 + (bval & 0xFF)) % BASE; s2 = (s1 + s2) % BASE; checksum = (s2 << 16) + s1;
public void update (byte[] buffer) { update(buffer, 0, buffer.length); }
boolean add(E o);
void add(int index, E o);
boolean add(E o);
{
public static QName valueOf(String qNameAsString) { String namespaceUri = "", prefix = null; int start = qNameAsString.indexOf('{'); int end = qNameAsString.indexOf('}'); if (start != -1) { if (end < start) { throw new IllegalArgumentException(qNameAsString); } namespaceUri = qNameAsString.substring(start + 1, end); qNameAsString = qNameAsString.substring(end + 1); } start = qNameAsString.indexOf(':'); if (start != -1) { prefix = qNameAsString.substring(0, start); qNameAsString = qNameAsString.substring(start + 1); } return new QName(namespaceUri, qNameAsString, prefix); }
}
public static QName valueOf(String qNameAsString) { String namespaceUri = "", prefix = null; int start = qNameAsString.indexOf('{'); int end = qNameAsString.indexOf('}'); if (start != -1) { if (end < start) { throw new IllegalArgumentException(qNameAsString); } namespaceUri = qNameAsString.substring(start + 1, end); qNameAsString = qNameAsString.substring(end + 1); } start = qNameAsString.indexOf(':'); if (start != -1) { prefix = qNameAsString.substring(0, start); qNameAsString = qNameAsString.substring(start + 1); } return new QName(namespaceUri, qNameAsString, prefix); }
protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType)
public ColorModel(int bits)
protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType) { int bits_sum = 0; for (int i = 0; i < bits.length; i++) { if (bits [i] < 0) throw new IllegalArgumentException (); bits_sum |= bits [i]; } if ((bits.length < cspace.getNumComponents()) || (bits_sum < 1)) throw new IllegalArgumentException (); this.pixel_bits = pixel_bits; this.bits = bits; this.cspace = cspace; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; this.transferType = transferType; }
int bits_sum = 0; for (int i = 0; i < bits.length; i++) { if (bits [i] < 0) throw new IllegalArgumentException (); bits_sum |= bits [i]; } if ((bits.length < cspace.getNumComponents()) || (bits_sum < 1)) throw new IllegalArgumentException (); this.pixel_bits = pixel_bits; this.bits = bits; this.cspace = cspace; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; this.transferType = transferType;
this(bits, nArray(bits / 4, 4), ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false, TRANSLUCENT, Buffers.smallestAppropriateTransferType(bits * 4));
protected ColorModel(int pixel_bits, int[] bits, ColorSpace cspace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType) { int bits_sum = 0; for (int i = 0; i < bits.length; i++) { if (bits [i] < 0) throw new IllegalArgumentException (); bits_sum |= bits [i]; } if ((bits.length < cspace.getNumComponents()) || (bits_sum < 1)) throw new IllegalArgumentException (); this.pixel_bits = pixel_bits; this.bits = bits; this.cspace = cspace; this.hasAlpha = hasAlpha; this.isAlphaPremultiplied = isAlphaPremultiplied; this.transparency = transparency; this.transferType = transferType; }
DataBuffer db,
public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location) { return new WritableRaster(sm, db, location); }
return new WritableRaster(sm, db, location);
return new WritableRaster(sm, location);
public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location) { return new WritableRaster(sm, db, location); }
public Object yyparse (yyInput yyLex)
public Object yyparse (yyInput yyLex, Object yydebug)
public Object yyparse (yyInput yyLex) throws java.io.IOException, yyException { if (yyMax <= 0) yyMax = 256; // initial size int yyState = 0, yyStates[] = new int[yyMax]; // state stack Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack int yyToken = -1; // current input int yyErrorFlag = 0; // #tks to shift yyLoop: for (int yyTop = 0;; ++ yyTop) { if (yyTop >= yyStates.length) { // dynamically increase int[] i = new int[yyStates.length+yyMax]; System.arraycopy(yyStates, 0, i, 0, yyStates.length); yyStates = i; Object[] o = new Object[yyVals.length+yyMax]; System.arraycopy(yyVals, 0, o, 0, yyVals.length); yyVals = o; } yyStates[yyTop] = yyState; yyVals[yyTop] = yyVal;//t if (yydebug != null) yydebug.push(yyState, yyVal); yyDiscarded: for (;;) { // discarding a token does not change stack int yyN; if ((yyN = YyDefRedClass.yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0;//t if (yydebug != null)//t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value()); } if ((yyN = YySindexClass.yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) {//t if (yydebug != null)//t yydebug.shift(yyState, YyTableClass.yyTable[yyN], yyErrorFlag-1); yyState = YyTableClass.yyTable[yyN]; // shift to yyN yyVal = yyLex.value(); yyToken = -1; if (yyErrorFlag > 0) -- yyErrorFlag; continue yyLoop; } if ((yyN = YyRindexClass.yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) yyN = YyTableClass.yyTable[yyN]; // reduce (yyN) else switch (yyErrorFlag) { case 0: yyerror("syntax error", yyExpecting(yyState));//t if (yydebug != null) yydebug.error("syntax error"); case 1: case 2: yyErrorFlag = 3; do { if ((yyN = YySindexClass.yySindex[yyStates[yyTop]]) != 0 && (yyN += yyErrorCode) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyErrorCode) {//t if (yydebug != null)//t yydebug.shift(yyStates[yyTop], YyTableClass.yyTable[yyN], 3); yyState = YyTableClass.yyTable[yyN]; yyVal = yyLex.value(); continue yyLoop; }//t if (yydebug != null) yydebug.pop(yyStates[yyTop]); } while (-- yyTop >= 0);//t if (yydebug != null) yydebug.reject(); throw new yyException("irrecoverable syntax error"); case 3: if (yyToken == 0) {//t if (yydebug != null) yydebug.reject(); throw new yyException("irrecoverable syntax error at end-of-file"); }//t if (yydebug != null)//t yydebug.discard(yyState, yyToken, yyname(yyToken),//t yyLex.value()); yyToken = -1; continue yyDiscarded; // leave stack alone } } int yyV = yyTop + 1-YyLenClass.yyLen[yyN];//t if (yydebug != null)//t yydebug.reduce(yyState, yyStates[yyV-1], yyN, YyRuleClass.yyRule[yyN], YyLenClass.yyLen[yyN]); yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) {case 4: // line 276 "XPathParser.y" { yyVal = new Root(); } break;case 5: // line 280 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(new Root()); yyVal = steps; /*$$ = new Step(new Root(), (Path) $2);*/ } break;case 6: // line 296 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(new Root()); yyVal = steps; /*Step step = new Step(s, (Path) $2);*/ /*$$ = new Step(new Root(), step);*/ } break;case 8: // line 321 "XPathParser.y" { Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; /*$$ = new Step((Expr) $1, (Path) $3);*/ } break;case 9: // line 337 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(s); steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; /*Step step = new Step(s, (Path) $3);*/ /*$$ = new Step((Expr) $1, step);*/ } break;case 10: // line 361 "XPathParser.y" { yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); } break;case 11: // line 365 "XPathParser.y" { yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); } break;case 12: // line 369 "XPathParser.y" { yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); } break;case 13: // line 373 "XPathParser.y" { yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST); } break;case 14: // line 377 "XPathParser.y" { yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST); } break;case 15: // line 384 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break;case 16: // line 390 "XPathParser.y" { List list = (List)yyVals[-1+yyTop]; list.add(yyVals[0+yyTop]); yyVal = list; } break;case 17: // line 414 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR); } break;case 18: // line 418 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR_OR_SELF); } break;case 19: // line 422 "XPathParser.y" { yyVal = new Integer(Selector.ATTRIBUTE); } break;case 20: // line 426 "XPathParser.y" { yyVal = new Integer(Selector.CHILD); } break;case 21: // line 430 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT); } break;case 22: // line 434 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT_OR_SELF); } break;case 23: // line 438 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING); } break;case 24: // line 442 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING_SIBLING); } break;case 25: // line 446 "XPathParser.y" { yyVal = new Integer(Selector.NAMESPACE); } break;case 26: // line 450 "XPathParser.y" { yyVal = new Integer(Selector.PARENT); } break;case 27: // line 454 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING); } break;case 28: // line 458 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING_SIBLING); } break;case 29: // line 462 "XPathParser.y" { yyVal = new Integer(Selector.SELF); } break;case 31: // line 471 "XPathParser.y" { yyVal = new NodeTypeTest(Node.PROCESSING_INSTRUCTION_NODE, (String) yyVals[-1+yyTop]); } break;case 32: // line 476 "XPathParser.y" { yyVal = new NodeTypeTest(((Short) yyVals[-1+yyTop]).shortValue()); } break;case 33: // line 483 "XPathParser.y" { yyVal = new Predicate((Expr) yyVals[-1+yyTop]); } break;case 35: // line 491 "XPathParser.y" { yyVal = new ParenthesizedExpr((Expr) yyVals[-1+yyTop]); } break;case 36: // line 495 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break;case 37: // line 499 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break;case 39: // line 507 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST); } break;case 40: // line 511 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); } break;case 41: // line 518 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break;case 42: // line 524 "XPathParser.y" { List list = (List) yyVals[0+yyTop]; list.add(0, yyVals[-2+yyTop]); yyVal = list; } break;case 44: // line 534 "XPathParser.y" { yyVal = new UnionExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 47: // line 543 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; /*$$ = new Step ((Expr) $1, (Path) $3);*/ } break;case 48: // line 559 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList(nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; /*Step step = new Step (s, (Path) $3);*/ /*$$ = new Step ((Expr) $1, step);*/ } break;case 50: // line 584 "XPathParser.y" { Predicate filter = (Predicate) yyVals[0+yyTop]; Selector s = new Selector(Selector.SELF, Collections.singletonList(filter)); Steps steps; if (yyVals[-1+yyTop] instanceof Steps) { steps = (Steps) yyVals[-1+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-1+yyTop]); } steps.path.addLast(s); yyVal = steps; /*$$ = new Step ((Expr) $1, s);*/ } break;case 52: // line 607 "XPathParser.y" { yyVal = new OrExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 54: // line 615 "XPathParser.y" { yyVal = new AndExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 56: // line 623 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false); } break;case 57: // line 627 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true); } break;case 59: // line 635 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, false); } break;case 60: // line 639 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, false); } break;case 61: // line 643 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, true); } break;case 62: // line 647 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, true); } break;case 64: // line 655 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.ADD); } break;case 65: // line 659 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.SUBTRACT); } break;case 67: // line 667 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MULTIPLY); } break;case 68: // line 671 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.DIVIDE); } break;case 69: // line 675 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MODULO); } break;case 71: // line 683 "XPathParser.y" { yyVal = new NegativeExpr((Expr) yyVals[0+yyTop]); } break;case 72: // line 690 "XPathParser.y" { yyVal = new Double((String) yyVals[0+yyTop] + ".0"); } break;case 73: // line 694 "XPathParser.y" { yyVal = new Double((String) yyVals[-1+yyTop] + ".0"); } break;case 74: // line 698 "XPathParser.y" { yyVal = new Double((String) yyVals[-2+yyTop] + "." + (String) yyVals[0+yyTop]); } break;case 75: // line 702 "XPathParser.y" { yyVal = new Double("0." + (String) yyVals[0+yyTop]); } break;case 77: // line 731 "XPathParser.y" { yyVal = new VariableReference(variableResolver, (String) yyVals[0+yyTop]); } break;case 78: // line 738 "XPathParser.y" { yyVal = new NameTest(null, true, true); } break;case 79: // line 742 "XPathParser.y" { QName qName = getQName((String) yyVals[-2+yyTop]); yyVal = new NameTest(qName, true, false); } break;case 80: // line 747 "XPathParser.y" { QName qName = getQName((String) yyVals[0+yyTop]); yyVal = new NameTest(qName, false, false); } break;case 82: // line 756 "XPathParser.y" { yyVal = (String) yyVals[-2+yyTop] + ':' + (String) yyVals[0+yyTop]; } break;case 83: // line 763 "XPathParser.y" { yyVal = new Short(Node.COMMENT_NODE); } break;case 84: // line 767 "XPathParser.y" { yyVal = new Short(Node.TEXT_NODE); } break;case 85: // line 771 "XPathParser.y" { yyVal = new Short(Node.PROCESSING_INSTRUCTION_NODE); } break;case 86: // line 775 "XPathParser.y" { yyVal = new Short((short) 0); } break; // line 986 "-" } yyTop -= YyLenClass.yyLen[yyN]; yyState = yyStates[yyTop]; int yyM = YyLhsClass.yyLhs[yyN]; if (yyState == 0 && yyM == 0) {//t if (yydebug != null) yydebug.shift(0, yyFinal); yyState = yyFinal; if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0;//t if (yydebug != null)//t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value()); } if (yyToken == 0) {//t if (yydebug != null) yydebug.accept(yyVal); return yyVal; } continue yyLoop; } if ((yyN = YyGindexClass.yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyState) yyState = YyTableClass.yyTable[yyN]; else yyState = YyDgotoClass.yyDgoto[yyM];//t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState); continue yyLoop; } } }
if (yyMax <= 0) yyMax = 256; int yyState = 0, yyStates[] = new int[yyMax]; Object yyVal = null, yyVals[] = new Object[yyMax]; int yyToken = -1; int yyErrorFlag = 0; yyLoop: for (int yyTop = 0;; ++ yyTop) { if (yyTop >= yyStates.length) { int[] i = new int[yyStates.length+yyMax]; System.arraycopy(yyStates, 0, i, 0, yyStates.length); yyStates = i; Object[] o = new Object[yyVals.length+yyMax]; System.arraycopy(yyVals, 0, o, 0, yyVals.length); yyVals = o; } yyStates[yyTop] = yyState; yyVals[yyTop] = yyVal; yyDiscarded: for (;;) { int yyN; if ((yyN = YyDefRedClass.yyDefRed[yyState]) == 0) { if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; } if ((yyN = YySindexClass.yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) { yyState = YyTableClass.yyTable[yyN]; yyVal = yyLex.value(); yyToken = -1; if (yyErrorFlag > 0) -- yyErrorFlag; continue yyLoop; } if ((yyN = YyRindexClass.yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) yyN = YyTableClass.yyTable[yyN]; else switch (yyErrorFlag) { case 0: yyerror("syntax error", yyExpecting(yyState)); case 1: case 2: yyErrorFlag = 3; do { if ((yyN = YySindexClass.yySindex[yyStates[yyTop]]) != 0 && (yyN += yyErrorCode) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyErrorCode) { yyState = YyTableClass.yyTable[yyN]; yyVal = yyLex.value(); continue yyLoop; } } while (-- yyTop >= 0); throw new yyException("irrecoverable syntax error"); case 3: if (yyToken == 0) { throw new yyException("irrecoverable syntax error at end-of-file"); } yyToken = -1; continue yyDiscarded; } } int yyV = yyTop + 1-YyLenClass.yyLen[yyN]; yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) { case 4: { yyVal = new Root(); } break; case 5: { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(new Root()); yyVal = steps; } break; case 6: { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(new Root()); yyVal = steps; } break; case 8: { Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; } break; case 9: { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(s); steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; } break; case 10: { yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); } break; case 11: { yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); } break; case 12: { yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); } break; case 13: { yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST); } break; case 14: { yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST); } break; case 15: { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break; case 16: { List list = (List)yyVals[-1+yyTop]; list.add(yyVals[0+yyTop]); yyVal = list; } break; case 17: { yyVal = new Integer(Selector.ANCESTOR); } break; case 18: { yyVal = new Integer(Selector.ANCESTOR_OR_SELF); } break; case 19: { yyVal = new Integer(Selector.ATTRIBUTE); } break; case 20: { yyVal = new Integer(Selector.CHILD); } break; case 21: { yyVal = new Integer(Selector.DESCENDANT); } break; case 22: { yyVal = new Integer(Selector.DESCENDANT_OR_SELF); } break; case 23: { yyVal = new Integer(Selector.FOLLOWING); } break; case 24: { yyVal = new Integer(Selector.FOLLOWING_SIBLING); } break; case 25: { yyVal = new Integer(Selector.NAMESPACE); } break; case 26: { yyVal = new Integer(Selector.PARENT); } break; case 27: { yyVal = new Integer(Selector.PRECEDING); } break; case 28: { yyVal = new Integer(Selector.PRECEDING_SIBLING); } break; case 29: { yyVal = new Integer(Selector.SELF); } break; case 31: { yyVal = new NodeTypeTest(Node.PROCESSING_INSTRUCTION_NODE, (String) yyVals[-1+yyTop]); } break; case 32: { yyVal = new NodeTypeTest(((Short) yyVals[-1+yyTop]).shortValue()); } break; case 33: { yyVal = new Predicate((Expr) yyVals[-1+yyTop]); } break; case 35: { yyVal = new ParenthesizedExpr((Expr) yyVals[-1+yyTop]); } break; case 36: { yyVal = new Constant(yyVals[0+yyTop]); } break; case 37: { yyVal = new Constant(yyVals[0+yyTop]); } break; case 39: { yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST); } break; case 40: { yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); } break; case 41: { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break; case 42: { List list = (List) yyVals[0+yyTop]; list.add(0, yyVals[-2+yyTop]); yyVal = list; } break; case 44: { yyVal = new UnionExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 47: { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; } break; case 48: { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList(nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; } break; case 50: { Predicate filter = (Predicate) yyVals[0+yyTop]; Selector s = new Selector(Selector.SELF, Collections.singletonList(filter)); Steps steps; if (yyVals[-1+yyTop] instanceof Steps) { steps = (Steps) yyVals[-1+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-1+yyTop]); } steps.path.addLast(s); yyVal = steps; } break; case 52: { yyVal = new OrExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 54: { yyVal = new AndExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break; case 56: { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false); } break; case 57: { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true); } break; case 59: { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, false); } break; case 60: { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, false); } break; case 61: { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, true); } break; case 62: { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, true); } break; case 64: { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.ADD); } break; case 65: { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.SUBTRACT); } break; case 67: { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MULTIPLY); } break; case 68: { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.DIVIDE); } break; case 69: { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MODULO); } break; case 71: { yyVal = new NegativeExpr((Expr) yyVals[0+yyTop]); } break; case 72: { yyVal = new Double((String) yyVals[0+yyTop] + ".0"); } break; case 73: { yyVal = new Double((String) yyVals[-1+yyTop] + ".0"); } break; case 74: { yyVal = new Double((String) yyVals[-2+yyTop] + "." + (String) yyVals[0+yyTop]); } break; case 75: { yyVal = new Double("0." + (String) yyVals[0+yyTop]); } break; case 77: { yyVal = new VariableReference(variableResolver, (String) yyVals[0+yyTop]); } break; case 78: { yyVal = new NameTest(null, true, true); } break; case 79: { QName qName = getQName((String) yyVals[-2+yyTop]); yyVal = new NameTest(qName, true, false); } break; case 80: { QName qName = getQName((String) yyVals[0+yyTop]); yyVal = new NameTest(qName, false, false); } break; case 82: { yyVal = (String) yyVals[-2+yyTop] + ':' + (String) yyVals[0+yyTop]; } break; case 83: { yyVal = new Short(Node.COMMENT_NODE); } break; case 84: { yyVal = new Short(Node.TEXT_NODE); } break; case 85: { yyVal = new Short(Node.PROCESSING_INSTRUCTION_NODE); } break; case 86: { yyVal = new Short((short) 0); } break; } yyTop -= YyLenClass.yyLen[yyN]; yyState = yyStates[yyTop]; int yyM = YyLhsClass.yyLhs[yyN]; if (yyState == 0 && yyM == 0) { yyState = yyFinal; if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; } if (yyToken == 0) { return yyVal; } continue yyLoop; } if ((yyN = YyGindexClass.yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyState) yyState = YyTableClass.yyTable[yyN]; else yyState = YyDgotoClass.yyDgoto[yyM]; continue yyLoop; } }
return yyparse(yyLex);
public Object yyparse (yyInput yyLex) throws java.io.IOException, yyException { if (yyMax <= 0) yyMax = 256; // initial size int yyState = 0, yyStates[] = new int[yyMax]; // state stack Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack int yyToken = -1; // current input int yyErrorFlag = 0; // #tks to shift yyLoop: for (int yyTop = 0;; ++ yyTop) { if (yyTop >= yyStates.length) { // dynamically increase int[] i = new int[yyStates.length+yyMax]; System.arraycopy(yyStates, 0, i, 0, yyStates.length); yyStates = i; Object[] o = new Object[yyVals.length+yyMax]; System.arraycopy(yyVals, 0, o, 0, yyVals.length); yyVals = o; } yyStates[yyTop] = yyState; yyVals[yyTop] = yyVal;//t if (yydebug != null) yydebug.push(yyState, yyVal); yyDiscarded: for (;;) { // discarding a token does not change stack int yyN; if ((yyN = YyDefRedClass.yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0;//t if (yydebug != null)//t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value()); } if ((yyN = YySindexClass.yySindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) {//t if (yydebug != null)//t yydebug.shift(yyState, YyTableClass.yyTable[yyN], yyErrorFlag-1); yyState = YyTableClass.yyTable[yyN]; // shift to yyN yyVal = yyLex.value(); yyToken = -1; if (yyErrorFlag > 0) -- yyErrorFlag; continue yyLoop; } if ((yyN = YyRindexClass.yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyToken) yyN = YyTableClass.yyTable[yyN]; // reduce (yyN) else switch (yyErrorFlag) { case 0: yyerror("syntax error", yyExpecting(yyState));//t if (yydebug != null) yydebug.error("syntax error"); case 1: case 2: yyErrorFlag = 3; do { if ((yyN = YySindexClass.yySindex[yyStates[yyTop]]) != 0 && (yyN += yyErrorCode) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyErrorCode) {//t if (yydebug != null)//t yydebug.shift(yyStates[yyTop], YyTableClass.yyTable[yyN], 3); yyState = YyTableClass.yyTable[yyN]; yyVal = yyLex.value(); continue yyLoop; }//t if (yydebug != null) yydebug.pop(yyStates[yyTop]); } while (-- yyTop >= 0);//t if (yydebug != null) yydebug.reject(); throw new yyException("irrecoverable syntax error"); case 3: if (yyToken == 0) {//t if (yydebug != null) yydebug.reject(); throw new yyException("irrecoverable syntax error at end-of-file"); }//t if (yydebug != null)//t yydebug.discard(yyState, yyToken, yyname(yyToken),//t yyLex.value()); yyToken = -1; continue yyDiscarded; // leave stack alone } } int yyV = yyTop + 1-YyLenClass.yyLen[yyN];//t if (yydebug != null)//t yydebug.reduce(yyState, yyStates[yyV-1], yyN, YyRuleClass.yyRule[yyN], YyLenClass.yyLen[yyN]); yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) {case 4: // line 276 "XPathParser.y" { yyVal = new Root(); } break;case 5: // line 280 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(new Root()); yyVal = steps; /*$$ = new Step(new Root(), (Path) $2);*/ } break;case 6: // line 296 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(new Root()); yyVal = steps; /*Step step = new Step(s, (Path) $2);*/ /*$$ = new Step(new Root(), step);*/ } break;case 8: // line 321 "XPathParser.y" { Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; /*$$ = new Step((Expr) $1, (Path) $3);*/ } break;case 9: // line 337 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList (nt)); Steps steps; if (yyVals[-2+yyTop] instanceof Steps) { steps = (Steps) yyVals[-2+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-2+yyTop]); } steps.path.addLast(s); steps.path.addLast(yyVals[0+yyTop]); yyVal = steps; /*Step step = new Step(s, (Path) $3);*/ /*$$ = new Step((Expr) $1, step);*/ } break;case 10: // line 361 "XPathParser.y" { yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); } break;case 11: // line 365 "XPathParser.y" { yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); } break;case 12: // line 369 "XPathParser.y" { yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); } break;case 13: // line 373 "XPathParser.y" { yyVal = new Selector (Selector.SELF, Collections.EMPTY_LIST); } break;case 14: // line 377 "XPathParser.y" { yyVal = new Selector (Selector.PARENT, Collections.EMPTY_LIST); } break;case 15: // line 384 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break;case 16: // line 390 "XPathParser.y" { List list = (List)yyVals[-1+yyTop]; list.add(yyVals[0+yyTop]); yyVal = list; } break;case 17: // line 414 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR); } break;case 18: // line 418 "XPathParser.y" { yyVal = new Integer(Selector.ANCESTOR_OR_SELF); } break;case 19: // line 422 "XPathParser.y" { yyVal = new Integer(Selector.ATTRIBUTE); } break;case 20: // line 426 "XPathParser.y" { yyVal = new Integer(Selector.CHILD); } break;case 21: // line 430 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT); } break;case 22: // line 434 "XPathParser.y" { yyVal = new Integer(Selector.DESCENDANT_OR_SELF); } break;case 23: // line 438 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING); } break;case 24: // line 442 "XPathParser.y" { yyVal = new Integer(Selector.FOLLOWING_SIBLING); } break;case 25: // line 446 "XPathParser.y" { yyVal = new Integer(Selector.NAMESPACE); } break;case 26: // line 450 "XPathParser.y" { yyVal = new Integer(Selector.PARENT); } break;case 27: // line 454 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING); } break;case 28: // line 458 "XPathParser.y" { yyVal = new Integer(Selector.PRECEDING_SIBLING); } break;case 29: // line 462 "XPathParser.y" { yyVal = new Integer(Selector.SELF); } break;case 31: // line 471 "XPathParser.y" { yyVal = new NodeTypeTest(Node.PROCESSING_INSTRUCTION_NODE, (String) yyVals[-1+yyTop]); } break;case 32: // line 476 "XPathParser.y" { yyVal = new NodeTypeTest(((Short) yyVals[-1+yyTop]).shortValue()); } break;case 33: // line 483 "XPathParser.y" { yyVal = new Predicate((Expr) yyVals[-1+yyTop]); } break;case 35: // line 491 "XPathParser.y" { yyVal = new ParenthesizedExpr((Expr) yyVals[-1+yyTop]); } break;case 36: // line 495 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break;case 37: // line 499 "XPathParser.y" { yyVal = new Constant(yyVals[0+yyTop]); } break;case 39: // line 507 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-2+yyTop], Collections.EMPTY_LIST); } break;case 40: // line 511 "XPathParser.y" { yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); } break;case 41: // line 518 "XPathParser.y" { List list = new ArrayList(); list.add(yyVals[0+yyTop]); yyVal = list; } break;case 42: // line 524 "XPathParser.y" { List list = (List) yyVals[0+yyTop]; list.add(0, yyVals[-2+yyTop]); yyVal = list; } break;case 44: // line 534 "XPathParser.y" { yyVal = new UnionExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 47: // line 543 "XPathParser.y" { Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; /*$$ = new Step ((Expr) $1, (Path) $3);*/ } break;case 48: // line 559 "XPathParser.y" { Test nt = new NodeTypeTest((short) 0); Selector s = new Selector(Selector.DESCENDANT_OR_SELF, Collections.singletonList(nt)); Steps steps; if (yyVals[0+yyTop] instanceof Steps) { steps = (Steps) yyVals[0+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[0+yyTop]); } steps.path.addFirst(s); steps.path.addFirst(yyVals[-2+yyTop]); yyVal = steps; /*Step step = new Step (s, (Path) $3);*/ /*$$ = new Step ((Expr) $1, step);*/ } break;case 50: // line 584 "XPathParser.y" { Predicate filter = (Predicate) yyVals[0+yyTop]; Selector s = new Selector(Selector.SELF, Collections.singletonList(filter)); Steps steps; if (yyVals[-1+yyTop] instanceof Steps) { steps = (Steps) yyVals[-1+yyTop]; } else { steps = new Steps(); steps.path.addFirst(yyVals[-1+yyTop]); } steps.path.addLast(s); yyVal = steps; /*$$ = new Step ((Expr) $1, s);*/ } break;case 52: // line 607 "XPathParser.y" { yyVal = new OrExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 54: // line 615 "XPathParser.y" { yyVal = new AndExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop]); } break;case 56: // line 623 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false); } break;case 57: // line 627 "XPathParser.y" { yyVal = new EqualityExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true); } break;case 59: // line 635 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, false); } break;case 60: // line 639 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, false); } break;case 61: // line 643 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], true, true); } break;case 62: // line 647 "XPathParser.y" { yyVal = new RelationalExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], false, true); } break;case 64: // line 655 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.ADD); } break;case 65: // line 659 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.SUBTRACT); } break;case 67: // line 667 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MULTIPLY); } break;case 68: // line 671 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.DIVIDE); } break;case 69: // line 675 "XPathParser.y" { yyVal = new ArithmeticExpr((Expr) yyVals[-2+yyTop], (Expr) yyVals[0+yyTop], ArithmeticExpr.MODULO); } break;case 71: // line 683 "XPathParser.y" { yyVal = new NegativeExpr((Expr) yyVals[0+yyTop]); } break;case 72: // line 690 "XPathParser.y" { yyVal = new Double((String) yyVals[0+yyTop] + ".0"); } break;case 73: // line 694 "XPathParser.y" { yyVal = new Double((String) yyVals[-1+yyTop] + ".0"); } break;case 74: // line 698 "XPathParser.y" { yyVal = new Double((String) yyVals[-2+yyTop] + "." + (String) yyVals[0+yyTop]); } break;case 75: // line 702 "XPathParser.y" { yyVal = new Double("0." + (String) yyVals[0+yyTop]); } break;case 77: // line 731 "XPathParser.y" { yyVal = new VariableReference(variableResolver, (String) yyVals[0+yyTop]); } break;case 78: // line 738 "XPathParser.y" { yyVal = new NameTest(null, true, true); } break;case 79: // line 742 "XPathParser.y" { QName qName = getQName((String) yyVals[-2+yyTop]); yyVal = new NameTest(qName, true, false); } break;case 80: // line 747 "XPathParser.y" { QName qName = getQName((String) yyVals[0+yyTop]); yyVal = new NameTest(qName, false, false); } break;case 82: // line 756 "XPathParser.y" { yyVal = (String) yyVals[-2+yyTop] + ':' + (String) yyVals[0+yyTop]; } break;case 83: // line 763 "XPathParser.y" { yyVal = new Short(Node.COMMENT_NODE); } break;case 84: // line 767 "XPathParser.y" { yyVal = new Short(Node.TEXT_NODE); } break;case 85: // line 771 "XPathParser.y" { yyVal = new Short(Node.PROCESSING_INSTRUCTION_NODE); } break;case 86: // line 775 "XPathParser.y" { yyVal = new Short((short) 0); } break; // line 986 "-" } yyTop -= YyLenClass.yyLen[yyN]; yyState = yyStates[yyTop]; int yyM = YyLhsClass.yyLhs[yyN]; if (yyState == 0 && yyM == 0) {//t if (yydebug != null) yydebug.shift(0, yyFinal); yyState = yyFinal; if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0;//t if (yydebug != null)//t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value()); } if (yyToken == 0) {//t if (yydebug != null) yydebug.accept(yyVal); return yyVal; } continue yyLoop; } if ((yyN = YyGindexClass.yyGindex[yyM]) != 0 && (yyN += yyState) >= 0 && yyN < YyTableClass.yyTable.length && YyCheckClass.yyCheck[yyN] == yyState) yyState = YyTableClass.yyTable[yyN]; else yyState = YyDgotoClass.yyDgoto[yyM];//t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState); continue yyLoop; } } }
{
public Expr clone(Object context) { NamespaceContext n = nsctx; if (context instanceof NamespaceContext) { n = (NamespaceContext) context; } ElementAvailableFunction f = new ElementAvailableFunction(n); int len = args.size(); List args2 = new ArrayList(len); for (int i = 0; i < len; i++) { args2.add(((Expr) args.get(i)).clone(context)); } f.setArguments(args2); return f; }
}
public Expr clone(Object context) { NamespaceContext n = nsctx; if (context instanceof NamespaceContext) { n = (NamespaceContext) context; } ElementAvailableFunction f = new ElementAvailableFunction(n); int len = args.size(); List args2 = new ArrayList(len); for (int i = 0; i < len; i++) { args2.add(((Expr) args.get(i)).clone(context)); } f.setArguments(args2); return f; }
{
public boolean references(QName var) { for (Iterator i = args.iterator(); i.hasNext(); ) { if (((Expr) i.next()).references(var)) { return true; } } return false; }
}
public boolean references(QName var) { for (Iterator i = args.iterator(); i.hasNext(); ) { if (((Expr) i.next()).references(var)) { return true; } } return false; }
Oid(int[] components)
public Oid(String strOid) throws GSSException
Oid(int[] components) { this.components = components; relative = false; }
this.components = components;
if (strOid == null) throw new NullPointerException(); this.strOid = strOid; try { StringTokenizer tok = new StringTokenizer(strOid, "."); components = new int[tok.countTokens()]; int i = 0; while (tok.hasMoreTokens() && i < components.length) { components[i++] = Integer.parseInt(tok.nextToken()); } } catch (Exception x) { throw new GSSException(GSSException.FAILURE); }
Oid(int[] components) { this.components = components; relative = false; }
public void read(InputStream in, Document doc, int pos)
public void read(InputStream in, Document document, int offset)
public void read(InputStream in, Document doc, int pos) throws BadLocationException, IOException { }
read(new InputStreamReader(in), document, offset);
public void read(InputStream in, Document doc, int pos) throws BadLocationException, IOException { }
public void write(OutputStream out, Document doc, int pos, int len)
public void write(OutputStream out, Document document, int offset, int len)
public void write(OutputStream out, Document doc, int pos, int len) throws BadLocationException, IOException { }
write(new OutputStreamWriter(out), document, offset, len);
public void write(OutputStream out, Document doc, int pos, int len) throws BadLocationException, IOException { }
encoding = System.getProperty("file.encoding");
encoding = SystemProperties.getProperty("file.encoding");
public InputStreamReader(InputStream in) { if (in == null) throw new NullPointerException(); this.in = in; try { encoding = System.getProperty("file.encoding"); // Don't use NIO if avoidable if(EncodingHelper.isISOLatin1(encoding)) { encoding = "ISO8859_1"; maxBytesPerChar = 1f; decoder = null; return; } Charset cs = EncodingHelper.getCharset(encoding); decoder = cs.newDecoder(); encoding = EncodingHelper.getOldCanonical(cs.name()); try { maxBytesPerChar = cs.newEncoder().maxBytesPerChar(); } catch(UnsupportedOperationException _){ maxBytesPerChar = 1f; } decoder.onMalformedInput(CodingErrorAction.REPLACE); decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); decoder.reset(); } catch(RuntimeException e) { encoding = "ISO8859_1"; maxBytesPerChar = 1f; decoder = null; } catch(UnsupportedEncodingException e) { encoding = "ISO8859_1"; maxBytesPerChar = 1f; decoder = null; } }
public OutputStreamWriter (OutputStream out)
public OutputStreamWriter (OutputStream out, String encoding_scheme) throws UnsupportedEncodingException
public OutputStreamWriter (OutputStream out) { this.out = out; outputBuffer = null; try { String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding); encoder = cs.newEncoder(); encodingName = EncodingHelper.getOldCanonical(cs.name()); } catch(RuntimeException e) { encoder = null; encodingName = "ISO8859_1"; } if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); } }
outputBuffer = null;
public OutputStreamWriter (OutputStream out) { this.out = out; outputBuffer = null; try { String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding); encoder = cs.newEncoder(); encodingName = EncodingHelper.getOldCanonical(cs.name()); } catch(RuntimeException e) { encoder = null; encodingName = "ISO8859_1"; } if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); } }
String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding);
if(EncodingHelper.isISOLatin1(encoding_scheme)) { encodingName = "ISO8859_1"; encoder = null; return; } try { if(encoding_scheme.equalsIgnoreCase("UnicodeBig") || encoding_scheme.equalsIgnoreCase("UTF-16") || encoding_scheme.equalsIgnoreCase("UTF16")) { encoding_scheme = "UTF-16BE"; out.write((byte)0xFE); out.write((byte)0xFF); } else if(encoding_scheme.equalsIgnoreCase("UnicodeLittle")){ encoding_scheme = "UTF-16LE"; out.write((byte)0xFF); out.write((byte)0xFE); } } catch(IOException ioe) { } outputBuffer = CharBuffer.allocate(BUFFER_SIZE); Charset cs = EncodingHelper.getCharset(encoding_scheme); if(cs == null) throw new UnsupportedEncodingException("Encoding "+encoding_scheme+ " unknown");
public OutputStreamWriter (OutputStream out) { this.out = out; outputBuffer = null; try { String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding); encoder = cs.newEncoder(); encodingName = EncodingHelper.getOldCanonical(cs.name()); } catch(RuntimeException e) { encoder = null; encodingName = "ISO8859_1"; } if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); } }
encodingName = EncodingHelper.getOldCanonical(cs.name());
encodingName = EncodingHelper.getOldCanonical(cs.name()); encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
public OutputStreamWriter (OutputStream out) { this.out = out; outputBuffer = null; try { String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding); encoder = cs.newEncoder(); encodingName = EncodingHelper.getOldCanonical(cs.name()); } catch(RuntimeException e) { encoder = null; encodingName = "ISO8859_1"; } if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); } }
if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); }
public OutputStreamWriter (OutputStream out) { this.out = out; outputBuffer = null; try { String encoding = System.getProperty("file.encoding"); Charset cs = Charset.forName(encoding); encoder = cs.newEncoder(); encodingName = EncodingHelper.getOldCanonical(cs.name()); } catch(RuntimeException e) { encoder = null; encodingName = "ISO8859_1"; } if(encoder != null) { encoder.onMalformedInput(CodingErrorAction.REPLACE); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); outputBuffer = CharBuffer.allocate(BUFFER_SIZE); } }
while (namespaces.containsValue(prefix))
if (namespaces.isEmpty()) return prefix; HashMap ctx = (HashMap) namespaces.getFirst(); while (ctx.containsValue(prefix))
String define(String uri, String prefix) { while (namespaces.containsValue(prefix)) { // Fabricate new prefix prefix = prefix + "_"; } namespaces.put(uri, prefix); return prefix; }
namespaces.put(uri, prefix);
ctx.put(uri, prefix);
String define(String uri, String prefix) { while (namespaces.containsValue(prefix)) { // Fabricate new prefix prefix = prefix + "_"; } namespaces.put(uri, prefix); return prefix; }
{
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
}
htmlEncoded = false;
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
boolean defined = false;
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
}
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (isDefined(nsuri)) {
if (isDefined(nsuri, prefix))
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
else if (uri != null && !isDefined(uri))
else if (uri != null && !isDefined(uri, prefix))
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
String nsvalue = "'" + encode(uri, true, true) + "'";
String nsvalue = "\"" + encode(uri, true, true) + "\"";
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
defined = true;
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
value = "'" + encode(a_nodeValue, true, true) + "'";
value = "\"" + encode(a_nodeValue, true, true) + "\"";
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix());
prefix = node.getPrefix(); if (uri != null && !isDefined(uri, prefix)) { prefix = define(uri, prefix);
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value));
value = node.getNodeValue(); int bbk = value.indexOf("]]>"); while (bbk != -1) { String head = value.substring(0, bbk + 2); out.write(encodeText("<![CDATA[" + head + "]]>")); value = value.substring(bbk + 2); bbk = value.indexOf("]]>"); } out.write(encodeText("<![CDATA[" + value + "]]>"));
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }
out.write("xml version='".getBytes("US-ASCII"));
out.write("xml version=\"".getBytes("US-ASCII"));
private void doSerialize(final Node node, final OutputStream out, boolean convertToCdata) throws IOException { if (out == null) { throw new NullPointerException("no output stream"); } String value, prefix; Node children; String uri = node.getNamespaceURI(); boolean defined = false; short nt = node.getNodeType(); if (convertToCdata && nt == Node.TEXT_NODE) { nt = Node.CDATA_SECTION_NODE; } switch (nt) { case Node.ATTRIBUTE_NODE: prefix = node.getPrefix(); if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri) || XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) || (prefix != null && prefix.startsWith("xmlns:"))) { String nsuri = node.getNodeValue(); if (isDefined(nsuri)) { break; } String name = node.getLocalName(); if (name == null) { name = node.getNodeName(); } define(nsuri, name); } else if (uri != null && !isDefined(uri)) { prefix = define(uri, prefix); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(nsvalue.getBytes(encoding)); defined = true; } out.write(SPACE); String a_nodeName = node.getNodeName(); out.write(encodeText(a_nodeName)); String a_nodeValue = node.getNodeValue(); if (mode == Stylesheet.OUTPUT_HTML && a_nodeName.equals(a_nodeValue) && isHTMLBoolean((Attr) node, a_nodeName)) { break; } out.write(EQ); value = "'" + encode(a_nodeValue, true, true) + "'"; out.write(encodeText(value)); break; case Node.ELEMENT_NODE: value = node.getNodeName(); out.write(BRA); out.write(encodeText(value)); if (uri != null && !isDefined(uri)) { prefix = define(uri, node.getPrefix()); String nsname = (prefix == null) ? "xmlns" : "xmlns:" + prefix; out.write(SPACE); out.write(encodeText(nsname)); out.write(EQ); String nsvalue = "'" + encode(uri, true, true) + "'"; out.write(encodeText(nsvalue)); defined = true; } NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { int len = attrs.getLength(); for (int i = 0; i < len; i++) { Attr attr = (Attr) attrs.item(i); if (discardDefaultContent && !attr.getSpecified()) { // NOOP } else { serialize(attr, out, false); } } } convertToCdata = cdataSectionElements.contains(value); children = node.getFirstChild(); if (children == null) { out.write(SLASH); out.write(KET); } else { out.write(KET); serialize(children, out, convertToCdata); out.write(BRA); out.write(SLASH); out.write(encodeText(value)); out.write(KET); } break; case Node.TEXT_NODE: value = node.getNodeValue(); if (!"yes".equals(node.getUserData("disable-output-escaping"))) { value = encode(value, false, false); } out.write(encodeText(value)); break; case Node.CDATA_SECTION_NODE: value = "<![CDATA[" + node.getNodeValue() + "]]>"; out.write(encodeText(value)); break; case Node.COMMENT_NODE: value = "<!--" + node.getNodeValue() + "-->"; out.write(encodeText(value)); Node cp = node.getParentNode(); if (cp != null && cp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: if (mode == Stylesheet.OUTPUT_XML) { if ("UTF-16".equalsIgnoreCase(encoding)) { out.write(0xfe); out.write(0xff); } if (!"yes".equals(node.getUserData("omit-xml-declaration")) && xmlDeclaration) { Document doc = (node instanceof Document) ? (Document) node : null; String version = (doc != null) ? doc.getXmlVersion() : null; if (version == null) { version = (String) node.getUserData("version"); } if (version == null) { version = "1.0"; } out.write(BRA); out.write(0x3f); out.write("xml version='".getBytes("US-ASCII")); out.write(version.getBytes("US-ASCII")); out.write(APOS); if (!("UTF-8".equalsIgnoreCase(encoding))) { out.write(" encoding='".getBytes("US-ASCII")); out.write(encoding.getBytes("US-ASCII")); out.write(APOS); } if ((doc != null && doc.getXmlStandalone()) || "yes".equals(node.getUserData("standalone"))) { out.write(" standalone='yes'".getBytes("US-ASCII")); } out.write(0x3f); out.write(KET); out.write(encodeText(eol)); } // TODO warn if not outputting the declaration would be a // problem } else if (mode == Stylesheet.OUTPUT_HTML) { // Ensure that encoding is accessible String mediaType = (String) node.getUserData("media-type"); if (mediaType == null) { mediaType = "text/html"; } String contentType = mediaType + "; charset=" + ((encoding.indexOf(' ') != -1) ? "\"" + encoding + "\"" : encoding); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Node html = null; for (Node ctx = node.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { html = ctx; break; } } if (html == null) { html = doc.createElement("html"); node.appendChild(html); } Node head = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("head".equalsIgnoreCase(name)) { head = ctx; break; } } } if (head == null) { head = doc.createElement("head"); Node c1 = null; for (Node ctx = html.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { c1 = ctx; break; } } if (c1 != null) { html.insertBefore(head, c1); } else { html.appendChild(head); } } Node meta = null; Node metaContent = null; for (Node ctx = head.getFirstChild(); ctx != null; ctx = ctx.getNextSibling()) { if (ctx.getNodeType() == Node.ELEMENT_NODE) { String name = ctx.getLocalName(); if (name == null) { name = ctx.getNodeName(); } if ("meta".equalsIgnoreCase(name)) { NamedNodeMap metaAttrs = ctx.getAttributes(); int len = metaAttrs.getLength(); String httpEquiv = null; Node content = null; for (int i = 0; i < len; i++) { Node attr = metaAttrs.item(i); String attrName = attr.getNodeName(); if ("http-equiv".equalsIgnoreCase(attrName)) { httpEquiv = attr.getNodeValue(); } else if ("content".equalsIgnoreCase(attrName)) { content = attr; } } if ("Content-Type".equalsIgnoreCase(httpEquiv)) { meta = ctx; metaContent = content; break; } } } } if (meta == null) { meta = doc.createElement("meta"); // Insert first Node first = head.getFirstChild(); if (first == null) { head.appendChild(meta); } else { head.insertBefore(meta, first); } Node metaHttpEquiv = doc.createAttribute("http-equiv"); meta.getAttributes().setNamedItem(metaHttpEquiv); metaHttpEquiv.setNodeValue("Content-Type"); } if (metaContent == null) { metaContent = doc.createAttribute("content"); meta.getAttributes().setNamedItem(metaContent); } metaContent.setNodeValue(contentType); // phew } children = node.getFirstChild(); if (children != null) { serialize(children, out, convertToCdata); } break; case Node.DOCUMENT_TYPE_NODE: DocumentType doctype = (DocumentType) node; out.write(BRA); out.write(BANG); out.write(encodeText("DOCTYPE ")); value = doctype.getNodeName(); out.write(encodeText(value)); String publicId = doctype.getPublicId(); if (publicId != null) { out.write(encodeText(" PUBLIC ")); out.write(APOS); out.write(encodeText(publicId)); out.write(APOS); } String systemId = doctype.getSystemId(); if (systemId != null) { out.write(encodeText(" SYSTEM ")); out.write(APOS); out.write(encodeText(systemId)); out.write(APOS); } String internalSubset = doctype.getInternalSubset(); if (internalSubset != null) { out.write(encodeText(internalSubset)); } out.write(KET); out.write(eol.getBytes(encoding)); break; case Node.ENTITY_REFERENCE_NODE: value = "&" + node.getNodeValue() + ";"; out.write(encodeText(value)); break; case Node.PROCESSING_INSTRUCTION_NODE: value = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; out.write(encodeText(value)); Node pp = node.getParentNode(); if (pp != null && pp.getNodeType() == Node.DOCUMENT_NODE) { out.write(encodeText(eol)); } break; } if (defined) { undefine(uri); } }