You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MediaNode.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.sass.internal.tree;
  17. import org.w3c.css.sac.SACMediaList;
  18. public class MediaNode extends Node {
  19. private static final long serialVersionUID = 2502097081457509523L;
  20. SACMediaList media;
  21. public MediaNode(SACMediaList media) {
  22. super();
  23. this.media = media;
  24. }
  25. public SACMediaList getMedia() {
  26. return media;
  27. }
  28. public void setMedia(SACMediaList media) {
  29. this.media = media;
  30. }
  31. @Override
  32. public String printState() {
  33. return buildString(PRINT_STRATEGY, true);
  34. }
  35. @Override
  36. public String toString() {
  37. return buildString(TO_STRING_STRATEGY, true);
  38. }
  39. @Override
  40. public void traverse() {
  41. }
  42. private String buildString(BuildStringStrategy strategy, boolean indent) {
  43. StringBuilder builder = new StringBuilder("@media ");
  44. if (media != null) {
  45. for (int i = 0; i < media.getLength(); i++) {
  46. if (i > 0) {
  47. builder.append(", ");
  48. }
  49. builder.append(media.item(i));
  50. }
  51. }
  52. builder.append(" {\n");
  53. for (Node child : children) {
  54. builder.append('\t');
  55. if (child instanceof BlockNode) {
  56. if (PRINT_STRATEGY.equals(strategy)) {
  57. builder.append(((BlockNode) child).buildString(indent));
  58. } else {
  59. builder.append(strategy.build(child));
  60. }
  61. } else {
  62. builder.append(strategy.build(child));
  63. }
  64. builder.append('\n');
  65. }
  66. builder.append("}");
  67. return builder.toString();
  68. }
  69. }