From: <ker...@us...> - 2013-11-06 07:09:51
|
Revision: 23316 http://jedit.svn.sourceforge.net/jedit/?rev=23316&view=rev Author: kerik-sf Date: 2013-11-06 07:09:37 +0000 (Wed, 06 Nov 2013) Log Message: ----------- Clicking node-set result shows element in editor - Saxon only! - this is done by letting saxon parse from SAX by itself, so the XPathAdapter interface is extended to let the adapter load the document. - data type displayed is more concise now (returns element(), not the actual qname of the element). - data model of the Node-set summary uses the results directly Modified Paths: -------------- plugins/XSLT/trunk/docs/users-guide.xml plugins/XSLT/trunk/xslt/NodeSetTableModel.java plugins/XSLT/trunk/xslt/Saxon9XPathAdapter.java plugins/XSLT/trunk/xslt/XMLFragmentsString.java plugins/XSLT/trunk/xslt/XPathAdapter.java plugins/XSLT/trunk/xslt/XPathExpressionPanel.java plugins/XSLT/trunk/xslt/XPathTool.java plugins/XSLT/trunk/xslt/XalanXPathAdapter.java plugins/XSLT/trunk/xslt/XalanXPathNode.java plugins/XSLT/trunk/xslt/XsltSettings.java Added Paths: ----------- plugins/XSLT/trunk/xslt/DOMXPathAdapter.java Modified: plugins/XSLT/trunk/docs/users-guide.xml =================================================================== --- plugins/XSLT/trunk/docs/users-guide.xml 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/docs/users-guide.xml 2013-11-06 07:09:37 UTC (rev 23316) @@ -329,18 +329,17 @@ <para>Press Ctrl-Enter when in the XPath expression text area to invoke the "Evaluate XPath" action.</para> </listitem> - </itemizedlist> - </para> - <para> - The following improvements should eventually be made to XPath Tool. - <itemizedlist> - <listitem> - <para> - When the result of an evaluation is a Node set, it would be nice - to have a "Hyper Search" type of result. In other words, each - node in the list could be clicked to highlight the relevant portion - of the XML doc in the current buffer. - </para> + <listitem><para>Select a node in the Node-set summary table to move current's + edit pane caret to the location of the node in the buffer. The file + will be opened if necessary.</para> + <para>This only works for nodes actually coming + from the source document: if you compute 1 + 1, it will not work.</para> + <para>This only work for the Saxon XPath engine. There may be a way to + implement it also for Xalan, but I've not found an obvious one.</para> + <para>The location information provided by the engine is not much: only + a line and column number, corresponding to the end of the parent element + start tag. So it's not easy to select the node, only to place the caret + at the relevant location.</para> </listitem> </itemizedlist> </para> @@ -462,6 +461,9 @@ <itemizedlist> <listitem><para>XPath tool: press Ctrl+Enter from expression panel to trigger evaluating the XPath expression.</para></listitem> <listitem><para>XPath tool: also grab default namespace from input document (xmlns=...).</para></listitem> + <listitem><para>XPath tool: selecting node results from the Node-set summary + opens the buffer if necessary and moves the caret to the location in the document. + This only works with Saxon XPath engine.</para></listitem> </itemizedlist> </para> <para> Added: plugins/XSLT/trunk/xslt/DOMXPathAdapter.java =================================================================== --- plugins/XSLT/trunk/xslt/DOMXPathAdapter.java (rev 0) +++ plugins/XSLT/trunk/xslt/DOMXPathAdapter.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -0,0 +1,113 @@ +/* + * DOMXPathAdapter.java - common code for DOM based XPathAdapters + * + * Copyright (c) 2013 Eric Le Lay + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package xslt; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.traversal.DocumentTraversal; +import org.w3c.dom.traversal.NodeFilter; +import org.w3c.dom.traversal.NodeIterator; + +import java.util.Map; +import java.util.HashMap; +import java.util.Collections; + +import org.gjt.sp.jedit.Buffer; +import org.gjt.sp.util.Log; + +import xml.CharSequenceReader; +import xml.PathUtilities; + +/** + * Common code for XPathAdapters based on DOM input. + * There is only xalan for now, but it's mainly to extract + * standard DOM operations from Xalan specific class. + */ +public abstract class DOMXPathAdapter implements XPathAdapter { + + @Override + public Document buildDocument(Buffer source) + throws IOException,ParserConfigurationException,SAXException + { + CharSequence chars = source.getSegment(0,source.getLength()); + CharSequenceReader reader = new CharSequenceReader(chars); + InputSource ss = new InputSource(reader); + ss.setSystemId(PathUtilities.pathToURL(source.getPath())); + return XPathTool.parse(ss); + } + + @Override + public Document buildDocument(URI source) + throws IOException,ParserConfigurationException,SAXException + { + String sourceURL = source.toString(); + InputSource inputSource = xml.Resolver.instance().resolveEntity("",sourceURL); + return XPathTool.parse(inputSource); + } + + @Override + public Map<String,List<String>> grabNamespaces(Document document) + { + Map<String,List<String>> bindings = new HashMap<String,List<String>>(); + + if (document.getImplementation().hasFeature("traversal", "2.0")) { + DocumentTraversal traversable = (DocumentTraversal) document; + NodeIterator iterator = traversable.createNodeIterator( + document, NodeFilter.SHOW_ELEMENT,null, true); + + Node node; + while ((node = iterator.nextNode()) != null) { + NamedNodeMap attrs = node.getAttributes(); + for(int i=0;i<attrs.getLength();i++) { + Node a = attrs.item(i); + + if("xmlns".equals(a.getPrefix()) + || (a.getPrefix() == null && "xmlns".equals(a.getLocalName()))) { + String prefix = a.getPrefix() == null ? "" : a.getLocalName(); + String ns = a.getNodeValue(); + List l; + if(bindings.containsKey(prefix)){ + l = bindings.get(prefix); + } else { + l = new ArrayList<String>(); + bindings.put(prefix,l); + } + if(!l.contains(ns)) { + l.add(ns); + } + } + } + } + } else { + Log.log(Log.ERROR,this,"DomImplementation doesn't support DOM Traversal"); + } + return Collections.emptyMap(); + } +} Property changes on: plugins/XSLT/trunk/xslt/DOMXPathAdapter.java ___________________________________________________________________ Added: svn:keywords + Id Author Revision Date Modified: plugins/XSLT/trunk/xslt/NodeSetTableModel.java =================================================================== --- plugins/XSLT/trunk/xslt/NodeSetTableModel.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/NodeSetTableModel.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -2,6 +2,7 @@ * NodeSetTableModel.java - Table model for XPath node set results * * Copyright (c) 2002 Robert McKinnon + * Copyright (c) 2013 Eric Le Lay * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,9 +22,10 @@ package xslt; import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.util.Log; import javax.swing.table.AbstractTableModel; - +import static xslt.XPathAdapter.XPathNode; /** * Table model for XPath node set results. * @@ -38,15 +40,15 @@ private static final int NAME_COL = 1; private static final int VALUE_COL = 2; - private static final String[] ALL_COLUMNS = {TYPE, NAME, VALUE}; - private static final String[] NO_NAME_COLUMN = {TYPE, VALUE}; - private static final String[] NO_VALUE_COLUMN = {TYPE, NAME}; - private static final String[] NO_NAME_OR_VALUE_COLUMN = {TYPE}; + private static final String[] ALL_COLUMNS_NAMES = {TYPE, NAME, VALUE}; + private static final int[] ALL_COLUMNS = {TYPE_COL, NAME_COL, VALUE_COL}; + private static final String EMPTY_STRING = ""; - private String[] columnNames = ALL_COLUMNS; - private Object[][] data; + private String[] columnNames = ALL_COLUMNS_NAMES; + private int[] columns = ALL_COLUMNS; + private XPathAdapter.Result data; /** @@ -64,7 +66,12 @@ if(data == null) { return 0; } else { - return data.length; + try { + return data.size(); + } catch(Exception e) { + Log.log(Log.WARNING, NodeSetTableModel.class, "Error getting result size", e); + return 0; + } } } @@ -73,16 +80,44 @@ * Implements method from interface {@link javax.swing.table.TableModel}. */ public Object getValueAt(int row, int col) { - Object cell = data[row][col]; - - if(cell == null) { - return EMPTY_STRING; - } else { - return cell; + try{ + if(row >= 0 && row < getRowCount()) { + XPathNode node = data.get(row); + if(col >= 0 && col < columns.length){ + switch(columns[col]){ + case TYPE_COL: + return node.getType(); + case NAME_COL: + return node.getName(); + case VALUE_COL: + return node.getDomValue(); + default: + throw new IllegalStateException("invalid column: "+columns[col]); + } + } } + }catch(Exception e){ + if(e instanceof IllegalStateException) throw (IllegalStateException)e; + else{ + Log.log(Log.WARNING, NodeSetTableModel.class, "Error getting result node info", e); + } + } + + return EMPTY_STRING; } + public XPathNode getValueAt(int row){ + if(row >= 0 && row < getRowCount()) { + try{ + return data.get(row); + }catch(Exception e){ + Log.log(Log.WARNING, NodeSetTableModel.class, "Error getting result node "+row, e); + } + } + return null; + } + /** * Overrides method from class {@link javax.swing.table.AbstractTableModel}. */ @@ -100,99 +135,53 @@ /** - * Overrides method from class {@link javax.swing.table.AbstractTableModel}. - */ - public void setValueAt(Object value, int row, int col) { - data[row][col] = value; - fireTableCellUpdated(row, col); - } - - - /** - * Sets the node type in the given row. - */ - public void setNodeType(String type, int row) { - setValueAt(type, row, TYPE_COL); - } - - - /** - * Sets the node name in the given row. - */ - public void setNodeName(String name, int row) { - setValueAt(name, row, NAME_COL); - } - - - /** - * Sets the node value in the given row. - */ - public void setNodeValue(String value, int row) { - setValueAt(value, row, VALUE_COL); - } - - - /** * Deletes current model rows, puts all columns back in model if necessary and * adds new rows equal to the given new row count. */ - public void resetRows(int newRowCount) { + public void resetRows(XPathAdapter.Result result) throws Exception { if(getRowCount() > 0) { fireTableRowsDeleted(0, getRowCount() - 1); } - if(columnNames != ALL_COLUMNS) { - setAllColumns(); - fireTableStructureChanged(); - } + this.data = result; - this.data = new Object[newRowCount][getColumnCount()]; + if(result.isNodeSet()){ + boolean isNodeWithName = false; + boolean isNodeWithValue = false; + XPathAdapter.XPathNode node; - for(int i = 0; i < newRowCount; i++) { - this.data[i] = new String[columnNames.length]; - } + for (int i = 0; i < result.size(); i++) { + node = result.get(i); - if(newRowCount > 0) { - fireTableRowsInserted(0, newRowCount - 1); - } - } + if (node != null) { + isNodeWithName = isNodeWithName || node.hasExpandedName(); + isNodeWithValue = isNodeWithValue || node.hasDomValue(); + } + } + int[] tmpcols = new int[ALL_COLUMNS.length]; + tmpcols[0] = TYPE_COL; + int icol = 1; + if(isNodeWithName){ + tmpcols[icol++] = NAME_COL; + } + if(isNodeWithValue){ + tmpcols[icol++] = VALUE_COL; + } - private void setAllColumns() { - this.columnNames = ALL_COLUMNS; - fireTableStructureChanged(); - } + columns = new int[icol]; + columnNames = new String[icol]; + for(int i=0;i<columns.length;i++){ + columns[i] = tmpcols[i]; + columnNames[i] = ALL_COLUMNS_NAMES[tmpcols[i]]; + } + fireTableStructureChanged(); - /** - * Removes the node name column from the table model. - */ - public void removeNameColumn() { - // Need to put values from the last column into the middle column - for(int i = 0; i < getRowCount(); i++) { - data[i][NAME_COL] = data[i][VALUE_COL]; + if(result.size() > 0) { + fireTableRowsInserted(0, result.size() - 1); + } } - - this.columnNames = NO_NAME_COLUMN; - fireTableStructureChanged(); } - - /** - * Removes the node value column from the table model. - */ - public void removeValueColumn() { - this.columnNames = NO_VALUE_COLUMN; - fireTableStructureChanged(); - } - - - /** - * Removes the node name and node value columns from the table model. - */ - public void removeNameOrValueColumn() { - this.columnNames = NO_NAME_OR_VALUE_COLUMN; - fireTableStructureChanged(); - } - } \ No newline at end of file Modified: plugins/XSLT/trunk/xslt/Saxon9XPathAdapter.java =================================================================== --- plugins/XSLT/trunk/xslt/Saxon9XPathAdapter.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/Saxon9XPathAdapter.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -1,7 +1,7 @@ /* * Saxon9XPathAdapter.java - use the XPath 2.0 Saxon engine * - * Copyright (c) 2010 Eric Le Lay + * Copyright (c) 2010,2013 Eric Le Lay * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,14 +21,17 @@ import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPathExpressionException; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import org.gjt.sp.jedit.Buffer; + import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Node; +import org.xml.sax.SAXException; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.List; @@ -36,49 +39,130 @@ import java.util.Iterator; import java.util.Collections; - +import net.sf.saxon.dom.NodeOverNodeInfo; +import net.sf.saxon.s9api.DocumentBuilder; +import net.sf.saxon.s9api.ItemTypeFactory; +import net.sf.saxon.s9api.Processor; +import net.sf.saxon.s9api.SaxonApiException; +import net.sf.saxon.s9api.XdmItem; +import net.sf.saxon.s9api.XdmNode; +import net.sf.saxon.s9api.XdmValue; +import net.sf.saxon.s9api.XPathCompiler; import net.sf.saxon.xpath.XPathFactoryImpl; -import net.sf.saxon.xpath.XPathExpressionImpl; import net.sf.saxon.trans.XPathException; import net.sf.saxon.type.Type; -import net.sf.saxon.om.SequenceIterator; +import net.sf.saxon.type.ItemType; import net.sf.saxon.om.NodeInfo; -/*import net.sf.saxon.om.GroundedIterator; -import net.sf.saxon.om.GroundedValue; -*/ -import net.sf.saxon.om.Item; -import net.sf.saxon.dom.DocumentWrapper; -import net.sf.saxon.dom.DOMNodeWrapper; -import net.sf.saxon.dom.DOMNodeList; -import net.sf.saxon.value.SequenceExtent; -import net.sf.saxon.value.Cardinality; import net.sf.saxon.Configuration; -import net.sf.saxon.type.TypeHierarchy; -import net.sf.saxon.type.ItemType; +import org.gjt.sp.util.Log; + +import xml.CharSequenceReader; +import xml.PathUtilities; + /** * Implementation of XPathAdapter using the Saxon 9 engine */ public class Saxon9XPathAdapter implements XPathAdapter { - final XPathFactoryImpl factory = new XPathFactoryImpl(); - - public Result evaluateExpression(Document doc, Map<String,String> prefixes, String expression) throws XPathException,XPathExpressionException { - XPath xpath = factory.newXPath(); - xpath.setNamespaceContext(new NamespaceContextImpl(prefixes)); - - XPathExpressionImpl expr = (XPathExpressionImpl)xpath.compile(expression); - - return new SaxonResult(expr.rawIterator(new DocumentWrapper(doc,doc.getBaseURI(),expr.getConfiguration())),expr.getConfiguration()); + final XPathFactoryImpl factory; + final Configuration config; + final Processor processor; + + public Saxon9XPathAdapter() { + config = new Configuration(); + config.setLineNumbering(true); + factory = new XPathFactoryImpl(config); + processor = new Processor(config); } - - + + @Override + public Document buildDocument(Buffer source) throws IOException,SAXException,SaxonApiException { + CharSequence chars = source.getSegment(0,source.getLength()); + CharSequenceReader reader = new CharSequenceReader(chars); + StreamSource ss = new StreamSource(reader, PathUtilities.pathToURL(source.getPath())); + return buildWrappedDocument(ss); + } + + @Override + public Document buildDocument(URI source) throws IOException,SAXException,SaxonApiException { + //TODO: would it make sense to set the resolver to xml.Resolver ? + StreamSource ss = new StreamSource(source.toString()); + return buildWrappedDocument(ss); + } + + private Document buildWrappedDocument(Source source) throws SaxonApiException,IOException,SAXException { + try { + DocumentBuilder builder = processor.newDocumentBuilder(); + XdmNode doc = builder.build(source); + return (Document)NodeOverNodeInfo.wrap(doc.getUnderlyingNode()); + } catch(SaxonApiException e) { + if(e.getCause() instanceof IOException) { + throw (IOException)e.getCause(); + } else if(e.getCause() instanceof SAXException) { + throw (SAXException)e.getCause(); + } else { + throw e; + } + } + } + + + public Map<String,List<String>> grabNamespaces(Document doc) throws IllegalArgumentException { + if(!(doc instanceof NodeOverNodeInfo))throw new IllegalArgumentException("Document givent to Saxon9XPathAdapter.grabNamespaces not of the right class"); + XdmNode node = new XdmNode(((NodeOverNodeInfo)doc).getUnderlyingNodeInfo()); + + XPathCompiler comp = processor.newXPathCompiler(); + + Map<String,List<String>> bindings = new HashMap<String,List<String>>(); + + try{ + XdmValue res = comp.evaluate( + "for $n in //*/namespace::* return ($n/name(), string($n))" + , node); + + for(int i=0;i<res.size()-1;){ + String prefix = res.itemAt(i++).getStringValue(); + String ns = res.itemAt(i++).getStringValue(); + if(XMLConstants.XML_NS_URI.equals(ns))continue; + List<String> bound = bindings.get(prefix); + if(bound == null){ + bound = new ArrayList<String>(); + bindings.put(prefix, bound); + } + if(!bound.contains(ns)){ + bound.add(ns); + } + } + }catch(SaxonApiException e){ + Log.log(Log.ERROR,this,"known node query failed",e); + } + return bindings; + } + + @Override + public Result evaluateExpression(Document doc, Map<String,String> prefixes, String expression) + throws SaxonApiException,XPathException + { + if(!(doc instanceof NodeOverNodeInfo))throw new IllegalArgumentException("Document givent to Saxon9XPathAdapter.evaluateExpression not of the right class"); + XdmNode node = new XdmNode(((NodeOverNodeInfo)doc).getUnderlyingNodeInfo()); + XPathCompiler comp = processor.newXPathCompiler(); + for(Map.Entry<String,String> en: prefixes.entrySet()){ + comp.declareNamespace(en.getKey(),en.getValue()); + } + + XdmValue res = comp.evaluate(expression, node); + + return new SaxonResult(res, processor); + } + + static class SaxonXPathNode implements XPathNode { - private Item item; + private XdmItem item; private ItemType it; - SaxonXPathNode(Item i,TypeHierarchy hierarchy){ + SaxonXPathNode(XdmItem i,ItemType it){ this.item = i; - this.it = Type.getItemType(item,hierarchy); + this.it = it; } public boolean hasExpandedName(){ @@ -94,7 +178,7 @@ return false; } } - + public boolean hasDomValue(){ switch (it.getPrimitiveType()) { case Type.DOCUMENT: @@ -104,140 +188,128 @@ return true; } } - + public String getType(){ - return it.toString(); + // too much details if not calling getPrimitiveItemType (like "element(Q{urn:joe}hello)") + return it.getPrimitiveItemType().toString(); } - + public String getName(){ - if(item instanceof NodeInfo){ - return ((NodeInfo)item).getDisplayName(); + if(item.getUnderlyingValue() instanceof NodeInfo){ + return ((NodeInfo)item.getUnderlyingValue()).getDisplayName(); }else { return null; } } - + public String getDomValue() throws XPathException{ - return SequenceExtent.makeSequenceExtent(item.iterate()).getStringValue(); + return item.getStringValue(); } - + + /** + * @return the line number of the node + */ + public int getLineNumber(){ + if(item.getUnderlyingValue() instanceof NodeInfo){ + return ((NodeInfo)item.getUnderlyingValue()).getLineNumber(); + }else { + throw new UnsupportedOperationException("I told you I didn't have location information !"); + } + } + + /** + * @return the column number of the node + */ + public int getColumnNumber(){ + if(item.getUnderlyingValue() instanceof NodeInfo){ + return ((NodeInfo)item.getUnderlyingValue()).getColumnNumber(); + }else { + throw new UnsupportedOperationException("I told you I didn't have location information !"); + } + } + + /** + * @return true for nodes, false overwise + */ + public boolean hasLocation() { + return (item.getUnderlyingValue() instanceof NodeInfo); + } + } - + static class SaxonResult implements Result{ - private SequenceExtent se; - private Configuration config; - - SaxonResult(SequenceIterator si,Configuration c) throws XPathException{ - SequenceExtent se = new SequenceExtent(si); - ItemType it = se.getItemType(c.getTypeHierarchy()); + private XdmValue value; + private ItemTypeFactory typeFactory; - this.se = se; - this.config = c; + SaxonResult(XdmValue value, Processor processor) throws XPathException{ + this.value = value; + this.typeFactory = new ItemTypeFactory(processor); } - + public String getType(){ - ItemType it = se.getItemType(config.getTypeHierarchy()); - if(se.getLength()==0) { + if(value.size()==0) { return "empty sequence"; - } else if(se.getLength() == 1) { - return it.toString(); } else { - return "sequence of "+it.toString(); + XdmItem itm = value.itemAt(0); + // too much details if not calling getPrimitiveItemType (like "element(Q{urn:joe}hello)") + ItemType type = typeFactory.getItemType(itm).getUnderlyingItemType().getPrimitiveItemType(); + if(value.size() == 1){ + return type.toString(); + }else{ + return "sequence of "+type.toString(); + } } } - + public boolean isNodeSet(){ return true; } - - public String getStringValue() throws XPathException{ - return se.getStringValue(); + + public String getStringValue() throws XPathException { + if(value.size()==0) { + return "()"; + } else if(value.size() == 1) { + return value.itemAt(0).getStringValue(); + } else { + StringBuilder sb = new StringBuilder(); + sb.append('('); + for(int i=0; i< value.size(); i++){ + XdmItem itm = value.itemAt(i); + if(i>0){ + sb.append(','); + } + sb.append(itm.getStringValue()); + } + sb.append(')'); + return sb.toString(); + } } - + public int size(){ - return se.getLength(); + return value.size(); } - + public XPathNode get(int i){ - return new SaxonXPathNode(se.itemAt(i),config.getTypeHierarchy()); + XdmItem itm = value.itemAt(i); + return new SaxonXPathNode(itm, typeFactory.getItemType(itm).getUnderlyingItemType()); } - + public XMLFragmentsString toXMLFragmentsString() throws XPathException { - XMLFragmentsString res = new XMLFragmentsString(se.getLength()); - for(int i=0;i<se.getLength();i++) { - Item it = se.itemAt(i); - if(it instanceof DOMNodeWrapper) { - res.setNode(i,(Node)((DOMNodeWrapper)it).getRealNode()); + XMLFragmentsString res = new XMLFragmentsString(value.size()); + for(int i=0;i<value.size();i++) { + XdmItem it = value.itemAt(i); + if(it instanceof XdmNode) { + res.setNode(i,NodeOverNodeInfo.wrap(((XdmNode)it).getUnderlyingNode())); } else { res.setText(i,it.getStringValue()); } } return res; } - + public String toString(){ - return "Saxon9Adapter.Result{"+se+"}"; + return "Saxon9Adapter.Result{"+value+"}"; } } - - public static class NamespaceContextImpl implements NamespaceContext{ - private Map<String,String> mappings; - private Map<String,List<String>> reverseMappings; - - public NamespaceContextImpl(Map<String,String> mappings) { - this.mappings = mappings; - } - - public String getNamespaceURI(String prefix){ - if(XMLConstants.XML_NS_PREFIX.equals(prefix)) { - return XMLConstants.XML_NS_URI; - } else if(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) { - return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; - } else if(mappings.containsKey(prefix)) { - return mappings.get(prefix); - } else if(prefix == null){ - throw new IllegalArgumentException("null prefix"); - } else { - return XMLConstants.NULL_NS_URI; - } - } - - public String getPrefix(String namespaceURI){ - Iterator it = getPrefixes(namespaceURI); - if(it.hasNext()) return (String)it.next(); - else return null; - } - - public Iterator getPrefixes(String namespaceURI){ - if(reverseMappings == null) { - initReverseMappings(); - } - - if(XMLConstants.XML_NS_URI.equals(namespaceURI)) { - return Collections.singletonList(XMLConstants.XML_NS_PREFIX).iterator(); - } else if(XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { - return Collections.singletonList(XMLConstants.XMLNS_ATTRIBUTE).iterator(); - } else if(reverseMappings.containsKey(namespaceURI)) { - return Collections.unmodifiableList(reverseMappings.get(namespaceURI)).iterator(); - } else if(namespaceURI == null){ - throw new IllegalArgumentException("null namespaceURI"); - } else { - return Collections.emptyList().iterator(); - } - } - - private void initReverseMappings() { - reverseMappings = new HashMap<String,List<String>>(); - for(Map.Entry<String,String> entry: mappings.entrySet()) { - List<String> l; - if(reverseMappings.containsKey(entry.getValue())) { - l = reverseMappings.get(entry.getValue()); - } else { - l = new LinkedList<String>(); - reverseMappings.put(entry.getValue(),l); - } - l.add(entry.getKey()); - } - } - } + } Modified: plugins/XSLT/trunk/xslt/XMLFragmentsString.java =================================================================== --- plugins/XSLT/trunk/xslt/XMLFragmentsString.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XMLFragmentsString.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -26,6 +26,7 @@ import org.w3c.dom.NodeList; import java.text.MessageFormat; +import javax.xml.XMLConstants; /** * Represents a sequence of XML fragments as a string. @@ -153,7 +154,7 @@ private void appendProcessingInstructionNode(Node node) { buffer.append("<?"); buffer.append(node.getNodeName()); - buffer.append(" "); + buffer.append(' '); buffer.append(node.getNodeValue()); buffer.append("?>"); buffer.append(NL); @@ -238,8 +239,11 @@ private void appendAttributes(NamedNodeMap attributes) { for(int i = 0; i < attributes.getLength(); i++) { + Node attr = attributes.item(i); + // skip ns declarations + if(XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI()))continue; buffer.append(' '); - appendAttribute(attributes.item(i)); + appendAttribute(attr); } } Modified: plugins/XSLT/trunk/xslt/XPathAdapter.java =================================================================== --- plugins/XSLT/trunk/xslt/XPathAdapter.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XPathAdapter.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -19,25 +19,52 @@ */ package xslt; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; +import java.util.List; import java.util.Map; +import org.w3c.dom.Document; + +import org.gjt.sp.jedit.Buffer; +import java.net.URI; + /** * interface embodying all the services required for the XPath Tool */ public interface XPathAdapter { - + /** + * construct an adapter-specific document from given input. + * The XPathAdapter doesn't have to monitor the source to invalidate + * the cache or whatever. + * @return a document for faster later processing or null if not applicable + */ + public Document buildDocument(Buffer source) throws Exception; + + /** + * construct an adapter-specific document from given input. + * The XPathAdapter doesn't have to monitor the source to invalidate + * the cache or whatever. + * @return a document for faster later processing or null if not applicable + */ + public Document buildDocument(URI source) throws Exception; + + + /** * evaluate expression against doc, given prefixes - * @param doc source document + * @param doc source document from previous call to buildDocument (can be null) * @param prefixes prefix->namespace bindings * @param expression xpath expression to evaluate * @return result of the evaluation */ public Result evaluateExpression(Document doc, Map<String,String> prefixes, String expression) throws Exception; - + /** + * get all namespace bindings from source document + * + */ + public Map<String,List<String>> grabNamespaces(Document document); + + /** * result of an evaluation. * Provides methods to get type, size and contents of the result. */ @@ -50,19 +77,19 @@ public String getStringValue() throws Exception; /** @return number of items in the node-set/sequence */ public int size() throws Exception; - + /** * @param i index of the wanted item. Contrary to positions, i starts at 0 * @return ith item of the result */ public XPathNode get(int i) throws Exception; - + /** * @return an XMLFragmentsString configured to represent this result */ public XMLFragmentsString toXMLFragmentsString() throws Exception; } - + /** one component of the Result, used in the Node-set summary table of the XPath tool */ public static interface XPathNode{ /** @return has got a name (e.g. an element has a name) */ @@ -79,5 +106,23 @@ * @return string value of this item */ public String getDomValue()throws Exception; + + /** + * @return the line number of the node, if any (1-based) + * @throws UnsupportedOperationException if not supported + */ + public int getLineNumber() throws UnsupportedOperationException; + + /** + * @return the column number of the node, if any (1-based) + * @throws UnsupportedOperationException if not supported + */ + public int getColumnNumber() throws UnsupportedOperationException; + + /** + * @return is location information available + */ + public boolean hasLocation(); + } } Modified: plugins/XSLT/trunk/xslt/XPathExpressionPanel.java =================================================================== --- plugins/XSLT/trunk/xslt/XPathExpressionPanel.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XPathExpressionPanel.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -36,7 +36,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -203,7 +202,7 @@ if (wildCardExpr != null) { Document xdoc = null; try { - xdoc = xpathTool.getCurrentDocument(); + xdoc = xpathTool.getCurrentDocument(xpathTool.getXPath()); } catch (Exception e) { XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathExpressionPanel.this); Modified: plugins/XSLT/trunk/xslt/XPathTool.java =================================================================== --- plugins/XSLT/trunk/xslt/XPathTool.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XPathTool.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -3,6 +3,7 @@ * * Copyright (C) 2002 Greg Merrill * 2002, 2003, 2004 Robert McKinnon + * 2013 Eric Le Lay * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,12 +34,11 @@ import java.awt.event.ItemListener; import java.io.File; import java.io.IOException; -import java.lang.reflect.Constructor; import java.net.URL; +import java.net.URI; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.ArrayList; import java.util.List; import javax.swing.ImageIcon; @@ -64,13 +64,14 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; -import org.apache.xpath.XPathAPI; -import org.apache.xpath.objects.XObject; import org.gjt.sp.jedit.buffer.JEditBuffer; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.EBMessage; +import org.gjt.sp.jedit.EditBus; +import org.gjt.sp.jedit.EditPane; import org.gjt.sp.jedit.View; import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.textarea.JEditTextArea; import org.gjt.sp.jedit.buffer.BufferAdapter; import org.gjt.sp.jedit.gui.DefaultFocusComponent; import org.gjt.sp.jedit.msg.BufferUpdate; @@ -80,16 +81,14 @@ import org.gjt.sp.util.Log; import org.gjt.sp.util.Task; import org.gjt.sp.util.ThreadUtilities; + +import static org.gjt.sp.jedit.EditBus.EBHandler; + import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.traversal.DocumentTraversal; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import xml.PathUtilities; +import static xslt.XPathAdapter.XPathNode; /** * GUI for evaluating XPath expressions. @@ -101,7 +100,7 @@ ActionListener, DefaultFocusComponent, ItemListener { public static final String XPATH_ADAPTER_PROP="xpath.adapter"; - + private View view; private final XsltAction grabNSAction = new GrabNSAction(); private final BufferOrFileVFSSelector inputSelectionPanel; @@ -112,10 +111,12 @@ private final ResultsPanel resultValuePanel = new ResultsPanel("xpath.result.value"); private final NodeSetResultsPanel nodeSetTablePanel = new NodeSetResultsPanel("xpath.result.node-set-summary"); private final XmlFragmentsPanel xmlFragmentsPanel = new XmlFragmentsPanel("xpath.result.xml-fragments"); - + private JPanel dataTypePanel; private boolean autoCompleteEnabled; private XPathAdapter adapter; + /* to be able to go to editor upon node-set summary selection */ + private String lastSourcePath; public XPathTool(View view) { super(new GridBagLayout()); @@ -124,7 +125,7 @@ expressionPanel = new XPathExpressionPanel(view); expressionPanel.addActionListener(this); nsPanel = new KeyValuePanel("xpath.ns"); - + inputSelectionPanel = new BufferOrFileVFSSelector(view,"xpath.source"); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(jEdit.getProperty("xpath.result.data-type.label")), BorderLayout.NORTH); @@ -142,7 +143,7 @@ gbc.fill = GridBagConstraints.BOTH; gbc.weightx = gbc.weighty = 1; gbc.gridy = 2; - + JSplitPane exprNSSplit = getSplitPane(expressionPanel,nsPanel,70); add(exprNSSplit, gbc); @@ -157,7 +158,7 @@ gbc.weighty = 6; gbc.fill = GridBagConstraints.BOTH; add(getSplitPane(), gbc); - + } @@ -172,7 +173,7 @@ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(true); - + DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(xml.Resolver.instance()); Document document = builder.parse(source); @@ -181,23 +182,6 @@ /** - * Returns string result of enclosing expression in a XPath <code>string</code> function and evaluating it. - */ - public static String evalString(Document document, String expression) throws TransformerException { - XObject xObject = XPathAPI.eval(document, "string(" + expression + ")"); - return xObject.xstr().toString(); - } - - - /** - * Returns string result of enclosing expression in a XPath <code>count</code> function and evaluating it. - */ - public static int evalCount(Document document, String expression) throws TransformerException { - XObject xObject = XPathAPI.eval(document, "count(" + expression + ")"); - return Integer.parseInt(xObject.xstr().toString()); - } - - /** * Clicks the evaluate XPath button. */ public void clickEvaluateButton() { @@ -205,9 +189,10 @@ } - private XPathAdapter getXPath() { + public XPathAdapter getXPath() { String xpath = jEdit.getProperty(XPATH_ADAPTER_PROP); if(adapter == null || !adapter.getClass().getName().equals(xpath)) { + DocumentCache.destroyCache(); try { adapter = (XPathAdapter)Class.forName(xpath).newInstance(); } catch(ClassNotFoundException e) { @@ -220,17 +205,22 @@ } return adapter; } - + public void actionPerformed(final ActionEvent event) { if(!inputSelectionPanel.isSourceFileDefined()) { GUIUtilities.message(this,"xpath.error.no-source",new Object[]{}); } else { ((JComponent)event.getSource()).setEnabled(false); ThreadUtilities.runInBackground(new Task(){ + @Override + public String getLabel() { + return jEdit.getProperty("xpath.evaluate.label"); + } + public void _run(){ try { evaluateExpression(); - + } catch (IllegalStateException e) { XSLTPlugin.processException(e, e.getMessage(), XPathTool.this); } catch (SAXException e) { // parse problem @@ -250,28 +240,37 @@ } - public Document getCurrentDocument() throws SAXException, ParserConfigurationException, IOException { + public Document getCurrentDocument(XPathAdapter xpath) throws Exception { if (inputSelectionPanel.isFileSelected()) { //take input from file String path = inputSelectionPanel.getSourceFile(); - return DocumentCache.getFromCache(path); + return DocumentCache.getFromCache(xpath,path); } else { // take input from active buffer - return DocumentCache.getFromCache(view.getBuffer()); + return DocumentCache.getFromCache(xpath,view.getBuffer()); } } private void evaluateExpression() throws Exception, IOException, SAXException, TransformerException { - Document document = getCurrentDocument(); + XPathAdapter xpath = getXPath(); + if(xpath != null) { - String expression = expressionPanel.getExpression(); + String sourcePath; + if (inputSelectionPanel.isFileSelected()) { //take input from file + sourcePath = inputSelectionPanel.getSourceFile(); + } else { // take input from active buffer + sourcePath = view.getBuffer().getPath(); + } - XPathAdapter xpath = getXPath(); - if(xpath != null) { + Document document = getCurrentDocument(xpath); + + String expression = expressionPanel.getExpression(); + XPathAdapter.Result result = xpath.evaluateExpression(document,nsPanel.getMap(),expression); Log.log(Log.DEBUG,this,"evaluateExpression returns : "+result); - + + lastSourcePath = sourcePath; expressionPanel.addToHistory(expression); - + dateTypeField.setText(result.getType()); setResultValue(result); setNodeSetResults(result); @@ -336,90 +335,32 @@ * Note: there are four data types in the XPath 1.0 data model: node-set, string, * number, and boolean. * - * @param xObject XObject containing results */ private void setNodeSetResults(XPathAdapter.Result result) throws Exception { NodeSetTableModel tableModel = nodeSetTablePanel.getTableModel(); - if (result.isNodeSet()) { - tableModel.resetRows(result.size()); - boolean isNodeWithName = false; - boolean isNodeWithValue = false; - XPathAdapter.XPathNode node; + tableModel.resetRows(result); + } - for (int i = 0; i < result.size(); i++) { - node = result.get(i); + private void grabNamespaces(){ + XPathAdapter xpath = getXPath(); + if(xpath != null){ + if(inputSelectionPanel.isSourceFileDefined()) { - if (node != null) { - isNodeWithName = isNodeWithName || node.hasExpandedName(); - isNodeWithValue = isNodeWithValue || node.hasDomValue(); - - tableModel.setNodeType(node.getType(), i); - tableModel.setNodeName(node.getName(), i); - tableModel.setNodeValue(node.getDomValue(), i); + Document document = null; + try { + document = getCurrentDocument(xpath); + } catch (SAXException e) { // parse problem + XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); + } catch (ParserConfigurationException e) { // parse problem + XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); + } catch (IOException e) { // parse problem + XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); + } catch (Exception e) { // catch-all + XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.unkown-problem"), XPathTool.this); } - } - if (!isNodeWithName && !isNodeWithValue) { - tableModel.removeNameOrValueColumn(); - } else if (!isNodeWithName) { - tableModel.removeNameColumn(); - } else if (!isNodeWithValue) { - tableModel.removeValueColumn(); - } - } else { - tableModel.resetRows(0); - } - } - - private void grabNamespaces(){ - if(inputSelectionPanel.isSourceFileDefined()) { - - Document document = null; - try { - document = getCurrentDocument(); - } catch (SAXException e) { // parse problem - XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); - } catch (ParserConfigurationException e) { // parse problem - XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); - } catch (IOException e) { // parse problem - XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.buffer-unparseable"), XPathTool.this); - } catch (Exception e) { // catch-all - XSLTPlugin.processException(e, jEdit.getProperty("xpath.result.message.unkown-problem"), XPathTool.this); - } - - if(document != null) { - Map<String,List<String>> bindings = new HashMap<String,List<String>>(); - - if (document.getImplementation().hasFeature("traversal", "2.0")) { - DocumentTraversal traversable = (DocumentTraversal) document; - NodeIterator iterator = traversable.createNodeIterator( - document, NodeFilter.SHOW_ELEMENT,null, true); - - Node node; - while ((node = iterator.nextNode()) != null) { - //Element e = (Element)node; - NamedNodeMap attrs = node.getAttributes(); - for(int i=0;i<attrs.getLength();i++) { - Node a = attrs.item(i); - - if("xmlns".equals(a.getPrefix()) - || (a.getPrefix() == null && "xmlns".equals(a.getLocalName()))) { - String prefix = a.getPrefix() == null ? "" : a.getLocalName(); - String ns = a.getNodeValue(); - List l; - if(bindings.containsKey(prefix)){ - l = bindings.get(prefix); - } else { - l = new ArrayList<String>(); - bindings.put(prefix,l); - } - if(!l.contains(ns)) { - l.add(ns); - } - } - } - } - + if(document != null) { + Map<String, List<String>> bindings = xpath.grabNamespaces(document); Map<String,String> finalMap = new HashMap<String,String>(); for(Map.Entry<String,List<String>> binding : bindings.entrySet()) { String prefix; @@ -430,7 +371,7 @@ } int len = binding.getValue().size(); if(!finalMap.containsKey(prefix) && len == 1) { - finalMap.put(prefix,binding.getValue().get(0)); + finalMap.put(prefix,binding.getValue().get(0)); } else { for(int i=0,j=0;i<len;j++){ String uniq = prefix+j; @@ -441,7 +382,7 @@ } } } - + Log.log(Log.DEBUG,this,"found:"+bindings); Log.log(Log.DEBUG,this,"found:"+finalMap); String[] keys = new String[finalMap.size()]; @@ -452,21 +393,94 @@ values[i] = binding.getValue(); i++; } - + nsPanel.setKeyValues(keys, values); - - } else { - Log.log(Log.ERROR,this,"DomImplementation doesn't support DOM Traversal"); } + + } else { + Log.log(Log.ERROR,this,"Source isn't defined"); + GUIUtilities.message(this,"xpath.ns.grab.error-no-source",new Object[]{}); } - - } else { - Log.log(Log.ERROR,this,"Source isn't defined"); - GUIUtilities.message(this,"xpath.ns.grab.error-no-source",new Object[]{}); } - } - + + private void gotoInEditor(int lineNumber, int columnNumber){ + new GotoDelayed(view.getEditPane(), lastSourcePath, lineNumber, columnNumber); + } + + static class GotoDelayed implements Runnable + { + private final EditPane editPane; + private volatile boolean loadedEventReceived = false; + private Buffer buffer; + private final int line; + private final int col; + + private GotoDelayed(EditPane editPane, String path, int line, int col) + { + this.editPane = editPane; + this.line = line; + this.col = col; + EditBus.addToBus(this); + buffer = getBuffer(editPane.getView(), path); + if(buffer == null) + { + EditBus.removeFromBus(this); + return; + } + editPane.setBuffer(buffer,false); + synchronized (this) + { + if (!loadedEventReceived && buffer.isLoaded()) + { + bufferLoaded(); + } + } + + } + + //{{{ getBuffer() method + private Buffer getBuffer(View view, String path) + { + if(buffer == null) + buffer = jEdit.openFile(view,path); + return buffer; + } //}}} + + public void run() + { + JEditTextArea textArea = editPane.getTextArea(); + // this will be the location of the end of the opening tag + // of the parent element + int pos = buffer.getLineStartOffset(line-1) + col - 1; + textArea.moveCaretPosition(pos); + textArea.requestFocus(); + } + + private void bufferLoaded() + { + synchronized (this) + { + if (!loadedEventReceived) + { + EditBus.removeFromBus(this); + loadedEventReceived = true; + ThreadUtilities.runInDispatchThread(this); + } + } + } + + @EBHandler + public void handleBufferUpdate(BufferUpdate msg) + { + if (msg.getWhat() == BufferUpdate.LOADED && + msg.getBuffer() == buffer) + { + bufferLoaded(); + } + } + } + /** * Panel housing the "Evaluate" button */ @@ -476,7 +490,7 @@ private JCheckBox autoCompleteCheck; EvaluatePanel() { - + grabNamespaces = grabNSAction.getButton(); String iconName = jEdit.getProperty("xpath.evaluate.button.icon"); @@ -492,7 +506,7 @@ button.setToolTipText(toolTipText); button.addActionListener(XPathTool.this); button.setName("xpath.evaluate"); - + Dimension dimension = new Dimension(76, 30); button.setMinimumSize(dimension); button.setPreferredSize(dimension); @@ -506,17 +520,17 @@ } private class GrabNSAction extends XsltAction { - + GrabNSAction(){ super("xpath.ns.grab"); } - + public void actionPerformed(ActionEvent e) { grabNamespaces(); } - + } - + /** * JTextArea that let's tab key change focus to the next component. */ @@ -543,10 +557,10 @@ int height = (int) textArea.getPreferredSize().getHeight(); this.textArea.setMinimumSize(new Dimension(width, height)); this.textArea.setName(name); - + add(label, BorderLayout.NORTH); add(new JScrollPane(this.textArea)); - + JPopupMenu popup = new JPopupMenu(); searchMenuItem = new JMenuItem("Hypersearch"); searchMenuItem.addActionListener(this); @@ -597,8 +611,13 @@ * implements interface {@link javax.swing.event.ListSelectionListener}. */ public void valueChanged(ListSelectionEvent event) { + if(event.getValueIsAdjusting())return; int selectedRow = this.nodeSetTablePanel.table.getSelectedRow(); this.xmlFragmentsPanel.highlightFragment(selectedRow); + XPathNode node = this.nodeSetTablePanel.getTableModel().getValueAt(selectedRow); + if(node != null && node.hasLocation()){ + gotoInEditor(node.getLineNumber(), node.getColumnNumber()); + } } @@ -707,7 +726,7 @@ BufferUpdate bufUpd = (BufferUpdate)message; DocumentCache.handleMessage(bufUpd); } - + public void stop() { DocumentCache.destroyCache(); } @@ -731,12 +750,12 @@ Document document; Object sourceObject; private static Map globalDocumentCache; - + static { createCacheMap(); } - public static Document getFromCache(JEditBuffer sourceBuffer) throws SAXException,ParserConfigurationException,IOException { + public static Document getFromCache(XPathAdapter xpath, JEditBuffer sourceBuffer) throws Exception { DocumentCache cacheObj = (DocumentCache) globalDocumentCache.get(sourceBuffer); if(cacheObj == null){ cacheObj = new BufferDocumentCache(sourceBuffer); @@ -744,10 +763,10 @@ globalDocumentCache.put(sourceBuffer,cacheObj); } } - return cacheObj.getDocument(); + return cacheObj.getDocument(xpath); } - - public static Document getFromCache(String sourceFileName) throws SAXException,ParserConfigurationException,IOException { + + public static Document getFromCache(XPathAdapter xpath, String sourceFileName) throws Exception { File sourceFile = new File(sourceFileName); DocumentCache cacheObj = (DocumentCache) globalDocumentCache.get(sourceFile); if(cacheObj == null){ @@ -756,13 +775,13 @@ globalDocumentCache.put(sourceFile,cacheObj); } } - return cacheObj.getDocument(); + return cacheObj.getDocument(xpath); } - + public static void destroyCache() { createCacheMap(); } - + public static void handleMessage(BufferUpdate bufUpd) { DocumentCache cacheObj = (DocumentCache) globalDocumentCache.get(bufUpd.getBuffer()); if (cacheObj == null) @@ -773,7 +792,7 @@ private static void createCacheMap() { globalDocumentCache = Collections.synchronizedMap(new HashMap()); } - + DocumentCache(Object srcObject) { this.sourceObject = srcObject; } @@ -786,11 +805,7 @@ document = null; } - synchronized void doParse(InputSource src) throws ParserConfigurationException, IOException, SAXException { - document = XPathTool.parse(src); - } - - public Document getDocument() throws SAXException,ParserConfigurationException,IOException { + public Document getDocument(XPathAdapter xpath) throws Exception { return document; } @@ -806,16 +821,16 @@ } @Override - public Document getDocument() throws SAXException,ParserConfigurationException,IOException{ + public Document getDocument(XPathAdapter adapter) throws Exception { File sourceFile = (File)sourceObject; - if (super.getDocument() == null + if (super.getDocument(adapter) == null || fileUpdateTime != sourceFile.lastModified()) { - InputSource inputSource = new InputSource(sourceFile.getName()); - doParse(inputSource); + URI u = sourceFile.toURI(); fileUpdateTime = sourceFile.lastModified(); + document = adapter.buildDocument(u); } - return super.getDocument(); + return super.getDocument(adapter); } } @@ -845,14 +860,12 @@ }); } - public Document getDocument() throws SAXException,ParserConfigurationException,IOException { - if (super.getDocument() == null) { - JEditBuffer sourceBuffer = (JEditBuffer)sourceObject; - String sourceURL = PathUtilities.pathToURL(((Buffer)sourceBuffer).getPath()); - InputSource inputSource = xml.Resolver.instance().resolveEntity("",sourceURL); - doParse(inputSource); + public Document getDocument(XPathAdapter adapter) throws Exception { + if (super.getDocument(adapter) == null) { + Buffer sourceBuffer = (Buffer)sourceObject; + document = adapter.buildDocument(sourceBuffer); } - return super.getDocument(); + return super.getDocument(adapter); } } Modified: plugins/XSLT/trunk/xslt/XalanXPathAdapter.java =================================================================== --- plugins/XSLT/trunk/xslt/XalanXPathAdapter.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XalanXPathAdapter.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -1,7 +1,7 @@ /* * XalanXPathAdapter.java - implements XPathAdapter using Xalan * - * Copyright (c) 2010 Eric Le Lay + * Copyright (c) 2010, 2013 Eric Le Lay * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -19,22 +19,13 @@ */ package xslt; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; import javax.xml.transform.TransformerException; + import org.w3c.dom.Document; -import org.w3c.dom.NodeList; import org.w3c.dom.Node; import java.util.Map; -import java.util.HashMap; -import java.util.List; -import java.util.LinkedList; -import java.util.Iterator; -import java.util.Collections; import org.apache.xpath.NodeSetDTM; import org.apache.xpath.XPathAPI; @@ -48,11 +39,10 @@ * Historically, it was included in XPathTool and the XPathAdapter * has been abstracted from its usage. */ -public class XalanXPathAdapter implements XPathAdapter { - +public class XalanXPathAdapter extends DOMXPathAdapter { + public Result evaluateExpression(Document doc, Map<String,String> prefixes, String expression) throws TransformerException { - PrefixResolverImpl res = new PrefixResolverImpl(prefixes); XObject xObject = XPathAPI.eval(doc, expression, res); Modified: plugins/XSLT/trunk/xslt/XalanXPathNode.java =================================================================== --- plugins/XSLT/trunk/xslt/XalanXPathNode.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XalanXPathNode.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -161,8 +161,10 @@ public String getDomValue() { + + String domValue = this.dtm.getNodeValue(this.nodeHandle); - + domValue += (" -- Location: "+dtm.getSourceLocatorFor(this.nodeHandle).getLineNumber()); if (hasDomValue()) { domValue = XSLTUtilities.removeIn(domValue, (char) 10); //remove '\r' to temporarily fix a bug in the display of results in Windows } @@ -170,4 +172,19 @@ return domValue; } + public int getLineNumber() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Location information not supported for Xalan"); + } + + public int getColumnNumber() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Location information not supported for Xalan"); + } + + + /** + * @return always false + */ + public boolean hasLocation() { + return false; + } } Modified: plugins/XSLT/trunk/xslt/XsltSettings.java =================================================================== --- plugins/XSLT/trunk/xslt/XsltSettings.java 2013-11-05 21:17:15 UTC (rev 23315) +++ plugins/XSLT/trunk/xslt/XsltSettings.java 2013-11-06 07:09:37 UTC (rev 23316) @@ -1,234 +1,252 @@ -/* - * XsltSettings.java - Represents a settings file. - * - * Copyright (C) 2003 Robert McKinnon - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package xslt; - -import org.gjt.sp.jedit.GUIUtilities; -import org.gjt.sp.jedit.MiscUtilities; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.EditPlugin; -import org.gjt.sp.util.Log; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import javax.swing.JFileChooser; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; - -import java.util.Map; - - -/** - * Represents a settings file containing the configuration for an XSLT pipeline. - * Is able to be written to a working Ant build.xml file. - * - * @author Robert McKinnon - rob...@us... - */ -public class XsltSettings { - - private XSLTProcessor processor; - - - public XsltSettings(XSLTProcessor processor) { - this.processor = processor; - } - - - public void loadFromFile() throws ParserConfigurationException, IOException, SAXException, TransformerException { - String[] selections = GUIUtilities.showVFSFileDialog(processor.getView(), getSettingsDirectory(), JFileChooser.OPEN_DIALOG, false); - - if(selections != null) { - String settingsFile = selections[0]; - Log.log(Log.DEBUG, this, "settings file: " + settingsFile); - - if(settingsFile.indexOf("://") == -1) { - settingsFile = "file:///" + settingsFile; - } - - InputSource source = new InputSource(settingsFile); - Document document = XPathTool.parse(source); - - String sourceFile = XPathTool.evalString(document, "/project/target[xslt][1]/xslt/@in"); - String resultFile = XPathTool.evalString(document, "/project/target/xslt[starts-with(@out, '$')=false()]/@out"); - Log.log(Log.DEBUG, this, "source: " + sourceFile); - Log.log(Log.DEBUG, this, "result: " + resultFile); - - int stylesheetCount = XPathTool.evalCount(document, "/project/target/xslt"); - int parameterCount = XPathTool.evalCount(document, "/project/target[xslt][1]/xslt/param"); - String[] stylesheets = new String[stylesheetCount]; - String[] parameterNames = new String[parameterCount]; - String[] parameterValues = new String[parameterCount]; - - for(int i = 0; i < stylesheetCount; i++) { - stylesheets[i] = XPathTool.evalString(document, "/project/target[xslt][" + (i + 1) + "]/xslt/@style"); - Log.log(Log.DEBUG, this, "stylsheet " + i + ": " + stylesheets[i]); - } - - for(int i = 0; i < parameterCount; i++) { - String parameterXPath = "/project/target[xslt][1]/xslt/param[" + (i + 1) + "]"; - parameterNames[i] = XPathTool.evalString(document, parameterXPath + "/@name"); - parameterValues[i] = XPathTool.evalString(document, parameterXPath + "/@expression"); - Log.log(Log.DEBUG, this, "parameter: " + parameterNames[i] + "=" + parameterValues[i]); - } - - processor.getInputSelectionPanel().setSourceFile(sourceFile); - - // special case if "New Untitled Buffer" was checked - if(resu... [truncated message content] |
From: <ker...@us...> - 2013-11-06 20:34:57
|
Revision: 23319 http://jedit.svn.sourceforge.net/jedit/?rev=23319&view=rev Author: kerik-sf Date: 2013-11-06 20:34:49 +0000 (Wed, 06 Nov 2013) Log Message: ----------- fix bug in DOMXPathAdapter not grabbing any namespace Modified Paths: -------------- plugins/XSLT/trunk/test/xslt/XSLTPluginXPathTest.java plugins/XSLT/trunk/xslt/DOMXPathAdapter.java Modified: plugins/XSLT/trunk/test/xslt/XSLTPluginXPathTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTPluginXPathTest.java 2013-11-06 07:10:24 UTC (rev 23318) +++ plugins/XSLT/trunk/test/xslt/XSLTPluginXPathTest.java 2013-11-06 20:34:49 UTC (rev 23319) @@ -31,6 +31,7 @@ import org.fest.swing.fixture.JPanelFixture; import org.fest.swing.fixture.JTableFixture; import org.fest.swing.timing.Pause; +import org.fest.swing.timing.Timeout; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.testframework.JEditRunner; @@ -88,8 +89,8 @@ xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); - xpathTool.textBox("xpath.result.data-type").requireText("text()"); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); + xpathTool.textBox("xpath.result.data-type").requireText("node-set of size 1"); xpathTool.textBox("xpath.result.value").requireText("world"); xpathTool.close(); @@ -130,7 +131,7 @@ }); xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.textBox("xpath.result.data-type").requireText("node-set of size 1"); xpathTool.textBox("xpath.result.xml-fragments").requireText("<xsl:value-of select=\".\"/>\n"); xpathTool.close(); @@ -157,6 +158,7 @@ xpathTool.button("xpath.evaluate").click(); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); final String contents = "<?xml version=\"1.0\" ?>\n" +"<hello>you</hello>"; @@ -170,7 +172,7 @@ xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.textBox("xpath.result.value").requireText("you"); xpathTool.close(); @@ -196,7 +198,7 @@ xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.textBox("xpath.result.value").requireText("world"); xpathTool.close(); @@ -222,7 +224,7 @@ xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.table("xpath.result.node-set-summary").cell(TableCell.row(0).column(0)).click(); assertEquals(xpathTool.textBox("xpath.result.xml-fragments").targetCastedTo(JTextArea.class).getHighlighter().getHighlights().length,1); assertEquals(xpathTool.textBox("xpath.result.xml-fragments").targetCastedTo(JTextArea.class).getHighlighter().getHighlights()[0].getStartOffset(),0); @@ -261,7 +263,7 @@ Pause.pause(1000); xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.table("xpath.result.node-set-summary").requireRowCount(2); xpathTool.table("xpath.result.node-set-summary").cell(TableCell.row(0).column(0)).requireValue("xs:integer"); xpathTool.table("xpath.result.node-set-summary").cell(TableCell.row(0).column(1)).requireValue(""); @@ -270,8 +272,8 @@ xpathTool.table("xpath.result.node-set-summary").cell(TableCell.row(1).column(1)).requireValue("select"); xpathTool.table("xpath.result.node-set-summary").cell(TableCell.row(1).column(2)).requireValue("."); - xpathTool.textBox("xpath.result.data-type").requireText("sequence of item()"); - xpathTool.textBox("xpath.result.value").requireText("2 ."); + xpathTool.textBox("xpath.result.data-type").requireText("sequence of xs:integer"); + xpathTool.textBox("xpath.result.value").requireText("(2,.)"); xpathTool.textBox("xpath.result.xml-fragments").requireText("2\nselect=\".\"\n"); @@ -306,7 +308,7 @@ new ClickT(Option.OK).start(); xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.close(); } @@ -332,7 +334,7 @@ new ClickT(Option.OK).start(); xpathTool.button("xpath.evaluate").click(); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.close(); } @@ -358,7 +360,7 @@ new ClickT(Option.OK).start(); action("xpath.evaluate"); - Pause.pause(1000); + xpathTool.button("xpath.evaluate").requireEnabled(Timeout.timeout(1000)); xpathTool.close(); } } Modified: plugins/XSLT/trunk/xslt/DOMXPathAdapter.java =================================================================== --- plugins/XSLT/trunk/xslt/DOMXPathAdapter.java 2013-11-06 07:10:24 UTC (rev 23318) +++ plugins/XSLT/trunk/xslt/DOMXPathAdapter.java 2013-11-06 20:34:49 UTC (rev 23319) @@ -105,6 +105,7 @@ } } } + return bindings; } else { Log.log(Log.ERROR,this,"DomImplementation doesn't support DOM Traversal"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ker...@us...> - 2013-11-09 16:26:41
|
Revision: 23327 http://jedit.svn.sourceforge.net/jedit/?rev=23327&view=rev Author: kerik-sf Date: 2013-11-09 16:26:34 +0000 (Sat, 09 Nov 2013) Log Message: ----------- update tests Modified Paths: -------------- plugins/XSLT/trunk/test/build.xml plugins/XSLT/trunk/test/xslt/Saxon9XPathAdapterTest.java plugins/XSLT/trunk/test/xslt/XalanXPathAdapterTest.java Added Paths: ----------- plugins/XSLT/trunk/test_data/namespaces/rebind.xml Modified: plugins/XSLT/trunk/test/build.xml =================================================================== --- plugins/XSLT/trunk/test/build.xml 2013-11-09 16:25:56 UTC (rev 23326) +++ plugins/XSLT/trunk/test/build.xml 2013-11-09 16:26:34 UTC (rev 23327) @@ -95,8 +95,12 @@ </selector> <!-- this selector holds just one test. This is optional. --> + <!-- override the value of test.current on the command line to run this test. + eg. LANG=en_GB.UTF-8 ant -Dtest.current=xslt/Saxon9XPathAdapterTest.java test + --> + <property name="test.current" value="xslt/XSLTPluginXPathTest.java"/> <selector id="testcases.current"> - <filename name="xslt/XSLTPluginXPathTest.java"/> + <filename name="${test.current}"/> </selector> <!-- this selector controls which tests to run, set the refid to either Modified: plugins/XSLT/trunk/test/xslt/Saxon9XPathAdapterTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/Saxon9XPathAdapterTest.java 2013-11-09 16:25:56 UTC (rev 23326) +++ plugins/XSLT/trunk/test/xslt/Saxon9XPathAdapterTest.java 2013-11-09 16:26:34 UTC (rev 23327) @@ -13,6 +13,7 @@ package xslt; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.MapAssert.*; import static org.gjt.sp.jedit.testframework.TestUtils.openFile; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -38,24 +39,21 @@ /** * unit tests of the Saxon 9 XPath engine adapter - * $Id$ */ -@RunWith(JEditRunner.class) public class Saxon9XPathAdapterTest{ - + @Rule public TestData testData = new TestData(); - + @Test public void testElement() throws Exception{ + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new Saxon9XPathAdapter(), b); + + Document source = xpath.buildDocument(xsl.toURI()); - Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); - Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -80,12 +78,11 @@ @Test public void testComment() throws Exception{ final File xsl = new File(testData.get(),"base_uri_bug/base-uri-bug.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new Saxon9XPathAdapter(), b); - + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + Document source = xpath.buildDocument(xsl.toURI()); + Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -102,7 +99,7 @@ assertTrue(n.hasDomValue()); assertEquals("comment()",n.getType()); assertEquals("",n.getName()); - + XMLFragmentsString frags = res.toXMLFragmentsString(); assertEquals(1,frags.getFragmentCount()); } @@ -110,19 +107,18 @@ @Test public void testNumberSequence() throws Exception{ final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new Saxon9XPathAdapter(), b); Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + Document source = xpath.buildDocument(xsl.toURI()); + Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); XPathAdapter.Result res = xpath.evaluateExpression(source, prefixes, "(1+1,1 div 2)"); - assertEquals("sequence of xs:decimal",res.getType()); - assertEquals("2 0.5",res.getStringValue()); + assertEquals("sequence of xs:integer",res.getType()); + assertEquals("(2,0.5)",res.getStringValue()); assertTrue(res.isNodeSet()); assertEquals(2,res.size()); @@ -133,7 +129,7 @@ assertEquals("xs:integer",n.getType()); assertEquals("2",n.getDomValue()); assertEquals(null,n.getName()); - + XMLFragmentsString frags = res.toXMLFragmentsString(); assertEquals(2,frags.getFragmentCount()); } @@ -141,11 +137,10 @@ @Test public void testEmptySequence() throws Exception{ final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new Saxon9XPathAdapter(), b); Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -153,7 +148,7 @@ XPathAdapter.Result res = xpath.evaluateExpression(source, prefixes, "/xsl:transform"); assertEquals("empty sequence",res.getType()); - assertEquals("",res.getStringValue()); + assertEquals("()",res.getStringValue()); assertTrue(res.isNodeSet()); assertEquals(0,res.size()); @@ -163,5 +158,34 @@ res.toString(); } + + @Test + public void testGrabNamespaces() throws Exception{ + final File xsl = new File(testData.get(),"namespaces/default_and_prefixed.xml"); + + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + Document source = xpath.buildDocument(xsl.toURI()); + + Map<String, List<String>> namespaces = xpath.grabNamespaces(source); + assertTrue(namespaces.containsKey("")); + assertThat(namespaces.get("")).containsOnly("urn:joe"); + assertThat(namespaces.get("world")).containsOnly("urn:world"); + } + + @Test + public void testGrabNamespacesRebind() throws Exception{ + final File xsl = new File(testData.get(),"namespaces/rebind.xml"); + + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); + + Map<String, List<String>> namespaces = xpath.grabNamespaces(source); + System.err.println("ns:"+namespaces); + assertTrue(namespaces.containsKey("")); + assertThat(namespaces.get("")).containsOnly("rround","omment"); + assertThat(namespaces.get("d")).containsOnly("ocument","ummy"); + } + } Modified: plugins/XSLT/trunk/test/xslt/XalanXPathAdapterTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XalanXPathAdapterTest.java 2013-11-09 16:25:56 UTC (rev 23326) +++ plugins/XSLT/trunk/test/xslt/XalanXPathAdapterTest.java 2013-11-09 16:26:34 UTC (rev 23327) @@ -22,6 +22,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.List; import org.fest.swing.timing.Pause; import org.gjt.sp.jedit.Buffer; @@ -44,11 +45,10 @@ @Test public void testElement() throws Exception{ final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new XalanXPathAdapter(), b); - + XalanXPathAdapter xpath = new XalanXPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -74,12 +74,11 @@ @Test public void testComment() throws Exception{ final File xsl = new File(testData.get(),"base_uri_bug/base-uri-bug.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new XalanXPathAdapter(), b); - + XalanXPathAdapter xpath = new XalanXPathAdapter(); - + + Document source = xpath.buildDocument(xsl.toURI()); + Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -105,11 +104,10 @@ @Test public void testNumber() throws Exception{ final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new XalanXPathAdapter(), b); - + XalanXPathAdapter xpath = new XalanXPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -127,12 +125,11 @@ @Test public void testEmptySequence() throws Exception{ final File xsl = new File(testData.get(),"simple/transform.xsl"); - Buffer b = openFile(xsl.getPath()); - Pause.pause(1000); - Document source = DocumentCache.getFromCache(new XalanXPathAdapter(), b); - + XalanXPathAdapter xpath = new XalanXPathAdapter(); - + + Document source = xpath.buildDocument(xsl.toURI()); + Map<String,String> prefixes = new HashMap<String,String>(); prefixes.put("xsl","http://www.w3.org/1999/XSL/Transform"); @@ -164,4 +161,33 @@ assertNull(ctx.getBaseIdentifier()); assertFalse(ctx.handlesNullPrefixes()); } + + @Test + public void testGrabNamespaces() throws Exception{ + final File xsl = new File(testData.get(),"namespaces/default_and_prefixed.xml"); + + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); + + Map<String, List<String>> namespaces = xpath.grabNamespaces(source); + assertTrue(namespaces.containsKey("")); + assertThat(namespaces.get("")).containsOnly("urn:joe"); + assertThat(namespaces.get("world")).containsOnly("urn:world"); + } + + @Test + public void testGrabNamespacesRebind() throws Exception{ + final File xsl = new File(testData.get(),"namespaces/rebind.xml"); + + Saxon9XPathAdapter xpath = new Saxon9XPathAdapter(); + + Document source = xpath.buildDocument(xsl.toURI()); + + Map<String, List<String>> namespaces = xpath.grabNamespaces(source); + System.err.println("ns:"+namespaces); + assertTrue(namespaces.containsKey("")); + assertThat(namespaces.get("")).containsOnly("rround","omment"); + assertThat(namespaces.get("d")).containsOnly("ocument","ummy"); + } } Added: plugins/XSLT/trunk/test_data/namespaces/rebind.xml =================================================================== --- plugins/XSLT/trunk/test_data/namespaces/rebind.xml (rev 0) +++ plugins/XSLT/trunk/test_data/namespaces/rebind.xml 2013-11-09 16:26:34 UTC (rev 23327) @@ -0,0 +1,6 @@ +<?xml version="1.0" ?> +<a xmlns:d="ummy" xmlns="rround"> + <b xmlns:d="ocument"/> + + <c xmlns="omment"/> +</a> Property changes on: plugins/XSLT/trunk/test_data/namespaces/rebind.xml ___________________________________________________________________ Added: svn:keywords + Id Author Revision Date Head This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ker...@us...> - 2013-11-09 16:27:32
|
Revision: 23328 http://jedit.svn.sourceforge.net/jedit/?rev=23328&view=rev Author: kerik-sf Date: 2013-11-09 16:27:22 +0000 (Sat, 09 Nov 2013) Log Message: ----------- fix bug in XSLT processor: encoding set in <xsl:output> was not applied This was because the result was written to a writer (with platform's default encoding), instead of letting the processor write to the file by himself. Modified Paths: -------------- plugins/XSLT/trunk/docs/users-guide.xml plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java plugins/XSLT/trunk/xslt/XSLTProcessor.java Added Paths: ----------- plugins/XSLT/trunk/test_data/encoding/ plugins/XSLT/trunk/test_data/encoding/accentedchar-iso-8859-1.xsl plugins/XSLT/trunk/test_data/encoding/accentedchar-utf8.xsl Modified: plugins/XSLT/trunk/docs/users-guide.xml =================================================================== --- plugins/XSLT/trunk/docs/users-guide.xml 2013-11-09 16:26:34 UTC (rev 23327) +++ plugins/XSLT/trunk/docs/users-guide.xml 2013-11-09 16:27:22 UTC (rev 23328) @@ -464,6 +464,8 @@ <listitem><para>XPath tool: selecting node results from the Node-set summary opens the buffer if necessary and moves the caret to the location in the document. This only works with Saxon XPath engine.</para></listitem> + <listitem><para>XSLT processor: when transforming to a file, the encoding specified + in the transform's <xsl:output> is taken into account.</para></listitem> </itemizedlist> </para> <para> Modified: plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2013-11-09 16:26:34 UTC (rev 23327) +++ plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2013-11-09 16:27:22 UTC (rev 23328) @@ -18,9 +18,10 @@ import static org.gjt.sp.jedit.testframework.TestUtils.view; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.nio.charset.Charset; import java.util.regex.Pattern; import javax.swing.text.JTextComponent; @@ -33,6 +34,7 @@ import org.fest.swing.fixture.JPanelFixture; import org.fest.swing.fixture.JTableFixture; import org.fest.swing.timing.Pause; +import org.fest.swing.timing.Timeout; import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.testframework.JEditRunner; import org.gjt.sp.jedit.testframework.TestData; @@ -65,7 +67,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); assertThat(b.getName().matches("Untitled-\\d+")); @@ -80,6 +82,10 @@ File xml = new File(testData.get(),"simple/source.xml"); File xsl = new File(testData.get(),"broken/transform.xsl"); + action("error-list-show"); + + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + final FrameFixture xsltProcessor = setupProcessor(xml,xsl,"",1); // an error will be reported @@ -88,15 +94,11 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); assertThat(b.getName().matches("Untitled-\\d+")); - action("error-list-show"); - - FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); - errorlist.tree().selectRow(1); assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error) xsl:ourrtput")); errorlist.close(); @@ -108,6 +110,9 @@ public void testXSLTBaseURIBug() throws IOException{ File xsl = new File(testData.get(),"base_uri_bug/base-uri-bug.xsl"); + action("error-list-show"); + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + final FrameFixture xsltProcessor = setupProcessor(xsl,xsl,"",1); // an error will be reported @@ -116,7 +121,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); @@ -124,9 +129,6 @@ xsltProcessor.close(); - action("error-list-show"); - FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); - errorlist.tree().selectRow(1); assertTrue(errorlist.tree().valueAt(1).startsWith("15: (XSLT error)")); errorlist.close(); @@ -138,19 +140,19 @@ File xml = new File(testData.get(),"simple/source.xml"); File xsl = new File(testData.get(),"broken/fails_at_runtime.xsl"); + action("error-list-show"); + + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + final FrameFixture xsltProcessor = setupProcessor(xml,xsl,"",1); xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); assertThat(b.getName().matches("Untitled-\\d+")); - action("error-list-show"); - - FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); - errorlist.tree().selectRow(1); assertTrue(errorlist.tree().valueAt(1).startsWith("16: (XSLT error)")); errorlist.close(); @@ -163,6 +165,9 @@ final File xml = new File(testData.get(),"broken/source.xml"); File xsl = new File(testData.get(),"simple/transform.xsl"); + action("error-list-show"); + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + final FrameFixture xsltProcessor = setupProcessor(xml,xsl,"",1); TestUtils.close(view(),view().getBuffer()); @@ -181,15 +186,12 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); xsltProcessor.close(); - action("error-list-show"); - FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); - errorlist.tree().selectRow(1); assertTrue(errorlist.tree().valueAt(1).startsWith("2: (SAX error) Content is not allowed in prolog")); errorlist.close(); @@ -269,7 +271,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.close(); @@ -297,7 +299,7 @@ xsltProcessor.checkBox("open-result").requireSelected().uncheck(); xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.checkBox("open-result").check(); xsltProcessor.close(); @@ -318,7 +320,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.close(); @@ -344,22 +346,26 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.close(); - Buffer b = view().getBuffer(); + Pause.pause(1000); + Buffer b; + if(result.exists()){ + b = TestUtils.openFile(result.getPath()); + + assertEquals(0,b.getLength()); + + TestUtils.close(TestUtils.view(),b); + } - assertEquals(0,b.getLength()); - - TestUtils.close(TestUtils.view(),b); - b = TestUtils.openFile(realOutput.getPath()); assertEquals("Hello world !",b.getText(0,b.getLength())); TestUtils.close(TestUtils.view(),b); - assertTrue(result.delete()); + if(result.exists())assertTrue(result.delete()); assertTrue(realOutput.delete()); } @@ -373,7 +379,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.close(); @@ -393,7 +399,7 @@ xsltProcessor.radioButton("xslt.stylesheets.buffer").check(); xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); xsltProcessor.radioButton("xslt.stylesheets.file").check(); xsltProcessor.close(); @@ -450,7 +456,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); @@ -470,7 +476,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); @@ -489,7 +495,7 @@ xsltProcessor.button("xslt.transform").click(); - Pause.pause(1000); + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); Buffer b = view().getBuffer(); @@ -497,6 +503,46 @@ TestUtils.close(TestUtils.view(),b); xsltProcessor.close(); } + + @Test + public void testOutputEncoding() throws IOException{ + File dest = new File(testData.get(),"encoding/result.xml"); + File xsl; + String encoding; + + if(Charset.defaultCharset().name().equals("UTF-8")){ + xsl = new File(testData.get(),"encoding/accentedchar-iso-8859-1.xsl"); + encoding="ISO-8859-1"; + }else{ + xsl = new File(testData.get(),"encoding/accentedchar-utf8.xsl"); + encoding="UTF-8"; + } + + final FrameFixture xsltProcessor = setupProcessor(xsl,xsl,dest.getPath(),1); + + xsltProcessor.button("xslt.transform").click(); + + xsltProcessor.button("xslt.transform").requireEnabled(Timeout.timeout(1000)); + + xsltProcessor.close(); + + try{ + BufferedReader rd = new BufferedReader(new InputStreamReader(new FileInputStream(dest), encoding)); + boolean found = false; + for(String line=rd.readLine(); line != null ; line=rd.readLine()){ + if(line.contains("<test>")){ + assertTrue("encoding error (should contain r\u00e9ussi)? "+line, line.contains("r\u00e9ussi")); + found = true; + } + } + rd.close(); + assertTrue(found); + + assertTrue(dest.delete()); + }catch(IOException e){ + fail("Exception should not happen: "+e); + } + } public FrameFixture setupProcessor(File xml, File xsl, final String dest,int version){ PluginOptionsFixture optionsF = TestUtils.pluginOptions(); Added: plugins/XSLT/trunk/test_data/encoding/accentedchar-iso-8859-1.xsl =================================================================== --- plugins/XSLT/trunk/test_data/encoding/accentedchar-iso-8859-1.xsl (rev 0) +++ plugins/XSLT/trunk/test_data/encoding/accentedchar-iso-8859-1.xsl 2013-11-09 16:27:22 UTC (rev 23328) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- This XSLT template demonstrates that the encoding of the output is + taken into account, since we write an accented character in non + platform default encoding and will be able to load it afterward. + --> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> + <xsl:param name="encoding"/> + + <xsl:output method="xml" encoding="ISO-8859-1"/> + <xsl:template match="/"> + <test>réussi !</test> + </xsl:template> + +</xsl:stylesheet> Property changes on: plugins/XSLT/trunk/test_data/encoding/accentedchar-iso-8859-1.xsl ___________________________________________________________________ Added: svn:keywords + Id Author Revision Date Head Added: plugins/XSLT/trunk/test_data/encoding/accentedchar-utf8.xsl =================================================================== --- plugins/XSLT/trunk/test_data/encoding/accentedchar-utf8.xsl (rev 0) +++ plugins/XSLT/trunk/test_data/encoding/accentedchar-utf8.xsl 2013-11-09 16:27:22 UTC (rev 23328) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- This XSLT template demonstrates that the encoding of the output is + taken into account, since we write an accented character in non + platform default encoding and will be able to load it afterward. + --> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> + <xsl:param name="encoding"/> + + <xsl:output method="xml" encoding="UTF-8"/> + <xsl:template match="/"> + <test>réussi !</test> + </xsl:template> + +</xsl:stylesheet> Property changes on: plugins/XSLT/trunk/test_data/encoding/accentedchar-utf8.xsl ___________________________________________________________________ Added: svn:keywords + Id Author Revision Date Head Modified: plugins/XSLT/trunk/xslt/XSLTProcessor.java =================================================================== --- plugins/XSLT/trunk/xslt/XSLTProcessor.java 2013-11-09 16:26:34 UTC (rev 23327) +++ plugins/XSLT/trunk/xslt/XSLTProcessor.java 2013-11-09 16:27:22 UTC (rev 23328) @@ -1,662 +1,659 @@ -/* - * XSLTProcessor.java - GUI for performing XSL Transformations - * - * Copyright 2002 Greg Merrill - * 2002, 2003 Robert McKinnon - * 2010 Eric Le Lay - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -package xslt; - -import java.awt.BorderLayout; -import java.awt.Cursor; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.Writer; -import java.io.FileWriter; -import java.io.StringWriter; -import java.io.IOException; -import java.util.Date; -import java.util.Map; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JToolBar; -import javax.swing.JCheckBox; -import javax.swing.SwingUtilities; - -import org.gjt.sp.jedit.Buffer; -import org.gjt.sp.jedit.View; -import org.gjt.sp.jedit.EditPane; -import org.gjt.sp.jedit.jEdit; -import org.gjt.sp.jedit.gui.DockableWindowManager; -import org.gjt.sp.jedit.gui.DefaultFocusComponent; -import org.gjt.sp.util.Log; -import org.gjt.sp.util.Task; -import org.gjt.sp.util.ThreadUtilities; - -import errorlist.*; - -import org.xml.sax.InputSource; -import org.xml.sax.SAXParseException; - -import javax.xml.transform.Result; -import javax.xml.transform.stream.StreamResult; - -/** - * GUI for performing XSL Transformations. - * - * @author Greg Merrill - * @author Robert McKinnon - rob...@us... - * @author Eric Le Lay - */ -public class XSLTProcessor extends JPanel implements DefaultFocusComponent { - public static final String DOCKABLE_NAME = "xslt-processor"; - private static final String OPEN_RESULT = "xslt.open-result"; - private static final String THREE_WAY = "xslt.three-way"; - - private View view; - private BufferOrFileVFSSelector resultPanel; - private XsltAction saveSettingsAction = new SaveSettingsAction(); - private XsltAction loadSettingsAction = new LoadSettingsAction(); - private XsltAction transformAction = new TransformAction(); - - private BufferOrFileVFSSelector inputSelectionPanel; - private StylesheetPanel stylesheetPanel; - private KeyValuePanel parameterPanel; - private JButton transformButton; - private JCheckBox openResultCheckBox; - private JCheckBox threeWayCheckBox; - - /** - * Constructor for the XSLTProcessor object. - * - */ - public XSLTProcessor(View theView, String position) { - super(); - - this.view = theView; - boolean sideBySide = position.equals(DockableWindowManager.TOP) || position.equals(DockableWindowManager.BOTTOM); - - initThreeWayCheckBox(); - initOpenResultCheckBox(); - this.resultPanel = new BufferOrFileVFSSelector(view,"xslt.result"); - this.inputSelectionPanel = new BufferOrFileVFSSelector(view,"xslt.source"); - this.stylesheetPanel = new StylesheetPanel(view, this); - this.parameterPanel = new KeyValuePanel("xslt.parameters"); - - JComponent transformPanel = initTransformToolBar(); - - if (sideBySide) { - createHorizontalLayout(inputSelectionPanel, transformPanel); - } else { - createVerticalLayout(inputSelectionPanel, transformPanel); - } - - setThreeWay(threeWayCheckBox.isSelected()); - - } - - public void focusOnDefaultComponent() { - if(transformButton != null) { - transformButton.requestFocus(); - } - } - - private void createVerticalLayout(JComponent sourcePanel, JComponent transformPanel) { - setLayout(new GridBagLayout()); - - sourcePanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); - stylesheetPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); - transformPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); - resultPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); - openResultCheckBox.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); - - GridBagConstraints c = new GridBagConstraints(); - - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 1; - c.gridheight = 1; - c.weightx = 1; - c.weighty = 0; - c.fill = GridBagConstraints.BOTH; - - add(threeWayCheckBox,c); - - c.gridy += c.gridheight; - c.gridheight = 4; - add(sourcePanel,c); - - JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, stylesheetPanel, parameterPanel); - splitPane.setOneTouchExpandable(true); - - c.gridy += c.gridheight; - c.gridheight = 10; - c.weighty = 1; - add(splitPane,c); - - c.gridy += c.gridheight; - c.gridheight = 1; - c.weighty = 0; - c.fill = GridBagConstraints.NONE; - c.anchor = GridBagConstraints.CENTER; - add(transformPanel,c); - c.gridy += c.gridheight; - c.gridheight = 4; - c.fill = GridBagConstraints.BOTH; - add(resultPanel,c); - c.gridy += c.gridheight; - c.gridheight = 1; - c.fill = GridBagConstraints.NONE; - add(openResultCheckBox,c); - } - - - private void createHorizontalLayout(JComponent sourcePanel, JComponent transformPanel) { - sourcePanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); - stylesheetPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); - transformPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); - resultPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); - openResultCheckBox.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); - - JPanel sourceAndResultPanel = new JPanel(new BorderLayout()); - sourceAndResultPanel.add(sourcePanel, BorderLayout.NORTH); - sourceAndResultPanel.add(resultPanel, BorderLayout.CENTER); - sourceAndResultPanel.add(openResultCheckBox, BorderLayout.SOUTH); - - JPanel extraParameterPanel = new JPanel(new BorderLayout()); - extraParameterPanel.add(threeWayCheckBox,BorderLayout.NORTH); - extraParameterPanel.add(parameterPanel, BorderLayout.CENTER); - extraParameterPanel.add(transformPanel, BorderLayout.SOUTH); - - JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,stylesheetPanel,extraParameterPanel); - split1.setDividerLocation(0.5); - split1.setResizeWeight(0.5); - split1.setOneTouchExpandable(true); - JSplitPane split2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split1,sourceAndResultPanel); - split2.setDividerLocation(0.66); - split2.setResizeWeight(0.66); - split2.setOneTouchExpandable(true); - -// setLayout(new GridBagLayout()); -// add(stylesheetPanel); -// add(extraParameterPanel); -// add(panel); - setLayout(new BorderLayout()); - add(split2,BorderLayout.CENTER); - } - - - /** - * Performs the transform action. - */ - public void clickTransformButton() { - transformAction.actionPerformed(null); - } - - - /** - * Performs the load settings action. - */ - public void clickLoadSettingsButton() { - loadSettingsAction.actionPerformed(null); - } - - - /** - * Performs the save settings action. - */ - public void clickSaveSettingsButton() { - saveSettingsAction.actionPerformed(null); - } - - - public boolean isThreeWay() { - return threeWayCheckBox.isSelected(); - } - - public void setThreeWay(boolean threeWay) { - inputSelectionPanel.setEnabled(!threeWay); - stylesheetPanel.setEnabled(!threeWay); - resultPanel.setEnabled(!threeWay); - openResultCheckBox.setEnabled(!threeWay); - if(threeWayCheckBox.isSelected() != threeWay) { - threeWayCheckBox.setSelected(threeWay); - } - } - - private void initThreeWayCheckBox(){ - - threeWayCheckBox = new JCheckBox(jEdit.getProperty("xslt.three-way.label")); - threeWayCheckBox.setSelected(jEdit.getBooleanProperty(THREE_WAY)); - threeWayCheckBox.setName("three-way"); - threeWayCheckBox.setToolTipText("xslt.three-way.tooltip"); - - // save preference for next time - threeWayCheckBox.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - setThreeWay(threeWayCheckBox.isSelected()); - jEdit.setBooleanProperty(THREE_WAY,threeWayCheckBox.isSelected()); - } - }); - } - - private void initOpenResultCheckBox() { - - openResultCheckBox = new JCheckBox(jEdit.getProperty("xslt.result.open-result.label")); - openResultCheckBox.setSelected(jEdit.getBooleanProperty(OPEN_RESULT)); - openResultCheckBox.setName("open-result"); - openResultCheckBox.setToolTipText("xslt.result.open-result.tooltip"); - - // save preference for next time - openResultCheckBox.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - jEdit.setBooleanProperty(OPEN_RESULT,openResultCheckBox.isSelected()); - } - }); - } - - - private JComponent initTransformToolBar() { - - JToolBar toolBar = new JToolBar(JToolBar.HORIZONTAL); - toolBar.setFloatable(false); - - toolBar.add(loadSettingsAction.getButton()); - toolBar.add(saveSettingsAction.getButton()); - toolBar.addSeparator(); - transformButton = transformAction.getButton(); - toolBar.add(transformButton); - - return toolBar; - } - - - public View getView() { - return view; - } - - public BufferOrFileVFSSelector getInputSelectionPanel() { - return inputSelectionPanel; - } - - public StylesheetPanel getStylesheetPanel() { - return stylesheetPanel; - } - - - public KeyValuePanel getParameterPanel() { - return parameterPanel; - } - - public BufferOrFileVFSSelector getResult() { - return this.resultPanel; - } - - public String getResultFile() { - if(isThreeWay()){ - int[] iBuffers = getThreeWayBuffers(); - return view.getEditPanes()[iBuffers[2]].getBuffer().getPath(); - } else if(getResult().isFileSelected()) { - return getInputSelectionPanel().getSourceFile(); - } else { - Buffer b = jEdit.newFile(view); - String path = b.getPath(); - jEdit.closeBuffer(view,b); - return path; - } - } - - public void setStylesheets(String[] stylesheets) { - this.stylesheetPanel.setStylesheets(stylesheets); - } - - - public void setStylesheetParameters(String[] names, String[] values) { - this.parameterPanel.setKeyValues(names, values); - } - - - /** - * Attempts to load settings from a user specified file. - */ - private void loadSettings() { - try { - XsltSettings settings = new XsltSettings(this); - settings.loadFromFile(); - } catch (Exception e) { - Log.log(Log.ERROR, this, e.toString()); - } - } - - - /** - * Attempts to save settings to a user specified file. - */ - private void saveSettings() { - try { - XsltSettings settings = new XsltSettings(this); - settings.writeToFile(); - } catch (IOException e) { - Log.log(Log.ERROR, this, e.toString()); - } - } - - public boolean shouldOpenResult() { - return openResultCheckBox.isSelected(); - } - - private void transform() { - if(isThreeWay()) { - if(view.getEditPanes().length != 3) { - XSLTPlugin.showMessageDialog("xslt.transform.message.three-edit-panes", this); - } else { - doTransform(); - } - } else if (!getStylesheetPanel().stylesheetsExist()) { - XSLTPlugin.showMessageDialog("xslt.transform.message.no-stylesheets", this); - } else if (!inputSelectionPanel.isSourceFileDefined()) { - XSLTPlugin.showMessageDialog("xslt.transform.message.no-source", this); - } else if (!resultPanel.isSourceFileDefined()) { - XSLTPlugin.showMessageDialog("xslt.transform.message.no-result", this); - } else { - doTransform(); - } - } - - - /** - * do the transform asynchronously. - * 3 stages: - * - (EDT, quick) prepare transform - * - (Task, maybe long) run transform - * - (EDT, async) process result - * - */ - private void doTransform() { - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - final Date start = new Date(); - - final String path; - final boolean outputToBuffer; - final Result result; - final File resultFile; - final Object[] stylesheets; - final Writer outputWriter; - - Buffer outputBuffer = null; - - if (isThreeWay()) { - EditPane[] editPanes = view.getEditPanes(); - int[] iBuffers = getThreeWayBuffers(); - - // input - path = editPanes[iBuffers[0]].getBuffer().getPath(); - - // stylesheet - stylesheets = new Object[]{editPanes[iBuffers[1]].getBuffer().getPath()}; - - // output - outputBuffer = editPanes[iBuffers[2]].getBuffer(); - - if(outputBuffer.isReadOnly()){ - //put the result in the correct edit pane - outputBuffer = jEdit.newFile(editPanes[iBuffers[2]]); - } - - outputToBuffer = true; - outputWriter = new StringWriter(); - result = new StreamResult(outputWriter); - result.setSystemId(xml.PathUtilities.pathToURL(outputBuffer.getPath())); - resultFile = null; - - } else { - if (inputSelectionPanel.isFileSelected()) { - path = inputSelectionPanel.getSourceFile(); - } else { - Buffer buffer = view.getBuffer(); - path = buffer.getPath(); - } - - // get the stylesheets now, before the current buffer has changed - stylesheets = getStylesheets(); - - outputToBuffer = !resultPanel.isFileSelected(); - if(outputToBuffer) { - resultFile = null; - outputBuffer = jEdit.newFile(view); - outputWriter = new StringWriter(); - result = new StreamResult(outputWriter); - result.setSystemId(xml.PathUtilities.pathToURL(outputBuffer.getPath())); - } else { - resultFile = new File(resultPanel.getSourceFile()); - outputBuffer = jEdit.getBuffer(resultFile.getAbsolutePath()); - try { - outputWriter = new FileWriter(resultFile); - } catch (IOException e) { - String message = jEdit.getProperty("xslt.transform.message.failure"); - XSLTPlugin.processException(e, message, XSLTProcessor.this); - return; - } - result = new StreamResult(outputWriter); - result.setSystemId(resultFile.toURI().toString()); - } - } - - // clear any existing error - XSLTPlugin.getErrorSource(view).clear(); - - final Buffer fOutputBuffer = outputBuffer; - - Task t = new Task() { - - @Override - public void _run() { - ErrorListenerToErrorList listener = new ErrorListenerToErrorList(view, ""); - try { - - - InputSource inputSource = xml.Resolver.instance().resolveEntity(/*publicId*/null,path); - - XSLTUtilities.transform(inputSource, stylesheets , getStylesheetParameters(), result, listener); - - } catch(SAXParseException spe){ - listener.sendSAXError(spe); - String message = jEdit.getProperty("xslt.transform.message.failure"); - XSLTPlugin.processException(spe, message, XSLTProcessor.this); - - } catch (Exception e) { - String message = jEdit.getProperty("xslt.transform.message.failure"); - XSLTPlugin.processException(e, message, XSLTProcessor.this); - } finally { - // close the output - try { - outputWriter.flush(); - } catch (IOException e) { - Log.log(Log.WARNING, XSLTProcessor.class, "unable to flush transform output"); - } - try { - outputWriter.close(); - } catch (IOException e) { - Log.log(Log.WARNING, XSLTProcessor.class, "unable to close transform output"); - } - - SwingUtilities.invokeLater(new Runnable(){ - @Override - public void run() { - if(outputToBuffer){ - // pull the content to the Untitled buffer - fOutputBuffer.remove(0,fOutputBuffer.getLength()); - fOutputBuffer.insert(0,outputWriter.toString()); - }else if (fOutputBuffer == null) { - // output to file, which wasn't open before - if(shouldOpenResult()) { - jEdit.openFile(view, resultFile.getAbsolutePath()); - } - } else { - // output to file, which was already open - fOutputBuffer.reload(view); - } - logTimeTaken(start); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - }); - } - } - }; - ThreadUtilities.runInBackground(t); - } - - - public int[] getThreeWayBuffers(){ - int[] res = new int[3]; - - Buffer[] buffers = new Buffer[3]; - EditPane[] editPanes = view.getEditPanes(); - int iXML = -1,iXSLT=-1, iResult = -1; - - for(int i=0;i<3;i++) { - buffers[i] = editPanes[i].getBuffer(); - if("xsl".equals(buffers[i].getMode().getName())) { - // why should it be Source XSL -> XSL Transform -> result - // and not Source XML -> XSL Transform -> XSL result ? - // So the canonical ordering is used when there are 2 XSL - if(iXSLT == -1){ - iXSLT = i; - }else{ - iXSLT = 3; - } - } else if(iXML == -1 && "xml".equals(buffers[i].getMode().getName())) { - // only the first XML buffer will be seen as input - iXML = i; - } else { - iResult = i; - } - } - - if(iXML == -1 || iXSLT == -1 || iXSLT == 3) { - //ambiguous, so resort to default positioning - iXML = 0; - iXSLT = 1; - iResult = 2; - } - - // input - res[0] = iXML; - - // stylesheet - res[1] = iXSLT; - - // output - res[2] = iResult; - - return res; - } - - - public String getInput() { - if(isThreeWay()){ - int[] iBuffers = getThreeWayBuffers(); - return view.getEditPanes()[iBuffers[0]].getBuffer().getPath(); - } else if(getInputSelectionPanel().isFileSelected()) { - return getInputSelectionPanel().getSourceFile(); - } else { - return view.getBuffer().getPath(); - } - } - - public Object[] getStylesheets() { - if(isThreeWay()){ - int[] iBuffers = getThreeWayBuffers(); - return new Object[]{ (view.getEditPanes()[iBuffers[1]]).getBuffer().getPath()}; - } else if (getStylesheetPanel().isFileSelected()) { - return getStylesheetPanel().getStylesheets(); - } else { - Buffer buffer = view.getBuffer(); - return new Object[]{buffer.getPath()}; - } - } - - - private Map getStylesheetParameters() { - return getParameterPanel().getMap(); - } - - - private void logTimeTaken(Date start) { - Date end = new Date(); - long timeTaken = end.getTime() - start.getTime(); - long secondsTaken = timeTaken / 1000; - long partialSecondsTaken = timeTaken % 1000; - Object[] param = {secondsTaken + "." + partialSecondsTaken}; - String status = jEdit.getProperty("xslt.transform.message.success", param); - Log.log(Log.MESSAGE, this, status); - } - - private class TransformAction extends XsltAction { - - TransformAction() { - super("xslt.transform"); - } - - public void actionPerformed(ActionEvent e) { - transform(); - } - - protected Dimension getButtonDimension() { - Dimension dimension = new Dimension(74, 30); - return dimension; - } - } - - - private class SaveSettingsAction extends XsltAction { - - SaveSettingsAction() { - super("xslt.settings.save"); - } - - public void actionPerformed(ActionEvent e) { - saveSettings(); - } - - } - - - private class LoadSettingsAction extends XsltAction { - - LoadSettingsAction() { - super("xslt.settings.load"); - } - - public void actionPerformed(ActionEvent e) { - loadSettings(); - } - - } - +/* + * XSLTProcessor.java - GUI for performing XSL Transformations + * + * Copyright 2002 Greg Merrill + * 2002, 2003 Robert McKinnon + * 2010 Eric Le Lay + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package xslt; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.Writer; +import java.io.FileWriter; +import java.io.StringWriter; +import java.io.IOException; +import java.util.Date; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JToolBar; +import javax.swing.JCheckBox; +import javax.swing.SwingUtilities; + +import org.gjt.sp.jedit.Buffer; +import org.gjt.sp.jedit.View; +import org.gjt.sp.jedit.EditPane; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.gui.DockableWindowManager; +import org.gjt.sp.jedit.gui.DefaultFocusComponent; +import org.gjt.sp.util.Log; +import org.gjt.sp.util.Task; +import org.gjt.sp.util.ThreadUtilities; + +import errorlist.*; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXParseException; + +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; + +/** + * GUI for performing XSL Transformations. + * + * @author Greg Merrill + * @author Robert McKinnon - rob...@us... + * @author Eric Le Lay + */ +public class XSLTProcessor extends JPanel implements DefaultFocusComponent { + public static final String DOCKABLE_NAME = "xslt-processor"; + private static final String OPEN_RESULT = "xslt.open-result"; + private static final String THREE_WAY = "xslt.three-way"; + + private View view; + private BufferOrFileVFSSelector resultPanel; + private XsltAction saveSettingsAction = new SaveSettingsAction(); + private XsltAction loadSettingsAction = new LoadSettingsAction(); + private XsltAction transformAction = new TransformAction(); + + private BufferOrFileVFSSelector inputSelectionPanel; + private StylesheetPanel stylesheetPanel; + private KeyValuePanel parameterPanel; + private JButton transformButton; + private JCheckBox openResultCheckBox; + private JCheckBox threeWayCheckBox; + + /** + * Constructor for the XSLTProcessor object. + * + */ + public XSLTProcessor(View theView, String position) { + super(); + + this.view = theView; + boolean sideBySide = position.equals(DockableWindowManager.TOP) || position.equals(DockableWindowManager.BOTTOM); + + initThreeWayCheckBox(); + initOpenResultCheckBox(); + this.resultPanel = new BufferOrFileVFSSelector(view,"xslt.result"); + this.inputSelectionPanel = new BufferOrFileVFSSelector(view,"xslt.source"); + this.stylesheetPanel = new StylesheetPanel(view, this); + this.parameterPanel = new KeyValuePanel("xslt.parameters"); + + JComponent transformPanel = initTransformToolBar(); + + if (sideBySide) { + createHorizontalLayout(inputSelectionPanel, transformPanel); + } else { + createVerticalLayout(inputSelectionPanel, transformPanel); + } + + setThreeWay(threeWayCheckBox.isSelected()); + + } + + public void focusOnDefaultComponent() { + if(transformButton != null) { + transformButton.requestFocus(); + } + } + + private void createVerticalLayout(JComponent sourcePanel, JComponent transformPanel) { + setLayout(new GridBagLayout()); + + sourcePanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); + stylesheetPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); + transformPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); + resultPanel.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); + openResultCheckBox.setBorder(BorderFactory.createEmptyBorder(8,0,0,0)); + + GridBagConstraints c = new GridBagConstraints(); + + c.gridx = 0; + c.gridy = 0; + c.gridwidth = 1; + c.gridheight = 1; + c.weightx = 1; + c.weighty = 0; + c.fill = GridBagConstraints.BOTH; + + add(threeWayCheckBox,c); + + c.gridy += c.gridheight; + c.gridheight = 4; + add(sourcePanel,c); + + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, stylesheetPanel, parameterPanel); + splitPane.setOneTouchExpandable(true); + + c.gridy += c.gridheight; + c.gridheight = 10; + c.weighty = 1; + add(splitPane,c); + + c.gridy += c.gridheight; + c.gridheight = 1; + c.weighty = 0; + c.fill = GridBagConstraints.NONE; + c.anchor = GridBagConstraints.CENTER; + add(transformPanel,c); + c.gridy += c.gridheight; + c.gridheight = 4; + c.fill = GridBagConstraints.BOTH; + add(resultPanel,c); + c.gridy += c.gridheight; + c.gridheight = 1; + c.fill = GridBagConstraints.NONE; + add(openResultCheckBox,c); + } + + + private void createHorizontalLayout(JComponent sourcePanel, JComponent transformPanel) { + sourcePanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); + stylesheetPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); + transformPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); + resultPanel.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); + openResultCheckBox.setBorder(BorderFactory.createEmptyBorder(6,0,0,0)); + + JPanel sourceAndResultPanel = new JPanel(new BorderLayout()); + sourceAndResultPanel.add(sourcePanel, BorderLayout.NORTH); + sourceAndResultPanel.add(resultPanel, BorderLayout.CENTER); + sourceAndResultPanel.add(openResultCheckBox, BorderLayout.SOUTH); + + JPanel extraParameterPanel = new JPanel(new BorderLayout()); + extraParameterPanel.add(threeWayCheckBox,BorderLayout.NORTH); + extraParameterPanel.add(parameterPanel, BorderLayout.CENTER); + extraParameterPanel.add(transformPanel, BorderLayout.SOUTH); + + JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,stylesheetPanel,extraParameterPanel); + split1.setDividerLocation(0.5); + split1.setResizeWeight(0.5); + split1.setOneTouchExpandable(true); + JSplitPane split2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split1,sourceAndResultPanel); + split2.setDividerLocation(0.66); + split2.setResizeWeight(0.66); + split2.setOneTouchExpandable(true); + +// setLayout(new GridBagLayout()); +// add(stylesheetPanel); +// add(extraParameterPanel); +// add(panel); + setLayout(new BorderLayout()); + add(split2,BorderLayout.CENTER); + } + + + /** + * Performs the transform action. + */ + public void clickTransformButton() { + transformAction.actionPerformed(null); + } + + + /** + * Performs the load settings action. + */ + public void clickLoadSettingsButton() { + loadSettingsAction.actionPerformed(null); + } + + + /** + * Performs the save settings action. + */ + public void clickSaveSettingsButton() { + saveSettingsAction.actionPerformed(null); + } + + + public boolean isThreeWay() { + return threeWayCheckBox.isSelected(); + } + + public void setThreeWay(boolean threeWay) { + inputSelectionPanel.setEnabled(!threeWay); + stylesheetPanel.setEnabled(!threeWay); + resultPanel.setEnabled(!threeWay); + openResultCheckBox.setEnabled(!threeWay); + if(threeWayCheckBox.isSelected() != threeWay) { + threeWayCheckBox.setSelected(threeWay); + } + } + + private void initThreeWayCheckBox(){ + + threeWayCheckBox = new JCheckBox(jEdit.getProperty("xslt.three-way.label")); + threeWayCheckBox.setSelected(jEdit.getBooleanProperty(THREE_WAY)); + threeWayCheckBox.setName("three-way"); + threeWayCheckBox.setToolTipText("xslt.three-way.tooltip"); + + // save preference for next time + threeWayCheckBox.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + setThreeWay(threeWayCheckBox.isSelected()); + jEdit.setBooleanProperty(THREE_WAY,threeWayCheckBox.isSelected()); + } + }); + } + + private void initOpenResultCheckBox() { + + openResultCheckBox = new JCheckBox(jEdit.getProperty("xslt.result.open-result.label")); + openResultCheckBox.setSelected(jEdit.getBooleanProperty(OPEN_RESULT)); + openResultCheckBox.setName("open-result"); + openResultCheckBox.setToolTipText("xslt.result.open-result.tooltip"); + + // save preference for next time + openResultCheckBox.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + jEdit.setBooleanProperty(OPEN_RESULT,openResultCheckBox.isSelected()); + } + }); + } + + + private JComponent initTransformToolBar() { + + JToolBar toolBar = new JToolBar(JToolBar.HORIZONTAL); + toolBar.setFloatable(false); + + toolBar.add(loadSettingsAction.getButton()); + toolBar.add(saveSettingsAction.getButton()); + toolBar.addSeparator(); + transformButton = transformAction.getButton(); + toolBar.add(transformButton); + + return toolBar; + } + + + public View getView() { + return view; + } + + public BufferOrFileVFSSelector getInputSelectionPanel() { + return inputSelectionPanel; + } + + public StylesheetPanel getStylesheetPanel() { + return stylesheetPanel; + } + + + public KeyValuePanel getParameterPanel() { + return parameterPanel; + } + + public BufferOrFileVFSSelector getResult() { + return this.resultPanel; + } + + public String getResultFile() { + if(isThreeWay()){ + int[] iBuffers = getThreeWayBuffers(); + return view.getEditPanes()[iBuffers[2]].getBuffer().getPath(); + } else if(getResult().isFileSelected()) { + return getInputSelectionPanel().getSourceFile(); + } else { + Buffer b = jEdit.newFile(view); + String path = b.getPath(); + jEdit.closeBuffer(view,b); + return path; + } + } + + public void setStylesheets(String[] stylesheets) { + this.stylesheetPanel.setStylesheets(stylesheets); + } + + + public void setStylesheetParameters(String[] names, String[] values) { + this.parameterPanel.setKeyValues(names, values); + } + + + /** + * Attempts to load settings from a user specified file. + */ + private void loadSettings() { + try { + XsltSettings settings = new XsltSettings(this); + settings.loadFromFile(); + } catch (Exception e) { + Log.log(Log.ERROR, this, e.toString()); + } + } + + + /** + * Attempts to save settings to a user specified file. + */ + private void saveSettings() { + try { + XsltSettings settings = new XsltSettings(this); + settings.writeToFile(); + } catch (IOException e) { + Log.log(Log.ERROR, this, e.toString()); + } + } + + public boolean shouldOpenResult() { + return openResultCheckBox.isSelected(); + } + + private void transform() { + if(isThreeWay()) { + if(view.getEditPanes().length != 3) { + XSLTPlugin.showMessageDialog("xslt.transform.message.three-edit-panes", this); + } else { + doTransform(); + } + } else if (!getStylesheetPanel().stylesheetsExist()) { + XSLTPlugin.showMessageDialog("xslt.transform.message.no-stylesheets", this); + } else if (!inputSelectionPanel.isSourceFileDefined()) { + XSLTPlugin.showMessageDialog("xslt.transform.message.no-source", this); + } else if (!resultPanel.isSourceFileDefined()) { + XSLTPlugin.showMessageDialog("xslt.transform.message.no-result", this); + } else { + doTransform(); + } + } + + + /** + * do the transform asynchronously. + * 3 stages: + * - (EDT, quick) prepare transform + * - (Task, maybe long) run transform + * - (EDT, async) process result + * + */ + private void doTransform() { + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + final Date start = new Date(); + + final String path; + final boolean outputToBuffer; + final Result result; + final File resultFile; + final Object[] stylesheets; + final Writer outputWriter; + + Buffer outputBuffer = null; + + if (isThreeWay()) { + EditPane[] editPanes = view.getEditPanes(); + int[] iBuffers = getThreeWayBuffers(); + + // input + path = editPanes[iBuffers[0]].getBuffer().getPath(); + + // stylesheet + stylesheets = new Object[]{editPanes[iBuffers[1]].getBuffer().getPath()}; + + // output + outputBuffer = editPanes[iBuffers[2]].getBuffer(); + + if(outputBuffer.isReadOnly()){ + //put the result in the correct edit pane + outputBuffer = jEdit.newFile(editPanes[iBuffers[2]]); + } + + outputToBuffer = true; + outputWriter = new StringWriter(); + result = new StreamResult(outputWriter); + result.setSystemId(xml.PathUtilities.pathToURL(outputBuffer.getPath())); + resultFile = null; + + } else { + if (inputSelectionPanel.isFileSelected()) { + path = inputSelectionPanel.getSourceFile(); + } else { + Buffer buffer = view.getBuffer(); + path = buffer.getPath(); + } + + // get the stylesheets now, before the current buffer has changed + stylesheets = getStylesheets(); + + outputToBuffer = !resultPanel.isFileSelected(); + if(outputToBuffer) { + resultFile = null; + outputBuffer = jEdit.newFile(view); + outputWriter = new StringWriter(); + result = new StreamResult(outputWriter); + result.setSystemId(xml.PathUtilities.pathToURL(outputBuffer.getPath())); + } else { + // let transformer write directly to file, if an encoding was chosen + // in the transform. + resultFile = new File(resultPanel.getSourceFile()); + outputBuffer = jEdit.getBuffer(resultFile.getAbsolutePath()); + result = new StreamResult(resultFile.toURI().toString()); + outputWriter = null; + } + } + + // clear any existing error + XSLTPlugin.getErrorSource(view).clear(); + + final Buffer fOutputBuffer = outputBuffer; + + Task t = new Task() { + + @Override + public void _run() { + ErrorListenerToErrorList listener = new ErrorListenerToErrorList(view, ""); + try { + + + InputSource inputSource = xml.Resolver.instance().resolveEntity(/*publicId*/null,path); + + XSLTUtilities.transform(inputSource, stylesheets , getStylesheetParameters(), result, listener); + + } catch(SAXParseException spe){ + listener.sendSAXError(spe); + String message = jEdit.getProperty("xslt.transform.message.failure"); + XSLTPlugin.processException(spe, message, XSLTProcessor.this); + + } catch (Exception e) { + String message = jEdit.getProperty("xslt.transform.message.failure"); + XSLTPlugin.processException(e, message, XSLTProcessor.this); + } finally { + // close the output + if(outputWriter!=null) { + try { + outputWriter.flush(); + } catch (IOException e) { + Log.log(Log.WARNING, XSLTProcessor.class, "unable to flush transform output"); + } + try { + outputWriter.close(); + } catch (IOException e) { + Log.log(Log.WARNING, XSLTProcessor.class, "unable to close transform output"); + } + } + + SwingUtilities.invokeLater(new Runnable(){ + @Override + public void run() { + if(outputToBuffer){ + // pull the content to the Untitled buffer + fOutputBuffer.remove(0,fOutputBuffer.getLength()); + fOutputBuffer.insert(0,outputWriter.toString()); + }else if (fOutputBuffer == null) { + // output to file, which wasn't open before + if(shouldOpenResult()) { + jEdit.openFile(view, resultFile.getAbsolutePath()); + } + } else { + // output to file, which was already open + fOutputBuffer.reload(view); + } + logTimeTaken(start); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }); + } + } + }; + ThreadUtilities.runInBackground(t); + } + + + public int[] getThreeWayBuffers(){ + int[] res = new int[3]; + + Buffer[] buffers = new Buffer[3]; + EditPane[] editPanes = view.getEditPanes(); + int iXML = -1,iXSLT=-1, iResult = -1; + + for(int i=0;i<3;i++) { + buffers[i] = editPanes[i].getBuffer(); + if("xsl".equals(buffers[i].getMode().getName())) { + // why should it be Source XSL -> XSL Transform -> result + // and not Source XML -> XSL Transform -> XSL result ? + // So the canonical ordering is used when there are 2 XSL + if(iXSLT == -1){ + iXSLT = i; + }else{ + iXSLT = 3; + } + } else if(iXML == -1 && "xml".equals(buffers[i].getMode().getName())) { + // only the first XML buffer will be seen as input + iXML = i; + } else { + iResult = i; + } + } + + if(iXML == -1 || iXSLT == -1 || iXSLT == 3) { + //ambiguous, so resort to default positioning + iXML = 0; + iXSLT = 1; + iResult = 2; + } + + // input + res[0] = iXML; + + // stylesheet + res[1] = iXSLT; + + // output + res[2] = iResult; + + return res; + } + + + public String getInput() { + if(isThreeWay()){ + int[] iBuffers = getThreeWayBuffers(); + return view.getEditPanes()[iBuffers[0]].getBuffer().getPath(); + } else if(getInputSelectionPanel().isFileSelected()) { + return getInputSelectionPanel().getSourceFile(); + } else { + return view.getBuffer().getPath(); + } + } + + public Object[] getStylesheets() { + if(isThreeWay()){ + int[] iBuffers = getThreeWayBuffers(); + return new Object[]{ (view.getEditPanes()[iBuffers[1]]).getBuffer().getPath()}; + } else if (getStylesheetPanel().isFileSelected()) { + return getStylesheetPanel().getStylesheets(); + } else { + Buffer buffer = view.getBuffer(); + return new Object[]{buffer.getPath()}; + } + } + + + private Map getStylesheetParameters() { + return getParameterPanel().getMap(); + } + + + private void logTimeTaken(Date start) { + Date end = new Date(); + long timeTaken = end.getTime() - start.getTime(); + long secondsTaken = timeTaken / 1000; + long partialSecondsTaken = timeTaken % 1000; + Object[] param = {secondsTaken + "." + partialSecondsTaken}; + String status = jEdit.getProperty("xslt.transform.message.success", param); + Log.log(Log.MESSAGE, this, status); + } + + private class TransformAction extends XsltAction { + + TransformAction() { + super("xslt.transform"); + } + + public void actionPerformed(ActionEvent e) { + transform(); + } + + protected Dimension getButtonDimension() { + Dimension dimension = new Dimension(74, 30); + return dimension; + } + } + + + private class SaveSettingsAction extends XsltAction { + + SaveSettingsAction() { + super("xslt.settings.save"); + } + + public void actionPerformed(ActionEvent e) { + saveSettings(); + } + + } + + + private class LoadSettingsAction extends XsltAction { + + LoadSettingsAction() { + super("xslt.settings.load"); + } + + public void actionPerformed(ActionEvent e) { + loadSettings(); + } + + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ker...@us...> - 2014-08-26 06:02:43
|
Revision: 23669 http://sourceforge.net/p/jedit/svn/23669 Author: kerik-sf Date: 2014-08-26 06:02:35 +0000 (Tue, 26 Aug 2014) Log Message: ----------- revbump 0.8.2, fix compile-on-save wrt symlinks errors reported by compile-on-save on symlinks were never cleaned: even if the error was corrected in the file and saved, it stayed because it was reported by the xslt engine on the symlink target and only errors related to the symlink were cleaned. Modified Paths: -------------- plugins/XSLT/trunk/XSLT.props plugins/XSLT/trunk/docs/users-guide.xml plugins/XSLT/trunk/test/build.xml plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java plugins/XSLT/trunk/xslt/XsltActions.java Added Paths: ----------- plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java plugins/XSLT/trunk/test_data/broken/symlink_to_invalid_xpath.xsl Modified: plugins/XSLT/trunk/XSLT.props =================================================================== --- plugins/XSLT/trunk/XSLT.props 2014-08-25 01:17:29 UTC (rev 23668) +++ plugins/XSLT/trunk/XSLT.props 2014-08-26 06:02:35 UTC (rev 23669) @@ -1,10 +1,10 @@ plugin.xslt.XSLTPlugin.activate=xslt.compile-on-save plugin.xslt.XSLTPlugin.name=XSLT plugin.xslt.XSLTPlugin.author=Robert McKinnon, Greg Merrill, Wim Le Page, Pieter Wellens, Eric Le Lay -plugin.xslt.XSLTPlugin.version=0.8.1 +plugin.xslt.XSLTPlugin.version=0.8.2 plugin.xslt.XSLTPlugin.docs=index.html plugin.xslt.XSLTPlugin.jars=xalan.jar serializer.jar -plugin.xslt.XSLTPlugin.depend.0=jdk 1.5 +plugin.xslt.XSLTPlugin.depend.0=jdk 1.6 plugin.xslt.XSLTPlugin.depend.1=jedit 05.00.99.00 plugin.xslt.XSLTPlugin.depend.2=plugin xml.XmlPlugin 2.8.5 plugin.xslt.XSLTPlugin.depend.3=plugin errorlist.ErrorListPlugin 2.1 Modified: plugins/XSLT/trunk/docs/users-guide.xml =================================================================== --- plugins/XSLT/trunk/docs/users-guide.xml 2014-08-25 01:17:29 UTC (rev 23668) +++ plugins/XSLT/trunk/docs/users-guide.xml 2014-08-26 06:02:35 UTC (rev 23669) @@ -457,6 +457,12 @@ <appendix id="changelog"> <title>Change log</title> <para> + <emphasis role="bold">Changes from 0.8.1 to 0.8.2</emphasis> + <itemizedlist> + <listitem><para>XSLT: compile on save clears errors from symlinked files.</para></listitem> + </itemizedlist> + </para> + <para> <emphasis role="bold">Changes from 0.8.0 to 0.8.1</emphasis> <itemizedlist> <listitem><para>XPath tool: press Ctrl+Enter from expression panel to trigger evaluating the XPath expression.</para></listitem> Modified: plugins/XSLT/trunk/test/build.xml =================================================================== --- plugins/XSLT/trunk/test/build.xml 2014-08-25 01:17:29 UTC (rev 23668) +++ plugins/XSLT/trunk/test/build.xml 2014-08-26 06:02:35 UTC (rev 23669) @@ -98,7 +98,7 @@ <!-- override the value of test.current on the command line to run this test. eg. LANG=en_GB.UTF-8 ant -Dtest.current=xslt/Saxon9XPathAdapterTest.java test --> - <property name="test.current" value="xslt/XSLTPluginXPathTest.java"/> + <property name="test.current" value="xslt/XSLTCompileTest.java"/> <selector id="testcases.current"> <filename name="${test.current}"/> </selector> Added: plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java (rev 0) +++ plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java 2014-08-26 06:02:35 UTC (rev 23669) @@ -0,0 +1,136 @@ +/* + * XSLTCompileTest.java + * :folding=explicit:collapseFolds=1: + * + * Copyright (C) 2010-2014 Eric Le Lay + * + * The XSLT plugin is licensed under the GNU General Public License, with + * the following exception: + * + * "Permission is granted to link this code with software released under + * the Apache license version 2.0, for example used by the Xalan package." + */ +package xslt; + +import static org.gjt.sp.jedit.testframework.TestUtils.action; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.regex.Pattern; + +import org.fest.swing.edt.GuiActionRunner; +import org.fest.swing.edt.GuiTask; +import org.fest.swing.fixture.FrameFixture; +import org.fest.swing.fixture.JPanelFixture; +import org.fest.swing.timing.Pause; +import org.gjt.sp.jedit.Buffer; +import org.gjt.sp.jedit.jEdit; +import org.gjt.sp.jedit.testframework.JEditRunner; +import org.gjt.sp.jedit.testframework.PluginOptionsFixture; +import org.gjt.sp.jedit.testframework.TestData; +import org.gjt.sp.jedit.testframework.TestUtils; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(JEditRunner.class) +public class XSLTCompileTest { + @Rule + public TestData testData = new TestData(); + + @Test + public void testNormal() throws IOException{ + File xsl = new File(testData.get(),"broken/transform.xsl"); + + /* + * the plugin must be activated manually, because : + * - it's not activated at startup because it is only activated if "compile on save" + * is checked, which is not the case by default + * - it's not activated when one of the classes of the plugin is loaded, + * since delegateFirst=true and XSLT.jar is present in the parent ClassLoader + * + * when running normally, there is no problem. + */ + jEdit.getPlugin("xslt.XSLTPlugin",true).getPluginJAR().activatePlugin(); + + PluginOptionsFixture optionsF = TestUtils.pluginOptions(); + JPanelFixture options = optionsF.optionPane("XSLT","xslt"); + Pause.pause(1000); + options.checkBox("compile-on-save").check(); + optionsF.OK(); + + TestUtils.openFile(xsl.getPath()); + + action("error-list-show"); + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + + action("save"); + Pause.pause(3000); + + errorlist.tree().selectRow(1); + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); + errorlist.close(); + } + + @Test + public void testSymlink() throws IOException{ + File xsl = new File(testData.get(),"broken/symlink_to_invalid_xpath.xsl"); + + /* see previous test for why plugin must be activated */ + jEdit.getPlugin("xslt.XSLTPlugin",true).getPluginJAR().activatePlugin(); + + PluginOptionsFixture optionsF = TestUtils.pluginOptions(); + JPanelFixture options = optionsF.optionPane("XSLT","xslt"); + Pause.pause(1000); + options.checkBox("compile-on-save").check(); + // Saxon is required + options.comboBox("factory").selectItem(Pattern.compile("XSLT 2\\.0.*")); + optionsF.OK(); + + final Buffer buffer = TestUtils.openFile(xsl.getPath()); + + action("error-list-show"); + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + + action("save"); + Pause.pause(3000); + + errorlist.tree().selectRow(1); + assertTrue(errorlist.tree().valueAt(1).startsWith("11: (XSLT error)")); + errorlist.close(); + + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + String text = buffer.getText(); + String bad = "@att-within-att"; + int offset = text.indexOf(bad); + buffer.remove(offset, bad.length()); + buffer.insert(offset, "."); + } + }); + try{ + + action("error-list-show"); + errorlist = TestUtils.findFrameByTitle("Error List"); + + action("save"); + Pause.pause(3000); + + assertEquals(0, errorlist.tree().target.getRowCount()); + errorlist.close(); + + }finally{ + TestUtils.action("undo"); + TestUtils.action("undo"); + TestUtils.action("save"); + Pause.pause(3000); + // otherwise the error @att-within-att error stays and makes testNormal fail + TestUtils.action("error-list-clear"); + TestUtils.close(TestUtils.view(), buffer); + } + } + +} Property changes on: plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id Author Revision Date \ No newline at end of property Modified: plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2014-08-25 01:17:29 UTC (rev 23668) +++ plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2014-08-26 06:02:35 UTC (rev 23669) @@ -223,40 +223,7 @@ errorlist.close(); } - @Test - public void testXSLTCompileOnSave() throws IOException{ - File xsl = new File(testData.get(),"broken/transform.xsl"); - - /* - * the plugin must be activated manually, because : - * - it's not activated at startup because it is only activated if "compile on save" - * is checked, which is not the case by default - * - it's not activated when one of the classes of the plugin is loaded, - * since delegateFirst=true and XSLT.jar is present in the parent ClassLoader - * - * when running normally, there is no problem. - */ - jEdit.getPlugin("xslt.XSLTPlugin",true).getPluginJAR().activatePlugin(); - - PluginOptionsFixture optionsF = TestUtils.pluginOptions(); - JPanelFixture options = optionsF.optionPane("XSLT","xslt"); - Pause.pause(1000); - options.checkBox("compile-on-save").requireNotSelected().check(); - optionsF.OK(); - - TestUtils.openFile(xsl.getPath()); - - action("error-list-show"); - FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); - action("save"); - Pause.pause(3000); - - errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); - errorlist.close(); - } - @Test public void testXSLTResultFile() throws IOException{ File xml = new File(testData.get(),"simple/source.xml"); Added: plugins/XSLT/trunk/test_data/broken/symlink_to_invalid_xpath.xsl =================================================================== --- plugins/XSLT/trunk/test_data/broken/symlink_to_invalid_xpath.xsl (rev 0) +++ plugins/XSLT/trunk/test_data/broken/symlink_to_invalid_xpath.xsl 2014-08-26 06:02:35 UTC (rev 23669) @@ -0,0 +1 @@ +link invalid_xpath.xsl \ No newline at end of file Property changes on: plugins/XSLT/trunk/test_data/broken/symlink_to_invalid_xpath.xsl ___________________________________________________________________ Added: svn:special ## -0,0 +1 ## +* \ No newline at end of property Modified: plugins/XSLT/trunk/xslt/XsltActions.java =================================================================== --- plugins/XSLT/trunk/xslt/XsltActions.java 2014-08-25 01:17:29 UTC (rev 23668) +++ plugins/XSLT/trunk/xslt/XsltActions.java 2014-08-26 06:02:35 UTC (rev 23669) @@ -118,11 +118,14 @@ @Override public void _run() { String path = buffer.getPath(); - ErrorListenerToErrorList listener = new ErrorListenerToErrorList(view, PathUtilities.pathToURL(buffer.getPath())); + ErrorListenerToErrorList listener = new ErrorListenerToErrorList(view, PathUtilities.pathToURL(path)); try { // clear any existing error listener.errorSource.removeFileErrors(path); + // clear any existing error reported upon compile-on-save + // on the target of the symlink + listener.errorSource.removeFileErrors(buffer.getSymlinkPath()); XSLTUtilities.compileStylesheet(path, listener); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ker...@us...> - 2014-08-30 14:55:17
|
Revision: 23670 http://sourceforge.net/p/jedit/svn/23670 Author: kerik-sf Date: 2014-08-30 14:55:09 +0000 (Sat, 30 Aug 2014) Log Message: ----------- clear all XSLT errors on compile-on-save It takes care of errors not cleared when errors are corrected in imported or included stylesheets as well as when editing symlinks. Modified Paths: -------------- plugins/XSLT/trunk/docs/users-guide.xml plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java plugins/XSLT/trunk/xslt/XsltActions.java Added Paths: ----------- plugins/XSLT/trunk/test_data/broken/error_in_imported.xsl Modified: plugins/XSLT/trunk/docs/users-guide.xml =================================================================== --- plugins/XSLT/trunk/docs/users-guide.xml 2014-08-26 06:02:35 UTC (rev 23669) +++ plugins/XSLT/trunk/docs/users-guide.xml 2014-08-30 14:55:09 UTC (rev 23670) @@ -459,7 +459,9 @@ <para> <emphasis role="bold">Changes from 0.8.1 to 0.8.2</emphasis> <itemizedlist> - <listitem><para>XSLT: compile on save clears errors from symlinked files.</para></listitem> + <listitem><para>XSLT: compile on save clears all errors (fixes + errors not cleared in symlinked files or errors from imported + templates not cleared).</para></listitem> </itemizedlist> </para> <para> Modified: plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java 2014-08-26 06:02:35 UTC (rev 23669) +++ plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java 2014-08-30 14:55:09 UTC (rev 23670) @@ -133,4 +133,59 @@ } } + @Test + public void testCompound() throws IOException{ + File xsl = new File(testData.get(),"broken/error_in_imported.xsl"); + + /* see previous test for why plugin must be activated */ + jEdit.getPlugin("xslt.XSLTPlugin",true).getPluginJAR().activatePlugin(); + + PluginOptionsFixture optionsF = TestUtils.pluginOptions(); + JPanelFixture options = optionsF.optionPane("XSLT","xslt"); + Pause.pause(1000); + options.checkBox("compile-on-save").check(); + // Saxon is required + options.comboBox("factory").selectItem(Pattern.compile("XSLT 2\\.0.*")); + optionsF.OK(); + + final Buffer buffer = TestUtils.openFile(xsl.getPath()); + + action("error-list-show"); + FrameFixture errorlist = TestUtils.findFrameByTitle("Error List"); + + action("save"); + Pause.pause(3000); + + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); + errorlist.close(); + + GuiActionRunner.execute(new GuiTask() { + @Override + protected void executeInEDT() throws Throwable { + String text = buffer.getText(); + String bad = "<xsl:import href=\"transform.xsl\"/>"; + int offset = text.indexOf(bad); + buffer.remove(offset, bad.length()); + } + }); + try{ + + action("error-list-show"); + errorlist = TestUtils.findFrameByTitle("Error List"); + + action("save"); + Pause.pause(30000); + + assertEquals(0, errorlist.tree().target.getRowCount()); + errorlist.close(); + + }finally{ + TestUtils.action("undo"); + TestUtils.action("save"); + Pause.pause(3000); + // otherwise the error stays and makes testNormal fail + TestUtils.action("error-list-clear"); + TestUtils.close(TestUtils.view(), buffer); + } + } } Added: plugins/XSLT/trunk/test_data/broken/error_in_imported.xsl =================================================================== --- plugins/XSLT/trunk/test_data/broken/error_in_imported.xsl (rev 0) +++ plugins/XSLT/trunk/test_data/broken/error_in_imported.xsl 2014-08-30 14:55:09 UTC (rev 23670) @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + + <xsl:import href="transform.xsl"/> + + <xsl:template match="/" /> +</xsl:stylesheet> Property changes on: plugins/XSLT/trunk/test_data/broken/error_in_imported.xsl ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id Author Revision Date Head \ No newline at end of property Modified: plugins/XSLT/trunk/xslt/XsltActions.java =================================================================== --- plugins/XSLT/trunk/xslt/XsltActions.java 2014-08-26 06:02:35 UTC (rev 23669) +++ plugins/XSLT/trunk/xslt/XsltActions.java 2014-08-30 14:55:09 UTC (rev 23670) @@ -122,10 +122,7 @@ try { // clear any existing error - listener.errorSource.removeFileErrors(path); - // clear any existing error reported upon compile-on-save - // on the target of the symlink - listener.errorSource.removeFileErrors(buffer.getSymlinkPath()); + XSLTPlugin.getErrorSource(view).clear(); XSLTUtilities.compileStylesheet(path, listener); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ker...@us...> - 2014-08-30 14:55:45
|
Revision: 23671 http://sourceforge.net/p/jedit/svn/23671 Author: kerik-sf Date: 2014-08-30 14:55:35 +0000 (Sat, 30 Aug 2014) Log Message: ----------- '(XSLT)' prefix in ErrorList Modified Paths: -------------- plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java plugins/XSLT/trunk/xslt/ErrorListenerToErrorList.java Modified: plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java 2014-08-30 14:55:09 UTC (rev 23670) +++ plugins/XSLT/trunk/test/xslt/XSLTCompileTest.java 2014-08-30 14:55:35 UTC (rev 23671) @@ -70,7 +70,7 @@ Pause.pause(3000); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT)")); errorlist.close(); } @@ -98,7 +98,7 @@ Pause.pause(3000); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("11: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("11: (XSLT)")); errorlist.close(); GuiActionRunner.execute(new GuiTask() { @@ -156,7 +156,7 @@ action("save"); Pause.pause(3000); - assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT)")); errorlist.close(); GuiActionRunner.execute(new GuiTask() { Modified: plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java =================================================================== --- plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2014-08-30 14:55:09 UTC (rev 23670) +++ plugins/XSLT/trunk/test/xslt/XSLTPluginTest.java 2014-08-30 14:55:35 UTC (rev 23671) @@ -100,7 +100,7 @@ assertThat(b.getName().matches("Untitled-\\d+")); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error) xsl:ourrtput")); + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT) xsl:ourrtput")); errorlist.close(); xsltProcessor.close(); TestUtils.close(TestUtils.view(),b); @@ -130,7 +130,7 @@ xsltProcessor.close(); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("15: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("15: (XSLT)")); errorlist.close(); TestUtils.close(TestUtils.view(),b); } @@ -154,7 +154,7 @@ assertThat(b.getName().matches("Untitled-\\d+")); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("16: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("16: (XSLT)")); errorlist.close(); xsltProcessor.close(); TestUtils.close(TestUtils.view(),b); @@ -219,7 +219,7 @@ Pause.pause(1000); errorlist.tree().selectRow(1); - assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT error)")); + assertTrue(errorlist.tree().valueAt(1).startsWith("6: (XSLT)")); errorlist.close(); } Modified: plugins/XSLT/trunk/xslt/ErrorListenerToErrorList.java =================================================================== --- plugins/XSLT/trunk/xslt/ErrorListenerToErrorList.java 2014-08-30 14:55:09 UTC (rev 23670) +++ plugins/XSLT/trunk/xslt/ErrorListenerToErrorList.java 2014-08-30 14:55:35 UTC (rev 23671) @@ -124,12 +124,12 @@ } errorSource.addError(new DefaultErrorSource.DefaultError(errorSource, level,path,line,0,col, - "(XSLT error) "+exception.getMessage())); + "(XSLT) "+exception.getMessage())); } else { path = PathUtilities.urlToPath(stylesheetPath); errorSource.addError(new DefaultErrorSource.DefaultError(errorSource, level,path,1,0,0, - "(XSLT error) "+exception.getMessage())); + "(XSLT) "+exception.getMessage())); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |