コード例 #1
0
 @Test
 public void testGetStylesheet() {
   Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
   Stylesheet expResult = new Stylesheet();
   expResult.getRules().add(instance);
   Stylesheet result = instance.getStylesheet();
   assertEquals(expResult, result);
 }
コード例 #2
0
  private static Style createStyle(String stylesheetText) {

    Stylesheet stylesheet = CSSParser.getInstance().parse(stylesheetText);
    Rule rule = stylesheet.getRules().get(0);
    Selector sel = rule.getUnobservedSelectorList().get(0);
    Declaration decl = rule.getUnobservedDeclarationList().get(0);
    return new Style(sel, decl);
  }
コード例 #3
0
 @Test
 public void testGetOriginAfterRemovingRuleFromStylesheet() {
   Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
   Stylesheet stylesheet = new Stylesheet();
   stylesheet.getRules().add(instance);
   stylesheet.setOrigin(StyleOrigin.INLINE);
   stylesheet.getRules().remove(instance);
   StyleOrigin result = instance.getOrigin();
   assertNull(result);
 }
コード例 #4
0
 @Test
 public void testGetOriginAfterSettingOriginBeforeAddingRuleToStylesheet() {
   Rule instance = new Rule(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
   Stylesheet stylesheet = new Stylesheet();
   stylesheet.setOrigin(StyleOrigin.INLINE);
   stylesheet.getRules().add(instance);
   StyleOrigin expResult = StyleOrigin.INLINE;
   StyleOrigin result = instance.getOrigin();
   assertEquals(expResult, result);
 }
コード例 #5
0
  /**
   * Recompose the value of the composed include list. Builds a composite list of all stylesheets
   * included by this stylesheet to any depth.
   *
   * @param including Stylesheet to recompose
   */
  void recomposeIncludes(Stylesheet including) {

    int n = including.getIncludeCount();

    if (n > 0) {
      if (null == m_includesComposed) m_includesComposed = new Vector();

      for (int i = 0; i < n; i++) {
        Stylesheet included = including.getInclude(i);
        m_includesComposed.addElement(included);
        recomposeIncludes(included);
      }
    }
  }
コード例 #6
0
ファイル: Variable.java プロジェクト: napile/napile.classpath
  /** Parse the contents of the variable */
  public void parseContents(Parser parser) {
    // Parse 'name' and 'select' attributes plus parameter contents
    super.parseContents(parser);

    // Add a ref to this var to its enclosing construct
    SyntaxTreeNode parent = getParent();
    if (parent instanceof Stylesheet) {
      // Mark this as a global variable
      _isLocal = false;
      // Check if a global variable with this name already exists...
      Variable var = parser.getSymbolTable().lookupVariable(_name);
      // ...and if it does we need to check import precedence
      if (var != null) {
        final int us = this.getImportPrecedence();
        final int them = var.getImportPrecedence();
        // It is an error if the two have the same import precedence
        if (us == them) {
          final String name = _name.toString();
          reportError(this, parser, ErrorMsg.VARIABLE_REDEF_ERR, name);
        }
        // Ignore this if previous definition has higher precedence
        else if (them > us) {
          _ignore = true;
          return;
        } else {
          var.disable();
        }
        // Add this variable if we have higher precedence
      }
      ((Stylesheet) parent).addVariable(this);
      parser.getSymbolTable().addVariable(this);
    } else {
      _isLocal = true;
    }
  }
コード例 #7
0
 void doApply(
     Stylesheet stylesheet,
     QName mode,
     Node context,
     int pos,
     int len,
     Node parent,
     Node nextSibling)
     throws TransformerException {
   if (children != null) {
     // Set current template to null
     Template saved = stylesheet.currentTemplate;
     stylesheet.currentTemplate = null;
     Object ret = select.evaluate(context, pos, len);
     // System.err.println(toString() + ": " + context+" -> "+ret);
     if (ret instanceof Collection) {
       Collection ns = (Collection) ret;
       List list = new ArrayList(ns);
       if (sortKeys != null) {
         for (Iterator i = sortKeys.iterator(); i.hasNext(); ) {
           SortKey sortKey = (SortKey) i.next();
           sortKey.init(stylesheet, mode, context, pos, len, parent, nextSibling);
         }
         Collections.sort(list, new XSLComparator(sortKeys));
       } else {
         Collections.sort(list, documentOrderComparator);
       }
       // Perform children for each node
       int l = list.size();
       int p = 1;
       for (Iterator i = list.iterator(); i.hasNext(); ) {
         Node node = (Node) i.next();
         stylesheet.current = node;
         children.apply(stylesheet, mode, node, p++, l, parent, nextSibling);
       }
     }
     // Restore current template
     stylesheet.currentTemplate = saved;
   }
   if (next != null) {
     next.apply(stylesheet, mode, context, pos, len, parent, nextSibling);
   }
 }
コード例 #8
0
ファイル: BuilderExample.java プロジェクト: dgkim11/examples
 public void example() {
   Stylesheet style =
       new Stylesheet.Builder(200, 500)
           .foregroundColor(new Color("yellow"))
           .backgroundColor(new Color("green"))
           .build();
   System.out.println("foregroundColor : " + style.getForegroundColor().getName());
   System.out.println("backgroundColor : " + style.getBackgroundColor().getName());
   System.out.println("fontSize : " + style.getFontSize());
   System.out.println("fontName : " + style.getFontName());
   System.out.println("width : " + style.getWidth());
   System.out.println("height : " + style.getHeight());
 }
コード例 #9
0
 void doApply(
     Stylesheet stylesheet,
     QName mode,
     Node context,
     int pos,
     int len,
     Node parent,
     Node nextSibling)
     throws TransformerException {
   Node result = null;
   Document doc = (parent instanceof Document) ? (Document) parent : parent.getOwnerDocument();
   short nodeType = source.getNodeType();
   if (nodeType == Node.ATTRIBUTE_NODE && parent.getFirstChild() != null) {
     // Ignore attributes added after child elements
   } else {
     // Namespace aliasing
     if (nodeType == Node.ELEMENT_NODE) {
       String prefix = source.getPrefix();
       if (prefix == null) prefix = "#default";
       String resultPrefix = (String) stylesheet.namespaceAliases.get(prefix);
       if (resultPrefix != null) {
         if ("#default".equals(resultPrefix)) resultPrefix = null;
         String uri = source.lookupNamespaceURI(resultPrefix);
         String name = source.getNodeName();
         // Create a new element node in the result document
         result = doc.createElementNS(uri, name);
         // copy attributes
         NamedNodeMap srcAttrs = source.getAttributes();
         NamedNodeMap dstAttrs = result.getAttributes();
         int l = srcAttrs.getLength();
         for (int i = 0; i < l; i++) {
           Node attr = srcAttrs.item(i);
           if (!Stylesheet.XSL_NS.equals(attr.getNamespaceURI())) {
             attr = attr.cloneNode(true);
             attr = doc.adoptNode(attr);
             dstAttrs.setNamedItemNS(attr);
           }
         }
       }
     }
     if (result == null) {
       // Create result node
       result = source.cloneNode(false);
       // Remove any XSL attributes
       NamedNodeMap attrs = result.getAttributes();
       if (attrs != null) {
         int l = attrs.getLength();
         for (int i = 0; i < l; i++) {
           Node attr = attrs.item(i);
           if (Stylesheet.XSL_NS.equals(attr.getNamespaceURI())) {
             attrs.removeNamedItem(attr.getNodeName());
             i--;
             l--;
           }
         }
       }
       Node result2 = doc.adoptNode(result);
       if (result2 == null) {
         String msg =
             "Error adopting node to result tree: "
                 + result
                 + " ("
                 + result.getClass().getName()
                 + ")";
         DOMSourceLocator l = new DOMSourceLocator(context);
         throw new TransformerException(msg, l);
       }
       result = result2;
     }
     if (nextSibling != null) parent.insertBefore(result, nextSibling);
     else parent.appendChild(result);
     if (nodeType == Node.ELEMENT_NODE)
       stylesheet.addNamespaceNodes(source, result, doc, elementExcludeResultPrefixes);
     // children
     if (children != null) children.apply(stylesheet, mode, context, pos, len, result, null);
   }
   // next sibling
   if (next != null) next.apply(stylesheet, mode, context, pos, len, parent, nextSibling);
 }
コード例 #10
0
 /**
  * Creates and returns a stylesheet builder configured with some useful default styles. The caller
  * can augment the sheet with additional styles and call {@code create}.
  */
 public static Stylesheet.Builder newSheetBuilder(Graphics gfx) {
   final Font font = FontCache.instance().REGULAR;
   int bgColor = 0xFFCCCCCC, ulColor = UL_COLOR, brColor = 0xFFAAAAAA;
   Background butBg = Background.roundRect(gfx, bgColor, 5, ulColor, 2).inset(5, 6, 2, 6);
   Background butSelBg = Background.roundRect(gfx, bgColor, 5, brColor, 2).inset(6, 5, 1, 7);
   Background disabledChangeViewButtonBackground =
       Background.roundRect(gfx, Palette.DIALOG_BACKGROUND, 5, ulColor, 2).inset(5, 6, 2, 6);
   return Stylesheet.builder()
       .add(Button.class, Style.BACKGROUND.is(butBg), Style.FONT.is(font))
       .add(Button.class, Style.Mode.SELECTED, Style.BACKGROUND.is(butSelBg))
       .add(Button.class, Style.ACTION_SOUND.is(SfxCache.instance().CLICK))
       .add(ToggleButton.class, Style.BACKGROUND.is(butBg))
       .add(ToggleButton.class, Style.Mode.SELECTED, Style.BACKGROUND.is(butSelBg))
       .add(
           CheckBox.class,
           Style.BACKGROUND.is(
               Background.roundRect(gfx, bgColor, 5, ulColor, 2).inset(3, 2, 0, 3)))
       .add(
           CheckBox.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(
               Background.roundRect(gfx, bgColor, 5, brColor, 2).inset(3, 2, 0, 3)))
       // flip ul and br to make Field appear recessed
       .add(
           Field.class,
           Style.BACKGROUND.is(Background.beveled(0xFFFFFFFF, brColor, ulColor).inset(5)),
           Style.HALIGN.left)
       .add(
           Field.class,
           Style.Mode.DISABLED,
           Style.BACKGROUND.is(Background.beveled(0xFFCCCCCC, brColor, ulColor).inset(5)))
       .add(
           Menu.class,
           Style.BACKGROUND.is(Background.bordered(0xFFFFFFFF, 0x00000000, 1).inset(6)))
       .add(
           MenuItem.class,
           Style.BACKGROUND.is(Background.solid(0xFFFFFFFF)),
           Style.HALIGN.left,
           Style.FONT.is(font))
       .add(
           MenuItem.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(Background.solid(0xFF000000)),
           Style.COLOR.is(0xFFFFFFFF))
       .add(Tabs.class, Tabs.HIGHLIGHTER.is(Tabs.textColorHighlighter(0xFF000000, 0xFFFFFFFF)))
       .add(Label.class, Style.FONT.is(font))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.BACKGROUND.is(butBg),
           Style.FONT.is(font))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.Mode.SELECTED,
           Style.BACKGROUND.is(butSelBg))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.Mode.DISABLED,
           Style.BACKGROUND.is(disabledChangeViewButtonBackground))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.TEXT_EFFECT.pixelOutline)
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.HIGHLIGHT.is(Palette.UNUSED_SPACE))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.COLOR.is(Palette.FOREGROUND))
       .add(
           GameInteractionArea.ChangeViewControl.ChangeViewButton.class,
           Style.ACTION_SOUND.is(SfxCache.instance().CLICK))
       .add(
           GameInteractionArea.ChangeViewControl.CountLabel.class,
           Style.FONT.is(font.derive(font.size * 0.85f)),
           Style.COLOR.is(GameColors.WHITE),
           Style.TEXT_EFFECT.pixelOutline,
           Style.HIGHLIGHT.is(GameColors.HUNTER_GREEN));
 }
