public static void exportSVG(File file, Algorithm algorithm, Config config, int width, int height)
      throws TransformerException, IOException {
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = impl.createDocument(svgNS, "svg", null);

    Element svgRoot = doc.getDocumentElement();

    svgRoot.setAttributeNS(null, "width", Integer.toString(width));
    svgRoot.setAttributeNS(null, "height", Integer.toString(height));

    SvgPainter painter = new SvgPainter(doc, svgRoot);

    AlgorithmPainter algorithmPainter = new AlgorithmPainter(algorithm, config, painter);

    algorithmPainter.setWidth(width);
    algorithmPainter.setHeight(height);
    algorithmPainter.paint();

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    FileOutputStream fos = new FileOutputStream(file);
    StreamResult result = new StreamResult(fos);

    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

    transformer.transform(source, result);

    fos.close();
  }
Exemplo n.º 2
0
  /**
   * Appends the XML representation of the given <code>OutputFormatType</code> (as FormatType[]) to
   * the passed <code>Element</code>.
   *
   * @param root
   * @param formats
   */
  public static void appendOutputFormats(Element root, FormatType[] formats) {
    LOG.entering();

    Element outputFormatsNode = XMLTools.appendElement(root, WFS, "wfs:OutputFormats");
    for (int i = 0; i < formats.length; i++) {
      Element formatNode =
          XMLTools.appendElement(outputFormatsNode, WFS, "wfs:Format", formats[i].getValue());
      if (formats[i].getInFilter() != null) {
        formatNode.setAttributeNS(
            DEEGREEWFS.toString(), "deegree:inFilter", formats[i].getInFilter().toString());
      }
      if (formats[i].getOutFilter() != null) {
        formatNode.setAttributeNS(
            DEEGREEWFS.toString(), "deegree:outFilter", formats[i].getOutFilter().toString());
      }
      if (formats[i].getSchemaLocation() != null) {
        formatNode.setAttributeNS(
            DEEGREEWFS.toString(),
            "deegree:schemaLocation",
            formats[i].getSchemaLocation().toString());
      }
    }

    LOG.exiting();
  }
Exemplo n.º 3
0
 /* PRIVATE METHODS */
 private DOMDocument createDomDocument(String rootName) {
   DOMDocument domDocument = new DOMDocument(nsURI, rootName, null);
   Document document = domDocument.getDocument();
   Element root = document.getDocumentElement();
   if (includeTypeInfo) {
     root.setAttributeNS(
         XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
         XMLConstants.XMLNS_ATTRIBUTE + ":" + nsPrefix,
         nsURI);
     root.setAttributeNS(
         XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
         XMLConstants.XMLNS_ATTRIBUTE + ":" + NamespaceConstants.NSPREFIX_SCHEMA_XSD,
         NamespaceConstants.NSURI_SCHEMA_XSD);
     root.setAttributeNS(
         XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
         XMLConstants.XMLNS_ATTRIBUTE + ":" + NamespaceConstants.NSPREFIX_SCHEMA_XSI,
         NamespaceConstants.NSURI_SCHEMA_XSI);
     root.setAttributeNS(
         XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
         XMLConstants.XMLNS_ATTRIBUTE + ":" + NamespaceConstants.NSPREFIX_SOAP_ENCODING,
         NamespaceConstants.NSURI_SOAP_ENCODING);
     root.setAttributeNS(
         XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
         XMLConstants.XMLNS_ATTRIBUTE + ":" + Constants.NS_PREFIX_XMLSOAP,
         Constants.NS_URI_XMLSOAP);
   }
   return domDocument;
 }
  public Element AbstractFeatureTypeEncode(
      Object object, Document document, Element value, XSDIdRegistry idSet) {
    Feature feature = (Feature) object;
    String id = feature.getIdentifier().getID();
    Name typeName;
    if (feature.getDescriptor() == null) {
      // no descriptor, assume WFS feature type name is the same as the name of the content
      // model type
      typeName = feature.getType().getName();
    } else {
      // honour the name set in the descriptor
      typeName = feature.getDescriptor().getName();
    }
    Element encoding =
        document.createElementNS(typeName.getNamespaceURI(), typeName.getLocalPart());
    if (!(feature instanceof SimpleFeature) && idSet != null) {
      if (idSet.idExists(id)) {
        // XSD type ids can only appear once in the same document, otherwise the document is
        // not schema valid. Attributes of the same ids should be encoded as xlink:href to
        // the existing attribute.
        encoding.setAttributeNS(XLINK.NAMESPACE, XLINK.HREF.getLocalPart(), "#" + id.toString());
        // make sure the attributes aren't encoded
        feature.setValue(Collections.emptyList());
        return encoding;
      } else {
        idSet.add(id);
      }
    }
    encoding.setAttributeNS(gml.getNamespaceURI(), "id", id);
    encodeClientProperties(feature, value);

    return encoding;
  }
  public static void main(String[] args) throws TransformerException, IOException {
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = impl.createDocument(svgNS, "svg", null);

    Element svgRoot = doc.getDocumentElement();

    svgRoot.setAttributeNS(null, "width", "400");
    svgRoot.setAttributeNS(null, "height", "450");

    Element rectangle = doc.createElementNS(svgNS, "rect");
    rectangle.setAttributeNS(null, "x", "10");
    rectangle.setAttributeNS(null, "y", "20");
    rectangle.setAttributeNS(null, "width", "100");
    rectangle.setAttributeNS(null, "height", "50");
    rectangle.setAttributeNS(null, "fill", "red");

    svgRoot.appendChild(rectangle);

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    File file = new File("/home/z/foo.svg");
    FileOutputStream fos = new FileOutputStream(file);
    StreamResult result = new StreamResult(fos);

    transformer.transform(source, result);

    fos.close();
  }
