@Override public void layout( final String name, final Dimension height, final Dimension width, final Orientation orientation) { final Document document = newDocumentBuilder().newDocument(); final Element layoutElem = document.createElement("LinearLayout"); layoutElem.setAttribute("xmlns:android", ANDROID_NS); layoutElem.setAttribute("android:layout_height", height.value()); layoutElem.setAttribute("android:layout_width", width.value()); layoutElem.setAttribute("android:orientation", orientation.value()); document.appendChild(layoutElem); final String layoutPath = pathResolver.getFocusedIdentifier(Path.ROOT, LAYOUT_PATH + SEP + name + XML_EXTENSION); if (fileManager.exists(layoutPath)) { LOGGER.severe("Layout '" + name + "' already exists"); return; } final MutableFile file = fileManager.createFile(layoutPath); final OutputStream output = file.getOutputStream(); XmlUtils.writeFormattedXml(output, document); try { output.close(); } catch (IOException e) { LOGGER.severe("Error closing stream: " + e.getMessage()); return; } // fileManager.createOrUpdateTextFileIfRequired(layoutPath, // XmlUtils.nodeToString(document), true); }
@Override public void view( final JavaType type, final String viewName, final String identifier, final JavaSymbolName fieldName, final Dimension height, final Dimension width) { final ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(type); Validate.notNull(typeDetails, "The type specified, '" + type + "'doesn't exist"); final JavaType viewType = new JavaType(viewName.contains(".") ? viewName : WIDGET_PACKAGE + "." + viewName); final String layout = RequestFactoryUtils.getStringAnnotationValue(typeDetails, ROO_ACTIVITY, "value", ""); if (!StringUtils.isEmpty(layout)) { final DocumentBuilder builder = newDocumentBuilder(); final String layoutPath = pathResolver.getFocusedIdentifier(Path.ROOT, LAYOUT_PATH + SEP + layout + XML_EXTENSION); InputStream inputStream = null; Document document = null; try { inputStream = fileManager.getInputStream(layoutPath); document = builder.parse(inputStream); } catch (final Exception e) { LOGGER.severe("Error reading layout XML: " + e.getMessage()); } finally { IOUtils.closeQuietly(inputStream); } if (document != null) { final Element root = document.getDocumentElement(); final Element viewElem = document.createElement(viewType.getSimpleTypeName()); final String id = StringUtils.isEmpty(identifier) ? fieldName.getSymbolName() : identifier; viewElem.setAttribute("android:id", ID_PREFIX + id); viewElem.setAttribute("android:layout_height", height.value()); viewElem.setAttribute("android:layout_width", width.value()); root.appendChild(viewElem); fileManager.createOrUpdateTextFileIfRequired( layoutPath, XmlUtils.nodeToString(document), true); } } final String physicalTypeIdentifier = typeDetails.getDeclaredByMetadataId(); final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_VIEW); if (!StringUtils.isEmpty(identifier)) { annotationBuilder.addStringAttribute("value", identifier); } annotations.add(annotationBuilder); final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(physicalTypeIdentifier, 0, annotations, fieldName, viewType); typeManagementService.addField(fieldBuilder.build()); }