/**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    DOMImplementation domImpl;
    Document doc;
    DOMConfiguration domConfig;
    DocumentType nullDocType = null;

    boolean canSet;
    boolean state;
    String parameter = "nAmEspace-declarations";
    domImpl = getImplementation();
    doc = domImpl.createDocument("http://www.w3.org/1999/xhtml", "html", nullDocType);
    domConfig = doc.getDomConfig();
    state = ((Boolean) domConfig.getParameter(parameter)).booleanValue();
    assertTrue("defaultFalse", state);
    canSet = domConfig.canSetParameter(parameter, Boolean.FALSE);
    assertTrue("canSetFalse", canSet);
    canSet = domConfig.canSetParameter(parameter, Boolean.TRUE);
    assertTrue("canSetTrue", canSet);
    domConfig.setParameter(parameter, Boolean.FALSE);
    state = ((Boolean) domConfig.getParameter(parameter)).booleanValue();
    assertFalse("setFalseEffective", state);
    domConfig.setParameter(parameter, Boolean.TRUE);
    state = ((Boolean) domConfig.getParameter(parameter)).booleanValue();
    assertTrue("setTrueEffective", state);
  }
Пример #2
0
 /**
  * Returns the implementation object of the current document.
  *
  * @return implementation-specific object
  */
 @JsxGetter
 public DOMImplementation getImplementation() {
   if (implementation_ == null) {
     implementation_ = new DOMImplementation();
     implementation_.setParentScope(getWindow());
     implementation_.setPrototype(getPrototype(implementation_.getClass()));
   }
   return implementation_;
 }
Пример #3
0
  public static void main(String[] args) {

    try {

      // Find the implementation
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      DocumentBuilder builder = factory.newDocumentBuilder();
      DOMImplementation impl = builder.getDOMImplementation();

      // Create the document
      DocumentType svgDOCTYPE =
          impl.createDocumentType(
              "svg",
              "-//W3C//DTD SVG 1.0//EN",
              "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
      Document doc = impl.createDocument("http://www.w3.org/2000/svg", "svg", svgDOCTYPE);

      // Fill the document
      Node rootElement = doc.getDocumentElement();
      ProcessingInstruction xmlstylesheet =
          doc.createProcessingInstruction(
              "xml-stylesheet", "type=\"text/css\" href=\"standard.css\"");
      Comment comment = doc.createComment("An example from Chapter 10 of Processing XML with Java");
      doc.insertBefore(comment, rootElement);
      doc.insertBefore(xmlstylesheet, rootElement);
      Node desc = doc.createElementNS("http://www.w3.org/2000/svg", "desc");
      rootElement.appendChild(desc);
      Text descText = doc.createTextNode("An example from Processing XML with Java");
      desc.appendChild(descText);

      // Serialize the document onto System.out
      TransformerFactory xformFactory = TransformerFactory.newInstance();
      Transformer idTransform = xformFactory.newTransformer();
      Source input = new DOMSource(doc);
      Result output = new StreamResult(System.out);
      idTransform.transform(input, output);

    } catch (FactoryConfigurationError e) {
      System.out.println("Could not locate a JAXP factory class");
    } catch (ParserConfigurationException e) {
      System.out.println("Could not locate a JAXP DocumentBuilder class");
    } catch (DOMException e) {
      System.err.println(e);
    } catch (TransformerConfigurationException e) {
      System.err.println(e);
    } catch (TransformerException e) {
      System.err.println(e);
    }
  }
Пример #4
0
  /**
   * Creates empty DOM Document using JAXP factoring. E.g.:
   *
   * <p>
   *
   * <pre>
   * Document doc = createDocument("book", null, null, null);
   * </pre>
   *
   * <p>creates new DOM of a well-formed document with root element named book.
   *
   * @param rootQName qualified name of root element. e.g. <code>myroot</code> or <code>ns:myroot
   *     </code>
   * @param namespaceURI URI of root element namespace or <code>null</code>
   * @param doctypePublicID public ID of DOCTYPE or <code>null</code>
   * @param doctypeSystemID system ID of DOCTYPE or <code>null</code> if no DOCTYPE required and
   *     doctypePublicID is also <code>null</code>
   * @throws DOMException if new DOM with passed parameters can not be created
   * @throws FactoryConfigurationError Application developers should never need to directly catch
   *     errors of this type.
   * @return new DOM Document
   */
  public static Document createDocument(
      String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID)
      throws DOMException {

    DOMImplementation impl = getDOMImplementation();

    if (doctypePublicID != null && doctypeSystemID == null) {
      throw new IllegalArgumentException(
          "System ID cannot be null if public ID specified. "); // NOI18N
    }

    DocumentType dtd = null;
    if (doctypeSystemID != null) {
      dtd = impl.createDocumentType(rootQName, doctypePublicID, doctypeSystemID);
    }

    return impl.createDocument(namespaceURI, rootQName, dtd);
  }
Пример #5
0
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    org.w3c.dom.bootstrap.DOMImplementationRegistry domImplRegistry;
    DOMImplementation domImpl;
    boolean hasFeature;
    String nullVersion = null;

    DOMImplementationList domImplList;
    int length;
    domImplRegistry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance();
    assertNotNull("domImplRegistryNotNull", domImplRegistry);
    domImplList = domImplRegistry.getDOMImplementationList("+cOrE");
    length = (int) domImplList.getLength();
    assertTrue("atLeastOne", (length > 0));
    for (int indexN10057 = 0; indexN10057 < domImplList.getLength(); indexN10057++) {
      domImpl = (DOMImplementation) domImplList.item(indexN10057);
      hasFeature = domImpl.hasFeature("+Core", nullVersion);
      assertTrue("hasCore", hasFeature);
    }
  }