Exemplo n.º 6
0
  private Element addLinkpool(Element topic, boolean prepend, String linkpoolType, Document doc) {
    Element relatedLinks = DITAUtil.findChildByClass(topic, "topic/related-links");
    if (relatedLinks == null) {
      relatedLinks = doc.createElementNS(null, "related-links");
      relatedLinks.setAttributeNS(null, "class", "- topic/related-links ");

      topic.insertBefore(relatedLinks, DITAUtil.findChildByClass(topic, "topic/topic"));
    }

    Element linkpool = doc.createElementNS(null, "linkpool");
    linkpool.setAttributeNS(null, "class", "- topic/linkpool ");

    if (mapHref != null && linkpoolType != null) {
      // mapkeyref is a standard DITA 1.2 attribute meant for this use.
      linkpool.setAttributeNS(null, "mapkeyref", mapHref + " type=" + linkpoolType);
    }

    Node before = null;
    if (prepend) {
      before = relatedLinks.getFirstChild();
    }
    relatedLinks.insertBefore(linkpool, before);

    return linkpool;
  }
Exemplo n.º 7
0
  public Document build() {
    Document document = getNamespaceAwareDocument();

    Element documentElement;
    if (prefixMapping == null) {
      documentElement = document.createElement(rootName);
    } else {
      documentElement =
          document.createElementNS(prefixMapping.getUri(), prefixMapping.qualify(rootName));
    }

    documentElement.setAttributeNS(XMLNS_ATTRIBUTE_NS_URI, XMLNS_ATTRIBUTE, defaultNamespaceName);
    for (NamespaceUriPrefixMapping nsMapping : namespaceDeclarations) {
      documentElement.setAttributeNS(
          XMLNS_ATTRIBUTE_NS_URI,
          XMLNS_ATTRIBUTE + ":" + nsMapping.getPrefix(),
          nsMapping.getUri());
    }

    for (XmlAttributeBuilder attributeBuilder : attributeBuilders) {
      documentElement.setAttributeNode(attributeBuilder.build(document));
    }

    for (XmlStandaloneNodeBuilder xmlBuilder : childNodeBuilders) {
      documentElement.appendChild(xmlBuilder.build(document));
    }

    document.appendChild(documentElement);
    return document;
  }
