Java 类javax.print.attribute.standard.DocumentName 实例源码

项目:javify    文件:IppRequest.java   
/**
 * Writes an attribute in TextSyntax into the stream.
 * <p>
 * By default attributes are qritten as TEXT_WITHOUT_LANGUAGE value-tag.
 * As some attributes in the JPS are TextSyntax attributes but actually
 * of NAME value-tag in IPP this method checks for these attributes and
 * writes them as NAME_WITHOUT_LANGUAGE value-tag into the stream.
 * </p>
 *
 * @param attribute the attribute
 * @param out the stream to write to
 * @throws IOException if thrown by the stream
 */
private void write(TextSyntax attribute) throws IOException
{
  // We only use *WithoutLanguage, correct according to spec.
  String name = ((Attribute) attribute).getName();

  if (attribute instanceof RequestingUserName
      || attribute instanceof JobName
      || attribute instanceof DocumentName
      || attribute instanceof JobOriginatingUserName)
    out.writeByte(IppValueTag.NAME_WITHOUT_LANGUAGE);
  else if (attribute instanceof DocumentFormat)
    out.writeByte(IppValueTag.MIME_MEDIA_TYPE);
  else
    out.writeByte(IppValueTag.TEXT_WITHOUT_LANGUAGE);

  out.writeShort(name.length());
  out.write(name.getBytes());
  out.writeShort(attribute.getValue().length());
  out.write(attribute.getValue().getBytes());
}
项目:jvm-stm    文件:IppRequest.java   
/**
 * Writes an attribute in TextSyntax into the stream.
 * <p>
 * By default attributes are qritten as TEXT_WITHOUT_LANGUAGE value-tag.
 * As some attributes in the JPS are TextSyntax attributes but actually
 * of NAME value-tag in IPP this method checks for these attributes and
 * writes them as NAME_WITHOUT_LANGUAGE value-tag into the stream.
 * </p>
 * 
 * @param attribute the attribute
 * @param out the stream to write to
 * @throws IOException if thrown by the stream
 */