Пример #6
0
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    DOMImplementation domImpl;
    Document doc;
    DOMConfiguration domConfig;
    DocumentType nullDocType = null;

    boolean canSet;
    DOMErrorHandler errorHandler = null;

    String parameter = "error-handler";
    DOMErrorHandler state;
    domImpl = getImplementation();
    doc = domImpl.createDocument("http://www.w3.org/1999/xhtml", "html", nullDocType);
    domConfig = doc.getDomConfig();
    canSet = domConfig.canSetParameter(parameter, ((Object) /*DOMErrorHandler */ errorHandler));
    assertTrue("canSetNull", canSet);
    domConfig.setParameter(parameter, ((Object) /*DOMErrorHandler */ errorHandler));
    state = (DOMErrorHandler) domConfig.getParameter(parameter);
    assertNull("errorHandlerIsNull", state);
  }
Пример #7
0
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    Document doc;
    DOMImplementation domImpl;
    Document newDoc;
    String namespaceURI;
    DocumentType nullDocType = null;

    Element docElem;
    String rootNS;
    String rootName;
    String qname;
    doc = (Document) load("hc_staff", false);
    docElem = doc.getDocumentElement();
    rootNS = docElem.getNamespaceURI();
    rootName = docElem.getTagName();
    domImpl = doc.getImplementation();
    qname = "dom3:" + rootName;
    newDoc = domImpl.createDocument(rootNS, qname, nullDocType);
    namespaceURI = newDoc.lookupNamespaceURI("dom3");
    assertEquals("nodelookupnamespaceuri02", rootNS, namespaceURI);
  }
  /**
   * Runs the test case.
   *
   * @throws Throwable Any uncaught exception causes test to fail
   */
  public void runTest() throws Throwable {
    DOMImplementation domImpl;
    Document doc;
    DOMConfiguration domConfig;
    DocumentType nullDocType = null;

    boolean canSet;
    boolean state;
    String parameter = "datatype-normalization";
    domImpl = getImplementation();
    doc = domImpl.createDocument("http://www.w3.org/1999/xhtml", "html", nullDocType);
    domConfig = doc.getDomConfig();
    domConfig.setParameter("validate", Boolean.FALSE);
    canSet = domConfig.canSetParameter(parameter, Boolean.TRUE);

    if (canSet) {
      domConfig.setParameter(parameter, Boolean.TRUE);
      state = ((Boolean) domConfig.getParameter("validate")).booleanValue();
      assertTrue("validateSet", state);
    }
  }
Пример #9
0
  public static void main(String[] args) throws Exception {
    // Create an SVG document.
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, "svg", null);

    // Create a converter for this document.
    SVGGraphics2D g = new SVGGraphics2D(doc);

    // Do some drawing.
    Shape circle = new Ellipse2D.Double(0, 0, 50, 50);
    g.setPaint(Color.red);
    g.fill(circle);
    g.translate(60, 0);
    g.setPaint(Color.green);
    g.fill(circle);
    g.translate(60, 0);
    g.setPaint(Color.blue);
    g.fill(circle);
    g.setSVGCanvasSize(new Dimension(180, 50));

    // Populate the document root with the generated SVG content.
    Element root = doc.getDocumentElement();
    g.getRoot(root);

    Writer out = new OutputStreamWriter(System.out, "UTF-8");
    g.stream(out, true);

    // Display the document.
    JSVGCanvas canvas = new JSVGCanvas();
    JFrame f = new JFrame();
    f.getContentPane().add(canvas);
    canvas.setSVGDocument(doc);
    f.pack();
    f.setVisible(true);
  }