Exemplo n.º 8
0
  /**
   * creates a svg element by specifiying its parameters
   *
   * @param handle the current svg handle
   * @param text the text for the new element
   * @return the created svg element
   */
  public Element createElement(SVGHandle handle, String text) {

    // the edited document
    Document doc = handle.getScrollPane().getSVGCanvas().getDocument();

    // creating the text element
    final Element element =
        doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), handledElementTagName);

    // getting the last color that has been used by the user
    String colorString = Editor.getColorChooser().getColorString(ColorManager.getCurrentColor());
    element.setAttributeNS(null, "style", "fill:" + colorString + ";stroke:none;");
    element.setAttributeNS(null, "style", "font-size:12pt;fill:" + colorString + ";");

    EditorToolkit.setAttributeValue(element, xAtt, drawingPoint.getX());
    EditorToolkit.setAttributeValue(element, yAtt, drawingPoint.getY());

    // creating the text node
    Text textValue = doc.createTextNode(text);
    element.appendChild(textValue);

    // inserting the element in the document and handling the undo/redo
    // support
    insertShapeElement(handle, element);
    handle.getSelection().handleSelection(element, false, false);

    return element;
  }
Exemplo n.º 9
0
  private RDFDocument getRDFDescription() {
    RDFDocument rdfDocument = RDFDocument.Factory.newInstance();
    RDFDocument.RDF rdf = rdfDocument.addNewRDF();
    RDFDocument.RDF.Description desc = rdf.addNewDescription();
    desc.setAbout("info:fedora/" + pid);

    // connect to Content Model
    {
      Element e =
          desc.getDomNode()
              .getOwnerDocument()
              .createElementNS("info:fedora/fedora-system:def/model#", "hasModel");
      e.setAttributeNS(
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "resource", "info:fedora/qucosa:CModel");
      desc.getDomNode().appendChild(e);
    }

    if (parentCollectionPid != null) {
      Element e =
          desc.getDomNode()
              .getOwnerDocument()
              .createElementNS(
                  "info:fedora/fedora-system:def/relations-external#", "isMemberOfCollection");
      e.setAttributeNS(
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
          "resource",
          "info:fedora/" + parentCollectionPid);
      desc.getDomNode().appendChild(e);
    }
    if (constituentPid != null) {
      Element e =
          desc.getDomNode()
              .getOwnerDocument()
              .createElementNS(
                  "info:fedora/fedora-system:def/relations-external#", "isConstituentOf");
      e.setAttributeNS(
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
          "resource",
          "info:fedora/" + constituentPid);
      desc.getDomNode().appendChild(e);
    }
    if (derivativeOfPid != null) {
      Element e =
          desc.getDomNode()
              .getOwnerDocument()
              .createElementNS(
                  "info:fedora/fedora-system:def/relations-external#", "isDerivationOf");
      e.setAttributeNS(
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
          "resource",
          "info:fedora/" + derivativeOfPid);
      desc.getDomNode().appendChild(e);
    }
    return rdfDocument;
  }
Exemplo n.º 10
0
 /*
  * Mock up an AppliesTo element using the supplied address
  */
 private Element createAppliesToElement(String addressUrl) {
   Document doc = DOMUtils.createDocument();
   Element appliesTo = doc.createElementNS(STSConstants.WSP_NS, "wsp:AppliesTo");
   appliesTo.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsp", STSConstants.WSP_NS);
   Element endpointRef = doc.createElementNS(STSConstants.WSA_NS_05, "wsa:EndpointReference");
   endpointRef.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsa", STSConstants.WSA_NS_05);
   Element address = doc.createElementNS(STSConstants.WSA_NS_05, "wsa:Address");
   address.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsa", STSConstants.WSA_NS_05);
   address.setTextContent(addressUrl);
   endpointRef.appendChild(address);
   appliesTo.appendChild(endpointRef);
   return appliesTo;
 }
