/** * Retrieves the location of an element node in the source file from which * the Document was created. This will only work for Document's created * with the method {@link #parse(InputSource, ServiceManager)} of this class. */ public static String getLocation(Element element) { return LocationAttributes.getLocationString(element); }
public static int getLineLocation(Element element) { return LocationAttributes.getLine(element); }
public static String getSystemIdLocation(Element element) { return LocationAttributes.getURI(element); }
Location rawLoc = LocationUtils.getLocation(config); return new LocationImpl(desc.toString(), rawLoc.getURI(), rawLoc.getLineNumber(), rawLoc.getColumnNumber());
private static void dumpLocation(Location loc, AttributesImpl attr, ContentHandler handler) throws SAXException { attr.addCDATAAttribute("uri", loc.getURI()); attr.addCDATAAttribute("line", Integer.toString(loc.getLineNumber())); attr.addCDATAAttribute("column", Integer.toString(loc.getColumnNumber())); simpleElement("location", attr, loc.getDescription(), handler); }
/** * Get the exception that was catched by this listener, if any. * * @return the exception */ public Throwable getThrowable() { if (exception == null) { return null; } Location loc = LocationUtils.getLocation(exception); if (LocationUtils.isKnown(loc)) { // Has a location: don't loose this precious information! return exception; } // No location: if it's just a wrapper, consider only the wrapped exception if (exception.getCause() != null) { return exception.getCause(); } // That's the actual exception! return exception; }
private void appendMessage(String text, String sourceName, int line, int column) { if (location == null) { location = new LocationImpl(null, sourceName, line, column); message = new StringBuffer(); } else { // Append a linefeed message.append("\n"); } message.append(text); }
public Location getLocation(Object obj, String description) { if (obj instanceof Configuration) { Configuration config = (Configuration)obj; String locString = config.getLocation(); Location result = LocationUtils.parse(locString); if (LocationUtils.isKnown(result)) { // Add description StringBuffer desc = new StringBuffer().append('<'); // Unfortunately Configuration.getPrefix() is not public try { if (config.getNamespace().startsWith("http://apache.org/cocoon/sitemap/")) { desc.append("map:"); } } catch (ConfigurationException e) { // no namespace: ignore } desc.append(config.getName()).append('>'); return new LocationImpl(desc.toString(), result); } else { return result; } } // Try next finders. return null; } };
public void warning(TransformerException ex) throws TransformerException { // TODO: We may want here to allow some special formatting of the messages, such as // "DEBUG:A debug message" or "INFO:Transforming <foo> in mode 'bar'" to use the different // log levels. This can include also deprecation logs for system-defined stylesheets // using "DEPRECATED:WARN:Styling 'foo' is replaced by 'bar'". if (logger.isWarnEnabled()) { Location loc = LocationUtils.getLocation(ex); logger.warn(ex.getMessage() + " at "+ loc == null ? uri : loc.toString()); } // Keep the warning (see below) warningEx = ex; }
public static int getColumnLocation(Element element) { return LocationAttributes.getColumn(element); }
public static Location getLocationObject(Element element) { return LocationAttributes.getLocation(element); }
/** * Get the location of a <code>Parameters</code> object, returning * {@link Location#UNKNOWN} if no location could be found. * * @param param * @return the location * @since 2.1.8 */ public static Location getLocation(Parameters param) { Location loc = null; if (param instanceof Locatable) { loc = ((Locatable)param).getLocation(); } return loc == null ? Location.UNKNOWN : loc; }
/** * Creates a W3C Document that remembers the location of each element in * the source file. The location of element nodes can then be retrieved * using the {@link #getLocation(Element)} method. * * @param inputSource the inputSource to read the document from * @param manager the service manager where to lookup the entity resolver */ public static Document parse(InputSource inputSource, SAXParser parser) throws SAXException, IOException { DOMBuilder builder = new DOMBuilder(); // Enhance the sax stream with location information ContentHandler locationHandler = new LocationAttributes.Pipe(builder); parser.parse(inputSource, locationHandler); return builder.getDocument(); }
/** * Get the exception that was catched by this listener, if any. * * @return the exception */ public Throwable getThrowable() { if (exception == null) { return null; } Location loc = LocationUtils.getLocation(exception); if (LocationUtils.isKnown(loc)) { // Has a location: don't loose this precious information! return exception; } // No location: if it's just a wrapper, consider only the wrapped exception if (exception.getCause() != null) { return exception.getCause(); } // That's the actual exception! return exception; }
/** * @see org.apache.cocoon.sitemap.ExecutionContext#getLocation() */ public Location getLocation() { return new LocationImpl("[sitemap]", this.wrappingProcessor.source.getURI()); }
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, par); Deprecation.logger.warn("NotifyingGenerator is deprecated in favor of ExceptionGenerator, at " + LocationUtils.getLocation(par)); this.notification = (Notifying) objectModel.get(Constants.NOTIFYING_OBJECT); if (this.notification == null) { throw new ProcessingException("Expected Constants.NOTIFYING_OBJECT not found in object model."); } }
public void buildLibrary(Element libraryElement) throws Exception { sourceURI = LocationAttributes.getURI(libraryElement); Element widgetsElement = DomHelper.getChildElement(libraryElement, FormsConstants.DEFINITION_NS, "widgets", true); WidgetDefinitionBuilderContext context = new WidgetDefinitionBuilderContext(this); // All child elements of the widgets element are widgets Element[] widgetElements = DomHelper.getChildElements(widgetsElement, FormsConstants.DEFINITION_NS); for (int i = 0; i < widgetElements.length; i++) { Element widgetElement = widgetElements[i]; buildWidgetDefinition(widgetElement, context); } }
public Form createForm(String uri) throws Exception { Source source = null; try { try { source = sourceResolver.resolveURI(uri); } catch (Exception e) { throw new FormsException("Could not resolve form definition URI.", e, new LocationImpl("[FormManager]", uri)); } return createForm(source); } finally { if (source != null) { sourceResolver.release(source); } } }
public void buildLibrary(Element libraryElement) throws Exception { sourceURI = LocationAttributes.getURI(libraryElement); this.assistant.getContext().setLocalLibrary(this); Element[] bindingElements = DomHelper.getChildElements(libraryElement, BindingManager.NAMESPACE); for (int i = 0; i < bindingElements.length; i++) { Element bindingElement = bindingElements[i]; Binding binding = this.assistant.getBindingForConfigurationElement(bindingElement); addBinding(binding); } }
public Location getLocation(Object obj, String description) { if (obj instanceof EcmaError) { EcmaError ex = (EcmaError)obj; if (ex.sourceName() != null) { return new LocationImpl(ex.getName(), ex.sourceName(), ex.lineNumber(), ex.columnNumber()); } else { return Location.UNKNOWN; } } else if (obj instanceof JavaScriptException) { JavaScriptException ex = (JavaScriptException)obj; if (ex.sourceName() != null) { return new LocationImpl(description, ex.sourceName(), ex.lineNumber(), -1); } else { return Location.UNKNOWN; } } return null; } };