Пример #10
0
  public static void build(State s) {
    DOMNodeList.build(s);
    DOMNode.build(s);
    DOMAttr.build(s);
    DOMNamedNodeMap.build(s);
    DOMDocumentType.build(s);
    DOMException.build(s);
    DOMElement.build(s);
    DOMCharacterData.build(s);
    DOMText.build(s);
    DOMConfiguration.build(s);
    DOMNotation.build(s);
    DOMCDataSection.build(s);
    DOMComment.build(s);
    DOMEntity.build(s);
    DOMEntityReference.build(s);
    DOMProcessingInstruction.build(s);
    DOMStringList.build(s);
    DOMDocumentFragment.build(s);

    // Document
    DOMDocument.build(s);
    DOMImplementation.build(s);

    // Set the remaining properties on DOMNode, due to circularity, and
    // summarize.
    createDOMProperty(
        s,
        DOMNode.PROTOTYPE,
        "attributes",
        Value.makeObject(
            DOMNamedNodeMap.INSTANCES, new Dependency(), new DependencyGraphReference()),
        DOMSpec.LEVEL_1);
    createDOMProperty(
        s,
        DOMNode.PROTOTYPE,
        "ownerDocument",
        Value.makeObject(DOMDocument.INSTANCES, new Dependency(), new DependencyGraphReference()),
        DOMSpec.LEVEL_1);
    s.multiplyObject(DOMNode.INSTANCES);
    DOMNode.INSTANCES = DOMNode.INSTANCES.makeSingleton().makeSummary();
  }
Пример #11
0
    /**
     * Draws a concreteDiagram as an SVG.
     *
     * <p>This approach is wholly declarative. It currently knows nothing about the on screen
     * rendering of the diagram. To make decisions based on the on screen rendering (such as better
     * label placement) we will, in future, have to build a GVT (from the Batik library) of the
     * SVGDocument.
     *
     * @returns An SVGDocument DOM structure representing the SVG.
     */
    @Override
    public SVGDocument toSVG(ConcreteDiagram cd) {
      // Get a DOMImplementation.
      DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();

      // Create an instance of org.w3c.dom.Document.
      String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
      SVGDocument document = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);

      // Get the root element (the 'svg' element).
      Element svgRoot = document.getDocumentElement();

      // Set the width and height attributes on the root 'svg' element.
      svgRoot.setAttributeNS(null, "width", Integer.toString(cd.getSize()));
      svgRoot.setAttributeNS(null, "height", Integer.toString(cd.getSize()));

      // Draw the shaded zones
      for (ConcreteZone z : cd.getShadedZones()) {
        Element path = document.createElementNS(svgNS, "path");
        path.setAttributeNS(null, "d", toSVGPath(z.getShape(cd.getBox())));
        path.setAttributeNS(null, "fill", "#cccccc"); // grey
        path.setAttributeNS(null, "z-index", Integer.toString(zOrder.SHADING.ordinal()));

        svgRoot.appendChild(path);
      }

      // TODO: Concrete* should return themselves as DocumentFragments
      for (CircleContour c : cd.getCircles()) {
        // Draw the circle
        Element circle = document.createElementNS(svgNS, "circle");
        circle.setAttributeNS(null, "cx", Double.toString(c.get_cx()));
        circle.setAttributeNS(null, "cy", Double.toString(c.get_cy()));
        circle.setAttributeNS(null, "r", Double.toString(c.get_radius()));
        circle.setAttributeNS(null, "z-index", Integer.toString(zOrder.CONTOUR.ordinal()));
        // Not pretty, but it works.
        Color strokeColor = c.color();
        circle.setAttributeNS(
            null, "stroke", (null == strokeColor) ? "black" : "#" + toHexString(c.color()));
        circle.setAttributeNS(null, "stroke-width", "2");
        circle.setAttributeNS(null, "fill", "none");
        svgRoot.appendChild(circle);

        // TODO: Put this text in a path around the circle
        // alternatively come up with some better label placement
        // algorithm
        Element text = document.createElementNS(svgNS, "text");
        text.setAttributeNS(null, "x", Double.toString(c.get_cx()));
        text.setAttributeNS(null, "y", Double.toString(c.get_cy() + c.get_radius()));
        text.setAttributeNS(null, "text-anchor", "middle");
        text.setAttributeNS(
            null, "fill", (null == strokeColor) ? "black" : "#" + toHexString(c.color()));
        text.setAttributeNS(null, "z-index", Integer.toString(zOrder.LABEL.ordinal()));

        Text textNode = document.createTextNode(c.ac.getLabel().getLabel());
        text.appendChild(textNode);
        svgRoot.appendChild(text);
      }

      for (ConcreteSpider cs : cd.getSpiders()) {
        for (ConcreteSpiderFoot f : cs.feet) {
          // Draw the foot
          Element circle = document.createElementNS(svgNS, "circle");
          circle.setAttributeNS(null, "cx", Double.toString(f.getX()));
          circle.setAttributeNS(null, "cy", Double.toString(f.getY()));
          circle.setAttributeNS(null, "r", Double.toString(ConcreteSpiderFoot.FOOT_RADIUS));
          circle.setAttributeNS(null, "z-index", Integer.toString(zOrder.SPIDER.ordinal()));

          circle.setAttributeNS(null, "stroke", "black");
          circle.setAttributeNS(null, "stroke-width", "2");
          circle.setAttributeNS(null, "fill", "black");
          svgRoot.appendChild(circle);
        }

        for (ConcreteSpiderLeg l : cs.legs) {
          Element line = document.createElementNS(svgNS, "line");
          line.setAttributeNS(null, "x1", Double.toString(l.from.getX()));
          line.setAttributeNS(null, "y1", Double.toString(l.from.getY()));
          line.setAttributeNS(null, "x2", Double.toString(l.to.getX()));
          line.setAttributeNS(null, "y2", Double.toString(l.to.getY()));
          line.setAttributeNS(null, "z-index", Integer.toString(zOrder.SPIDER.ordinal()));

          line.setAttributeNS(null, "stroke", "black");
          line.setAttributeNS(null, "stroke-width", "2");
          line.setAttributeNS(null, "fill", "black");
          svgRoot.appendChild(line);
        }
      }
      return document;
    }