Exemplo n.º 11
0
  /*
   * (non-Javadoc)
   * @see org.eclipse.sapphire.modeling.ValuePropertyBinding#write(java.lang.String)
   */
  @Override
  public void write(String value) {
    String val = value;

    // System.out.println( "VALUE ___________________ " + val );

    XmlElement parent = xml(true);
    /*
     * In some cases the parent node and the child nodes will be same, we need to ensure that we dont create them
     * accidentally again
     */
    // System.out.println( "QNamespaceValueBinding.write() - Parent local name:" +
    // parent.getLocalName() );
    XmlElement qNameElement = null;
    if (parent.getLocalName().equals(params[0])) {
      qNameElement = parent;
    } else {
      qNameElement = parent.getChildElement(params[0], true);
    }

    if (qNameElement != null && val != null) {
      // System.out.println( "QNamespaceValueBinding.write() - 1" );
      val = value.trim();
      org.w3c.dom.Element qnameDef = qNameElement.getDomNode();
      /*
       * Check to ensure that the attribute is not added multiple times, check if the attribute already exist if
       * yes remove it add add it afresh
       */
      Attr oldQnsAttribute =
          qnameDef.getAttributeNode(PortletAppModelConstants.DEFAULT_QNAME_NS_DECL);
      if (oldQnsAttribute == null) {
        // System.out.println( "QNamespaceValueBinding.write() - Attrib does not exist" );
        qnameDef.setAttributeNS(
            PortletAppModelConstants.XMLNS_NS_URI,
            PortletAppModelConstants.DEFAULT_QNAME_NS_DECL,
            val);
      } else {
        // System.out.println( "QNamespaceValueBinding.write() - Attrib  exist" );
        qnameDef.removeAttributeNode(oldQnsAttribute);
        qnameDef.setAttributeNS(
            PortletAppModelConstants.XMLNS_NS_URI,
            PortletAppModelConstants.DEFAULT_QNAME_NS_DECL,
            val);
      }

    } // Remove the nod/e if it exists and current value is null
    else if (qNameElement != null && val == null) {
      qNameElement.remove();
    }
  }
Exemplo n.º 12
0
  /** Mock object creator (for unit testing purposes) */
  public HarvesterVerb() {
    try {
      /* Load DOM Document */
      factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      Thread t = Thread.currentThread();
      DocumentBuilder builder = factory.newDocumentBuilder();
      builderMap.put(t, builder);

      DOMImplementation impl = builder.getDOMImplementation();
      Document namespaceHolder =
          impl.createDocument(
              "http://www.oclc.org/research/software/oai/harvester",
              "harvester:namespaceHolder",
              null);
      namespaceElement = namespaceHolder.getDocumentElement();
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:harvester",
          "http://www.oclc.org/research/software/oai/harvester");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:xsi",
          "http://www.w3.org/2001/XMLSchema-instance");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/", "xmlns:oai20", "http://www.openarchives.org/OAI/2.0/");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_GetRecord",
          "http://www.openarchives.org/OAI/1.1/OAI_GetRecord");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_Identify",
          "http://www.openarchives.org/OAI/1.1/OAI_Identify");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_ListIdentifiers",
          "http://www.openarchives.org/OAI/1.1/OAI_ListIdentifiers");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_ListMetadataFormats",
          "http://www.openarchives.org/OAI/1.1/OAI_ListMetadataFormats");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_ListRecords",
          "http://www.openarchives.org/OAI/1.1/OAI_ListRecords");
      namespaceElement.setAttributeNS(
          "http://www.w3.org/2000/xmlns/",
          "xmlns:oai11_ListSets",
          "http://www.openarchives.org/OAI/1.1/OAI_ListSets");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 13
0
  /**
   * Copy in-scope namespace declarations of the decl node to the decl node itself so that this move
   * won't change the in-scope namespace bindings.
   */
  private void copyInscopeNSAttributes(Element e) {
    Element p = e;
    Set<String> inscopes = new HashSet<String>();
    while (true) {
      NamedNodeMap atts = p.getAttributes();
      for (int i = 0; i < atts.getLength(); i++) {
        Attr a = (Attr) atts.item(i);
        if (Constants.NS_XMLNS.equals(a.getNamespaceURI())) {
          String prefix;
          if (a.getName().indexOf(':') == -1) prefix = "";
          else prefix = a.getLocalName();

          if (inscopes.add(prefix) && p != e) {
            // if this is the first time we see this namespace bindings,
            // copy the declaration.
            // if p==decl, there's no need to. Note that
            // we want to add prefix to inscopes even if p==Decl

            e.setAttributeNodeNS((Attr) a.cloneNode(true));
          }
        }
      }

      if (p.getParentNode() instanceof Document) break;

      p = (Element) p.getParentNode();
    }

    if (!inscopes.contains("")) {
      // if the default namespace was undeclared in the context of decl,
      // it must be explicitly set to "" since the new environment might
      // have a different default namespace URI.
      e.setAttributeNS(Constants.NS_XMLNS, "xmlns", "");
    }
  }