private void write(TextSyntax attribute) throws IOException
{
  // We only use *WithoutLanguage, correct according to spec.
  String name = ((Attribute) attribute).getName();

  if (attribute instanceof RequestingUserName
      || attribute instanceof JobName
      || attribute instanceof DocumentName
      || attribute instanceof JobOriginatingUserName)
    out.writeByte(IppValueTag.NAME_WITHOUT_LANGUAGE);
  else if (attribute instanceof DocumentFormat)
    out.writeByte(IppValueTag.MIME_MEDIA_TYPE);
  else
    out.writeByte(IppValueTag.TEXT_WITHOUT_LANGUAGE);

  out.writeShort(name.length());
  out.write(name.getBytes());
  out.writeShort(attribute.getValue().length());
  out.write(attribute.getValue().getBytes());     
}
项目:cn1    文件:WinPrintJob.java   
private String getDocName(final Object doc,
                final AttributeSet... attrSets) {
    Attribute name = getAttribute(DocumentName.class, attrSets);

    if (name == null) {
        name = getAttribute(JobName.class, attrSets);
    }

    if ((name == null) && (doc instanceof Component)) {
        Component c = (Component) doc;

        while (c != null) {
            if (c instanceof Frame) {
                if (((Frame) c).getTitle().length() > 0) {
                    return ((Frame) c).getTitle();
                }
            }
            c = c.getParent();
        }
    }

    return name != null ? ((TextSyntax) name).getValue()
                    : WinPrintService.DEFAULT_JOB_NAME.getValue();
}
项目:cn1    文件:CUPSClient.java   
private Object[] getDefaultAttributeValueEx(Class category) {
    if (Destination.class.isAssignableFrom(category)) {
        return new Object[0];
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName(
                (String) AccessController
                        .doPrivileged(new PrivilegedAction() {
                            public Object run() {
                                return System.getProperty("user.name");
                            }
                        }), Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Java print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Java print document",
                Locale.US) };
    }
    return null;
}
项目:cn1    文件:CUPSClient.java   
private Object[] getSupportedAttributeValuesEx(Class category,
        DocFlavor flavor) {
    if (Destination.class.isAssignableFrom(category)) {
        String ms = flavor.getMediaSubtype();

        if (ms.equalsIgnoreCase("gif") || ms.equalsIgnoreCase("jpeg")
                || ms.equalsIgnoreCase("png")
                || ms.equalsIgnoreCase("postscript")
                || flavor.getClass() == DocFlavor.SERVICE_FORMATTED.class) {
            try {
                return new Object[] { new Destination(new URI(
                        "file:///foo/bar")) };
            } catch (URISyntaxException e) {
                // return empty array - values are not supported
                return new Object[0];
            }
        }
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName("I.A.Muser", Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Foo print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Foo document", Locale.US) };
    }
    return null;
}
项目:JamVM-PH    文件:IppRequest.java   
/**
 * Writes an attribute in TextSyntax into the stream.
 * <p>
 * By default attributes are qritten as TEXT_WITHOUT_LANGUAGE value-tag.
 * As some attributes in the JPS are TextSyntax attributes but actually
 * of NAME value-tag in IPP this method checks for these attributes and
 * writes them as NAME_WITHOUT_LANGUAGE value-tag into the stream.
 * </p>
 * 
 * @param attribute the attribute
 * @param out the stream to write to
 * @throws IOException if thrown by the stream
 */
private void write(TextSyntax attribute) throws IOException
{
  // We only use *WithoutLanguage, correct according to spec.
  String name = ((Attribute) attribute).getName();

  if (attribute instanceof RequestingUserName
      || attribute instanceof JobName
      || attribute instanceof DocumentName
      || attribute instanceof JobOriginatingUserName)
    out.writeByte(IppValueTag.NAME_WITHOUT_LANGUAGE);
  else if (attribute instanceof DocumentFormat)
    out.writeByte(IppValueTag.MIME_MEDIA_TYPE);
  else
    out.writeByte(IppValueTag.TEXT_WITHOUT_LANGUAGE);

  out.writeShort(name.length());
  out.write(name.getBytes());
  out.writeShort(attribute.getValue().length());
  out.write(attribute.getValue().getBytes());     
}
项目:classpath    文件:IppRequest.java   
/**
 * Writes an attribute in TextSyntax into the stream.
 * <p>
 * By default attributes are qritten as TEXT_WITHOUT_LANGUAGE value-tag.
 * As some attributes in the JPS are TextSyntax attributes but actually
 * of NAME value-tag in IPP this method checks for these attributes and
 * writes them as NAME_WITHOUT_LANGUAGE value-tag into the stream.
 * </p>
 *
 * @param attribute the attribute
 * @param out the stream to write to
 * @throws IOException if thrown by the stream
 */
private void write(TextSyntax attribute) throws IOException
{
  // We only use *WithoutLanguage, correct according to spec.
  String name = ((Attribute) attribute).getName();

  if (attribute instanceof RequestingUserName
      || attribute instanceof JobName
      || attribute instanceof DocumentName
      || attribute instanceof JobOriginatingUserName)
    out.writeByte(IppValueTag.NAME_WITHOUT_LANGUAGE);
  else if (attribute instanceof DocumentFormat)
    out.writeByte(IppValueTag.MIME_MEDIA_TYPE);
  else
    out.writeByte(IppValueTag.TEXT_WITHOUT_LANGUAGE);

  out.writeShort(name.length());
  out.write(name.getBytes());
  out.writeShort(attribute.getValue().length());
  out.write(attribute.getValue().getBytes());
}
项目:freeVM    文件:CUPSClient.java   
private Object[] getDefaultAttributeValueEx(Class category) {
    if (Destination.class.isAssignableFrom(category)) {
        return new Object[0];
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName(
                (String) AccessController
                        .doPrivileged(new PrivilegedAction() {
                            public Object run() {
                                return System.getProperty("user.name");
                            }
                        }), Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Java print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Java print document",
                Locale.US) };
    }
    return null;
}
项目:freeVM    文件:CUPSClient.java   
private Object[] getSupportedAttributeValuesEx(Class category,
        DocFlavor flavor) {
    if (Destination.class.isAssignableFrom(category)) {
        String ms = flavor.getMediaSubtype();

        if (ms.equalsIgnoreCase("gif") || ms.equalsIgnoreCase("jpeg")
                || ms.equalsIgnoreCase("png")
                || ms.equalsIgnoreCase("postscript")
                || flavor.getClass() == DocFlavor.SERVICE_FORMATTED.class) {
            try {
                return new Object[] { new Destination(new URI(
                        "file:///foo/bar")) };
            } catch (URISyntaxException e) {
                // return empty array - values are not supported
                return new Object[0];
            }
        }
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName("I.A.Muser", Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Foo print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Foo document", Locale.US) };
    }
    return null;
}
项目:freeVM    文件:WinPrintJob.java   
private String getDocName(final Object doc,
                final AttributeSet... attrSets) {
    Attribute name = getAttribute(DocumentName.class, attrSets);

    if (name == null) {
        name = getAttribute(JobName.class, attrSets);
    }

    if ((name == null) && (doc instanceof Component)) {
        Component c = (Component) doc;

        while (c != null) {
            if (c instanceof Frame) {
                if (((Frame) c).getTitle().length() > 0) {
                    return ((Frame) c).getTitle();
                }
            }
            c = c.getParent();
        }
    }

    return name != null ? ((TextSyntax) name).getValue()
                    : WinPrintService.DEFAULT_JOB_NAME.getValue();
}
项目:freeVM    文件:CUPSClient.java   
private Object[] getDefaultAttributeValueEx(Class category) {
    if (Destination.class.isAssignableFrom(category)) {
        return new Object[0];
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName(
                (String) AccessController
                        .doPrivileged(new PrivilegedAction() {
                            public Object run() {
                                return System.getProperty("user.name");
                            }
                        }), Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Java print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Java print document",
                Locale.US) };
    }
    return null;
}
项目:freeVM    文件:CUPSClient.java   
private Object[] getSupportedAttributeValuesEx(Class category,
        DocFlavor flavor) {
    if (Destination.class.isAssignableFrom(category)) {
        String ms = flavor.getMediaSubtype();

        if (ms.equalsIgnoreCase("gif") || ms.equalsIgnoreCase("jpeg")
                || ms.equalsIgnoreCase("png")
                || ms.equalsIgnoreCase("postscript")
                || flavor.getClass() == DocFlavor.SERVICE_FORMATTED.class) {
            try {
                return new Object[] { new Destination(new URI(
                        "file:///foo/bar")) };
            } catch (URISyntaxException e) {
                // return empty array - values are not supported
                return new Object[0];
            }
        }
    } else if (RequestingUserName.class.isAssignableFrom(category)) {
        return new Object[] { new RequestingUserName("I.A.Muser", Locale.US) };
    } else if (JobName.class.isAssignableFrom(category)) {
        return new Object[] { new JobName("Foo print job", Locale.US) };
    } else if (DocumentName.class.isAssignableFrom(category)) {
        return new Object[] { new DocumentName("Foo document", Locale.US) };
    }
    return null;
}
项目:cn1    文件:CUPSClient.java   
private void getSupportedAttributeCategoriesEx(ArrayList clazz) {
    if (!clazz.contains(Destination.class)) {
        clazz.add(Destination.class);
    }
    if (!clazz.contains(RequestingUserName.class)) {
        clazz.add(RequestingUserName.class);
    }
    if (!clazz.contains(JobName.class)) {
        clazz.add(JobName.class);
    }
    if (!clazz.contains(DocumentName.class)) {
        clazz.add(DocumentName.class);
    }
}
项目:freeVM    文件:CUPSClient.java   
private void getSupportedAttributeCategoriesEx(ArrayList clazz) {
    if (!clazz.contains(Destination.class)) {
        clazz.add(Destination.class);
    }
    if (!clazz.contains(RequestingUserName.class)) {
        clazz.add(RequestingUserName.class);
    }
    if (!clazz.contains(JobName.class)) {
        clazz.add(JobName.class);
    }
    if (!clazz.contains(DocumentName.class)) {
        clazz.add(DocumentName.class);
    }
}
项目:freeVM    文件:CUPSClient.java   
private void getSupportedAttributeCategoriesEx(ArrayList clazz) {
    if (!clazz.contains(Destination.class)) {
        clazz.add(Destination.class);
    }
    if (!clazz.contains(RequestingUserName.class)) {
        clazz.add(RequestingUserName.class);
    }
    if (!clazz.contains(JobName.class)) {
        clazz.add(JobName.class);
    }
    if (!clazz.contains(DocumentName.class)) {
        clazz.add(DocumentName.class);
    }
}
项目:cn1    文件:GetUnsupportedAttributesTest.java   
public void testIsAttributeValueSupported() throws Exception {
    System.out
            .println("============= START GetUnsupportedAttributesTest ================");

    PrintService[] services;
    DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
            DocFlavor.INPUT_STREAM.POSTSCRIPT,
            DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };

    services = PrintServiceLookup.lookupPrintServices(null, null);
    TestUtil.checkServices(services);
    if (services.length > 0) {
        for (int i = 0, ii = services.length; i < ii; i++) {
            System.out.println("----------- " + services[i].getName()
                    + "----------");

            URI uri = null;
            try {
                uri = new URI("file:///c:/no/such/dir/print.out");
                //uri = File.createTempFile("xxx", null).toURI();
            } catch (URISyntaxException e) {
                fail();
            }

            AttributeSet attrs = new HashAttributeSet();
            attrs.add(Finishings.EDGE_STITCH);
            attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
            attrs.add(new Destination(uri));
            attrs.add(new DocumentName("Doc X", Locale.US));
            attrs.add(new JobName("Job Y", Locale.US));
            attrs.add(new RequestingUserName("User Z", Locale.US));

            for (int j = 0; j < flavors.length; j++) {
                if (services[i].isDocFlavorSupported(flavors[j])) {
                    AttributeSet aset = services[i]
                            .getUnsupportedAttributes(flavors[j], attrs);
                    if (aset == null) {
                        fail("At least one attribute is unsupported");
                    }
                    if (aset != null) {
                        Attribute[] aarr = aset.toArray();
                        System.out
                                .println("Usupported attributes fo DocFlavor "
                                        + flavors[j]);
                        for (int k = 0, kk = aarr.length; k < kk; k++) {
                            System.out.println("\t" + aarr[k]);
                        }
                    }
                }
            }
        }
    }

    System.out
            .println("============= END GetUnsupportedAttributesTest ================");
}
项目:freeVM    文件:GetUnsupportedAttributesTest.java   
public void testIsAttributeValueSupported() throws Exception {
    System.out
            .println("============= START GetUnsupportedAttributesTest ================");

    PrintService[] services;
    DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
            DocFlavor.INPUT_STREAM.POSTSCRIPT,
            DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };

    services = PrintServiceLookup.lookupPrintServices(null, null);
    TestUtil.checkServices(services);
    if (services.length > 0) {
        for (int i = 0, ii = services.length; i < ii; i++) {
            System.out.println("----------- " + services[i].getName()
                    + "----------");

            URI uri = null;
            try {
                uri = new URI("file:///c:/no/such/dir/print.out");
                //uri = File.createTempFile("xxx", null).toURI();
            } catch (URISyntaxException e) {
                fail();
            }

            AttributeSet attrs = new HashAttributeSet();
            attrs.add(Finishings.EDGE_STITCH);
            attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
            attrs.add(new Destination(uri));
            attrs.add(new DocumentName("Doc X", Locale.US));
            attrs.add(new JobName("Job Y", Locale.US));
            attrs.add(new RequestingUserName("User Z", Locale.US));

            for (int j = 0; j < flavors.length; j++) {
                if (services[i].isDocFlavorSupported(flavors[j])) {
                    AttributeSet aset = services[i]
                            .getUnsupportedAttributes(flavors[j], attrs);
                    if (aset == null) {
                        fail("At least one attribute is unsupported");
                    }
                    if (aset != null) {
                        Attribute[] aarr = aset.toArray();
                        System.out
                                .println("Usupported attributes fo DocFlavor "
                                        + flavors[j]);
                        for (int k = 0, kk = aarr.length; k < kk; k++) {
                            System.out.println("\t" + aarr[k]);
                        }
                    }
                }
            }
        }
    }

    System.out
            .println("============= END GetUnsupportedAttributesTest ================");
}
项目:freeVM    文件:GetUnsupportedAttributesTest.java   
public void testIsAttributeValueSupported() throws Exception {
    System.out
            .println("============= START GetUnsupportedAttributesTest ================");

    PrintService[] services;
    DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
            DocFlavor.INPUT_STREAM.POSTSCRIPT,
            DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };

    services = PrintServiceLookup.lookupPrintServices(null, null);
    TestUtil.checkServices(services);
    if (services.length > 0) {
        for (int i = 0, ii = services.length; i < ii; i++) {
            System.out.println("----------- " + services[i].getName()
                    + "----------");

            URI uri = null;
            try {
                uri = new URI("file:///c:/no/such/dir/print.out");
                //uri = File.createTempFile("xxx", null).toURI();
            } catch (URISyntaxException e) {
                fail();
            }

            AttributeSet attrs = new HashAttributeSet();
            attrs.add(Finishings.EDGE_STITCH);
            attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
            attrs.add(new Destination(uri));
            attrs.add(new DocumentName("Doc X", Locale.US));
            attrs.add(new JobName("Job Y", Locale.US));
            attrs.add(new RequestingUserName("User Z", Locale.US));

            for (int j = 0; j < flavors.length; j++) {
                if (services[i].isDocFlavorSupported(flavors[j])) {
                    AttributeSet aset = services[i]
                            .getUnsupportedAttributes(flavors[j], attrs);
                    if (aset == null) {
                        fail("At least one attribute is unsupported");
                    }
                    if (aset != null) {
                        Attribute[] aarr = aset.toArray();
                        System.out
                                .println("Usupported attributes fo DocFlavor "
                                        + flavors[j]);
                        for (int k = 0, kk = aarr.length; k < kk; k++) {
                            System.out.println("\t" + aarr[k]);
                        }
                    }
                }
            }
        }
    }

    System.out
            .println("============= END GetUnsupportedAttributesTest ================");
}