/** * @param offset Make the locator of this error start "offset" number of frames from * the point where this method is called (a positive number results in * less frames in the locator). */ public static XProcException javaError(Throwable throwable, int offset) { StackTraceElement[] base = new RuntimeException().getStackTrace(); return javaError(throwable, offset, base, 1); }
cause = javaError(cause, offset, base, baseOffset); else
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { Query query = query(arguments[0].head().getStringValue()); List<String> text = sequenceToList(arguments[1]); List<CSSStyledText> styledText = new ArrayList<CSSStyledText>(); if (arguments.length > 2) { List<String> style = sequenceToList(arguments[2]); if (style.size() != text.size()) throw new RuntimeException("Lengths of text and style sequences must match"); for (int i = 0; i < text.size(); i++) styledText.add(new CSSStyledText(text.get(i), style.get(i))); } else for (int i = 0; i < text.size(); i++) styledText.add(new CSSStyledText(text.get(i), "")); for (DotifyTranslator t : provider.get(query)) try { return iterableToSequence(t.fromStyledTextToBraille().transform(styledText)); } catch (UnsupportedOperationException e) {} throw new RuntimeException("Could not find a DotifyTranslator for query: " + query); } catch (Exception e) { throw new XPathException("dotify:translate failed", XProcException.javaError(e, 0)); } } };
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { Query query = query(arguments[0].head().getStringValue()); List<String> text = sequenceToList(arguments[1]); List<CSSStyledText> styledText = new ArrayList<CSSStyledText>(); if (arguments.length > 2) { List<String> style = sequenceToList(arguments[2]); if (style.size() != text.size()) throw new RuntimeException("Lengths of text and style sequences must match"); for (int i = 0; i < text.size(); i++) styledText.add(new CSSStyledText(text.get(i), style.get(i))); } else for (int i = 0; i < text.size(); i++) styledText.add(new CSSStyledText(text.get(i), "")); for (LiblouisTranslator t : translators.get(query)) try { return iterableToSequence(t.fromStyledTextToBraille().transform(styledText)); } catch (UnsupportedOperationException e) {} throw new RuntimeException("Could not find a LiblouisTranslator for query: " + query); } catch (Exception e) { throw new XPathException("louis:translate failed", XProcException.javaError(e, 0)); } } };
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { Query query = query(((AtomicSequence)arguments[0]).getStringValue()); String[] text = sequenceToArray(arguments[1]); Hyphenator hyphenator; try { hyphenator = hyphenators.get(query).iterator().next(); } catch (NoSuchElementException e) { throw new RuntimeException("Could not find a hyphenator for query: " + query); } return arrayToSequence(hyphenator.asFullHyphenator().transform(text));} catch (Exception e) { throw new XPathException("louis:hyphenate failed", XProcException.javaError(e, 0)); } } };
protected XProcException handleException(Throwable e) { XProcException xe = (e instanceof XProcException) ? (XProcException)e : XProcException.javaError(e, 1, new RuntimeException().getStackTrace(), 1); if (getRootStep(xe.getStep()) != getRootStep(getStep())) xe = xe.rebaseOnto(getStep()); return xe; }
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { String axes = arguments[0].head().getStringValue(); NodeInfo tableElement = (NodeInfo)arguments[1].head(); // FIXME: why does this not work? // URI base = new URI(tableElement.getBaseURI()); XdmNode result = Iterators.getOnlyElement( SaxonHelper.transform( new TableAsList(axes), Collections.singleton(tableElement).iterator(), context.getConfiguration())); result = (XdmNode)result.axisIterator(Axis.CHILD).next(); // because result is document-node return result.getUnderlyingNode(); } catch (TransformerException e) { throw new XPathException("css:render-table-by failed", XProcException.javaError(e, 0)); } } };