Exemplo n.º 14
0
  @Test
  public void test() throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();

    String docStr =
        "<system systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'"
            + " uri='/cache/data/xrc36316.bin'"
            + " xmlns:xr='urn:oasis:names:tc:entity:xmlns:xml:catalog'"
            + " xr:systemId='http://www.w3.org/2001/rddl/rddl-xhtml.dtd'"
            + " xmlns:NS1='http://xmlresolver.org/ns/catalog'"
            + " NS1:time='1170267571097'/>";

    ByteArrayInputStream bais = new ByteArrayInputStream(docStr.getBytes());

    Document doc = builder.parse(bais);

    Element root = doc.getDocumentElement();

    String systemId = root.getAttribute("systemId");

    // Change the prefix on the "time" attribute so that the list would
    // become unsorted
    // before my fix to
    // xml-xerces/java/src/com/sun/org/apache/xerces/internal/dom/ElementImpl.java
    root.setAttributeNS("http://xmlresolver.org/ns/catalog", "xc:time", "100");

    String systemId2 = root.getAttribute("systemId");

    Assert.assertEquals(systemId, systemId2);
  }
Exemplo n.º 15
0
 private void declareNamespace(Element e, String prefix, String uri) {
   if (prefix.length() > 0) {
     e.setAttributeNS(XML_NAMESPACES_NAMESPACE_URI, "xmlns:" + prefix, uri);
   } else {
     e.setAttribute("xmlns", uri);
   }
 }
Exemplo n.º 16
0
  /**
   * Constructor SignedInfo
   *
   * @param doc <code>SignedInfo</code> is placed in this document
   * @param signatureMethodURI URI representation of the Digest and Signature algorithm
   * @param hMACOutputLength
   * @param canonicalizationMethodURI URI representation of the Canonicalization method
   * @throws XMLSecurityException
   */
  public SignedInfo(
      Document doc,
      String signatureMethodURI,
      int hMACOutputLength,
      String canonicalizationMethodURI)
      throws XMLSecurityException {
    super(doc);

    c14nMethod =
        XMLUtils.createElementInSignatureSpace(this.doc, Constants._TAG_CANONICALIZATIONMETHOD);

    c14nMethod.setAttributeNS(null, Constants._ATT_ALGORITHM, canonicalizationMethodURI);
    this.constructionElement.appendChild(c14nMethod);
    XMLUtils.addReturnToElement(this.constructionElement);

    if (hMACOutputLength > 0) {
      this.signatureAlgorithm =
          new SignatureAlgorithm(this.doc, signatureMethodURI, hMACOutputLength);
    } else {
      this.signatureAlgorithm = new SignatureAlgorithm(this.doc, signatureMethodURI);
    }

    signatureMethod = this.signatureAlgorithm.getElement();
    this.constructionElement.appendChild(signatureMethod);
    XMLUtils.addReturnToElement(this.constructionElement);
  }
  public Element createHeaderElements(Document egoDom, Element rootElement, String graphType) {
    Element key;

    // add schema namespace to the root element
    rootElement.setAttributeNS(
        "http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");

    // add reference to the kml schema
    rootElement.setAttribute(
        "xsi:schemaLocation",
        "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");

    // add some useful comments to the file
    rootElement.appendChild(
        egoDom.createComment("Graph generated on: " + DateUtils.getCurrentDateAndTime()));
    //		rootElement.appendChild(xmlDoc.createComment("Graph generated by: " +
    // rdf.getContextParam("systemName") + " Version: " + rdf.getContextParam("systemVersion") + "
    // Build: " + rdf.getContextParam("buildVersion")));

    // create key element for node
    for (int row = 0; row < nodeAttr.length; row++) {
      key = createKeyElement(egoDom, "node", nodeAttr[row][0], nodeAttr[row][1]);
      rootElement.appendChild(key);
    }

    // create key element for edge
    for (int row = 0; row < edgeAttr.length; row++) {
      key = createKeyElement(egoDom, "edge", edgeAttr[row][0], edgeAttr[row][1]);
      rootElement.appendChild(key);
    }

    return rootElement;
  }
