public class ZoomOperation implements MapOperation { /** The logger used by this class. */ private static final LogDispatcher logger = LocalizationFactory.createLogger(ZoomOperation.class); /** Used to retrieve localized exception messages. */ private static final ExceptionLocalizer exceptionLocalizer = LocalizationFactory.createExceptionLocalizer(ZoomOperation.class); // javadoc inherited public String perform(Map params) throws IllegalArgumentException, Exception { String direction = WidgetServiceHelper.getParameter(params, P_DIR); Integer x = WidgetServiceHelper.getIntParameter(params, P_X); Integer y = WidgetServiceHelper.getIntParameter(params, P_Y); String t = WidgetServiceHelper.getParameter(params, P_T); Integer offx = WidgetServiceHelper.getIntParameter(params, P_OFFX); Integer offy = WidgetServiceHelper.getIntParameter(params, P_OFFY); Integer zoom = WidgetServiceHelper.getIntParameter(params, P_ZOOM); if (null == direction) { throw new IllegalArgumentException(exceptionLocalizer.format("widget-missing-dir-parameter")); } if (null == zoom) { throw new IllegalArgumentException( exceptionLocalizer.format("widget-missing-zoom-parameter")); } if (null != t && null != offx && null != offy && DIR_IN.equals(direction)) { return zoomInPhoto(zoom.intValue(), t, offx.intValue(), offy.intValue()); } if (null != t && null != offx && null != offy && DIR_OUT.equals(direction)) { return zoomOutPhoto(zoom.intValue(), t, offx.intValue(), offy.intValue()); } else if ((null != x) && (null != y) && DIR_IN.equals(direction)) { return zoomInMap(zoom.intValue(), x.intValue(), y.intValue()); } else if ((null != x) && (null != y) && DIR_OUT.equals(direction)) { return zoomOutMap(zoom.intValue(), x.intValue(), y.intValue()); } throw new IllegalArgumentException( exceptionLocalizer.format("widet-invalid-zoom-operation-params")); } private String zoomInPhoto(int currentZoom, String t, int offx, int offy) { if (logger.isDebugEnabled()) { logger.debug("Executing zoomInPhoto(zoom=" + currentZoom + ", t=" + t + ")"); } return OperationHelper.getInstance().getSatZoomIn(t, offx, offy); } private String zoomOutPhoto(int currentZoom, String t, int offx, int offy) { if (logger.isDebugEnabled()) { logger.debug("Executing zoomOutPhoto(zoom=" + currentZoom + ", t=" + t + ")"); } return OperationHelper.getInstance().getSatZoomOut(t, offx, offy); } private String zoomInMap(int currentZoom, int x, int y) { if (logger.isDebugEnabled()) { logger.debug("Executing zoomInMap(zoom=" + currentZoom + ", x=" + x + ", y=" + y + ")"); } return OperationHelper.getInstance().getMapZoomIn(x, y, currentZoom); } private String zoomOutMap(int currentZoom, int x, int y) { if (logger.isDebugEnabled()) { logger.debug("Executing zoomOutMap(zoom=" + currentZoom + ", x=" + x + ", y=" + y + ")"); } return OperationHelper.getInstance().getMapZoomOut(x, y, currentZoom); } }
/** Composite that displays the form sections that constitute the device overview page */ public class DeviceOverviewForm extends Composite implements XPathFocusable { /** Used for logging */ private static final LogDispatcher LOGGER = LocalizationFactory.createLogger(DeviceOverviewForm.class); /** Used to retrieve localized exception messages. */ private static final ExceptionLocalizer EXCEPTION_LOCALIZER = LocalizationFactory.createExceptionLocalizer(DeviceOverviewForm.class); /** The prefix for resources associated with this class. */ private static final String RESOURCE_PREFIX = "DeviceOverviewForm."; /** Constant for device overview forms margin height */ private static final int MARGIN_HEIGHT = EditorMessages.getInteger("Editor.marginHeight").intValue(); /** Constant for device overview forms margin width */ private static final int MARGIN_WIDTH = EditorMessages.getInteger("Editor.marginWidth").intValue(); /** Constant for device overview forms horizontal spacing */ private static final int HORIZONTAL_SPACING = EditorMessages.getInteger("Editor.horizontalSpacing").intValue(); /** Constant for device overview forms vertical spacing */ private static final int VERTICAL_SPACING = EditorMessages.getInteger("Editor.verticalSpacing").intValue(); /** The text for the Restore Defaults button. */ private static final String RESTORE_DEFAULTS_TEXT = DevicesMessages.getString(RESOURCE_PREFIX + "restoreDefaults.text"); /** Create a filter so that only device elements are included in the selection. */ private static final ODOMSelectionFilter DEVICE_FILTER = new ODOMSelectionFilter( null, new String[] {DeviceRepositorySchemaConstants.DEVICE_ELEMENT_NAME}, new ODOMSelectionFilterConfiguration(true, true)); /** FormSection that displays the hierarchy document in a tree format. */ private DeviceHierarchySection deviceHierarchySection; /** The ODOMEditor context for the device repository */ private DeviceEditorContext context; /** The Restore Defaults button. */ private Button restoreButton; /** Maintain the selected element so that we restore it if necessary (via the restore action). */ private Element deviceIDElement; /** * Initializes a <code>DeviceOverviewForm</code> with the given arguments * * @param parent the parent composite * @param style a bitset used to specify any styles * @param context the DeviceEditorContext. */ public DeviceOverviewForm(Composite parent, int style, DeviceEditorContext context) { super(parent, style); this.context = context; createDisplayArea(); } /** Creates the display area for this form */ private void createDisplayArea() { // create the top level layout for the form GridLayout layout = new GridLayout(); layout.marginHeight = MARGIN_HEIGHT; layout.marginWidth = MARGIN_WIDTH; layout.verticalSpacing = VERTICAL_SPACING; layout.horizontalSpacing = HORIZONTAL_SPACING; GridData data = new GridData(GridData.FILL_BOTH); setLayout(layout); setLayoutData(data); // set the background color to white Color white = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); setBackground(white); // add an alerts and actions section AlertsActionsSection alerts = new AlertsActionsSection(this, SWT.NONE, context); alerts.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // add a two column contianer for the form sections. The first // column will display the DeviceHierarchy section and the second // column will display the primary and secondary pattern sections. Composite formContainer = new Composite(this, SWT.NONE); GridLayout formLayout = new GridLayout(2, false); formLayout.marginWidth = 0; formLayout.marginHeight = 0; formLayout.horizontalSpacing = HORIZONTAL_SPACING; GridData formData = new GridData(GridData.FILL_BOTH); formContainer.setLayout(formLayout); formContainer.setLayoutData(formData); formContainer.setBackground(white); // add the hierarchy section to the formContainer deviceHierarchySection = new DeviceHierarchySection(formContainer, SWT.NONE, context); GridData hierarchyData = new GridData(GridData.FILL_VERTICAL); deviceHierarchySection.setLayoutData(hierarchyData); // add a scroll area for the patterns sections ScrolledComposite controlsScroller = new ScrolledComposite(formContainer, SWT.H_SCROLL | SWT.V_SCROLL); controlsScroller.setLayout(new FillLayout()); controlsScroller.setLayoutData(new GridData(GridData.FILL_BOTH)); controlsScroller.setExpandHorizontal(true); controlsScroller.setExpandVertical(true); controlsScroller.setAlwaysShowScrollBars(false); controlsScroller.setBackground(white); // add the container for the patterns sections Composite patternContainer = new Composite(controlsScroller, SWT.NONE); GridLayout patternLayout = new GridLayout(); patternLayout.marginHeight = 0; patternLayout.marginWidth = 0; patternLayout.verticalSpacing = VERTICAL_SPACING; GridData patternData = new GridData(GridData.FILL_BOTH); patternContainer.setLayout(patternLayout); patternContainer.setLayoutData(patternData); patternContainer.setBackground(white); // Add the primary patterns section PrimaryPatternsSection primaryPatterns = new PrimaryPatternsSection(patternContainer, SWT.NONE, context); primaryPatterns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add the secondary patterns section SecondaryPatternsSection secondaryPatterns = new SecondaryPatternsSection(patternContainer, SWT.NONE, context); secondaryPatterns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); createRestoreMechanism(patternContainer); TACPatternsSection TACPatterns = new TACPatternsSection(patternContainer, SWT.NONE, context); TACPatterns.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); patternContainer.setSize(patternContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT)); patternContainer.layout(); controlsScroller.setMinSize(patternContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT)); controlsScroller.setContent(patternContainer); layout(); } /** * Get the name of the selected device. * * @return the name of the selected device or null if none selected. */ String getSelectedDeviceName() { String selectedDeviceName = null; if (deviceIDElement != null) { selectedDeviceName = deviceIDElement.getAttributeValue(DeviceRepositorySchemaConstants.DEVICE_NAME_ATTRIBUTE); } return selectedDeviceName; } /** * Add the restore button and the standard element handling facility. * * @param parent the parent composite for the resotre button. */ private void createRestoreMechanism(Composite parent) { restoreButton = new Button(parent, SWT.NONE); restoreButton.setText(RESTORE_DEFAULTS_TEXT); restoreButton.setEnabled(!context.isAdminProject()); restoreButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); restoreButton.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { widgetDefaultSelected(e); } public void widgetDefaultSelected(SelectionEvent event) { if (deviceIDElement != null) { ((DeviceODOMElement) deviceIDElement).restore(); } } }); // Add a listener to the selection manager which responds to device // element selections. context .getODOMSelectionManager() .addSelectionListener( new ODOMElementSelectionListener() { public void selectionChanged(ODOMElementSelectionEvent event) { ODOMElementSelection selection = event.getSelection(); if (!selection.isEmpty()) { Element deviceElement = (Element) selection.getFirstElement(); // Retrieve the device name. final String deviceName = deviceElement.getAttributeValue( DeviceRepositorySchemaConstants.DEVICE_NAME_ATTRIBUTE); deviceIDElement = context .getDeviceRepositoryAccessorManager() .retrieveDeviceIdentification(deviceName); if (deviceIDElement == null) { Object params = new Object[] { deviceName, context.getDeviceRepositoryAccessorManager().getDeviceRepositoryName() }; LOGGER.error("device-not-found", params); String message = EXCEPTION_LOCALIZER.format("device-not-found", params); throw new UndeclaredThrowableException(new RepositoryException(message)); } else { DeviceODOMElement parent = (DeviceODOMElement) deviceIDElement.getParent(); if (parent == null) { LOGGER.error("device-no-parent", deviceName); String message = EXCEPTION_LOCALIZER.format("device-no-parent", deviceName); throw new UndeclaredThrowableException(new RepositoryException(message)); } else { parent.submitRestorableName(deviceName); } } } else { deviceIDElement = null; } } }, DEVICE_FILTER); } // javadoc inherited public boolean setFocus(XPath path) { // todo implement this return false; } }
/** * The include element. Allows an XML or plain text file to be processed, causing the content to be * incorporated into the page being generated. */ public class IncludeElementImpl extends AbstractExprElementImpl { /** Used for logging */ private static final LogDispatcher logger = LocalizationFactory.createLogger(IncludeElementImpl.class); /** Used to retrieve localized exception messages. */ private static final ExceptionLocalizer exceptionLocalizer = LocalizationFactory.createExceptionLocalizer(IncludeElementImpl.class); // Javadoc inherited. protected int exprElementStart(MarinerRequestContext context, PAPIAttributes papiAttributes) throws PAPIException { // This tag specifically does not push itself onto the page context // element stack (it can't have children anyway). However, it // is important that there is an element in that stack in order to // allow the integration process to operate correctly. return SKIP_ELEMENT_BODY; } // Javadoc inherited. protected int exprElementEnd(MarinerRequestContext context, PAPIAttributes papiAttributes) throws PAPIException { IncludeAttributes attributes = (IncludeAttributes) papiAttributes; if (attributes.getHref() == null) { throw new PAPIException(exceptionLocalizer.format("include-href-missing")); } else { // @todo this is a bit duff since it relies on markup naming not to change; do this a // different way // Set up the markup that will be sent down the pipeline StringBuffer markup = new StringBuffer(); InputSource inputSource; markup.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); markup .append("<urid:fetch xmlns:urid=\"") .append(Namespace.URID.getURI()) .append("\" href=\"") .append(attributes.getHref()) .append("\""); if (attributes.getParse() != null) { markup.append(" parse=\"").append(attributes.getParse()).append("\""); } if (attributes.getEncoding() != null) { markup.append(" encoding=\"").append(attributes.getEncoding()).append("\""); } markup.append("/>"); if (logger.isDebugEnabled()) { logger.debug("Set up inclusion command as: " + markup.toString()); } inputSource = new InputSource(new StringReader(markup.toString())); // Set up and execute the pipeline to perform the required // inclusion MarinerPageContext pageContext = ContextInternals.getMarinerPageContext(context); XMLReader reader = MarlinSAXHelper.getXMLReader(context); reader.setContentHandler(MarlinSAXHelper.getContentHandler(context)); // @todo this is nasty: we assume that the reader is actually an XMLPipelineFilter XMLPipelineFilter filter = (XMLPipelineFilter) reader; XMLPipelineContext pipelineContext = filter.getPipelineContext(); // set the Base URI in the pipeline's context try { URL baseURI = pageContext.getAbsoluteURL(pageContext.getRequestURL(false)); if (logger.isDebugEnabled()) { logger.debug("Setting Base URI " + baseURI); } pipelineContext.pushBaseURI(baseURI.toExternalForm()); } catch (MalformedURLException e) { throw new PAPIException(e); } PipelineIntegrationUtilities.setUpIntegration( filter, pageContext.getCurrentElement(), context, pageContext.getCurrentOutputBuffer()); if (logger.isDebugEnabled()) { logger.debug("Executing inclusion"); } // Execute the inclusion try { reader.parse(inputSource); } catch (IOException e) { throw new PAPIException(e); } catch (SAXException e) { throw new PAPIException(e); } finally { PipelineIntegrationUtilities.tearDownIntegration(filter); } } if (logger.isDebugEnabled()) { logger.debug("Successful execution of inclusion"); } return CONTINUE_PROCESSING; } // javadoc inherited boolean hasMixedContent() { return false; } }