Пример #12
0
  public String saveShow(String fn, ShowFileData showData) {
    _calendar = new GregorianCalendar();
    String showName =
        showData.getSettings().get(_title) + "_" + _format.format(_calendar.getTime()) + ".show";

    try {
      new File(fn).mkdirs();
      FileWriter _fileWriter = new FileWriter(fn + "/" + showName);
      BufferedWriter _outputFile = new BufferedWriter(_fileWriter);

      // Create the document
      Document doc = _impl.createDocument(null, _fileType, null);

      Element root = doc.getDocumentElement();

      Element settings = doc.createElement(_settings);
      Element patch = doc.createElement(_patch);
      Element cues = doc.createElement(_cues);
      Element magic = doc.createElement(_magicSheet);

      addText(doc, settings, _recordMode, showData.getSettings().get(_recordMode));
      addText(doc, settings, _totalChannels, showData.getSettings().get(_totalChannels));
      addText(doc, settings, _totalDimmers, showData.getSettings().get(_totalDimmers));
      addText(doc, settings, _dUpTime, showData.getSettings().get(_dUpTime));
      addText(doc, settings, _dDownTime, showData.getSettings().get(_dDownTime));
      addText(doc, settings, _gotoCueTime, showData.getSettings().get(_gotoCueTime));
      addText(doc, settings, _title, showData.getSettings().get(_title));
      addText(doc, settings, _comment, showData.getSettings().get(_comment));

      addText(doc, settings, _channelPerLine, showData.getSettings().get(_channelPerLine));
      addText(doc, settings, _channelHGroup, showData.getSettings().get(_channelHGroup));
      addText(doc, settings, _channelVGroup, showData.getSettings().get(_channelVGroup));

      for (Integer chan : showData.getPatch().keySet())
        if (showData.getPatch().get(chan).size() > 0)
          addChannel(doc, patch, chan, showData.getPatch().get(chan));

      for (FadeData fade : showData.getCueList()) addFade(doc, cues, fade);

      Position p;
      for (Integer chan : showData.getMagicSheet().keySet()) {
        MagicChannelData mChan = showData.getMagicSheet().get(chan);

        if (!(mChan._x == 0 && mChan._x == 0))
          addMagicChannel(doc, magic, chan, mChan._x, mChan._y);
      }

      root.appendChild(settings);
      root.appendChild(patch);
      root.appendChild(cues);
      root.appendChild(magic);

      // Serialize the document onto System.out
      TransformerFactory xformFactory = TransformerFactory.newInstance();
      Transformer idTransform = xformFactory.newTransformer();
      Source input = new DOMSource(doc);
      // Result output = new StreamResult(System.out);
      // idTransform.transform(input, output);
      Result output = new StreamResult(_outputFile);
      idTransform.transform(input, output);

      _outputFile.close();
      _fileWriter.close();
    } catch (FactoryConfigurationError e) {
      System.out.println("Could not locate a JAXP factory class");
    } catch (DOMException e) {
      System.err.println(e);
    } catch (TransformerConfigurationException e) {
      System.err.println(e);
    } catch (TransformerException e) {
      System.err.println(e);
    } catch (IOException e) {
      System.err.println(e);
    }

    return showName;
  }