Exemplo n.º 18
0
  /**
   * This method does the actual work of adding a newly created parameter edit and adding it to the
   * parameter edits set.
   */
  private static void addParmEditDirective(
      String targetID, String name, String value, IPerson person, Document plf, Element parmSet)
      throws PortalException {

    String ID = null;

    try {
      ID = getDLS().getNextStructDirectiveId(person);
    } catch (Exception e) {
      throw new PortalException(
          "Exception encountered while "
              + "generating new parameter edit node "
              + "Id for userId="
              + person.getID(),
          e);
    }
    Element parm = plf.createElement(Constants.ELM_PARM_EDIT);
    parm.setAttribute(Constants.ATT_TYPE, Constants.ELM_PARM_EDIT);
    parm.setAttribute(Constants.ATT_ID, ID);
    parm.setIdAttribute(Constants.ATT_ID, true);
    parm.setAttributeNS(Constants.NS_URI, Constants.ATT_TARGET, targetID);
    parm.setAttribute(Constants.ATT_NAME, name);
    parm.setAttribute(Constants.ATT_USER_VALUE, value);
    parmSet.appendChild(parm);
  }
Exemplo n.º 19
0
 private Node entry() {
   Element element = element(Namespace.ATOM.getUrl(), ENTRY);
   element.setAttributeNS(
       Namespace.XMLNS.getUrl(), Namespace.SNX.getNSPrefix(), Namespace.SNX.getUrl());
   Node root = rootNode(element);
   return root;
 }
Exemplo n.º 20
0
  /**
   * Returns a DOM node for the entire workspace. This includes the block workspace, any custom
   * factories, canvas view state and position, pages
   *
   * @return the DOM node for the entire workspace.
   */
  public Node getSaveNode() {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);

      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.newDocument();

      Element documentElement =
          document.createElementNS(Constants.XML_CODEBLOCKS_NS, "cb:CODEBLOCKS");
      // schema reference
      documentElement.setAttributeNS(
          XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
          "xsi:schemaLocation",
          Constants.XML_CODEBLOCKS_NS + " " + Constants.XML_CODEBLOCKS_SCHEMA_URI);

      Node workspaceNode = workspace.getSaveNode(document);
      if (workspaceNode != null) {
        documentElement.appendChild(workspaceNode);
      }

      document.appendChild(documentElement);
      validate(document);

      return document;
    } catch (ParserConfigurationException e) {
      throw new RuntimeException(e);
    }
  }
 /**
  * Crée l'élément DOM correspondant à l'affichage, si nécessaire en créant l'élément DOM parent.
  */
 private void creerNoeud(final MyCompoundEdit cedit) {
   if (attribut) {
     Element elparent = (Element) affParent.getNoeud();
     if (elparent == null) {
       affParent.creerNoeud(cedit);
       elparent = (Element) affParent.getNoeud();
     }
     final String nom = cfg.nomAttribut(refNoeud);
     final String espace = cfg.espaceAttribut(refNoeud);
     elparent.setAttributeNS(espace, nom, "");
     noeud = elparent.getAttributeNodeNS(espace, nom);
     cedit.addEdit(new FormUndoableEdit(FormUndoableEdit.TypeEdition.AJOUTER, this));
   } else {
     noeud = JaxeElement.nouvelElementDOM(doc, refNoeud);
     Element elparent = (Element) affParent.getNoeud();
     if (elparent == null) {
       affParent.creerNoeud(cedit);
       elparent = (Element) affParent.getNoeud();
       elparent.appendChild(noeud.getOwnerDocument().createTextNode("\n"));
     }
     final Element suivant = affParent.trouverSuivant(refNoeud);
     final Node textnode = noeud.getOwnerDocument().createTextNode("\n");
     if (suivant == null) {
       elparent.appendChild(noeud);
       elparent.appendChild(textnode);
     } else {
       elparent.insertBefore(noeud, suivant);
       elparent.insertBefore(textnode, suivant);
     }
     cedit.addEdit(new FormUndoableEdit(FormUndoableEdit.TypeEdition.AJOUTER, this));
   }
   affParent.lireEnfants();
   doc.textPane.miseAJourArbre();
 }