コード例 #11
0
  /**
   * Adds all recomposable values for this precedence level into the recomposableElements Vector
   * that was passed in as the first parameter. All elements added to the recomposableElements
   * vector should extend ElemTemplateElement.
   *
   * @param recomposableElements a Vector of ElemTemplateElement objects that we will add all of our
   *     recomposable objects to.
   */
  public void recompose(Vector recomposableElements) throws TransformerException {

    // recomposeImports();         // Calculate the number of this import.
    // recomposeIncludes(this);    // Build the global include list for this stylesheet.

    // Now add in all of the recomposable elements at this precedence level

    int n = getIncludeCountComposed();

    for (int i = -1; i < n; i++) {
      Stylesheet included = getIncludeComposed(i);

      // Add in the output elements

      int s = included.getOutputCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getOutput(j));
      }

      // Next, add in the attribute-set elements

      s = included.getAttributeSetCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getAttributeSet(j));
      }

      // Now the decimal-formats

      s = included.getDecimalFormatCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getDecimalFormat(j));
      }

      // Now the keys

      s = included.getKeyCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getKey(j));
      }

      // And the namespace aliases

      s = included.getNamespaceAliasCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getNamespaceAlias(j));
      }

      // Next comes the templates

      s = included.getTemplateCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getTemplate(j));
      }

      // Then, the variables

      s = included.getVariableOrParamCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getVariableOrParam(j));
      }

      // And lastly the whitespace preserving and stripping elements

      s = included.getStripSpaceCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getStripSpace(j));
      }

      s = included.getPreserveSpaceCount();
      for (int j = 0; j < s; j++) {
        recomposableElements.addElement(included.getPreserveSpace(j));
      }
    }
  }
コード例 #12
0
ファイル: ElemTemplateElement.java プロジェクト: nuxleus/lcmc
 /**
  * Return the system identifier for the current document event.
  *
  * <p>If the system identifier is a URL, the parser must resolve it fully before passing it to the
  * application.
  *
  * @return A string containing the system identifier, or null if none is available.
  * @see #getPublicId
  */
 public String getSystemId() {
   Stylesheet sheet = getStylesheet();
   return (sheet == null) ? null : sheet.getHref();
 }