bugged
stringlengths
6
599k
fixed
stringlengths
10
599k
__index_level_0__
int64
0
1.13M
public SimpleDateFormat() { /* * There does not appear to be a standard API for determining * what the default pattern for a locale is, so use package-scope * variables in DateFormatSymbols to encapsulate this. */ super(); Locale locale = Locale.getDefault(); calendar = new GregorianCalendar(locale); computeCenturyStart(); tokens = new Vector(); formatData = new DateFormatSymbols(locale); pattern = (formatData.dateFormats[DEFAULT] + ' ' + formatData.timeFormats[DEFAULT]); compileFormat(pattern); numberFormat = NumberFormat.getInstance(locale); numberFormat.setGroupingUsed (false); }
public SimpleDateFormat() { /* * There does not appear to be a standard API for determining * what the default pattern for a locale is, so use package-scope * variables in DateFormatSymbols to encapsulate this. */ super(); Locale locale = Locale.getDefault(); calendar = new GregorianCalendar(locale); computeCenturyStart(); tokens = new ArrayList(); formatData = new DateFormatSymbols(locale); pattern = (formatData.dateFormats[DEFAULT] + ' ' + formatData.timeFormats[DEFAULT]); compileFormat(pattern); numberFormat = NumberFormat.getInstance(locale); numberFormat.setGroupingUsed (false); }
9,382
public final String format (Date date) { StringBuffer sb = new StringBuffer (); format (date, sb, new FieldPosition (MONTH_FIELD)); return sb.toString(); }
public final StringBuffer format (Object obj, StringBuffer buf, FieldPosition pos) { StringBuffer sb = new StringBuffer (); format (date, sb, new FieldPosition (MONTH_FIELD)); return sb.toString(); }
9,384
public final String format (Date date) { StringBuffer sb = new StringBuffer (); format (date, sb, new FieldPosition (MONTH_FIELD)); return sb.toString(); }
public final String format (Date date) { StringBuffer sb = new StringBuffer (); format (date, sb, new FieldPosition (MONTH_FIELD)); return sb.toString(); }
9,385
public void beginDraggingFrame(JComponent frame);
void beginDraggingFrame(JComponent frame);
9,387
public void endDraggingFrame(JComponent frame);
void endDraggingFrame(JComponent frame);
9,388
public void dragFrame(JComponent frame, int x, int y);
void dragFrame(JComponent frame, int x, int y);
9,389
public void setHorizontalAlignment(int alignment) { hori_align = alignment; }
public void setHorizontalAlignment(int alignment) { hori_align = alignment; }
9,390
public void setHorizontalTextPosition(int textPosition) { hori_text_pos = textPosition; }
public void setHorizontalTextPosition(int textPosition) { hori_text_pos = textPosition; }
9,391
public void setText(String text) { this.text = text; revalidate(); repaint(); }
public void setText(String text) { this.text = text; revalidate(); repaint(); }
9,392
getAlignedSizeRequirements(SizeRequirements[] children) { return null; // TODO }
getAlignedSizeRequirements(SizeRequirements[] children) { float minLeft = 0; float minRight = 0; float prefLeft = 0; float prefRight = 0; float maxLeft = 0; float maxRight = 0; for (int i = 0; i < children.length; i++) { float myMinLeft = children[i].minimum * children[i].alignment; float myMinRight = children[i].minimum - myMinLeft; minLeft = Math.max(myMinLeft, minLeft); minRight = Math.max(myMinRight, minRight); float myPrefLeft = children[i].preferred * children[i].alignment; float myPrefRight = children[i].preferred - myMinLeft; prefLeft = Math.max(myPrefLeft, prefLeft); prefRight = Math.max(myPrefRight, prefRight); float myMaxLeft = children[i].maximum * children[i].alignment; float myMaxRight = children[i].maximum - myMinLeft; maxLeft = Math.max(myMaxLeft, maxLeft); maxRight = Math.max(myMaxRight, maxRight); } int minSize = (int) (minLeft + minRight); int prefSize = (int) (prefLeft + prefRight); int maxSize = (int) (maxLeft + maxRight); return new SizeRequirements(minSize, prefSize, maxSize, 0.5F); // TODO }
9,393
TemplateNode clone(Stylesheet stylesheet) { return new ApplyImportsNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet)); }
TemplateNode clone(Stylesheet stylesheet) { return new ApplyImportsNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet)); }
9,394
public MappedBlockDeviceSupport(Device parent, long offset, long length) throws IOException { super(parent.getBus(), "mapped-" + parent.getId()); this.parent = parent; try { this.parentApi = (BlockDeviceAPI)parent.getAPI(BlockDeviceAPI.class); } catch (ApiNotFoundException ex) { throw new IOException("BlockDeviceAPI not found on parent device", ex); } this.offset = offset; this.length = length; if (offset < 0) { throw new IndexOutOfBoundsException("offset < 0"); } if (length < 0) { throw new IndexOutOfBoundsException("length < 0"); } if (offset + length > parentApi.getLength()) { throw new IndexOutOfBoundsException("offset + length > parent.length"); } registerAPI(BlockDeviceAPI.class, this); }
public MappedBlockDeviceSupport(Device parent, long offset, long length) throws IOException { super(parent.getBus(), "mapped-" + parent.getId()); this.parent = parent; try { this.parentApi = (BlockDeviceAPI)parent.getAPI(BlockDeviceAPI.class); } catch (ApiNotFoundException ex) { final IOException ioe = new IOException("BlockDeviceAPI not found on device"); ioe.initCause(ex); throw ioe; } this.offset = offset; this.length = length; if (offset < 0) { throw new IndexOutOfBoundsException("offset < 0"); } if (length < 0) { throw new IndexOutOfBoundsException("length < 0"); } if (offset + length > parentApi.getLength()) { throw new IndexOutOfBoundsException("offset + length > parent.length"); } registerAPI(BlockDeviceAPI.class, this); }
9,396
public CharBuffer put (char[] src, int offset, int length) { checkArraySize(src.length, offset, length); checkForOverflow(length); for (int i = offset; i < offset + length; i++) put (src [i]); return this; }
public CharBuffer put (CharBuffer src) { checkArraySize(src.length, offset, length); checkForOverflow(length); for (int i = offset; i < offset + length; i++) put (src [i]); return this; }
9,397
public CharBuffer put (char[] src, int offset, int length) { checkArraySize(src.length, offset, length); checkForOverflow(length); for (int i = offset; i < offset + length; i++) put (src [i]); return this; }
public CharBuffer put (char[] src, int offset, int length) { checkArraySize(src.length, offset, length); checkForOverflow(length); for (int i = offset; i < offset + length; i++) put (src [i]); return this; }
9,398
final public static CharBuffer wrap(char[] array, int offset, int length) { return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false); }
public static final CharBuffer wrap(char[] array, int offset, int length) { return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false); }
9,399
public void installUI(JComponent c) { tree = (JTree) c; configureLayoutCache(); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); tree.setFont(defaults.getFont("Tree.font")); tree.setForeground(defaults.getColor("Tree.foreground")); tree.setBackground(defaults.getColor("Tree.background")); tree.setOpaque(true); tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand")); rightChildIndent = defaults.getInt("Tree.rightChildIndent"); leftChildIndent = defaults.getInt("Tree.leftChildIndent"); setRowHeight(defaults.getInt("Tree.rowHeight")); tree.requestFocusInWindow(false); setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); currentCellRenderer = createDefaultCellRenderer(); rendererPane = createCellRendererPane(); createdRenderer = true; setCellEditor(createDefaultCellEditor()); createdCellEditor = true; TreeModel mod = tree.getModel(); setModel(mod); tree.setRootVisible(true); if (mod != null) tree.expandPath(new TreePath(mod.getRoot())); treeSelectionModel = tree.getSelectionModel(); drawingCache = new Hashtable(); nodeDimensions = createNodeDimensions(); propertyChangeListener = createPropertyChangeListener(); focusListener = createFocusListener(); treeSelectionListener = createTreeSelectionListener(); mouseInputListener = new MouseInputHandler(null, null, null); keyListener = createKeyListener(); selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); componentListener = createComponentListener(); cellEditorListener = createCellEditorListener(); treeExpansionListener = createTreeExpansionListener(); treeModelListener = createTreeModelListener(); editingRow = -1; lastSelectedRow = -1; installKeyboardActions(); tree.addPropertyChangeListener(propertyChangeListener); tree.addFocusListener(focusListener); tree.addTreeSelectionListener(treeSelectionListener); tree.addMouseListener(mouseInputListener); tree.addKeyListener(keyListener); tree.addPropertyChangeListener(selectionModelPropertyChangeListener); tree.addComponentListener(componentListener); tree.addTreeExpansionListener(treeExpansionListener); if (treeModel != null) treeModel.addTreeModelListener(treeModelListener); completeUIInstall(); }
public void installUI(JComponent c) { tree = (JTree) c; configureLayoutCache(); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); tree.setFont(defaults.getFont("Tree.font")); tree.setForeground(defaults.getColor("Tree.foreground")); tree.setBackground(defaults.getColor("Tree.background")); tree.setOpaque(true); tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand")); rightChildIndent = defaults.getInt("Tree.rightChildIndent"); leftChildIndent = defaults.getInt("Tree.leftChildIndent"); setRowHeight(defaults.getInt("Tree.rowHeight")); tree.requestFocusInWindow(false); setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); currentCellRenderer = createDefaultCellRenderer(); rendererPane = createCellRendererPane(); createdRenderer = true; setCellEditor(createDefaultCellEditor()); createdCellEditor = true; TreeModel mod = tree.getModel(); setModel(mod); if (mod != null) tree.expandPath(new TreePath(mod.getRoot())); treeSelectionModel = tree.getSelectionModel(); drawingCache = new Hashtable(); nodeDimensions = createNodeDimensions(); propertyChangeListener = createPropertyChangeListener(); focusListener = createFocusListener(); treeSelectionListener = createTreeSelectionListener(); mouseInputListener = new MouseInputHandler(null, null, null); keyListener = createKeyListener(); selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); componentListener = createComponentListener(); cellEditorListener = createCellEditorListener(); treeExpansionListener = createTreeExpansionListener(); treeModelListener = createTreeModelListener(); editingRow = -1; lastSelectedRow = -1; installKeyboardActions(); tree.addPropertyChangeListener(propertyChangeListener); tree.addFocusListener(focusListener); tree.addTreeSelectionListener(treeSelectionListener); tree.addMouseListener(mouseInputListener); tree.addKeyListener(keyListener); tree.addPropertyChangeListener(selectionModelPropertyChangeListener); tree.addComponentListener(componentListener); tree.addTreeExpansionListener(treeExpansionListener); if (treeModel != null) treeModel.addTreeModelListener(treeModelListener); completeUIInstall(); }
9,400
public TreePath(Object element) { // Create Path path = new Object[1]; path[0] = element; } // TreePath()
public TreePath(Object[] path) { // Create Path path = new Object[1]; path[0] = element; } // TreePath()
9,401
public TreePath(Object element) { // Create Path path = new Object[1]; path[0] = element; } // TreePath()
public TreePath(Object element) { // Create Path path = new Object[1]; path[0] = element; } // TreePath()
9,402
public void removeCellEditorListener(CellEditorListener listener);
void removeCellEditorListener(CellEditorListener listener);
9,403
void convertCdataSectionElements(Document doc, Node node, List list) { if (node.getNodeType() == Node.ELEMENT_NODE) { boolean match = false; for (Iterator i = list.iterator(); i.hasNext(); ) { QName qname = (QName) i.next(); if (match(qname, node)) { match = true; break; } } if (match) { Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.getNodeType() == Node.TEXT_NODE) { Node cdata = doc.createCDATASection(ctx.getNodeValue()); node.replaceChild(cdata, ctx); ctx = cdata; } ctx = ctx.getNextSibling(); } } } Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.hasChildNodes()) { convertCdataSectionElements(doc, ctx, list); } ctx = ctx.getNextSibling(); } }
void convertCdataSectionElements(Document doc, Node node, List list) if (node.getNodeType() == Node.ELEMENT_NODE) boolean match = false; for (Iterator i = list.iterator(); i.hasNext(); ) QName qname = (QName) i.next(); if (match(qname, node)) match = true; break; } } if (match) Node ctx = node.getFirstChild(); while (ctx != null) if (ctx.getNodeType() == Node.TEXT_NODE) Node cdata = doc.createCDATASection(ctx.getNodeValue()); node.replaceChild(cdata, ctx); ctx = cdata; } ctx = ctx.getNextSibling(); } } } Node ctx = node.getFirstChild(); while (ctx != null) if (ctx.hasChildNodes()) convertCdataSectionElements(doc, ctx, list); } ctx = ctx.getNextSibling(); } }
9,404
void convertCdataSectionElements(Document doc, Node node, List list) { if (node.getNodeType() == Node.ELEMENT_NODE) { boolean match = false; for (Iterator i = list.iterator(); i.hasNext(); ) { QName qname = (QName) i.next(); if (match(qname, node)) { match = true; break; } } if (match) { Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.getNodeType() == Node.TEXT_NODE) { Node cdata = doc.createCDATASection(ctx.getNodeValue()); node.replaceChild(cdata, ctx); ctx = cdata; } ctx = ctx.getNextSibling(); } } } Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.hasChildNodes()) { convertCdataSectionElements(doc, ctx, list); } ctx = ctx.getNextSibling(); } }
void convertCdataSectionElements(Document doc, Node node, List list) { if (node.getNodeType() == Node.ELEMENT_NODE) { boolean match = false; for (Iterator i = list.iterator(); i.hasNext(); ) { QName qname = (QName) i.next(); if (match(qname, node)) { match = true; break; if (match) { Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.getNodeType() == Node.TEXT_NODE) { Node cdata = doc.createCDATASection(ctx.getNodeValue()); node.replaceChild(cdata, ctx); ctx = cdata; ctx = ctx.getNextSibling(); Node ctx = node.getFirstChild(); while (ctx != null) { if (ctx.hasChildNodes()) { convertCdataSectionElements(doc, ctx, list); ctx = ctx.getNextSibling();
9,405
public Object getParameter(String name) { if (stylesheet != null) { return stylesheet.bindings.get(new QName(null, name), null, 1, 1); } return null; }
public Object getParameter(String name) if (stylesheet != null) return stylesheet.bindings.get(new QName(null, name), null, 1, 1); } return null; }
9,406
public Object getParameter(String name) { if (stylesheet != null) { return stylesheet.bindings.get(new QName(null, name), null, 1, 1); } return null; }
public Object getParameter(String name) { if (stylesheet != null) { return stylesheet.bindings.get(new QName(null, name), null, 1, 1); return null;
9,407
boolean match(QName qname, Node node) { String ln1 = qname.getLocalPart(); String ln2 = node.getLocalName(); if (ln2 == null) { return ln1.equals(node.getNodeName()); } else { String uri1 = qname.getNamespaceURI(); String uri2 = node.getNamespaceURI(); return (uri1.equals(uri2) && ln1.equals(ln2)); } }
boolean match(QName qname, Node node) String ln1 = qname.getLocalPart(); String ln2 = node.getLocalName(); if (ln2 == null) return ln1.equals(node.getNodeName()); } else String uri1 = qname.getNamespaceURI(); String uri2 = node.getNamespaceURI(); return (uri1.equals(uri2) && ln1.equals(ln2)); } }
9,408
boolean match(QName qname, Node node) { String ln1 = qname.getLocalPart(); String ln2 = node.getLocalName(); if (ln2 == null) { return ln1.equals(node.getNodeName()); } else { String uri1 = qname.getNamespaceURI(); String uri2 = node.getNamespaceURI(); return (uri1.equals(uri2) && ln1.equals(ln2)); } }
boolean match(QName qname, Node node) { String ln1 = qname.getLocalPart(); String ln2 = node.getLocalName(); if (ln2 == null) { return ln1.equals(node.getNodeName()); else { String uri1 = qname.getNamespaceURI(); String uri2 = node.getNamespaceURI(); return (uri1.equals(uri2) && ln1.equals(ln2));
9,409
void reindent(Document doc, Node node, int offset) { if (node.hasChildNodes()) { boolean markupContent = false; boolean textContent = false; List children = new LinkedList(); Node ctx = node.getFirstChild(); while (ctx != null) { switch (ctx.getNodeType()) { case Node.ELEMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: markupContent = true; break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.COMMENT_NODE: textContent = true; break; } children.add(ctx); ctx = ctx.getNextSibling(); } if (markupContent) { if (textContent) { // XXX handle mixed content differently? } int nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_NODE) { for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); reindent(doc, ctx, offset + 1); } } else { StringBuffer buf = new StringBuffer(); buf.append('\n'); for (int i = 0; i < offset + 1; i++) { buf.append(INDENT_WHITESPACE); } String ws = buf.toString(); for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); node.insertBefore(doc.createTextNode(ws), ctx); reindent(doc, ctx, offset + 1); } buf = new StringBuffer(); buf.append('\n'); ws = buf.toString(); for (int i = 0; i < offset; i++) { buf.append(INDENT_WHITESPACE); } node.appendChild(doc.createTextNode(ws)); } } } }
void reindent(Document doc, Node node, int offset) if (node.hasChildNodes()) boolean markupContent = false; boolean textContent = false; List children = new LinkedList(); Node ctx = node.getFirstChild(); while (ctx != null) switch (ctx.getNodeType()) case Node.ELEMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: markupContent = true; break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.COMMENT_NODE: textContent = true; break; } children.add(ctx); ctx = ctx.getNextSibling(); } if (markupContent) if (textContent) // XXX handle mixed content differently? } int nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_NODE) for (Iterator i = children.iterator(); i.hasNext(); ) ctx = (Node) i.next(); reindent(doc, ctx, offset + 1); } } else StringBuffer buf = new StringBuffer(); buf.append('\n'); for (int i = 0; i < offset + 1; i++) buf.append(INDENT_WHITESPACE); } String ws = buf.toString(); for (Iterator i = children.iterator(); i.hasNext(); ) ctx = (Node) i.next(); node.insertBefore(doc.createTextNode(ws), ctx); reindent(doc, ctx, offset + 1); } buf = new StringBuffer(); buf.append('\n'); ws = buf.toString(); for (int i = 0; i < offset; i++) buf.append(INDENT_WHITESPACE); } node.appendChild(doc.createTextNode(ws)); } } } }
9,410
void reindent(Document doc, Node node, int offset) { if (node.hasChildNodes()) { boolean markupContent = false; boolean textContent = false; List children = new LinkedList(); Node ctx = node.getFirstChild(); while (ctx != null) { switch (ctx.getNodeType()) { case Node.ELEMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: markupContent = true; break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.COMMENT_NODE: textContent = true; break; } children.add(ctx); ctx = ctx.getNextSibling(); } if (markupContent) { if (textContent) { // XXX handle mixed content differently? } int nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_NODE) { for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); reindent(doc, ctx, offset + 1); } } else { StringBuffer buf = new StringBuffer(); buf.append('\n'); for (int i = 0; i < offset + 1; i++) { buf.append(INDENT_WHITESPACE); } String ws = buf.toString(); for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); node.insertBefore(doc.createTextNode(ws), ctx); reindent(doc, ctx, offset + 1); } buf = new StringBuffer(); buf.append('\n'); ws = buf.toString(); for (int i = 0; i < offset; i++) { buf.append(INDENT_WHITESPACE); } node.appendChild(doc.createTextNode(ws)); } } } }
void reindent(Document doc, Node node, int offset) { if (node.hasChildNodes()) { boolean markupContent = false; boolean textContent = false; List children = new LinkedList(); Node ctx = node.getFirstChild(); while (ctx != null) { switch (ctx.getNodeType()) { case Node.ELEMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: markupContent = true; break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.COMMENT_NODE: textContent = true; break; children.add(ctx); ctx = ctx.getNextSibling(); if (markupContent) { if (textContent) { // XXX handle mixed content differently? int nodeType = node.getNodeType(); if (nodeType == Node.DOCUMENT_NODE) { for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); reindent(doc, ctx, offset + 1); else { StringBuffer buf = new StringBuffer(); buf.append('\n'); for (int i = 0; i < offset + 1; i++) { buf.append(INDENT_WHITESPACE); String ws = buf.toString(); for (Iterator i = children.iterator(); i.hasNext(); ) { ctx = (Node) i.next(); node.insertBefore(doc.createTextNode(ws), ctx); reindent(doc, ctx, offset + 1); buf = new StringBuffer(); buf.append('\n'); ws = buf.toString(); for (int i = 0; i < offset; i++) { buf.append(INDENT_WHITESPACE); node.appendChild(doc.createTextNode(ws));
9,411
public void setOutputProperties(Properties oformat) throws IllegalArgumentException { if (oformat == null) { outputProperties.clear(); } else { outputProperties.putAll(oformat); } }
public void setOutputProperties(Properties oformat) throws IllegalArgumentException if (oformat == null) outputProperties.clear(); } else outputProperties.putAll(oformat); } }
9,412
public void setOutputProperties(Properties oformat) throws IllegalArgumentException { if (oformat == null) { outputProperties.clear(); } else { outputProperties.putAll(oformat); } }
public void setOutputProperties(Properties oformat) throws IllegalArgumentException { if (oformat == null) { outputProperties.clear(); else { outputProperties.putAll(oformat);
9,413
public void setParameter(String name, Object value) { if (stylesheet != null) { stylesheet.bindings.set(new QName(null, name), value, Bindings.PARAM); } }
public void setParameter(String name, Object value) if (stylesheet != null) stylesheet.bindings.set(new QName(null, name), value, Bindings.PARAM); } }
9,414
public void setParameter(String name, Object value) { if (stylesheet != null) { stylesheet.bindings.set(new QName(null, name), value, Bindings.PARAM); } }
public void setParameter(String name, Object value) { if (stylesheet != null) { stylesheet.bindings.set(new QName(null, name), value, Bindings.PARAM);
9,415
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
static boolean strip(Stylesheet stylesheet, Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,416
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,417
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); if (nextSibling != null) parent.insertBefore(child, nextSibling); else parent.appendChild(child); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,418
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } return true; } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,419
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { String text = node.getNodeValue(); String[] tokens = tokenizeWhitespace(text); if (tokens.length > 1) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,420
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.setNodeValue(tokens[0]); Node parent = node.getParentNode(); Node nextSibling = node.getNextSibling(); Document doc = node.getOwnerDocument(); for (int i = 1; i < tokens.length; i++) { Node newChild = (nt == Node.CDATA_SECTION_NODE) ? doc.createCDATASection(tokens[i]) : doc.createTextNode(tokens[i]); if (nextSibling != null) parent.insertBefore(newChild, nextSibling); else parent.appendChild(newChild); } } return !stylesheet.isPreserved((Text) node, true); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,421
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,422
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { boolean remove = strip(stylesheet, child); Node next = child.getNextSibling(); if (remove) node.removeChild(child); child = next; } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,423
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
void strip(Node node) throws TransformerConfigurationException { short nt = node.getNodeType(); if (nt == Node.ENTITY_REFERENCE_NODE) { // Replace entity reference with its content Node parent = node.getParentNode(); Node child = node.getFirstChild(); if (child != null) { strip(child); } while (child != null) { Node next = child.getNextSibling(); node.removeChild(child); parent.insertBefore(child, node); child = next; } parent.removeChild(node); } if (nt == Node.TEXT_NODE || nt == Node.CDATA_SECTION_NODE) { if (!stylesheet.isPreserved((Text) node)) { node.getParentNode().removeChild(node); } else { String text = node.getNodeValue(); String stripped = text.trim(); if (!text.equals(stripped)) { node.setNodeValue(stripped); } } } else { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { strip(child); } } }
9,424
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(stylesheet, context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,425
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException // Get the source tree DOMSource source; synchronized (factory.resolver) factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) if (parent == null) // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) // Done transforming, reset document if (doc instanceof DomDocument) ((DomDocument) doc).setBuilding(false); } throw e; } } else // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) Document resultDoc; if (parent == null) // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) clone = resultDoc.adoptNode(clone); } if (nextSibling != null) parent.insertBefore(clone, nextSibling); } else parent.appendChild(clone); } } else // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) switch (parent.getNodeType()) case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) } if (ctx != null) parent.insertBefore(doctype, ctx); } else parent.appendChild(doctype); } } } if (version != null) parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) if (created) DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) try writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) ex = e2; } } catch (IOException e) ex = e; } if (ex != null) if (errorListener != null) errorListener.error(new TransformerException(ex)); } else ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) SAXResult sr = (SAXResult) outputTarget; try ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) if (errorListener != null) errorListener.error(new TransformerException(e)); } else e.printStackTrace(System.err); } } } }
9,426
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); throw e; else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); if (nextSibling != null) { parent.insertBefore(clone, nextSibling); else { parent.appendChild(clone); else { // Cannot append document to another tree parent = clone; created = true; String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { if (ctx != null) { parent.insertBefore(doctype, ctx); else { parent.appendChild(doctype); if (version != null) { parent.setUserData("version", version, stylesheet); if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); if (standalone) { parent.setUserData("standalone", "yes", stylesheet); if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); list.add(new QName(uri, localName, prefix)); if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); catch (IOException e2) { ex = e2; catch (IOException e) { ex = e; if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); else { ex.printStackTrace(System.err); else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); else { e.printStackTrace(System.err);
9,427
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,428
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,429
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type DocumentType doctype = new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,430
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId); resultDoc.insertBefore(doctype, root); } } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,431
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(root.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,432
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,433
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
public void transform(Source xmlSource, Result outputTarget) throws TransformerException { // Get the source tree DOMSource source; synchronized (factory.resolver) { factory.resolver.setUserResolver(uriResolver); factory.resolver.setUserListener(errorListener); source = factory.resolver.resolveDOM(xmlSource, null, null); } Node context = source.getNode(); Document doc = (context instanceof Document) ? (Document) context : context.getOwnerDocument(); if (doc instanceof DomDocument) { // Suppress mutation events ((DomDocument) doc).setBuilding(true); // TODO find a better/more generic way of doing this than // casting } // Get the result tree Node parent = null, nextSibling = null; if (outputTarget instanceof DOMResult) { DOMResult dr = (DOMResult) outputTarget; parent = dr.getNode(); nextSibling = dr.getNextSibling(); Document rdoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); if (rdoc instanceof DomDocument) { // Suppress mutation events and allow multiple root elements DomDocument drdoc = (DomDocument) rdoc; drdoc.setBuilding(true); drdoc.setCheckWellformedness(false); // TODO find a better/more generic way of doing this than // casting } } boolean created = false; // Transformation if (stylesheet != null) { if (parent == null) { // Create a new document to hold the result DomDocument resultDoc = new DomDocument(); resultDoc.setBuilding(true); resultDoc.setCheckWellformedness(false); parent = resultDoc; created = true; } // Make a copy of the source node, and strip it context = context.cloneNode(true); strip(context); // XSLT transformation try { // Set output properties in the underlying stylesheet ((TransformerOutputProperties) outputProperties).apply(); stylesheet.initTopLevelVariables(context); TemplateNode t = stylesheet.getTemplate(null, context, false); if (t != null) { stylesheet.current = context; t.apply(stylesheet, null, context, 1, 1, parent, nextSibling); } } catch (TransformerException e) { // Done transforming, reset document if (doc instanceof DomDocument) { ((DomDocument) doc).setBuilding(false); } throw e; } } else { // Identity transform Node clone = context.cloneNode(true); if (context.getNodeType() != Node.DOCUMENT_NODE) { Document resultDoc; if (parent == null) { // Create a new document to hold the result DomDocument rd = new DomDocument(); rd.setBuilding(true); rd.setCheckWellformedness(false); parent = resultDoc = rd; created = true; } else { resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); } Document sourceDoc = context.getOwnerDocument(); if (sourceDoc != resultDoc) { clone = resultDoc.adoptNode(clone); } if (nextSibling != null) { parent.insertBefore(clone, nextSibling); } else { parent.appendChild(clone); } } else { // Cannot append document to another tree parent = clone; created = true; } } String method = outputProperties.getProperty(OutputKeys.METHOD); int outputMethod = "html".equals(method) ? Stylesheet.OUTPUT_HTML : "text".equals(method) ? Stylesheet.OUTPUT_TEXT : Stylesheet.OUTPUT_XML; String encoding = outputProperties.getProperty(OutputKeys.ENCODING); String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC); String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM); String version = outputProperties.getProperty(OutputKeys.VERSION); boolean omitXmlDeclaration = "yes".equals(outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION)); boolean standalone = "yes".equals(outputProperties.getProperty(OutputKeys.STANDALONE)); String mediaType = outputProperties.getProperty(OutputKeys.MEDIA_TYPE); String cdataSectionElements = outputProperties.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); boolean indent = "yes".equals(outputProperties.getProperty(OutputKeys.INDENT)); if (created) { // Discover document element DomDocument resultDoc = (DomDocument) parent; Node root = resultDoc.getDocumentElement(); // Add doctype if specified if ((publicId != null || systemId != null) && root != null) { // We must know the name of the root element to // create the document type resultDoc.appendChild(new DomDoctype(resultDoc, root.getNodeName(), publicId, systemId)); } resultDoc.setBuilding(false); resultDoc.setCheckWellformedness(true); } else if (publicId != null || systemId != null) { switch (parent.getNodeType()) { case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); DOMImplementation impl = resultDoc.getImplementation(); DocumentType doctype = impl.createDocumentType(resultDoc.getNodeName(), publicId, systemId); // Try to insert doctype before first element Node ctx = parent.getFirstChild(); for (; ctx != null && ctx.getNodeType() != Node.ELEMENT_NODE; ctx = ctx.getNextSibling()) { } if (ctx != null) { parent.insertBefore(doctype, ctx); } else { parent.appendChild(doctype); } } } if (version != null) { parent.setUserData("version", version, stylesheet); } if (omitXmlDeclaration) { parent.setUserData("omit-xml-declaration", "yes", stylesheet); } if (standalone) { parent.setUserData("standalone", "yes", stylesheet); } if (mediaType != null) { parent.setUserData("media-type", mediaType, stylesheet); } if (cdataSectionElements != null) { List list = new LinkedList(); StringTokenizer st = new StringTokenizer(cdataSectionElements); while (st.hasMoreTokens()) { String name = st.nextToken(); String localName = name; String uri = null; String prefix = null; int ci = name.indexOf(':'); if (ci != -1) { // Use namespaces defined on xsl:output node to resolve // namespaces for QName prefix = name.substring(0, ci); localName = name.substring(ci + 1); uri = stylesheet.output.lookupNamespaceURI(prefix); } list.add(new QName(uri, localName, prefix)); } if (!list.isEmpty()) { Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); convertCdataSectionElements(resultDoc, parent, list); } } if (indent) { parent.normalize(); strip(stylesheet, parent); Document resultDoc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument(); reindent(resultDoc, parent, 0); } // Render result to the target device if (outputTarget instanceof DOMResult) { if (created) { DOMResult dr = (DOMResult) outputTarget; dr.setNode(parent); dr.setNextSibling(null); } } else if (outputTarget instanceof StreamResult) { StreamResult sr = (StreamResult) outputTarget; IOException ex = null; try { writeStreamResult(parent, sr, outputMethod, encoding); } catch (UnsupportedEncodingException e) { try { writeStreamResult(parent, sr, outputMethod, "UTF-8"); } catch (IOException e2) { ex = e2; } } catch (IOException e) { ex = e; } if (ex != null) { if (errorListener != null) { errorListener.error(new TransformerException(ex)); } else { ex.printStackTrace(System.err); } } } else if (outputTarget instanceof SAXResult) { SAXResult sr = (SAXResult) outputTarget; try { ContentHandler ch = sr.getHandler(); LexicalHandler lh = sr.getLexicalHandler(); if (lh == null && ch instanceof LexicalHandler) { lh = (LexicalHandler) ch; } SAXSerializer serializer = new SAXSerializer(); serializer.serialize(parent, ch, lh); } catch (SAXException e) { if (errorListener != null) { errorListener.error(new TransformerException(e)); } else { e.printStackTrace(System.err); } } } }
9,434
void writeStreamResult(Node node, StreamResult sr, int outputMethod, String encoding) throws IOException { OutputStream out = null; boolean created = false; try { out = sr.getOutputStream(); if (out == null) { Writer writer = sr.getWriter(); if (writer != null) { out = new WriterOutputStream(writer); } } if (out == null) { String systemId = sr.getSystemId(); try { URL url = new URL(systemId); URLConnection connection = url.openConnection(); // We need to call setDoInput(false), because our // implementation of the file protocol allows writing // (unlike Sun), but it will fail with a FileNotFoundException // if we also open the connection for input and the output // file doesn't yet exist. connection.setDoInput(false); connection.setDoOutput(true); out = connection.getOutputStream(); } catch (MalformedURLException e) { out = new FileOutputStream(systemId); } catch (UnknownServiceException e) { URL url = new URL(systemId); out = new FileOutputStream(url.getPath()); } created = true; } out = new BufferedOutputStream(out); StreamSerializer serializer = new StreamSerializer(outputMethod, encoding, null); if (stylesheet != null) { Collection celem = stylesheet.outputCdataSectionElements; serializer.setCdataSectionElements(celem); } serializer.serialize(node, out); out.flush(); } finally { try { if (out != null && created) { out.close(); } } catch (IOException e) { } } }
void writeStreamResult(Node node, StreamResult sr, int outputMethod, String encoding) throws IOException OutputStream out = null; boolean created = false; try out = sr.getOutputStream(); if (out == null) Writer writer = sr.getWriter(); if (writer != null) out = new WriterOutputStream(writer); } } if (out == null) String systemId = sr.getSystemId(); try URL url = new URL(systemId); URLConnection connection = url.openConnection(); // We need to call setDoInput(false), because our // implementation of the file protocol allows writing // (unlike Sun), but it will fail with a FileNotFoundException // if we also open the connection for input and the output // file doesn't yet exist. connection.setDoInput(false); connection.setDoOutput(true); out = connection.getOutputStream(); } catch (MalformedURLException e) out = new FileOutputStream(systemId); } catch (UnknownServiceException e) URL url = new URL(systemId); out = new FileOutputStream(url.getPath()); } created = true; } out = new BufferedOutputStream(out); StreamSerializer serializer = new StreamSerializer(outputMethod, encoding, null); if (stylesheet != null) Collection celem = stylesheet.outputCdataSectionElements; serializer.setCdataSectionElements(celem); } serializer.serialize(node, out); out.flush(); } finally try if (out != null && created) out.close(); } } catch (IOException e) } } }
9,435
void writeStreamResult(Node node, StreamResult sr, int outputMethod, String encoding) throws IOException { OutputStream out = null; boolean created = false; try { out = sr.getOutputStream(); if (out == null) { Writer writer = sr.getWriter(); if (writer != null) { out = new WriterOutputStream(writer); } } if (out == null) { String systemId = sr.getSystemId(); try { URL url = new URL(systemId); URLConnection connection = url.openConnection(); // We need to call setDoInput(false), because our // implementation of the file protocol allows writing // (unlike Sun), but it will fail with a FileNotFoundException // if we also open the connection for input and the output // file doesn't yet exist. connection.setDoInput(false); connection.setDoOutput(true); out = connection.getOutputStream(); } catch (MalformedURLException e) { out = new FileOutputStream(systemId); } catch (UnknownServiceException e) { URL url = new URL(systemId); out = new FileOutputStream(url.getPath()); } created = true; } out = new BufferedOutputStream(out); StreamSerializer serializer = new StreamSerializer(outputMethod, encoding, null); if (stylesheet != null) { Collection celem = stylesheet.outputCdataSectionElements; serializer.setCdataSectionElements(celem); } serializer.serialize(node, out); out.flush(); } finally { try { if (out != null && created) { out.close(); } } catch (IOException e) { } } }
void writeStreamResult(Node node, StreamResult sr, int outputMethod, String encoding) throws IOException { OutputStream out = null; boolean created = false; try { out = sr.getOutputStream(); if (out == null) { Writer writer = sr.getWriter(); if (writer != null) { out = new WriterOutputStream(writer); if (out == null) { String systemId = sr.getSystemId(); try { URL url = new URL(systemId); URLConnection connection = url.openConnection(); // We need to call setDoInput(false), because our // implementation of the file protocol allows writing // (unlike Sun), but it will fail with a FileNotFoundException // if we also open the connection for input and the output // file doesn't yet exist. connection.setDoInput(false); connection.setDoOutput(true); out = connection.getOutputStream(); catch (MalformedURLException e) { out = new FileOutputStream(systemId); catch (UnknownServiceException e) { URL url = new URL(systemId); out = new FileOutputStream(url.getPath()); created = true; out = new BufferedOutputStream(out); StreamSerializer serializer = new StreamSerializer(outputMethod, encoding, null); if (stylesheet != null) { Collection celem = stylesheet.outputCdataSectionElements; serializer.setCdataSectionElements(celem); serializer.serialize(node, out); out.flush(); finally { try { if (out != null && created) { out.close(); catch (IOException e) {
9,436
public abstract void setOutputProperties(Properties outputformat) throws IllegalArgumentException;
public abstract void setOutputProperties(Properties oformat) throws IllegalArgumentException;
9,437
public abstract void transform(Source source, Result result) throws TransformerException;
public abstract void transform(Source source, Result result) throws TransformerException;
9,438
public LexicalHandler getLexicalHandler() { return lexhandler; }
public LexicalHandler getLexicalHandler() { return lexhandler; }
9,439
public URLConnection openConnection() throws IOException { return handler.openConnection(this); }
public URLConnection openConnection() throws IOException { return handler.openConnection(this); }
9,440
public String getPath() { int quest = (file == null) ? -1 : file.indexOf('?'); return quest < 0 ? getFile() : file.substring(0, quest); }
public String getPath() { int quest = (file == null) ? -1 : file.indexOf('?'); return quest < 0 ? getFile() : file.substring(0, quest); }
9,441
public static final String toString(byte[] ba, int offset, int length) { char[] buf = new char[length * 2]; for (int i = 0, j = 0, k; i < length;) { k = ba[offset + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); }
public static String toString(byte[] ba) { char[] buf = new char[length * 2]; for (int i = 0, j = 0, k; i < length;) { k = ba[offset + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); }
9,442
public static final String toString(byte[] ba, int offset, int length) { char[] buf = new char[length * 2]; for (int i = 0, j = 0, k; i < length;) { k = ba[offset + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); }
public static final String toString(byte[] ba, int offset, int length) { char[] buf = new char[length * 2]; for (int i = 0, j = 0, k; i < length;) { k = ba[offset + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); }
9,443
public DERValue read() throws IOException { int tag = in.read(); if (tag == -1) throw new EOFException(); encBuf.write(tag); int len = readLength(); DERValue value = null; if ((tag & CONSTRUCTED) == CONSTRUCTED) { in.mark(2048); byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, CONSTRUCTED_VALUE, encBuf.toByteArray()); in.reset(); encBuf.reset(); return value; } switch (tag & 0xC0) { case UNIVERSAL: value = new DERValue(tag, len, readUniversal(tag, len), encBuf.toByteArray()); encBuf.reset(); break; case CONTEXT: byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, encoded, encBuf.toByteArray()); encBuf.reset(); break; case APPLICATION: // This should not be reached, since (I think) APPLICATION is // always constructed. throw new DEREncodingException("non-constructed APPLICATION data"); default: throw new DEREncodingException("PRIVATE class not supported"); } return value; }
public static DERValue read(byte[] encoded) throws IOException { int tag = in.read(); if (tag == -1) throw new EOFException(); encBuf.write(tag); int len = readLength(); DERValue value = null; if ((tag & CONSTRUCTED) == CONSTRUCTED) { in.mark(2048); byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, CONSTRUCTED_VALUE, encBuf.toByteArray()); in.reset(); encBuf.reset(); return value; } switch (tag & 0xC0) { case UNIVERSAL: value = new DERValue(tag, len, readUniversal(tag, len), encBuf.toByteArray()); encBuf.reset(); break; case CONTEXT: byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, encoded, encBuf.toByteArray()); encBuf.reset(); break; case APPLICATION: // This should not be reached, since (I think) APPLICATION is // always constructed. throw new DEREncodingException("non-constructed APPLICATION data"); default: throw new DEREncodingException("PRIVATE class not supported"); } return value; }
9,444
public DERValue read() throws IOException { int tag = in.read(); if (tag == -1) throw new EOFException(); encBuf.write(tag); int len = readLength(); DERValue value = null; if ((tag & CONSTRUCTED) == CONSTRUCTED) { in.mark(2048); byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, CONSTRUCTED_VALUE, encBuf.toByteArray()); in.reset(); encBuf.reset(); return value; } switch (tag & 0xC0) { case UNIVERSAL: value = new DERValue(tag, len, readUniversal(tag, len), encBuf.toByteArray()); encBuf.reset(); break; case CONTEXT: byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, encoded, encBuf.toByteArray()); encBuf.reset(); break; case APPLICATION: // This should not be reached, since (I think) APPLICATION is // always constructed. throw new DEREncodingException("non-constructed APPLICATION data"); default: throw new DEREncodingException("PRIVATE class not supported"); } return value; }
public DERValue read() throws IOException { int tag = in.read(); if (tag == -1) throw new EOFException(); encBuf.write(tag); int len = readLength(); DERValue value = null; if ((tag & CONSTRUCTED) == CONSTRUCTED) { in.mark(2048); byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, CONSTRUCTED_VALUE, encBuf.toByteArray()); in.reset(); encBuf.reset(); return value; } switch (tag & 0xC0) { case UNIVERSAL: value = new DERValue(tag, len, readUniversal(tag, len), encBuf.toByteArray()); encBuf.reset(); break; case CONTEXT: byte[] encoded = new byte[len]; in.read(encoded); encBuf.write(encoded); value = new DERValue(tag, len, encoded, encBuf.toByteArray()); encBuf.reset(); break; case APPLICATION: // This should not be reached, since (I think) APPLICATION is // always constructed. throw new DEREncodingException("non-constructed APPLICATION data"); default: throw new DEREncodingException("PRIVATE class not supported"); } return value; }
9,445
public static KeyPairGenerator 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) {} } throw new NoSuchAlgorithmException(algorithm); }
public static KeyPairGenerator 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 e) { } } throw new NoSuchAlgorithmException(algorithm); }
9,446
public static Signature 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) {} } throw new NoSuchAlgorithmException(algorithm); }
public static Signature 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 e) { } } throw new NoSuchAlgorithmException(algorithm); }
9,447
public FileInputStream(File file) throws FileNotFoundException { SecurityManager s = System.getSecurityManager(); if (s != null) s.checkRead(file.getPath()); ch = FileChannelImpl.create(file, FileChannelImpl.READ); }
public FileInputStream(String name) throws FileNotFoundException { SecurityManager s = System.getSecurityManager(); if (s != null) s.checkRead(file.getPath()); ch = FileChannelImpl.create(file, FileChannelImpl.READ); }
9,448
public FileInputStream(File file) throws FileNotFoundException { SecurityManager s = System.getSecurityManager(); if (s != null) s.checkRead(file.getPath()); ch = FileChannelImpl.create(file, FileChannelImpl.READ); }
public FileInputStream(File file) throws FileNotFoundException { SecurityManager s = System.getSecurityManager(); if (s != null) s.checkRead(file.getPath()); ch = FileChannelImpl.create(file, FileChannelImpl.READ); }
9,449
public static KeyStore getInstance(String type) throws KeyStoreException { Provider[] p = Security.getProviders(); for (int i = 0; i < p.length; i++) { try { return getInstance(type, p[i]); } catch (KeyStoreException ignore) { } } throw new KeyStoreException(type); }
public static KeyStore getInstance(String type) throws KeyStoreException { Provider[] p = Security.getProviders(); for (int i = 0; i < p.length; i++) { try { return getInstance(type, p[i]); } catch (KeyStoreException e) { } } throw new KeyStoreException(type); }
9,450
NumberNode(TemplateNode children, TemplateNode next, Expr value, TemplateNode format, String lang, int letterValue, String groupingSeparator, int groupingSize) { super(children, next, format, lang, letterValue, groupingSeparator, groupingSize); this.value = value; }
NumberNode(TemplateNode children, TemplateNode next, Expr value, TemplateNode format, String lang, int letterValue, String groupingSeparator, int groupingSize) { super(children, next, format, lang, letterValue, groupingSeparator, groupingSize); this.value = value; }
9,451
NumberNode(TemplateNode children, TemplateNode next, Expr value, TemplateNode format, String lang, int letterValue, String groupingSeparator, int groupingSize) { super(children, next, format, lang, letterValue, groupingSeparator, groupingSize); this.value = value; }
NumberNode(TemplateNode children, TemplateNode next, Expr value, TemplateNode format, String lang, int letterValue, String groupingSeparator, int groupingSize) { super(children, next, format, lang, letterValue, groupingSeparator, groupingSize); this.value = value; }
9,452
TemplateNode clone(Stylesheet stylesheet) { return new NumberNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet), value.clone(stylesheet), format, lang, letterValue, groupingSeparator, groupingSize); }
TemplateNode clone(Stylesheet stylesheet) { return new NumberNode((children == null) ? null : children.clone(stylesheet), (next == null) ? null : next.clone(stylesheet), value.clone(stylesheet), format, lang, letterValue, groupingSeparator, groupingSize); }
9,453
public Iterator iterator() { final int headerOffset = getAttributeOffset() + IndexRoot.SIZE; return new IndexEntryIterator(getFileRecord(), this, headerOffset + getHeader() .getFirstEntryOffset()); }
public Iterator<IndexEntry> iterator() { final int headerOffset = getAttributeOffset() + IndexRoot.SIZE; return new IndexEntryIterator(getFileRecord(), this, headerOffset + getHeader() .getFirstEntryOffset()); }
9,455
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
9,457
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
9,458
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
9,459
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); mem.setInts(pixels, 0, ofs, width); } }
protected void doDrawAlphaRaster(Raster raster, int srcX, int srcY, int dstX, int dstY, int width, int height, int color) { final byte[] buf = new byte[width]; final int[] pixels = new int[width]; final int c1 = color & 0xFF; final int c2 = (color >> 8) & 0xFF; final int c3 = (color >> 16) & 0xFF; for (int row = 0; row < height; row++) { final int ofs = offset + ((dstY + row) * bytesPerLine) + (dstX << 2); raster.getDataElements(srcX, srcY + row, width, 1, buf); mem.getInts(ofs, pixels, 0, width);// System.out.print(" w" + width + " "); for (int i = 0; i < width; i++) { final int dst = pixels[i]; final int alpha = (buf[i] & 0xFF);// System.out.print(NumberUtils.hex(alpha, 2)); final int d1 = (dst & 0xFF); final int d2 = (dst >> 8) & 0xFF; final int d3 = (dst >> 16) & 0xFF; final int r1 = ((alpha * (c1 - d1)) >> 8) + d1; final int r2 = ((alpha * (c2 - d2)) >> 8) + d2; final int r3 = ((alpha * (c3 - d3)) >> 8) + d3; pixels[i] = (r1 & 0xFF) + ((r2 & 0xFF) << 8) + ((r3 & 0xFF) << 16); // pixels[i] = (alpha & 0xFF) + ((alpha & 0xFF) << 8) + ((alpha & 0xFF) << 16);// pixels[i] = (alpha > 128) ? color : dst; }// System.out.println(); if (modified) { mem.setInts(pixels, 0, ofs, width); } } }
9,460
public Object getDataElements(int x, int y, int w, int h, Object outData) { return sampleModel.getDataElements(x-sampleModelTranslateX, y-sampleModelTranslateY, w, h, outData, dataBuffer); }
public Object getDataElements(int x, int y, int w, int h, Object outData) { return sampleModel.getDataElements(x-sampleModelTranslateX, y-sampleModelTranslateY, w, h, outData, dataBuffer); }
9,461
public Object getDataElements(int x, int y, int w, int h, Object outData) { return sampleModel.getDataElements(x-sampleModelTranslateX, y-sampleModelTranslateY, w, h, outData, dataBuffer); }
public Object getDataElements(int x, int y, int w, int h, Object outData) { return sampleModel.getDataElements(x-sampleModelTranslateX, y-sampleModelTranslateY, w, h, outData, dataBuffer); }
9,462
public abstract void setInt(int memPtr, int value, int count);
public abstract void setInt(int memPtr, int value);
9,463
public JCheckBoxMenuItem() { // TODO } // JCheckBoxMenuItem()
public JCheckBoxMenuItem() { // TODO } // JCheckBoxMenuItem()
9,464
public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJCheckBoxMenuItem(this); } // if return accessibleContext; } // getAccessibleContext()
public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJCheckBoxMenuItem(this); } // if return accessibleContext; } // getAccessibleContext()
9,465
public Object[] getSelectedObjects() { return null; // TODO } // getSelectedObjects()
public Object[] getSelectedObjects() { return null; // TODO } // getSelectedObjects()
9,466
public boolean getState() { return false; // TODO } // getState()
public boolean getState() { return false; // TODO } // getState()
9,467
protected String paramString() { return null; // TODO } // paramString()
protected String paramString() { return null; // TODO } // paramString()
9,468
public synchronized void setState(boolean state) { // TODO } // setState()
public synchronized void setState(boolean state) { // TODO } // setState()
9,469
public Object[] getSelectedObjects() { //Returns an array (length 1) containing the label or null if the button is not selected. return null; }
public Object[] getSelectedObjects() { //Returns an array (length 1) containing the label or null if the button is not selected. return null; }
9,470
public static final CertificateFactory getInstance(String type) throws CertificateException { Provider[] p = Security.getProviders (); for (int i = 0; i < p.length; i++) { String classname = p[i].getProperty ("CertificateFactory." + type); if (classname != null) return getInstance (classname, type, p[i]); } throw new CertificateException(type); }
public static final CertificateFactory getInstance(String type) throws CertificateException { Provider[] p = Security.getProviders (); for (int i = 0; i < p.length; i++) { String classname = p[i].getProperty ("CertificateFactory." + type); if (classname != null) return getInstance (classname, type, p[i]); } throw new CertificateException(type); }
9,471
private void queueEvent() { synchronized (queueLock) { queue++; if (queue == 1) SwingUtilities.invokeLater(new Runnable() { public void run() { drainEvents(); } }); } }
private void queueEvent() { synchronized (queueLock) { queue++; if (queue == 1) SwingUtilities.invokeLater(new Runnable() { public void run() { drainEvents(); } }); } }
9,472
public XMLReader getXMLReader() { return reader; } // getXMLReader()
public XMLReader getXMLReader() { return reader; } // getXMLReader()
9,473
public void setInputSource(InputSource source) { this.inputSource = source; } // setInputSource()
public void setInputSource(InputSource source) { this.inputSource = source; } // setInputSource()
9,474
public void setSystemId(String systemID) { if (inputSource != null) { inputSource.setSystemId(systemID); } } // setSystemId()
public void setSystemId(String systemID) { if (inputSource != null) { inputSource.setSystemId(systemID); } } // setSystemId()
9,475
public void setSystemId(String systemID) { if (inputSource != null) { inputSource.setSystemId(systemID); } } // setSystemId()
public void setSystemId(String systemID) { if (inputSource != null) { inputSource.setSystemId(systemID); // setSystemId()
9,476
public void setXMLReader(XMLReader reader) { this.reader = reader; } // setXMLReader()
public void setXMLReader(XMLReader reader) { this.reader = reader; } // setXMLReader()
9,477
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
public static InputSource sourceToInputSource(Source source) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
9,478
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
9,479
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
9,480
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
9,481
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } return ok ? retval : null; }
public static InputSource sourceToInputSource (Source in) { InputSource retval; boolean ok = false; if (in instanceof SAXSource) { return ((SAXSource) in).inputSource; } if (in.getSystemId () != null) { retval = new InputSource (in.getSystemId ()); ok = true; } else retval = new InputSource (); if (in instanceof StreamSource) { StreamSource ss = (StreamSource) in; if (ss.getReader () != null) { retval.setCharacterStream (ss.getReader ()); ok = true; } else if (ss.getInputStream () != null) { retval.setByteStream (ss.getInputStream ()); ok = true; } if (ss.getPublicId () != null) retval.setPublicId (ss.getPublicId ()); } }
9,482
public StructMember(String a_name, TypeCode a_type, IDLType a_type_def) { name = a_name; type = a_type; type_def = a_type_def; }
public StructMember() { name = a_name; type = a_type; type_def = a_type_def; }
9,484
public StructMember(String a_name, TypeCode a_type, IDLType a_type_def) { name = a_name; type = a_type; type_def = a_type_def; }
public StructMember(String a_name, TypeCode a_type, IDLType a_type_def) { name = a_name; type = a_type; type_def = a_type_def; }
9,485
public AlreadyBoundException(String s) { super(s); }
public AlreadyBoundException() { super(s); }
9,486
public AlreadyBoundException(String s) { super(s); }
public AlreadyBoundException(String s) { }
9,487