Exemplo n.º 22
0
    /** Turns a List<CubicCurve2D.Float> into a SVG Element representing a sketch of that spline. */
    Element splineToSketch(SVGDocument document, List<CubicCurve2D.Float> spline) {
      String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

      // <g> is an SVG group
      // TODO: add a random(ish) rotation to the group
      Element group = document.createElementNS(svgNS, "g");

      // For each curve in the path, draw along it using a "brush".  In
      // our case the brush is a simple circle, but this could be changed
      // to something more advanced.
      for (CubicCurve2D.Float curve : spline) {
        // TODO: magic number & step in loop guard
        for (double i = 0.0; i <= 1.0; i += 0.01) {
          Point2D result = evalParametric(curve, i);

          // Add random jitter at some random positive or negative
          // distance along the unit normal to the tangent of the
          // curve
          Point2D n = vectorUnitNormal(evalParametricTangent(curve, i));
          float dx = (float) ((Math.random() - 0.5) * n.getX());
          float dy = (float) ((Math.random() - 0.5) * n.getY());

          Element brush = document.createElementNS(svgNS, "circle");
          brush.setAttribute("cx", Double.toString(result.getX() + dx));
          brush.setAttribute("cy", Double.toString(result.getY() + dy));
          // TODO: magic number for circle radius
          brush.setAttribute("r", Double.toString(1.0));
          brush.setAttribute("fill", "green");
          brush.setAttributeNS(null, "z-index", Integer.toString(zOrder.CONTOUR.ordinal()));
          group.appendChild(brush);
        }
      }

      return group;
    }
Exemplo n.º 23
0
  static Element functionName(Document document, Node parent, String name, int nargs) {
    Element function = element(document, parent, new QName(OGC.NAMESPACE, "FunctionName"));
    function.setAttributeNS("", "nArgs", nargs + "");
    function.appendChild(document.createTextNode(name));

    return function;
  }
Exemplo n.º 24
0
  protected void cacheBufferedImage(
      Element imageElement, BufferedImage buf, SVGGeneratorContext generatorContext)
      throws SVGGraphics2DIOException {

    ByteArrayOutputStream os;

    if (generatorContext == null) throw new SVGGraphics2DRuntimeException(ERR_CONTEXT_NULL);

    try {
      os = new ByteArrayOutputStream();
      // encode the image in memory
      encodeImage(buf, os);
      os.flush();
      os.close();
    } catch (IOException e) {
      // should not happen since we do in-memory processing
      throw new SVGGraphics2DIOException(ERR_UNEXPECTED, e);
    }

    // ask the cacher for a reference
    String ref = imageCacher.lookup(os, buf.getWidth(), buf.getHeight(), generatorContext);

    // set the URL
    imageElement.setAttributeNS(XLINK_NAMESPACE_URI, XLINK_HREF_QNAME, getRefPrefix() + ref);
  }
 private Node getUsername(Document doc, Element header) {
   Element e = doc.createElement("username");
   e.appendChild(
       doc.createTextNode(
           ((Element) doc.getElementsByTagNameNS(COM_NS, "userName").item(0)).getTextContent()));
   e.setAttributeNS(XSI_NS, "xsi:type", "xsd:string");
   return e;
 }
Exemplo n.º 26
0
  /**
   * Receive notification of the beginning of an element.
   *
   * <p>The Parser will invoke this method at the beginning of every element in the XML document;
   * there will be a corresponding endElement() event for every startElement() event (even when the
   * element is empty). All of the element's content will be reported, in order, before the
   * corresponding endElement() event.
   *
   * <p>If the element name has a namespace prefix, the prefix will still be attached. Note that the
   * attribute list provided will contain only attributes with explicit values (specified or
   * defaulted): #IMPLIED attributes will be omitted.
   *
   * @param ns The namespace of the node
   * @param localName The local part of the qualified name
   * @param name The element name.
   * @param atts The attributes attached to the element, if any.
   * @see #endElement
   * @see org.xml.sax.Attributes
   */
  public void startElement(String ns, String localName, String name, Attributes atts)
      throws org.xml.sax.SAXException {

    Element elem;

    // Note that the namespace-aware call must be used to correctly
    // construct a Level 2 DOM, even for non-namespaced nodes.
    if ((null == ns) || (ns.length() == 0)) elem = m_doc.createElementNS(null, name);
    else elem = m_doc.createElementNS(ns, name);

    append(elem);

    try {
      int nAtts = atts.getLength();

      if (0 != nAtts) {
        for (int i = 0; i < nAtts; i++) {

          // System.out.println("type " + atts.getType(i) + " name " + atts.getLocalName(i) );
          // First handle a possible ID attribute
          if (atts.getType(i).equalsIgnoreCase("ID")) setIDAttribute(atts.getValue(i), elem);

          String attrNS = atts.getURI(i);

          String attrQName = atts.getQName(i);
          if ((attrQName.equals("xmlns") || attrQName.startsWith("xmlns:"))) {
            elem.setAttributeNS("http://www.w3.org/2000/xmlns/", attrQName, atts.getValue(i));
          } else {
            elem.setAttributeNS(atts.getURI(i), attrQName, atts.getValue(i));
          }
        }
      }

      // append(elem);

      m_elemStack.push(elem);

      m_currentNode = elem;

      // append(elem);
    } catch (java.lang.Exception de) {
      // de.printStackTrace();
      throw new org.xml.sax.SAXException(de);
    }
  }
Exemplo n.º 27
0
  public Document startTable(String format) {

    // patch format - FOP only supports table-layout=fixed
    format = "table-layout=fixed," + format;

    // <table>
    // <table-header>
    //  <table-row>
    //   <table-cell>
    //    <block>
    //    ...
    // </table-header>
    // <table-body>
    //  <table-row>
    //   <table-cell>
    //    <block>
    //    ...
    push("table", format);
    Element table = cursor;

    // mark as cvs if applicable - non fo namespace attributes won't be picked up by push() and
    // attributes()
    if ("true".equals(attribute("genj:csv", format))) {
      containsCSV = true;
      cursor.setAttributeNS(NS_GENJ, "genj:csv", "true");

      String prefix = attribute("genj:csvprefix", format);
      if (prefix != null) cursor.setAttributeNS(NS_GENJ, "genj:csvprefix", prefix);
    }

    // head/body & row
    if (format.indexOf("genj:header=true") >= 0) {
      push("table-header");
      push("table-row", "color=#ffffff,background-color=#c0c0c0,font-weight=bold");
    } else {
      push("table-body");
      push("table-row");
    }

    // cell and done
    push("table-cell", "border=" + table.getAttribute("border"));
    push("block");

    return this;
  }
Exemplo n.º 28
0
  /** {@inheritDoc} */
  protected void marshallAttributes(XMLObject samlObject, Element domElement)
      throws MarshallingException {
    NameIDPolicy policy = (NameIDPolicy) samlObject;

    if (policy.getFormat() != null) {
      domElement.setAttributeNS(null, NameIDPolicy.FORMAT_ATTRIB_NAME, policy.getFormat());
    }

    if (policy.getSPNameQualifier() != null) {
      domElement.setAttributeNS(
          null, NameIDPolicy.SP_NAME_QUALIFIER_ATTRIB_NAME, policy.getSPNameQualifier());
    }

    if (policy.getAllowCreateXSBoolean() != null) {
      domElement.setAttributeNS(
          null, NameIDPolicy.ALLOW_CREATE_ATTRIB_NAME, policy.getAllowCreateXSBoolean().toString());
    }
  }
Exemplo n.º 29
0
  static Element capabilities(Document document, Node parent) {
    Element capabilities = element(document, parent, OGC.Filter_Capabilities);
    capabilities.setAttributeNS("", "version", "1.0.0");

    scalarCapabilities(document, capabilities);
    spatialCapabilities(document, capabilities);
    idCapabilities(document, capabilities);

    return capabilities;
  }
Exemplo n.º 30
0
 /**
  * Determines the transformation needed to get the cached image to scale & position properly. Sets
  * x and y attributes on the element accordingly.
  */
 protected AffineTransform handleTransform(
     Element imageElement,
     double x,
     double y,
     double srcWidth,
     double srcHeight,
     double dstWidth,
     double dstHeight,
     SVGGeneratorContext generatorContext) {
   // In this the default case, <image> element, we just
   // set x, y, width and height attributes.
   // No additional transform is necessary.
   imageElement.setAttributeNS(null, SVG_X_ATTRIBUTE, generatorContext.doubleString(x));
   imageElement.setAttributeNS(null, SVG_Y_ATTRIBUTE, generatorContext.doubleString(y));
   imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, generatorContext.doubleString(dstWidth));
   imageElement.setAttributeNS(
       null, SVG_HEIGHT_ATTRIBUTE, generatorContext.doubleString(dstHeight));
   return null;
 }